diff --git a/TombLib/TombLib/LevelData/Compilers/Rooms.cs b/TombLib/TombLib/LevelData/Compilers/Rooms.cs index 1224b8a2d..0539d09cf 100644 --- a/TombLib/TombLib/LevelData/Compilers/Rooms.cs +++ b/TombLib/TombLib/LevelData/Compilers/Rooms.cs @@ -667,7 +667,8 @@ private tr_room BuildRoom(Room room) }, Lighting1 = 0, Lighting2 = 0, - Attributes = 0 + Attributes = 0, + Normal = normal }; // Pack the light according to chosen lighting model @@ -709,7 +710,12 @@ private tr_room BuildRoom(Room room) } else { - existingIndex = roomVertices.IndexOf(v => v.Position == trVertex.Position && v.Color == trVertex.Color); + existingIndex = roomVertices.IndexOf(v => + v.Position == trVertex.Position && + v.Lighting1 == trVertex.Lighting1 && + v.Attributes == trVertex.Attributes && + v.Lighting2 == trVertex.Lighting2 && + v.Normal == trVertex.Normal); if (existingIndex == -1) { existingIndex = roomVertices.Count; diff --git a/TombLib/TombLib/LevelData/Compilers/TombEngine/Rooms.cs b/TombLib/TombLib/LevelData/Compilers/TombEngine/Rooms.cs index 86ce048b3..282723570 100644 --- a/TombLib/TombLib/LevelData/Compilers/TombEngine/Rooms.cs +++ b/TombLib/TombLib/LevelData/Compilers/TombEngine/Rooms.cs @@ -644,6 +644,7 @@ private TombEngineRoom BuildRoom(Room room) var span = CollectionsMarshal.AsSpan(roomVertices); for (int i = 0; (uint)i < (uint)span.Length; i++) if (span[i].Position == trVertex.Position && + span[i].Normal == trVertex.Normal && span[i].Color == trVertex.Color && span[i].DoubleSided == trVertex.DoubleSided) { diff --git a/TombLib/TombLib/LevelData/Room.cs b/TombLib/TombLib/LevelData/Room.cs index 9cc2ffc08..d6380acb1 100644 --- a/TombLib/TombLib/LevelData/Room.cs +++ b/TombLib/TombLib/LevelData/Room.cs @@ -1870,6 +1870,8 @@ public void GetGeometryStatistics(out int vertices, out int faces) // Apply the transform to the vertex var position = MathC.HomogenousTransform(vertex.Position, worldTransform); + var normal = MathC.HomogenousTransform(vertex.Normal, normalTransform); + normal = Vector3.Normalize(normal); var trVertex = new tr_room_vertex { Position = new tr_vertex @@ -1880,7 +1882,8 @@ public void GetGeometryStatistics(out int vertices, out int faces) }, Lighting1 = 0, Lighting2 = 0, - Attributes = 0 + Attributes = 0, + Normal = normal }; // HACK: Find a vertex with same coordinates and merge with it. @@ -1896,7 +1899,12 @@ public void GetGeometryStatistics(out int vertices, out int faces) } else { - existingIndex = roomVertices.IndexOf(v => v.Position == trVertex.Position && v.Color == trVertex.Color); + existingIndex = roomVertices.IndexOf(v => + v.Position == trVertex.Position && + v.Lighting1 == trVertex.Lighting1 && + v.Attributes == trVertex.Attributes && + v.Lighting2 == trVertex.Lighting2 && + v.Normal == trVertex.Normal); if (existingIndex == -1) { existingIndex = roomVertices.Count;