0

I am working with a Three.js Quaternion and I am having trouble saving my object's property for the Quaternion.

GLmol.prototype.initializeScene = function() {
   this.scene = new THREE.Scene();
   this.scene.fog = new THREE.Fog(this.bgColor, 100, 200);

   this.modelGroup = new THREE.Object3D();
   this.rotationGroup = new THREE.Object3D();
   this.rotationGroup.useQuaternion = true;

   this.rotationGroup.quaternion = new THREE.Quaternion(0.7235552851867599, -0.004228243257681183 , 0.004646778667168487, 0.6902378421133389);
   console.log(this.rotationGroup.quaternion)

   this.rotationGroup.add(this.modelGroup);

   this.scene.add(this.rotationGroup);
   this.setupLights(this.scene);
};

The problem I am getting is that when I set the this.rotationGroup.quaternion = new THREE.Quaternion(), it doesn't save the Quaternion object. When I look at the output I get

THREE.Quaternion (w:1 x:0 y:0 z:0)

Why do you think this is happening?

3
  • did you called the initializeScene() function? Commented Apr 15, 2017 at 17:25
  • Yes, It is called because I get the output from console.log(this.rotationGroup.quaternion), however its not the value that was set in the line right before. Commented Apr 15, 2017 at 17:28
  • Also, If I make a variable called, var test = new THREE.Quaternion(3, 3, 3, 3), and console.log(test) it works properly. Commented Apr 15, 2017 at 17:29

1 Answer 1

1

The Object3D.quaternion property is immutable, so this code is invalid:

rotationGroup.quaternion = new THREE.Quaternion( x, y, z, w );

Instead, use .quaternion.copy( q ) or .quaternion.set( x, y, z, w ).

Also see this answer.

three.js r.84

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I used set and everything works properly. I am modifying code and they tried the way I did, however, it was actually set earlier in code and the line I was copying did nothing. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.