diff options
author | Danila Shutov <dcbrwn2@gmail.com> | 2020-06-07 19:14:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-07 18:14:00 +0200 |
commit | fe1f72ab0ac8bcc233c91eb5b2d71bd2d2574cf8 (patch) | |
tree | 4be77389e38c97dd1391439f212db642b16fac0b /src/client/mesh.cpp | |
parent | 8fc9e7eb117849202b87bf3d764cd3eac6f68c74 (diff) | |
download | minetest-fe1f72ab0ac8bcc233c91eb5b2d71bd2d2574cf8.tar.gz minetest-fe1f72ab0ac8bcc233c91eb5b2d71bd2d2574cf8.tar.bz2 minetest-fe1f72ab0ac8bcc233c91eb5b2d71bd2d2574cf8.zip |
Recalculate mesh normals for CAOs (#10000)
Diffstat (limited to 'src/client/mesh.cpp')
-rw-r--r-- | src/client/mesh.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/client/mesh.cpp b/src/client/mesh.cpp index 4d73ead8a..91781373c 100644 --- a/src/client/mesh.cpp +++ b/src/client/mesh.cpp @@ -328,6 +328,26 @@ void recalculateBoundingBox(scene::IMesh *src_mesh) src_mesh->setBoundingBox(bbox); } +bool checkMeshNormals(scene::IMesh *mesh) +{ + u32 buffer_count = mesh->getMeshBufferCount(); + + for (u32 i = 0; i < buffer_count; i++) { + scene::IMeshBuffer *buffer = mesh->getMeshBuffer(i); + + // Here we intentionally check only first normal, assuming that if buffer + // has it valid, then most likely all other ones are fine too. We can + // check all of the normals to have length, but it seems like an overkill + // hurting the performance and covering only really weird broken models. + f32 length = buffer->getNormal(0).getLength(); + + if (!isfinite(length) || fabs(length) < 1e-10) + return false; + } + + return true; +} + scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer) { switch (mesh_buffer->getVertexType()) { |