1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Recalculate mesh normals for CAOs (#10000)

This commit is contained in:
Danila Shutov 2020-06-07 19:14:00 +03:00 committed by GitHub
parent 8fc9e7eb11
commit fe1f72ab0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 0 deletions

View file

@ -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()) {