[SOLVED] Problems calculating mesh normal buffers

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.

Here is the post-transform images:

And here you can see the fact of some parts dissappiaring

Another one:

And the last one, only moving pamera a pixel respect the last one

PD: It is not camera Frustum, the other parts are shown.

The parts disappear as it animates or as you move the camera? Are they one giant mesh or separate meshes?

As to the other… the normal lines still look right. Are you recalculating those too?

Thanks for your fast response. :wink:

The model contains originally ony one mesh, but we need to split in 2 because there are two materials, and JMoneky only supports 1 material by mesh.
You can sew in that diagram (breakdown of FBX importer nodes):

If it disappears as you move the camera then most likely it’s a bad bounding shape and it’s being culled.

It dessapears when moving camera, not-animated model. Animations run well.
What could be the problem of badly culling?!?

This isn’t fun anymore.

I was reviewing and it is configured to use FaceCullMode.Off (property obteined from FBX).
If I change to another, for instance FaceCullMode.FrontAndBack the model is not shown.

This has nothing to do with face culling.

You will find that people who are short on time really hate to repeat themselves. So I will leave you to others who may be more patient. Good luck with your issue.

thank you anyway

pspeed means something like this: updateModelBound vs updateWorldBound

I have a question: How do you generate the “spikes” that point into the normal direction?

Hi!!

Im not sure my problem is like that. Im working in a FBX conversor to j3o, then i`m processing/migrating data to jmonkey-support and save j30.
Lately, when loaded this j3o is when I detect this deffective.

To show spins with normal I use “TangentBinormalGenerator”
For instance:

// Show normals ---------------------------------
for (Geometry geom : this.lookForGeometries(this.loadedModel)) {
      try {
          // Geometry debug = new Geometry("Debug " + geom.getName(), TangentBinormalGenerator.genTbnLines(geom.getMesh(), 1.0f));
          Geometry debug = new Geometry("Debug " + geom.getName(), TangentBinormalGenerator.genNormalLines(geom.getMesh(), 15.0f));
          Material debugMat = this.assetManager.loadMaterial("Common/Materials/VertexColor.j3m");
          debugMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
          debug.setMaterial(debugMat);
          debug.setCullHint(Spatial.CullHint.Never);
          debug.getLocalTranslation().set(geom.getLocalTranslation());
          debug.getLocalScale().set(geom.getLocalScale());
          geom.getParent().attachChild(debug);
      } catch (Exception ex) {
            ex.printStackTrace();
      }
}

Bye.

Yes, I know what you are doing.

Did you compute the bounding shape (e.g. bounding box or bounding sphere or bounding capsule)?

Because if things disappear when you move the camera around and your bounding shape has zero radius, then this sub-mesh might disappear - so it’s most likely a missing bounding shape (like pspeed wanted to say, but you ignored this totally - he has a big knowledge about 3D coding stuff - much more than you or me).

Ohhhh!! It runs!!!

I am sorry, i did not understand you.
I thought that my problem was in calculating new normal buffers, not that I needed to force refresh bounds.
I thought that model bounds were not required at “conversion time”, only in “play time”.

Thank you very much.

PD: Sorry “pspeed” if i did not undestand you before.
PD: Of course ANY OF YOU are better than me, I am starting with all this concepts.