I need a point midway between two bones' rest positions

I can’t get matrices to work in my head. There should be a simple multiplication to get this, but my feeble attempts result in seemingly random placement of the ‘midpoint’.

I have an animated character (its bones are not in their rest position), and I need to get a point ‘along a bone’ - specifically, the point is directly on the line between two bone transforms.

Getting that point in the animation space or world space is easy, but I need to get it in the armature’s ‘rest space’, working back from the animation space somehow. SkinnedMeshRenderer.bindposes seems to be related, but I’m at a loss. Any math gurus able to expand on this?

bones : List.<Transform> = new List.<Transform>( smr.bones ); // copy bones into a list for IndexOf

// find point between bone #index and #index2:
var ray : Ray;
ray.origin = bones[index].position;
ray.direction = bones[index2].position-ray.origin;

centerInWorldSpace = ray.origin + ray.direction * desiredLength; // works!

ray.origin = smr.bindposes[index] * bones[index].position; // doesn't land on the bone line
// or is that right, and the complex logic i haven't copied here is getting the wrong index? i don't even know where to look.

centerInAnimationSpace = ray.origin + ray.direction * desiredlength; // would work if the ray was built correctly

1 Answer

1

Well the bindpose converts the position of the bone relative to the parent (root) of the mesh in local coordinates. So don’t you need to do:

ray.origin = (smr.bindposes[index] * (bones[index].position - meshHolder.position))+meshHolder.position;

Sorry - think I'm being thick their - now I think it's actually the parent it's offseting from so it would be: ray.origin = (smr.bindposes[index] * (bones[index].localPosition))+meshHolder.position;

I am an utter failure at applied math, so I made a purely logical solution instead :S Now I've just got a helper component sitting on objects that might want this functionality - it has to be set up in edit mode, but as it turns out, I want to exclude helper bones anyway so it's kind of a good thing. Answer marked as accepted because someone who knows what mathwords mean can certainly make it work from there.