Jump to content


Samuel Girardin

Recommended Posts



I add for some tests  BABYLON.Bone.prototype.getAbsolutePosition , this was easy returning m12,m13,m14 of the bone's _worldTransform matrix. Now,  I try to add setAbsolutePosition method to bone, and I failed. Certainly due to my bad matrix knowledge, I tried to get some inspiration from Gwenael push about Mesh..setAbsolutePosition. With no succes. 


If someone got an idea to achieve that (Gwenael ?!) , it would be super cool !



Link to comment
Share on other sites

Hi gwenael ! 


So about skeleton and bones : I really want to be able to move one bone, or a group of bones to an absolute position. I  understand the recursivity of Bone.prototype.getAbsoluteMatrix. I thought if I did something like the inverse of this method, By first translate the root bone and apply this transformations to all other bones, I would be able get THE bone MATRIX I want for moving my bone to his expected place. I failed, I try during several days.

If you want to have a look here is a link : http://www.visualiser.fr/Babylon/Skin/Default.htm


Here is some screen capture with explanations... I would like to be able a bone or or group of bone where I want. I understand, when the skeleton is animated, I have to apply thoses transformations after the skeleton is updated. If you have one solution or some new ways I didn't explored... Thks. Sam.




Link to comment
Share on other sites

Bones have a function called updateMatrix which update the associated matrix.


The final matrix (absolutematrix) transmitted to shaders is built using this matrix and the bone's parent absolutematrix:

BABYLON.Bone.prototype.getAbsoluteMatrix = function () {

        var matrix = this._matrix.clone();
        var parent = this._parent;
        while (parent) {
            matrix = matrix.multiply(parent.getLocalMatrix());
            parent = parent.getParent();
        return matrix;
Link to comment
Share on other sites

Here is a very small test project to show what I am trying to do...




The project has (1) a mesh with skeleton, and (2) a box that is nearby and slightly rotated, like so:





What I am trying to have happen is that the "head" bone gets positioned and rotated in the same world space as the box, like so:




I have a stub started, but nothing else because everything I have tried has failed :(


So if anyone can help with a function implementation like that below, which would accept a bone and a mesh, and then move that bone to the mesh and rotate, many thanks in advance!

    THEGAME.Engine.prototype.moveBoneToMesh = function (bone, mesh) {               // ********************        // need some help here...        // this function should set "bone" position and orientation to         // be equal to "mesh"        // ********************        var matrix = mesh.getWorldMatrix().clone();                     // also, calling updateMatrix here seems to do nothing, regardless        // of what matrix value is sent in?        bone.updateMatrix(matrix);          }
Link to comment
Share on other sites

Hey Andy  (it starts like a french song !)


I think we try to achieve the same thing. I work on other stuff for now... Perhaps I don't understand your problem, but it seems you don t manage to see any mesh displacement or transformation.


In my case I manage to displace  (the hand of my 3D mesh). Not at the right place ... For that, if  I don't call something like  : 

this.scene.beginAnimation(this.meshSkeleton , 0,1,true, 1); 

I can't have the transformation when I use 


I'm almost sure calling the skeleton animation just from one frame tell to the engine to update all the skeleton. Without that I can't see any tranformation(there must be an other way to update the skeleton)

My problem is to compute the right matrix ...  Perhaps this can help. I'm a bit lost on this..




Link to comment
Share on other sites

Andy, could you try that ?


I'm not sure to have -the- solution, but it sounds good.. I use dude.babylon if you want to test my code.


Edit : Transformation are relative to the box position.

// the dummy box with 2 rotations tricks to well orient the headthis.dummyHelper.rotation.y =- Math.PI / 2;this.dummyHelper.rotation.z = Math.PI / 2;var matrix:BABYLON.Matrix = this.dummyHelper.getWorldMatrix().clone();    matrix.invert();// in this case index=7 is the bone head root , if you want to try with the hand the index = 34this.meshSkeleton.bones[7].updateMatrix(this.meshSkeleton.bones[7].getAbsoluteMatrix().clone().multiply(matrix));


Link to comment
Share on other sites

Thanks for trying and sharing!


Unfortunately it is not working with my mesh. If I send in the topmost parent bone ("hip"), then it works, but any other child I try does a bad scale, rotate and transform on the mesh.


Maybe it is something specific with my mesh - I haven't tried it with "dude" yet.


I'll keep playing with it - it must be a hierarchical issue - if I start with the hip bone and then work through the children, maybe it can be fixed.

Link to comment
Share on other sites

Just pinging this one again, does anyone have any further ideas on this? 


Basically, I need to set world position and rotation of a bone inside a skeleton to have the same rotation and position as a mesh in the world. I am not understanding the bone's matrix and parent relationship enough to pull this off.


More details here -



Link to comment
Share on other sites

Do you mean the inverse of the parent's absoluteMatrix?


Something like the following? Although this doesn't seem to quite work...

THEGAME.Engine.prototype.moveBoneToMesh = function (bone, mesh) {        var meshMatrix = mesh.getWorldMatrix().clone();        meshMatrix.invert();        var boneMatrix = bone.getAbsoluteMatrix().clone();        boneMatrix = boneMatrix.multiply(meshMatrix);        if (bone._parent) {            var parentMatrix = bone._parent.getAbsoluteMatrix().clone();            parentMatrix.invert();            boneMatrix = boneMatrix.multiply(parentMatrix);        }        bone.updateMatrix(boneMatrix);        that._scene.beginAnimation(bone._skeleton, 0, 1, true, 1);    }
Link to comment
Share on other sites

Okay, here is a jsfiddle - 




If you go there and:


  • click the "Copy Bones" button. This creates a series of box meshes that mirror the skeleton of the guy in the scene.
  • click the "Move to Bones" button. What _should_ happen is that the bones in the skeleton move over to their respective meshes in the "copy" of the skeleton to the left. So they should translate, rotate (no need to scale) to the box meshes in the skeleton to the left.
  • looking at my code, the problem function is right at the top - moveSkeletonToBones. In there, I want to iterate through each bone in the skeleton, and orient it (translate and rotate) to its respective "copy" of the bone to the left.

Thanks for any ideas. I think this would be a powerful function for rag dolls and programmatic animation of the skeleton!

Link to comment
Share on other sites

heh, that would be easy wouldn't it :)


But my what my ultimate goal here is to create a ragdoll. So, the box meshes to the left will eventually have physics added to them and joints created between them.


Then, by matching the position and rotation of the box meshes to the bones in the skeleton, I should have a ragdoll... That's the idea anyway :D I am open to other suggestions though.

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...