2017-04-15 34 views
0

我正在使用Three.js四元数,并且无法保存我的对象的四元数属性。JavaScript对象属性不会更新变量集

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); 
}; 

我得到的问题是,当我设置this.rotationGroup.quaternion =新THREE.Quaternion(),它不保存四元数的对象。当我看到我得到的输出时

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

为什么你认为这是发生?

+0

您是否调用了'initializeScene()'函数? – adricadar

+0

是的,它被调用是因为我从console.log(this.rotationGroup.quaternion)获得了输出,但是它不是在前一行中设置的值。 – Kyle

+0

另外,如果我创建一个名为var test = new THREE.Quaternion(3,3,3,3)和console.log(test)的变量,它可以正常工作。 – Kyle

回答

1

Object3D.quaternion属性是不变的,所以这段代码是无效的:

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

相反,使用.quaternion.copy(q).quaternion.set(x, y, z, w)

另请参阅this answer

three.js r.84

+0

谢谢,我使用了set,​​一切正常。我正在修改代码,他们尝试了我的方式,但是,它实际上是在代码中设置的,而我正在复制的行什么都没做。谢谢。 – Kyle