From 036318e94e6b9f7d84daf5667368605ec034b28a Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Wed, 4 Sep 2024 21:37:46 +0200 Subject: [PATCH] Fixed glTF normals when transforms have not been applied in Blender. close #929 --- neo/idlib/MapFile_gltf.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/neo/idlib/MapFile_gltf.cpp b/neo/idlib/MapFile_gltf.cpp index 1a99a951..442de586 100644 --- a/neo/idlib/MapFile_gltf.cpp +++ b/neo/idlib/MapFile_gltf.cpp @@ -153,14 +153,11 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); } - idVec3 normal; - - normal.x = vec.x; - normal.y = vec.y; - normal.z = vec.z; - - normal *= transform; + // w = 0 because we only want to rotate the normal + idVec4 normal4D( vec.x, vec.y, vec.z, 0.0f ); + normal4D *= transform; + idVec3 normal = normal4D.ToVec3(); // renormalize because previous transforms may contain scale operations normal.Normalize(); @@ -203,13 +200,10 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); } - idVec3 tangent; + idVec4 tangent4D( vec.x, vec.y, vec.z, 0.0f ); + tangent4D *= transform; - tangent.x = vec.x; - tangent.y = vec.y; - tangent.z = vec.z; - - tangent *= transform; + idVec3 tangent = tangent4D.ToVec3(); tangent.Normalize(); mesh->verts[i].SetTangent( tangent );