2017-04-15 75 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