Jump to content

Custom order for transformations execution


piermonn
 Share

Recommended Posts

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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):

post-14995-0-40046600-1434465442.png

 

Whereas I have this result with the same program in JavaFX:

post-14995-0-58516200-1434465442.png

 

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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