【发布时间】:2016-03-28 12:14:03
【问题描述】:
我需要在 Three.js 中多次使用相同的矩阵。我有一个 Object3D,并且在执行此操作时我得到了 console.log 的正确矩阵:
console.log (scene.getObjectByName( "Pointer" ).matrix)
结果是这样的:
T…E.Matrix4 {元素:Float32Array[16]} 元素:Float32Array[16] 0:11:02:03:04:05:16:07:08:09:0 10:11 1:0 12:-150 13:0 14:0 15:1
请注意,第 12 个元素的值为 -150(在 obj.translationX(-150) 之后)。
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);
// output:elements: Float32Array[16] 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1
返回一个恒等矩阵(表示第 12 个元素为:0)
这里有什么问题?
更新:在渲染循环内... newMat.copy(...).. 工作正常!
【问题讨论】:
-
你在对象名称上吗?指针首先调用 updateMatrix 我看到这是容器对象,如 THREE.Object3D
-
我尝试了 object ubdateMatrix()... 但这没有帮助。是的,Pointer 是一个 containerObject..我放在 loadedJsonObject 的地方
-
child_clone.applyMatrix(container[i].object3d.children[j].parent.matrix); // 这是不好的 child_clone.applyMatrix(container[i].object3d.children[j].parent.parent.matrix); child_clone.applyMatrix(container[i].object3d.children[j].parent.parent.parent.matrix); child_clone.applyMatrix(container[i].object3d.children[j].parent.parent.parent.parent.matrix); child_clone.updateMatrixWorld() 道德是将矩阵从父容器应用到您的子容器,然后 updateMatrixWorld (实际上我的矩阵根本没有更新,原因是我正在创建自己的对象而不是 three.js Object3D 容器
标签: javascript matrix three.js