变量集上的Javascript对象属性未更新
我正在使用Three.js四元数,但在保存对象的属性以获取四元数时遇到问题变量集上的Javascript对象属性未更新,javascript,three.js,Javascript,Three.js,我正在使用Three.js四元数,但在保存对象的属性以获取四元数时遇到问题 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
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时,它不会保存四元数对象。当我查看输出时,我得到
THREE.Quaternion (w:1 x:0 y:0 z:0)
您认为这是为什么?Object3D.quaternion属性是不可变的,因此此代码无效:
rotationGroup.quaternion = new THREE.Quaternion( x, y, z, w );
而是使用.quaternion.copy q或.quaternion.set x、y、z、w
另见
three.js r.84您调用了initializeScene函数吗?是的,之所以调用它是因为我从console.logthis.rotationGroup.quaternion获得了输出,但是它不是前面一行中设置的值。另外,如果我调用变量var test=new three.Quaternion3,3,3,3和console.logtest,它工作正常。谢谢,我使用了set,一切正常。我正在修改代码,他们尝试了我的方法,但是,它实际上是在代码的前面设置的,而我复制的行没有做任何事情。非常感谢。