bone.getAbsolutePosition does not return correct position

Hello,

I am trying to get the bone position using bone.getAbsolutePosition(), but it does not seem to give me the correction position.

I think the problem is caused by line 18 where mesh.rotation.x = Math.PI * .25, but isn’t the function bone.getAbsolutePosition() supposed to return the bone position with all transformations?

Thanks.

Hi @KimiZhong

The documentation for bone.getAbsolutePosition() is probably misleading. I think the world space here means the coordinate space of the full skeleton (compare to the local space of a bone, it is a “world space”), it is not the world space of the entire scene.

Screen Shot 2022-03-19 at 10.09.13 AM

So if you applied a rotation to your mesh, you also need to apply the transformation to bone.getAbsolutePosition() to get the world position of your bone in the scene. See:

I added the rotation around x axis by doing this:

const matrix = BABYLON.Matrix.RotationYawPitchRoll(0, Math.PI * 0.25, 0);
boneLineOptions.points[1] = BABYLON.Vector3.TransformCoordinates(boneLineOptions.points[1], matrix);
1 Like

Thanks @slin. That makes a lot of sense.

BTW,

Not sure if it could be helpful for you. Do you know babylon.js inspector has a debugger for skeleton? You can turn it on by toggling the enable switch button.

yea, I’ve already turned on this great visualizing tool. :wink:

In the end, I am trying to find the direction of a bone from an imported animation, but I haven’t found a good way to do that yet.

You have to pass it the skeleton’s mesh:

2 Likes

https://doc.babylonjs.com/typedoc/classes/babylon.bone#getdirection

Bone.getDirection should work for that.

Blockquote You have to pass it the skeleton’s mesh:

That makes sense. Mesh already has the transformation matrix mesh.getWorldMatrix().

Thanks for all the help @slin :slight_smile:

Thanks @adam.

According to the document, bone.getDirection() returns the world direction of an axis in the bone space. Does that mean that I need to feed Vector3.Up() to it in my case?

That sounds right.