From 7822245f7c7ae5b45a9fd6834f48e09a6c600c16 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 20:52:22 +0000 Subject: [PATCH 1/3] Initial plan From 9cfdaaac4d540afc82a19aaad99ef93cf25401d9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 20:59:15 +0000 Subject: [PATCH 2/3] fix: preserve imported geometry split normals during vertex merging Agent-Logs-Url: https://github.com/TombEngine/Tomb-Editor/sessions/03769294-8ac2-4288-892a-996f68d5d414 Co-authored-by: Nickelony <20436882+Nickelony@users.noreply.github.com> --- TombLib/TombLib/LevelData/Compilers/Rooms.cs | 5 +++-- TombLib/TombLib/LevelData/Compilers/TombEngine/Rooms.cs | 1 + TombLib/TombLib/LevelData/Room.cs | 7 +++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/TombLib/TombLib/LevelData/Compilers/Rooms.cs b/TombLib/TombLib/LevelData/Compilers/Rooms.cs index 1224b8a2dc..9ee08a212c 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,7 @@ private tr_room BuildRoom(Room room) } else { - existingIndex = roomVertices.IndexOf(v => v.Position == trVertex.Position && v.Color == trVertex.Color); + existingIndex = roomVertices.IndexOf(v => v == trVertex && 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 86ce048b32..2827235709 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 9cc2ffc08a..ca582aa62c 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,7 @@ 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 == trVertex && v.Normal == trVertex.Normal); if (existingIndex == -1) { existingIndex = roomVertices.Count; From 52adaebcce07d1d454f193879da1f45f057f3cd1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 21:00:08 +0000 Subject: [PATCH 3/3] refine: make imported geometry vertex merge comparison explicit Agent-Logs-Url: https://github.com/TombEngine/Tomb-Editor/sessions/03769294-8ac2-4288-892a-996f68d5d414 Co-authored-by: Nickelony <20436882+Nickelony@users.noreply.github.com> --- TombLib/TombLib/LevelData/Compilers/Rooms.cs | 7 ++++++- TombLib/TombLib/LevelData/Room.cs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/TombLib/TombLib/LevelData/Compilers/Rooms.cs b/TombLib/TombLib/LevelData/Compilers/Rooms.cs index 9ee08a212c..0539d09cf6 100644 --- a/TombLib/TombLib/LevelData/Compilers/Rooms.cs +++ b/TombLib/TombLib/LevelData/Compilers/Rooms.cs @@ -710,7 +710,12 @@ private tr_room BuildRoom(Room room) } else { - existingIndex = roomVertices.IndexOf(v => v == trVertex && v.Normal == trVertex.Normal); + 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/Room.cs b/TombLib/TombLib/LevelData/Room.cs index ca582aa62c..d6380acb12 100644 --- a/TombLib/TombLib/LevelData/Room.cs +++ b/TombLib/TombLib/LevelData/Room.cs @@ -1899,7 +1899,12 @@ public void GetGeometryStatistics(out int vertices, out int faces) } else { - existingIndex = roomVertices.IndexOf(v => v == trVertex && v.Normal == trVertex.Normal); + 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;