Hi!!
I have a problem manipulating mesh buffers. The reason of doing that is that I`m developing a FBX importer, and with animation we have a lot of problems between THOUSAND of transforms in anyplace (model, skeleton, deformers, …).
Due to that we found that migrating all transforms to meshes this problems disappears.
That is, I want to translate to mesh buffers all transforms (translation, rotation, scale) from all hierarchical tree from nodes and spatials to mesh points. This is OK por POSITION buffer, I compose transform from parents, and apply to mesh position buffers, and lately reset parent transforms. Something like that
try {
for (Geometry geom : geometries) {
Mesh mesh = geom.getMesh();
Transform trasnformToTraslateToMeshBuffers = geom.getLocalTransform().clone().combineWithParent(geom.getParent().getWorldTransform());
migrateTransformsToMesh(trasnformToTraslateToMeshBuffers, geometry, mesh);
}
} finally {
// At last: Remove all transforms for Nodes and Geometries (reset)
for (Geometry geom : geometries) {
Spatial parent = geom;
while (parent != null) {
parent.getLocalTransform().loadIdentity();
parent = parent.getParent();
}
}
}
private static void migrateTransformsToMesh(Transform trasnformToTraslateToMeshBuffers, GeometryFbxDataNode geomFBXdataNode, Mesh mesh) {
TempVars vars = TempVars.get();
migrateTransformsToMeshOfBuffer(trasnformToTraslateToMeshBuffers, mesh, Type.Position, 3, vars.skinPositions);
// Transform trasnformToTraslateToMeshBuffersNormals = FbxUtils.toTransform(FbxUtils.toMatrix(trasnformToTraslateToMeshBuffers).invert().transpose());
// Transform trasnformToTraslateToMeshBuffersNormals = FbxUtils.toTransform(FbxUtils.toMatrix(trasnformToTraslateToMeshBuffers).transpose().invert());
migrateTransformsToMeshOfBuffer(trasnformToTraslateToMeshBuffers, mesh, Type.Normal, 3, vars.skinNormals);
migrateTransformsToMeshOfBuffer(trasnformToTraslateToMeshBuffers, mesh, Type.Tangent, 4, vars.skinTangents);
vars.release();
}
But my problem is when I try to apply this transforms to NORMAL buffer. I try:
·Applying the same transform as in position points:
migrateTransformsToMeshOfBuffer(trasnformToTraslateToMeshBuffers, mesh, Type.Position, 3, vars.skinPositions);
· Applying the “transpose of the inverse of that matrix” (this seems fine: http://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/geometry/transforming-normals )
Transform trasnformToTraslateToMeshBuffersNormals = FbxUtils.toTransform(FbxUtils.toMatrix(trasnformToTraslateToMeshBuffers).invert().transpose());
migrateTransformsToMeshOfBuffer(trasnformToTraslateToMeshBuffers, mesh, Type.Normal, 3, vars.skinNormals);
· The inverse of that:
Transform trasnformToTraslateToMeshBuffersNormals = FbxUtils.toTransform(FbxUtils.toMatrix(trasnformToTraslateToMeshBuffers).transpose().invert());
migrateTransformsToMeshOfBuffer(trasnformToTraslateToMeshBuffers, mesh, Type.Normal, 3, vars.skinNormals);
But nothing work fine. The result of this migration it that the model is badly painted and some parts of the body dissapears, depending there camera is.
In this first image you can see orignial model, tunned with “Common/MatDefs/Misc/ShowNormals.j3md” material and moreover the debug geom calculed with TangentBinormalGenerator.genNormalLines(geom.getMesh(), 15.0f))
After migrating transforms, the material is shwn different (this show us it is badly calculated) but the debug of normal are the same, it seems fine. (in the next one posts I will show you, i can`t upload more than one image by post)
Can anyone help me?
Thanks in advance.