Jump to content

Position relative to bone joint (bone local space)


Recommended Posts

Hi guys,

after beating my head against this for a while, I came to the conclusion that I need a break and possibly some support.
I want to calculate the position of theObject mesh in the local space of theBone which is attached to theMesh.

The code I write for it is:

// combine the bone World Matrix with the transform of the mesh
var boneInverse = theBone.getWorldMatrix().multiply(theMesh.getWorldMatrix());

// calculate object position relative to the bone joint
console.log('object world position: '+objectMesh.position);
var relPos = BABYLON.Vector3.TransformCoordinates(objectMesh.position, boneInverse);
console.log('object rel position: '+relPos);

But the problem is I keep getting weird results...
I tried switching theBone.getWorldMatrix() with theBone.getAbsoluteMatrix() with no luck.
It is still unclear the difference between the two me and I could not find anything in the doc.


Link to comment
Share on other sites

Thank you very much for the reply: this is exactly what I ended up coding, a skeleton visualizer and a bone matrix updater.
Turned out, my calculations were correct the problem I experienced instead was related to how I override bone matrixes while an animation is playing: basically when calculating how to dynamically adjust the rotation of a bone, I was using theBone.getWorldMatrix() but the resulting matrix was not up-to-date.
So my bone adjustment looked wrong, while it was just the matrix that was out-dated: so a small function such as this one https://github.com/BabylonJS/Babylon.js/blob/master/src/Debug/babylon.skeletonViewer.ts#L119 solved!

Now I'm experiencing a new issue though: I have an additional mesh attached to a bone of the skeleton for which I override the matrix of the animation: while the main mesh animates using my adjusted values, the attached mesh plays the original animation, without my overrides. I'm running 2.3.0: any clue?

I will try to update to 2.4.0 preview, just to see if it changes.
Thanks so far!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...