I have the 3dsmax origin transform matrix (in 3DSMax) for an 3d object like:
transform=Transform(Matrix(
Vector(0.9848077, 0.1736482, 0),
Vector(-0.1736482, 0.9848077, 0),
Vector(0, 0, 1)),
Vector(0, 0, 0));
Now I´m checking the matrixWorld.elements of this object imported in Threejs and they look like this
0.98480769139541,0,-0.17364818203015844,0,0,1,0,0,0.17364818203015844,0,0.98480769139541,0,0,0,0,1
Seems I find all the same values back in matrixWorld elements, but seems they are ordered/organized differently…
Can someone helping me understand the order? Or, at least, how to achieve the same order for the values I originally got in 3dsmax?
Thanks
May I ask how have you imported the object into three.js
? Which loader have you been used?
GLTF Loader with Draco Compression
loader = new THREE.GLTFLoader();
THREE.DRACOLoader.setDecoderPath( config.dracoPath );
loader.setDRACOLoader( new THREE.DRACOLoader() );
Notice that in 3DSMax y and z axis are swapped compared to three.js
's coordinate system.
According to this resource, the first three vectors of your 3ds Max matrix should be the basis vectors and the last one the world position.
I suggest you use Matrix4.extractBasis() to extract the three basis vectors and Vector3.setFromMatrixPosition() to extract the world position and then compare these vectors with the 3ds Max data. This will make it easier than directly comparing the matrices.
Ok, 1st part I understand so far (hope), so I did:
var xAxis = new THREE.Vector3();
var yAxis = new THREE.Vector3();
var zAxis = new THREE.Vector3();
And then:
obj.matrixWorld.extractBasis( xAxis, yAxis, zAxis);
But what about the next step?
Vector3.setFromMatrixPosition()
var worldPosition = new THREE.Vector3();
worldPosition.setFromMatrixPosition( obj.matrixWorld );
Ok understood. So by doing so I get:
xAxis = {x: 0.98480769139541, y: 0, z: -0.17364818203015844}
yAxis = {x: 0, y: 1, z: 0}
zAxis = {x: 0.17364818203015844, y: 0, z: 0.98480769139541}
worldPosition = {x: 0, y: 0, z: 0}
Which, compared to the 3DS-matrix origin looks same same, but different:
Matrix(
Vector(0.9848077, 0.1736482, 0),
Vector(-0.1736482, 0.9848077, 0),
Vector(0, 0, 1)),
Vector(0, 0, 0));
Even if I would swap y and z axis, it wouldn´t look same, right?
TBH, I have no idea where the difference comes from. Does the imported model look correct?
To follow up on this, I managed to sort the matrices and get the values set correct for i/o. Now next problem. I got an 2 axis rotation xy in 3DMAX. Its imported as .gltf and, after importing, the models rotation/position looks 1:1 in Threejs as it looked in 3DSMAX.
I now do nothing in Threejs then export the values from the matrices back out from Threejs to save them.
Now the problem. 3DSMAX origin transform matrices look like this:
transform=Transform(Matrix(
Vector(0.9848077, 0.1736482, 0),
Vector(-0.1710101, 0.9698462, -0.1736482),
Vector(-0.03015369, 0.1710101, 0.9848077)),
Vector(0, 0, 0));
Threejs, even if the model is represented correctly (looks same same like in 3dsmax) the matrices differ
. Most wrong is the value in the 3rd Vector3 (3.4368 … where it should be -0.03015369):
transform=Transform(Matrix(
Vector(0.9848076969913874, 0.17101004808231274, -0.030153685099034887), Vector(-0.17364815366184194, 0.9698462583378354, -0.17101004808231274), Vector(3.4368702955234594e-9, 0.17364815366184194, 0.9848076969913874)),
Vector(0, 0, 0));
Any idea what´s going wrong here?