问题
I would like to know how threejs ordering multiple matrix?
For instance ,
......
var mesh = new THREE.Mesh( geometry, material );
mesh.position.set( 0, 20, 0 ); // T , transform matrix
mesh.rotation.set( 0, Math.PI, 0 );//R , rotation matrix
mesh.scale.set( 1, 1, 10 );//S , scale matrix
So , how threejs to combine three matrix? It will according my set value order(In my example , it is TRS , so final matrix should T*R*S ) or fixed order (For instance, it is always using SRT ordering , the finally matrix is S*R*T)?
回答1:
You can specify the parameters as you have done so long as the mesh property 'matrixAutoUpdate' is true and you only want it in order by scale, rotation then translation (typical).
If you need something more complicated, such as a specific series of translations and rotations, then you should set matrixAutoUpdate to false and calculate the matrix yourself.
Important note: when using the matrix multiply function, you must do it in 'reverse' order. For example if you want to position a limb then logically you would:
1) do local rotation (such as arm up/down)
2) move limb with respect to its offset (put it at its joint)
3) rotate according to body rotation
4) move to body offset
The actual operations would be done in reverse:
arm_mesh.matrixAutoUpdate = false;
var mat4: THREE.Matrix4 = new THREE.Matrix4();
var arm_matrix = arm_mesh.matrix;
arm_matrix.identity(); // reset
arm_matrix.multiply(mat4.makeTranslation(body_pos.x, body_pos.y, body_pos.z));
arm_matrix.multiply(mat4.makeRotationFromQuaternion(body_rotation));
arm_matrix.multiply(mat4.makeTranslation(arm_offset.x, arm_offset.y, arm_offset.z));
arm_matrix.multiply(mat4.makeRotationFromEuler(new THREE.Euler(arm_angle, 0, 0)));
Of course this does not utilize or account for parent/child relationships.
来源:https://stackoverflow.com/questions/22178476/threejs-transform-matrix-ordering