I have a mesh that has origin point at the bottom. I want to move it by -132 on Z axis. If I change the position of the Mesh it is on the correct position. But If I translate it on the Z axis by -132, the mesh is off by 20. Why am I not getting the same result?
The way I am translating the matrix:
matrix = new THREE.Matrix4().makeTranslation( 0, 0, -132 )
mesh.geometry.applyMatrix( matrix );
Here is the image of the mesh:
And here is image after the translation by 132. It's off by 20.
Some more info: Position of the mesh is at: 419, -830, 500
and Rotation is: 0, -0.52, 0
So the Z coordinate is at 500; But I have to move it down by -132. If it move it by moving the position down 132 it is on correct position. But I want to translate the matrix to get the origin point down by 132. Here is also the matrix:
Best How To :
update after further clarifications and chat
The whole proint is that 3D transformatins are not commutative. This means that translating and then rotating is different that rotating and then translating (will produce different results). In some special cases these can coincide (e.g origins are at
0,0,0 and so on..), but in general they have different results.
Furthermore there is the issue with relative coordinates and nesting 3D objects inside other 3D objects. The final (world) transform of an object is affected whether it is inside other object or not.
Finally, the actual mesh position (local transform) versus vertices position plays a role in the way the mesh (and the geometry) will be (eventualy) projected onto 2D, so the projection angle changes (see above).
As clarified, the question is about shifting a mesh in such a way as to shift the origin, so further transformations (e.g rotations) can be done with respect to this shifted origin. A standard way to achieve this behaviour, in 3D programing, is to include pivots or wrappers around the mesh and position the mesh relatively inside with respect to the wrapper. Then apply any further transformations (e.g rotations) on the wrapper itself. This gives the effect that the mesh is rotating with respect to another axis (instead of the center).
The way this happens is that the wrapper indeed rotates around its own origin (i.e at
0,0,0) but the mesh inside is shifted so it appears as rotating with respect to another axis. A common example of this is modelling a 3D car wheel, which can rotate around its own axis (i.e spinning) but also it translates with the rest of the car. So one adds a wrapper around the wheel, where the wrapper is indeed translated with the rest of the car, but the wheel is rotated inside the wrapper as if no translation is present (kind of reverse situation of what you need here, but same difference).
You may optionaly want to check the MOD3 pivot modifier which creates custom pivots as origin points/axes (ps i'm author of the port). A wheel modifier is also included in MOD3 which solves what is described above as the wheel problem in 3D.
To use a wrapper 3D Object in your code do something like this:
// create the pivot wrapper
var pivot = new THREE.Object3D();
pivot.name = "PIVOT";
pivot.add( mesh );
scene.add( pivot );
// shift the mesh inside pivot
// position wrapper in the scene,
// position in the place where mesh would be
pivot.position.set(419, -830, 500);
pivot.rotation.set(0, -0.52, 0);
// now mesh appears rotated around the z = -132 axis instead of the center
// because the wrapper is actually rotated around its center,
// but its center coincides with the shifted mesh by z = -132
a related answer here