Jump to content

How to get mesh rotation in [angle,x, y, z] format ?


Recommended Posts

So I am integrating babylon with raytracer. And all I know is I need to provide rotation of each meshes  in (angle, x, y, z) format. 


Is this format a Quaternion in first place?


And anyway when I tried to get rotation in quaternion format (by doing mesh.rotationQuaternion ), I am getting error  as I have set mesh rotation by mesh.rotaion and not mesh.rotationQuaternion . So both the property seems exclusive to each other. How does this work ? Logically rotation is rotation by whichever method you set or get. No ?



Link to comment
Share on other sites

Hi dsman!  Um, can you use yourmesh.rotation.toQuaternion() ?


Mesh don't have a .rotationQuaternion by default.  It is added when/if needed, by system.  You can add one, anytime...


mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);


But after that, I THINK you must use things like...


        mesh.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(0, 0, 0);




        mesh.rotate(BABYLON.Axis.X, 0, BABYLON.Space.LOCAL);

        mesh.rotate(BABYLON.Axis.Y, 0, BABYLON.Space.LOCAL);
        mesh.rotate(BABYLON.Axis.Z, 0, BABYLON.Space.LOCAL);


Maybe this will help.  Be well. 

Link to comment
Share on other sites

If I do meshrotation = mesh.rotation.toQuaternion() , how do I get angle , x, y, z  from meshrotation object?   meshrotation has properties like meshrotation.x , meshrotation.y, meshrotation.z, meshrotation.w  but which one is angle and which one is rest ? 


I am asking because I applied Math.PI/4    angle on x axis  (By mesh.rotation.x = Math.PI/4)  and after that if I do meshrotation= mesh.rotation.toQuaternion(), meshrotation.x = 0.382683

meshrotation.y = 0


meshrotation.w  =0.92387953


Now no If I rotate at different angle ,  .x , .y, .z  properties changes respectively  but .w remains the same. 


So I am wondering if this toQuternion() will give me the format that I want. 


Format I want is Angle, x , y, z . 

Link to comment
Share on other sites

Well let me make it simpler.. 



1. I have a model converted/imported from 3D max. 

2. In babylon, I am looping through all meshes and want rotation of each meshes in (angle, x, y, z ) format. AS  I need to provide it to other ray tracing application. 

3. I am doing meshrotation = mesh.rotation.toQuaternion() .  I realized (meshrotation.w * 180 ) becomes my 'angle'  

4. Now , I only need to know what does meshrotation.x  , meshrotation.y , meshrotation.z  is actually ? If the given mesh has rotation of 45 degree on all axis, then  I get value of meshrotation.x = 6.1232 , meshrotation.y = 6.1232 , meshrotation.z = 6.1232  .. So what does  6.1232 tell us here ?



All I want is mesh's rotation in (angle, x,y, z) format (where x,y,z  is axis around which rotation is to be made, according to raytracer specification)


Here I have figured out the angle part. Only this x,y,z is mystery . I read the link you gave. But I am still not able to get how to I get the rotation axis x,y,z  . 

Link to comment
Share on other sites


In BJS, mesh.rotation.x, y, z are properties valuing the mesh rotation around its local x, y, z axis (y first, then x, finally z) not around a given other axis.

These values are expressed in radians, not degrees. These are Euler angles.


The mesh orientation expression with only an axis and an angle around this axis is quite a quaternion expression.

It's possible to convert from an expression to the other : http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles

There are converting tools in BJS also.


I don't know what properties are valued when you import a mesh from 3D max.

I didn't understand what were the values you got and know after importation (mesh.rotation ?).

Maybe someone working with 3D max could tell us what mesh rotation values are imported with.

Link to comment
Share on other sites

Ok. So based on DBWel 's answer at http://www.html5gamedevs.com/topic/14349-meshrebase/?p=82414   and Radian to degree conversion ( http://www.rapidtables.com/convert/number/radians-to-degrees.htm )  I have figured it out in this way : 



 currentmesh.getWorldMatrix().decompose(scale, rot, trans);


preangle = Math.acos(rot.w) * 2 ;

 if (angle == 0)
                sin = 1;
               sin = Math.sin(preangle / 2);

rotx = rot.x / sin;  // rotation axis x-coordinate
roty = rot.y / sin;   // rotation axis y-coordinate
rotz = rot.z / sin;   // rotation axis z-coordinate

angle = preangle * 180 / Math.PI ;   // final angle  in degree

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