Javascript 从对象复制THREE.js矩阵

Javascript 从对象复制THREE.js矩阵,javascript,matrix,three.js,Javascript,Matrix,Three.js,我需要在Three.js中重复使用同一个矩阵。我有一个Object3D,执行此操作时,我得到了正确的console.log矩阵: console.log (scene.getObjectByName( "Pointer" ).matrix) 结果是: T…E.Matrix4{elements:Float32Array[16]} 元素:Float32Array[16]0:11:02:03:04:05:16:07:08:09:010:1112:012:-15013:014:015:1 请注意,

我需要在Three.js中重复使用同一个矩阵。我有一个Object3D,执行此操作时,我得到了正确的console.log矩阵:

  console.log (scene.getObjectByName( "Pointer" ).matrix)
结果是:

T…E.Matrix4{elements:Float32Array[16]} 元素:Float32Array[16]0:11:02:03:04:05:16:07:08:09:010:1112:012:-15013:014:015:1

请注意,第12个元素的值为-150(在obj.translationX(-150)之后)

var newMat=newthree.Matrix4();
log(scene.getObjectByName(“指针”).matrix.elements)
//输出:[1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1]
newMat=newMat.copy(scene.getObjectByName(“指针”).matrix);
控制台日志(newMat);
//输出:元素:Float32Array[16]1,0,0,0,0,1,0,0,0,1,0,0,0,0,1
返回同一矩阵(表示第12个元素为:0)

这里怎么了


更新:在renderloop中。。。新材料副本(…)。。很好

three.js将在根据对象位置、比例和旋转呈现页面时更新对象矩阵。因此,当您设置对象矩阵时,它将很快被重写。 要手动设置对象矩阵,必须将“自动更新”设置为false

object.matrixAutoUpdate = false;
然后使用你的代码

  var newMat = new THREE.Matrix4();
  console.log(scene.getObjectByName("Pointer").matrix.elements)
  // output: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
  newMat = newMat.copy(scene.getObjectByName("Pointer").matrix);
  console.log(newMat);

three.js将在根据对象位置、比例和旋转呈现页面时更新对象矩阵。因此,当您设置对象矩阵时,它将很快被重写。 要手动设置对象矩阵,必须将“自动更新”设置为false

object.matrixAutoUpdate = false;
然后使用你的代码

  var newMat = new THREE.Matrix4();
  console.log(scene.getObjectByName("Pointer").matrix.elements)
  // output: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
  newMat = newMat.copy(scene.getObjectByName("Pointer").matrix);
  console.log(newMat);

你在调用updateMatrix的对象名指针上吗?首先,我看到这是像THREE一样的容器对象。Object3Di尝试了对象ubdateMatrix()。。。但这没有帮助。是指针是一个containerObject..其中我放置了loadedJsonObjectchild_clone.applyMatrix(容器[i].object3d.children[j].parent.matrix);//这是错误的child_clone.applyMatrix(容器[i].object3d.children[j].parent.parent.matrix);child_clone.applyMatrix(容器[i].object3d.children[j].parent.parent.parent.matrix);child_clone.applyMatrix(容器[i].object3d.children[j].parent.parent.parent.parent.matrix);updateMatrix World()的寓意是将矩阵从父容器应用到子容器,然后再应用到updateMatrix World(实际上,我的矩阵根本没有更新,原因是我创建了自己的对象,而不是three.js Object3D container您是否首先在对象名指针上调用updateMatrix我看到这是容器对象,如three.Object3Di尝试对象ubdateMatrix()…但这没有帮助。是的指针是一个containerObject..其中我放置了加载的JSONObjectChild_clone.applyMatrix(容器[i].object3d.children[j].parent.matrix);//这是一个坏的child_clone.applyMatrix(容器[i].object3d.children[j].parent.parent.parent.matrix);child_clone.applyMatrix(容器[i].object3d.children[j].parent.parent.parent.parent.matrix);child_clone.UpdateMatrix()将矩阵从父容器应用到子容器,然后更新matrix World(实际上,我的矩阵根本没有更新,原因是我在创建我自己的对象,而不是three.js Object3D Container。除非您熟悉库的内部工作并了解这样做的后果,否则不要设置
matrixAutoUpdate=false
。除非您熟悉,否则不要设置
matrixAutoUpdate=false
了解库的内部工作,并了解这样做的后果。