I'm working with a 4x4 transformation matrix in Octave that encodes rotation and position data. After confirming that this matrix represents a valid transformation, I want to use it to set the matrixWorld property of a three.js Object3D object. This involves setting the position and rotation of the object based on the transformation matrix.
Based on information from the three.js documentation and various discussions online, it seems that setting nameOfObject.matrixAutoUpdate
to false is crucial. However, despite trying different approaches to set nameOfObject.matrixWorld
, the object still renders at the origin with no rotation.
Here are the methods I've attempted within an update method before calling render()
:
// Creating a three.js matrix
var tempMatrix = new THREE.Matrix4();
tempMatrix.fromArray(arrayContainingTransformationMatrix);
// Values are correctly set
console.log(tempMatrix.elements);
// The following approaches were tried individually
// First approach (unsuccessful)
nameOfObject.matrixAutoUpdate = false;
nameOfObject.matrixWorld.copy(tempMatrix);
// Second approach (also unsuccessful)
// Based on a related SO question
nameOfObject.matrixAutoUpdate = false;
nameOfObject.matrix.copy(tempMatrix);
nameOfObject.updateMatrixWorld(true);
// Third approach (also unsuccessful)
nameOfObject.matrixAutoUpdate = false;
nameOfObject.matrixWorld.fromArray(arrayContainingTransformationMatrix);
// Regardless of the approach, the console shows correct values
console.log(sphere1.matrixWorld.elements);
Some additional points to consider:
- I understand that setting
matrixAutoUpdate
to false may not need to be repeated in every iteration, but I have done so as a precaution. - Modifying
nameOfObject.position
based on the fourth column of the transformation matrix results in the expected position change, ruling out a rendering issue. - While it's advised not to call
updateMatrix()
when manually adjusting the matrix, information on the implications ofupdateMatrixWorld()
is less abundant.
Any advice on this matter would be greatly appreciated. If needed, I will delve into the source code, but I believe there might be a simple solution I am overlooking in my use of three.js.