- Home /
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
Answer by whydoidoit · Mar 27, 2013 at 09:27 AM
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;
Got me pointed in the right direction! From your snippet I managed to get the bones to clump together in a reasonable pattern, but it's clear (now, to me) that the bindpose relies on the parent bone and not just the mesh itself.
It seems like I need to reset the bind poses of each bone in order to reconstruct the original bone structure.
So, uh. Can I set a transform's data from the bindpose matrix with a function? I'd hardly trust me to write that, I am horrendous with mathematics.
Resetting localPosition and localRotation of each bone using bindpose somehow should snap the skeleton to its default pose, then I can just store the bone relationships and restore the pose it WAS in.
Argh, it might be better to write a helper component to just store this stuff on Start... it's late, I'll wonder more when I wake up.
I am an utter failure at applied math, so I made a purely logical solution ins$$anonymous$$d :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.
Your answer
