Inverse Kinematics


#41

Fixed an issue where nodes with multiple children did not calculate rotations correctly.

My TODO list is getting very small. It’s mostly gruntwork from here on out. I’ll be writing the script bindings now and submit my first pull request. I can work on constraints for future versions.

 * TODO
 *  - Add support for manually updating initial pose.
 *  - Script bindings.
 *  - Optimise.
 *  - Profile.
 *  - Documentation.
 *
 * FUTURE
 *  - Support for "stretchiness" with min/max lengths.
 *  - Support for "stiffness" factor, describes how well a bone rotates.
 *  - Apply bullet constraints to joints.

#42

I’ve just tested and it works great :grinning:

For target nodes, I think it would be better to use node ID instead of node name in the Editor, to match every other components (Constraint, Constraint2D, OffmeshConnection…) behavior (and to allow simply dragging the node in the target slot).

I’ll do some more tests, and report feedback. Let me know if I can help in any way :wink:


#43

You should setup a patreon so we can all donate for your amazing work. :slight_smile:


#44

I’m happy to report the first version has been merged into master! All features you’ve seen in this thread are now available.

https://github.com/urho3d/Urho3D/pull/1871

If you have questions, feature suggestions, or bug reports, I look forward to hearing from you. I will be actively maintaining this.

There is a new sample, 45_InverseKinematics, that you can look at. Here’s what it looks like:

The next thing I will be working on is @1vanK’s suggestion to add constraint support.


#45

Congrats! The IK samples in C++, AngelScript, and Lua are also available in Web platform now. https://urho3d.github.io/samples/


#46

The papers I’ve found on FABRIK aren’t very clear on how constraints should be implemented. Sometimes they’re even cryptic. Nevertheless, I think I’ve been making some progress.

My first attempt at implementing constraints failed. I first thought you could apply constraints to the entire tree every iteration, but as you can see, the algorithm no longer converges. (Here, I’m trying to force one of those joints to always be straight no matter what, but it seems he’d rather remain gay).

I’m now working on my second attempt where constraints are applied per node as the tree is being iterated. The math is cumbersome as it involves computing joint rotations and transforming to and from local space.

It looks like this could work. I think I have to apply constraints during forwards iteration as well as during backwards iteration (right now it’s only during backwards iteration). Calculating local joint angles is going to be a lot harder in forward iteration, I’m not yet sure how to tackle this.

The nature of the FABRIK algorithm makes constraint support inherently inefficient, because FABRIK has no need for joint angles and works entirely in global space. Joint constraints require joint angles in local space. There is an unfortunate performance penalty, which is fairly evident by just looking at the code.


#47

Well, IK constraints were always different from normal contraints (look at how Blender handles IK).
I think you should make universal constraint matrix out of all constraints and apply just that.
That will be a bit more efficient in loop. The other approach is to not require constraints to be justified at all times,
just get to the point iteratively. Just my $.00002 :slight_smile:


#48

I don’t think one giant constraint matrix is suitable in this situation. The constraints are being applied during iteration, meaning the tree is in a partial state of being solved. But if you want we can discuss it in more detail and I can explain the algorithm more closely to you.

I tried applying all constraints at once after iterating the tree every time, but it caused the algorithm to diverge.


#49

Well, I don’t want to disturb you, I’m just passing by. I just remember all these IK lectures telling that you either
solve constraint analytically (all at once) or use Jacobian matrix and solve numerically (iteratively solving
differential equation system).
But what I wanted to say is that constraints for IK in Blender are different from other constraints
and they work independently of constraint system. I think this is way to go. Also I think you’d want only
angular constraints at first.

Also, is it possible to use sparse chains in your IK system, i.e. I want the system to know about a set of bones,
but not touch others. I.E.
an arm consists of bones AB-CD-E (fingers omitted). I want A and C to be moved by IK, others should
just rotate together with parents not touched by constraint. Will it work?


#50

There are some good resources here (which you may already checked):
http://wiki.roblox.com/index.php?title=Inverse_kinematics
https://github.com/FedUni/caliko and https://github.com/lo-th/fullik (with a demo here)
However I didn’t succeed in implementing them.


#51

Is there an example on how to do aim offsets? Not only a look at constraint, but something like this:


#53

Seems simple enough. He’s created a number of predefined poses for the different angles the gun could be at and then he’s blending between those poses when crossing a threshold (first part of the video).

Since you know the target direction, you can slide the gun around on an imaginary sphere depending on the direction, calculate the hand positions and rotations, and use IK to move the hands there.

I’m still working on constraints whenever I have free time, but this should be possible without them.


#54

Sorry if i’m being too much of a newbie, but do you have a link with an example of pose blending in Urho? I’ve been trying to use pose blending to improve several animation in my game, heavily inspired by this, but i can’t get my head around it.


#55

@smellymumbler have you looked at IK demo with current Urho? it shows sort of IK + animation blending.

If you want to blend between animations, look at AnimationController and use layers. For more complicated cases use AnimationState (s). It is very sad there’s no really goood example on these, but if you look at Character demo,
you might understand part of it then go back and ask more specific questions.


#56

I did. But, at least in my head, the animation blending idea does not really work for what i’m aiming for. You have two different layers and you have a blending amount between the two. This is nice: you can make a running animation turn into a walking animation, smoothly, based on user input.

However, what i’m aiming for is a little different: i have two poses: a standing one and another one in full run. My animation clip is the result of an interpolation between those two poses + input from the user. Are those two different layers? Can i blend them normally?


#57

You can blend on the same layer too. You will always use a combination of blending on the same layer and additional layers. I know the system explodes the brain, but I was enlightened after looking some GDC presentation on youtube
about layered animation, I dn’t remember title. The idea is that you need to transit from one animation to another on
the same layer, so just play new pose animation on the same layer at appropriate time and it will blend into it.
Probably not best thing performance-wise, but it should work.


#58

And also, if you really understand presentation you use for inspiration, please share, I was not able to understand their way.


#59

Blending there is just done on arbitrary response curves between frames. (Desmos graphs for a few MKCB curves: https://www.desmos.com/calculator/bg75j7xv5c)

The “survey wheel” is just circumference vs. distance. Given a distance traveled the degrees turned can be found given the circumference (or diameter/radius -> circ) which drives animation timing.

The “ticks” in the wheel are a bit of a red-herring that looks more important than it is, they’re just visual helpers for where the timings are, the circumference is the important part. The stroke cycles of each leg are overlayed on top of each other into a final gait cycle in the wheel. (Girard, Computational Modeling for the Computer Animation of Legged Figures goes into the nitty gritty as far as actually simulating but most of the math is still valid for finding cycle timings from existing animation).


#60

Well, i was trying to achieve this differently by timing lowest leg position and change animation speed to
minimize sliding. The problem is that I failed somewhere and could not achieve the goal this way.
I don’t want root motion animation, it is too unflexible… Procedural walk loop looks so promising but I was not able to
get 60fps as it was too many calculations per frame…


#61

If your goal is to recreate what the Wolfire people achieved with Overgrowth: Let Urho3D do the heavy lifting for you. You don’t have to implement blending between keyframes, let Urho3D’s animation do that.

  1. Create a walking animation
  2. Create a running animation with the same length as the walking animation (important! If they’re the same length you can easily synchronise them)

Now you can control the speed of both animations depending on stride (the “conveyor wheel” approach) and you can blend between both animations (using layers) depending on the player’s velocity.

Overgrowth isn’t using IK to prevent foot sliding; they still have that problem, it’s just well corrected. They do use IK to align the foot vertically so it’s always touching the ground.