问题
I would like to save the info that represents the relative difference between two THREE.Object3d. I prefer to save the data as a transformation matrix.
Can someone knows what do i need to do to get this?
I would like to have a matrix4 that later on i could apply on an object and it will move/rotate by the same values.
Thanks
回答1:
So you have two transformations A and B you are looking for the transformation T that transforms A into B, right? Formally this is written as
B = T · A
Now you can think of going from A to B, as going back from A to identity (I) and then from identity to B i.e.
Going back from A to I:
I = inv(A) · A
Going from I to B
B = B · I
Chaining that up you get
B = B · inv(A) · A
Add a few parentheses to highlight things:
B = ( B · inv(A) ) · A
Comparing that with the first equation we see that
T = B · inv(A)
回答2:
For each object you can do a
matrix.decompose( position, quaternion, scale )
to get back the position, quaternion and scale and then for the quaternion you can do
matrix.makeRotationFromQuaternion( quaternion )
and then store the appropriate differences you need.
来源:https://stackoverflow.com/questions/47960768/3d-three-js-difference-matrix