Jump to content

Get and Set Quaternion?


Wintersun
 Share

Recommended Posts

Hello, newbie here coming from both 3d World and Web dev World.

currently I'm working on a project and I've made 3 handles for user to rotate the mesh on local Axis everything works fine. when the user finished doing what he does, I save the object rotation by getting the quaternion like this mesh.rotationQuaternion and save it either as separate values for x y z and w or whole object, but after reloading when I apply the same quaternion rotation to the object like mesh.rotationQuaternion = new BABYLON.Quaternion(this.rx, this.ry, this.rz, this.ra); I get a squashed and streched mesh in so many ways and it's not the same shape at all. What am I doing wrong?

Link to comment
Share on other sites

Hi @Wintersun and welcome from me. You can just put your basic methods into a PG to see what happens. Here is a simple example where one box is created and rotated, the rotation stored, the box rotated again and the stored rotation applied to a different box obtaining the first rotation. If you want to re-apply it to the original box then take out the comment from the penultimate line.

https://www.babylonjs-playground.com/#4GEDM2

Perhaps you can build on this to show how you carry out rotations, store them and re-apply them.

 

Link to comment
Share on other sites

4 hours ago, Wintersun said:

mesh.rotationQuaternion = new BABYLON.Quaternion(this.rx, this.ry, this.rz, this.ra);

Here is another example.  Note what the Quaternion is (y,x,z), so different than Vector3.
https://www.babylonjs-playground.com/#1ST43U#54
Still that should do any squashing if you get those backwards...
edit: oops. the main constructor is x,y,z,a, but I normally use RotationYawPitchRoll.

If the rotationQuaternion is NOT set then you need to get the mesh.rotation!

Link to comment
Share on other sites

You know I searched a lot with keywords like "Axis" or "Moving object with Axis" or "Rotation Axis" the keyword was "GIZMO" I'm such an idiot and all I got was someone else trying to do the same and he had the movement axis. You can't even imagine the code I have right now. It's monster, even with refactoring.

Thank you very much guys. should have done it earlier. it will definitely help. hope I don't encounter the same problem.

Link to comment
Share on other sites

17 hours ago, brianzinn said:

I have definitely some moments where I found something I made from scratch -- WAY too many times to mention! :)  The Gizmo is included with BabylonJS, but here is another one that might give you some ideas - they are separate projects:
https://ssatguru.github.io/BabylonJS-EditControl/demo

Thank you very much. I feel you dude.

 

15 hours ago, Pryme8 said:

Knowing how to script your own gizmos too (even though you say a waste of time) is a pretty valid skill/good practice.

not that I mean it's wasted because I didn't learn anything but sometimes it's actually more of a trial and error than learning. this wasn't the latter although It helped a lot.

 

Ok, I've setup gizmo didn't know It was on the alpha version of babylon but it's really solid and does everything I wanted it to do although the same problem with camera angle and sometimes inverse moving on x and y axis is still there but that's not a big problem. the problem with squash is gone now but I found a bug :

after touching the gizmo doesn't matter if you move or rotate or scale or not, the position of x will be inverted I mean if it's positive it will be negative if it's negative it will be positive.

the other thing is the rotation of x and y will be inverted and at the same time swapped with each other so in example If I have something like this =>

position : (x: 1, y:1, z:1);

qRotation: (x:0.5, y:0.4, z:0.2, w:0.1)

after just touching the bounding box of gizmo (not even moving) the result will be :

position : (x: -1, y:1, z:1);

qRotation: (x:-0.4, y: -0.5, z:0.1, w:0.2);

the scale won't change.

dunno if it's a bug or I'm doing something wrong but I'm not manipulating anything in the process just storing and retrieving. I'm gonna make a playground If I can.

edit:

z and w will be swapped as well. Scale Y will be inverted too.

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