Dynamic / inertial bones constraint ?

I have and idea for a constraint. I started to work on it but I’m new at python and terrible at math.


Better to see this movie to understand what it will do:


The bone (or object) wouldn’t need a target, but in practice I don’t think the pyconstraint scripts allow to find out any other info about the object except its provided matrix. So I think the constrained object could target itself and so we would have access to the target_object data.

I can think on a bunch of ways of implementing this, but i’m really math-handicapped and nOOb with python.

I only have loose clues since I am reading thru the python API:
-There’s this evaluatePose(frame) method for objects, which I guess is opens a way to inquire about pose bones at diferent times.
-The idea is that bones with this constraint are inertial. When their parent/armature moves or rotates, the bone tries to stay behind, then accelerates, then disaccelerates, passes the point and accelerates back.
-tips and roots of involved bones can be used to calculate speeds and acceleration.

I don’t know if this can be implemented with no targets or targeting itself - but a second idea would be to have a second bone as target. The target bone is normal (stiff) and the constrained object is lagged.

Any ideas ?

The guts for this are already in Blender. What we need is a coder to link up the soft and rigid body physics systems directly to the armature system. Just to be clear, I am not that coder.

I made some progress of this using some pendulum math. The results are interesting, but I found a little problem here:

def doTarget(target_object, subtarget_bone, target_matrix, id_properties_of_constraint):
    print 'do target'
    if subtarget_bone:
        print subtarget_bone
    return target_matrix

(this code does nothing, just proves some error)
If the BONE to which the constraint is applied is part of the same ARMATURE the target bone is, then evaluatePose(frame) produces an infinite doTarget loop, resulting in a ‘Memory Error’ in the console.

For now, I am testing with a second Armature.001, which is a complete copy but uses the same pose ipos. I managed to get a bone act as a ‘bunny ear’, oscillating after a lagged target acceleration using evaluatePose. But this inability to evalluate other bone within the same armature over time is frustrating.

still have not enough knowledge of blender to try this, but that’s something I really want to try. Keep us posted on your progress !


I wrote a crude code. I feel in diapers coding in python so I prefer to explain what it does with an image:


Basically, doTarget calculates the target bone’s acceleration over the last N frames, and its current velocity. The best option is to use the parent bone as target and calculate motion of its TAIL, which is a vector independent of constraints or Ipo curves - it’s just a final position, so it makes things easier

then doConstraint bends the bone in an opposite direction of the acceleration vector, when in motion. When [the target, parent…] is stopped, the bone oscillates a little until it completely stops. The math is very simple, but the code is a piece of horror right now. I need to clean up in order to show it.

The problem with this is that it will not work in a confortable way, because: as I said before, if the targetbone is in the same armature object than the constrained bone, the evaluatePose method will create a infinite doTarget loop and a memory error, and the constraint won’t work.

That’s why in this example, the target bone is the bone’s parent in ANOTHER armature (see image) object. But the armature datablock and the action is the same.

I am not sure I will get help in this forum. Perhaps I should report this as a bug. I wonder if this is fixable.

The other way is using softbodies and parenting bones to vertices, but it’s a lot of a mess for a simple effect IMO.

hi, look this http://www.youtube.com/watch?v=DR2tK7tYl2g. (sorry i lost the code)

this code is based in a PID controller. Info here -> http://en.wikipedia.org/wiki/PID_controller

loc = error # target location - contrained bone location

Proportional = K.loc
Integrator = loc[curframe-1] + loc[curframe-2] … + loc[curframe-n] (n size of buffer)
Differential = loc[curframe] - loc[curframe-1]

final loc = P + I + D

for this, i make some hacks, like “Blender.acumulators” than breaks compatibility with pycontraints and animation system.

I recode all for new, and work fine. Only works translation

Here a .blend with pyconstraint. http://cesio.arg.googlepages.com/secondary.blend

I saw Continue Physics in pyconstaint and works well!!

hey cesio, that’s cool… and doesn’t mess with evaluatePose. I’ll take a look, thank you!

yea, you dont need evaluatePose.
but need cache vectors for calcule errors.

my script isnt phisicaly correct, i think if you use pendulum math got better results.

I think that a GHOST armature object could be created, not linked to the scene, only once.
How do I code this?
-> Query if an object named ‘myarmature_ghost’ exists
-> Else create ‘myarmature_ghost’

Here’s a demo of using softbodies with armatures that’s very similar to the example you provided. Maybe you can somehow automate this setup with python?

MOV video file

.blend file for video demo

wiki link for the basic setup

Hope that helps.

Thanks, Kernod. Yes, I’d seen that method before. I was trying to avoid the mess of using real physics for such a simple effect but, now I have a python mess anyway :slight_smile: