Rotate meshnode normals correctly instead of recalculating

This commit is contained in:
Lars Mueller 2024-12-09 00:45:37 +01:00 committed by sfan5
parent 21437090b8
commit 3c5e0d10fc
2 changed files with 8 additions and 6 deletions

@ -1673,8 +1673,6 @@ void MapblockMeshGenerator::drawMeshNode()
modified = false;
if (modified) {
recalculateBoundingBox(mesh);
// FIXME: we should rotate the normals too, instead of recalculating
meshmanip->recalculateNormals(mesh, true, false);
}
} else {
warningstream << "drawMeshNode(): missing mesh" << std::endl;

@ -249,10 +249,14 @@ static void rotateMesh(scene::IMesh *mesh, float degrees)
float c = std::cos(degrees);
float s = std::sin(degrees);
auto rotator = [c, s] (video::S3DVertex *vertex) {
float u = vertex->Pos.*U;
float v = vertex->Pos.*V;
vertex->Pos.*U = c * u - s * v;
vertex->Pos.*V = s * u + c * v;
auto rotate_vec = [c, s] (v3f &vec) {
float u = vec.*U;
float v = vec.*V;
vec.*U = c * u - s * v;
vec.*V = s * u + c * v;
};
rotate_vec(vertex->Pos);
rotate_vec(vertex->Normal);
};
applyToMesh(mesh, rotator);
}