Samuel Girardin Posted February 11, 2014 Share Posted February 11, 2014 Hi, 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 ! Sam. Quote Link to comment Share on other sites More sharing options...
Samuel Girardin Posted February 11, 2014 Author Share Posted February 11, 2014 ... Quote Link to comment Share on other sites More sharing options...
Samuel Girardin Posted February 12, 2014 Author Share Posted February 12, 2014 ... Quote Link to comment Share on other sites More sharing options...
gwenael Posted February 18, 2014 Share Posted February 18, 2014 Hi Samuel, Really sorry but I have been so busy recently by a project at work that I haven't spent time on this forum. I haven't played so far with bones in BabylonJS but I might be able to look at it. Could you share what you have done so far? Quote Link to comment Share on other sites More sharing options...
Samuel Girardin Posted February 18, 2014 Author Share Posted February 18, 2014 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. Quote Link to comment Share on other sites More sharing options...
AndyBeaulieu Posted February 20, 2014 Share Posted February 20, 2014 I am trying to do the something very similar... Given the position and rotation of a mesh in the world, I want to position a bone in the same position and orientation. Does anyone have any ideas on this? Thanks! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 21, 2014 Share Posted February 21, 2014 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; }; Quote Link to comment Share on other sites More sharing options...
AndyBeaulieu Posted February 22, 2014 Share Posted February 22, 2014 Thanks!! I'm still not getting it though. It seems like no matter what I send to bone.updateMatrix(), the deformation does not update on the mesh. It's like my changes are lost in the call to _updateDifferenceMatrix(), but I don't see how. I will try to make a demo of the issue, but any thoughts are welcome! Quote Link to comment Share on other sites More sharing options...
AndyBeaulieu Posted February 22, 2014 Share Posted February 22, 2014 Here is a very small test project to show what I am trying to do... http://www.andybeaulieu.com/downloads/BoneSetAbsolutePosition_022214.zip 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); } Quote Link to comment Share on other sites More sharing options...
Samuel Girardin Posted February 23, 2014 Author Share Posted February 23, 2014 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 this.meshSkeleton.bones[index].updateMatrix(matrix)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.. Sam Quote Link to comment Share on other sites More sharing options...
AndyBeaulieu Posted February 23, 2014 Share Posted February 23, 2014 Hi Samuel, Adding in a call to beginAnimation _did_ succeed in applying the deformation to my mesh, thanks! But I have the same outstanding issue as yourself now - I am not sure how to compute the correct matrix either. Quote Link to comment Share on other sites More sharing options...
Samuel Girardin Posted February 24, 2014 Author Share Posted February 24, 2014 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)); Quote Link to comment Share on other sites More sharing options...
AndyBeaulieu Posted February 25, 2014 Share Posted February 25, 2014 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. Quote Link to comment Share on other sites More sharing options...
AndyBeaulieu Posted February 28, 2014 Share Posted February 28, 2014 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 - http://www.html5gamedevs.com/topic/3736-babylonboneprototypesetabsoluteposition/?p=25777 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 28, 2014 Share Posted February 28, 2014 Starting from :this.meshSkeleton.bones[7].getAbsoluteMatrix().clone().multiply(matrix) I think it is just a matter of getting the inverse of the absoluteMatrix to block parent hierarchy Quote Link to comment Share on other sites More sharing options...
AndyBeaulieu Posted February 28, 2014 Share Posted February 28, 2014 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); } Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 3, 2014 Share Posted March 3, 2014 Could you prepare me a small sample somewhere ? (jsfiddle is great) I promise to find what you need Quote Link to comment Share on other sites More sharing options...
AndyBeaulieu Posted March 4, 2014 Share Posted March 4, 2014 Okay, here is a jsfiddle - http://jsfiddle.net/andybeaulieu/9Ffv5/37/ 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! Quote Link to comment Share on other sites More sharing options...
AndyBeaulieu Posted March 11, 2014 Share Posted March 11, 2014 *bump* ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 11, 2014 Share Posted March 11, 2014 I'm on it Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 11, 2014 Share Posted March 11, 2014 I have a question: why are you not just moving the dude where the bones are ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 11, 2014 Share Posted March 11, 2014 Like this:http://jsfiddle.net/9Ffv5/40/ Quote Link to comment Share on other sites More sharing options...
AndyBeaulieu Posted March 12, 2014 Share Posted March 12, 2014 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 I am open to other suggestions though. Quote Link to comment Share on other sites More sharing options...
Samuel Girardin Posted March 12, 2014 Author Share Posted March 12, 2014 Hey Andy, Just for illustrated, I think you want to achieve something like that (stage3D demo (rip)). Shoot the ragoll. I'm right ? Quote Link to comment Share on other sites More sharing options...
AndyBeaulieu Posted March 12, 2014 Share Posted March 12, 2014 Yes Samuel - exactly! Nice demo by the way Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.