Issues with applied recalculated normals being again changed
Posted: Fri Mar 04, 2011 5:24 am
I have a skinned/animated model with hugely messed up normals (most likely some bug in the exporter or importer) after importing it into Irrlicht.
Now I have two major issues I ran into when attempting to fix this:
I wrote a little function that walks through all meshbuffers of a given animated mesh, inspects all vertices in there and recalculates all normals completely from scratch. That works fine and gives acceptable results if I use it on my scenenode->getMesh()'s mesh.
The first problem I ran into is, instead of creating a new animated mesh scene node directly from scenemanger->getMesh()'s mesh, I did this:
The idea was that I don't do it on *afterwards* on every single scene node, but once on the gobal mesh copy in the scene manager's mesh cache.
Sadly this didn't work. When I created any scene nodes from that mesh, they would have totally ruined normals again.
Update: Fixed this now by using setDirty() for the meshbuffer which I previously didn't by mistake - it doesn't fix the second issue though:
The second problem I ran into is, as soon as I activate updateNormalsWhenAnimating(true) on the scenenode->getMesh() *after* fixing the normals successfully, this ruins them again - if I leave this at false, they work fine (but aren't adjusted for animations). I expected them to be based on my recalculated, fixed normals - instead they appear to be taken from the original broken ones for some reason? (Please note this still happens despite me setting the meshbuffer dirty after the manipulations!)
This problem is pretty visible and not just a performance issue, rather trashing all model's normals when animated since I can either have them all borked or not adjusted during animation (which results in them also being borked for complex animations).
Does anyone have an idea what I could do about those two problems (especially the latter one)?
Now I have two major issues I ran into when attempting to fix this:
I wrote a little function that walks through all meshbuffers of a given animated mesh, inspects all vertices in there and recalculates all normals completely from scratch. That works fine and gives acceptable results if I use it on my scenenode->getMesh()'s mesh.

Code: Select all
if (manager->getMeshCache()->isMeshLoaded(meshpath) == false) {
//mesh is new, fix normals for it:
mesh = manager->getMesh(meshpath);
if (mesh && strendswith(meshpath, ".b3d")) {
//fix the normals!
recalculatesmoothnormals((SAnimatedMesh*)mesh);
}
}else{
//mesh is already present and fixed:
mesh = manager->getMesh(meshpath);
}
Sadly this didn't work. When I created any scene nodes from that mesh, they would have totally ruined normals again.
Update: Fixed this now by using setDirty() for the meshbuffer which I previously didn't by mistake - it doesn't fix the second issue though:

This problem is pretty visible and not just a performance issue, rather trashing all model's normals when animated since I can either have them all borked or not adjusted during animation (which results in them also being borked for complex animations).
Does anyone have an idea what I could do about those two problems (especially the latter one)?