Jump to content

Rag Doll Help (was BABYLON.Bone.prototype.setAbsolutePosition)


AndyBeaulieu
 Share

Recommended Posts

OK, so this is somewhat related to this previous thread which I was going to give up on, but my stubbornness brought me back to it :)

 

I am trying to get a rag doll working and here is a lame jsfiddle of where I am at:

 

http://jsfiddle.net/andybeaulieu/9Ffv5/42/

 

If you go there and click the button at the top, you will see that

 

  • the skeleton of the guy mesh is copied to a series of box meshes on the left.
     
  • physics is added to the "arm copies" using box imposters and joints
     
  • I am trying to apply the same position and rotation for the "arm copies" on the left to the equivalent skeleton bones on the right, thus creating a rag doll effect.

As you can see, I have the POSITION of the bones being copied ok, using a Translation. But I cannot get the Rotation to work, and the guy's arms are all bent wrong  :wacko:

 

Near the top of the code, at line 58, is where I need help I think - I have the starting Quaternion of the bone mesh, and the current Quaternion, and I want to apply the difference in those to the bone matrix. Because this causes some really bizzarre rotations and problems, I have the code to do that commented out. What am I missing here to do this rotation?

            // ********************            //                 // THIS IS WHERE I NEED HELP!            // Apply the difference in Rotation between the Start Mesh Rotation            // and the current Rotation to the bone            //            // ********************            // rotation TEST ONLY            if (boneMeshParent) {                var matrixRotationStart = new BABYLON.Matrix();                boneMesh.saveStartRotationQuaternion.toRotationMatrix(matrixRotationStart);                var matrixRotationCurrent = new BABYLON.Matrix();                boneMesh.rotationQuaternion.toRotationMatrix(matrixRotationCurrent);                // I must have this matrix multiply out of order? I dunno                //matrixRotationStart.invert();                //var matrixRotation = matrixRotationStart.multiply(matrixRotationCurrent);                //boneMatrix = boneMatrix.multiply(matrixRotation);            }
Link to comment
Share on other sites

Just to be a bit more clear on this - if you run the jsfiddle here - http://jsfiddle.net/andybeaulieu/9Ffv5/42/

 

You will see the issue I have, circled in red below - I need to rotate the bones in the arms equal to the rotation of the bone meshes to the left.  My thought is to use the difference in the rotation quaternions at the rest position and the current position, but that doesn't work. 

 

By the way, I think if I can get past this rotation issue, I can create a generic rag doll helper for Babylon, which would very cool - basically you could just pass in a mesh with a skeleton, and have a pretty good rag doll automatically generated from it.

 

 

ragdollweirdness.png

Link to comment
Share on other sites

This demo is nice for me! But I think you not align the z-axle (or y if when u think in babylon.js coordinates) with the parent element
Im not shure, but this problem I know from my first blender bone studies. Maybe this video will clear some questions. Its Blender, but the concept is the same

http://www.blenderguru.com/videos/introduction-to-rigging/

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.

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

Loading...
 Share

  • Recently Browsing   0 members

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