From the naming and documentation I would assume that setPreTransformMatrix is equivalent to VertexData.transform.
Playground: Babylon.js Playground
// ------------------------------------------
function getVertexData() {
return BABYLON.VertexData.CreateBox({ size: 1 });
// let vertexData = new BABYLON.VertexData()
// vertexData.positions = [
// 0,0,0,
// 0,0,1,
// 1,0,0
// ]
// vertexData.indices = [
// 0,1,2
// ]
// return vertexData;
}
// ------------------------------------------
// flip y and z: https://gamedev.stackexchange.com/a/7917
let matrixFlixYZ = BABYLON.Matrix.FromArray([
1.0, 0.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0,
]);
// ------------------------------------------
let mesh1 = new BABYLON.Mesh("mesh 1", scene);
let vd1 = getVertexData();
vd1.transform(matrixFlixYZ);
vd1.applyToMesh(mesh1);
mesh1.position = new BABYLON.Vector3(-1, 2, 0);
// ------------------------------------------
let mesh2 = new BABYLON.Mesh("mesh 2", scene);
let vd2 = getVertexData();
vd2.applyToMesh(mesh2);
mesh2.setPreTransformMatrix(matrixFlixYZ);
mesh2.position = new BABYLON.Vector3(1, 2, 0);
// -----------------------------------------
so I would assume that mesh1 and mesh2 are equivalent.
As you can see, with VertexData.transform
, the triangles are wrongly oriented and I can see the inside faces.
With setPreTransformMatrix
the visibility is not affected.
Expected:
Both boxes should be “wrong”
Actual:
setPreTransformMatrix does not affect the triangle visibility
Context: I am importing triangles from an external, right handed system.
Also, it is not clear for me how setPreTransformMatrix
works with regard to child nodes.
If I have
TransformNode1 (setPreTransformMatrix, rotation, position)
|- TransformNode2 (setPreTransformMatrix, rotation, position)
|- Mesh (setPreTransformMatrix, rotation, position)
then I would assume the WorldMatrix is calculated from inner to outer, so
Mesh.setPreTransformMatrix -> Mesh.rotation -> Mesh.position -> TransformNode2.setPreTransformMatrix -> TransformNode2.rotation -> TransformNode2.position -> TransformNode1.setPreTransformMatrix -> TransformNode1.rotation -> TransformNode1.position
Is that correct?