Javascript对象属性未在变量集上更新

时间:2017-04-15 17:21:04

标签: javascript three.js

我正在使用Three.js Quaternion,我无法保存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);
};

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

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

为什么你认为这种情况正在发生?

1 个答案:

答案 0 :(得分: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