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:
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:
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)?