问题
i need to to same matrix mulitiply in Three.js. I had an Object3D and i get the right matrix to console.log when doing this:
console.log (scene.getObjectByName( "Pointer" ).matrix)
the result is like:
T…E.Matrix4 {elements: Float32Array[16]} elements: 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
note here that the 12th element have the value -150 (after a 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
giving back an identiy matrix (meaning the 12th element is: 0)
Whats is wrong here?
UPDATE: inside the renderloop... newMat.copy(...).. works fine!
回答1:
three.js will update the object matrix when it render the page according the object position, scale, rotation. So when you set the object matrix, it will sooner be rewrited. To manually set the object matrix, you have to set autoupdate to false.
object.matrixAutoUpdate = false;
then use the your code.
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);
来源:https://stackoverflow.com/questions/36262075/copy-three-js-matrix-from-object