piermonn Posted June 16, 2015 Share Posted June 16, 2015 Hi everyone! I am struggling with the BabylonJS transformations model and I ask for help about it. I need to create a program where the user chooses transformations one after another (that is to say I can have to perform a rotation, then a translation, than a scaling...). However, it seems I can't have the correct result based on the specific order given by the user and I think it is because BabylonJS executes translation then rotation then scaling (I compare results with a JavaFX program which allows me to add transformations in any order). Is there anyway I can bypass the BabylonJS order? Thanks in advance for your answers.Pierre Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 16, 2015 Share Posted June 16, 2015 Hi Piermonn, welcome to the forum, good to have you with us. I'm Wingnut, expert wannabe, blowhard yapper, topic railroader, and generally the guy who everyone wants to see get run over by a beer truck. How ya doon? I hope well. [snip - massive text removed because Wingnut misunderstood the issue] IF, by chance, you are speaking-of NON-imported mesh, then you can set .position, .rotation, and .scaling in any order you wish. Each setting requires one line of code, so you can arrange the order of the code lines in any order, of course. Our Playground Demo #3 shows all sorts of position, rotation, and scaling... in all sorts of orders. Play around in there, do experiments, hit RUN over and over, grab a zip for playing at home. I hope I didn't misunderstand your issue. Tell us a bit more, if you please. Imported mesh? Locally-produced mesh? And again, welcome! Party on! Quote Link to comment Share on other sites More sharing options...
piermonn Posted June 16, 2015 Author Share Posted June 16, 2015 Hi Wingnut! Thank you for your answer. I'm using locally produced meshes, such as Box and Sphere. To explain better what I mean, I will show you an example. With the following transformations (in this precise order): - translation(-2.4, 0.2, -1)- rotation(Axis(0.0, 1.0, -1.0), -0.9)- rotation(Axis(0.0, 1.0, -1.0), -0.8)- scale(1, 2, 1)- rotation(Axis(0.0, 1.0, -1.0), 0.8) I have this result with BabylonJS (using translate and rotate method, and object.scaling.x/y/z for scaling): Whereas I have this result with the same program in JavaFX: I believe this is because BabylonJS executes the transformations in a particular order whereas JavaFX multiplies the matrices in the order they come. But I may mistaken and prefer asking to understand what is the reason of it Thanks! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted June 16, 2015 Share Posted June 16, 2015 About the order things are done, I think everything is in the computeWorldMatrix() method : https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Mesh/babylon.abstractMesh.ts#L416 So, I guess the right order is : - scaling- rotation : Y, X then Z (I'm sure of this one !)- translation (position settings) You can't change it. This matrix is passed to the vertex shader which computes thus world positions for each vertex.Unless maybe you code your own vertex shader ... Quote Link to comment Share on other sites More sharing options...
jerome Posted June 16, 2015 Share Posted June 16, 2015 rotations aren't accumulated unless you re-compute the mesh WorldMatrix each step : http://www.html5gamedevs.com/topic/14697-mis-understanding-rotations-and-translations-local-and-world/?p=83663 Quote Link to comment Share on other sites More sharing options...
piermonn Posted June 16, 2015 Author Share Posted June 16, 2015 OK, this explains the result difference then I will try to change the way the world matrix is calculated (a bit hacky but it seems I can't do better) to get my final result. Thanks anyway! Quote Link to comment Share on other sites More sharing options...
Temechon Posted June 17, 2015 Share Posted June 17, 2015 Why not do something like this ? translation(-2.4, 0.2, -1)computeWorldMatrix(true);- rotation(Axis(0.0, 1.0, -1.0), -0.9)computeWorldMatrix(true);- rotation(Axis(0.0, 1.0, -1.0), -0.8)computeWorldMatrix(true);- scale(1, 2, 1)computeWorldMatrix(true);- rotation(Axis(0.0, 1.0, -1.0), 0.8)computeWorldMatrix(true); Not very clean, but I think it should work. Quote Link to comment Share on other sites More sharing options...
piermonn Posted June 17, 2015 Author Share Posted June 17, 2015 Unfortunately it doesn't work. I guess the scale is local (because it is set to _localScaling in the computeWorldMatrix method) and that's why results are different. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 17, 2015 Share Posted June 17, 2015 Hello Piermonn, you have another option: you can control the way the matrix is built by using mesh.setPivotMatrix:https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Mesh/babylon.abstractMesh.ts#L336 By setting only this matrix (and leaving everything else untouched), you can control the way the final world matrix is produced. for instance:var mat = BABYLON.Matrix.Translation(..)mesh.setPivotMatrix(mat.multiply(BABYLOn.Scaling(...)) Quote Link to comment Share on other sites More sharing options...
piermonn Posted June 18, 2015 Author Share Posted June 18, 2015 Oh this will be far easier, I'm going to test.Thanks! 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.