Skip to content

Commit

Permalink
Refactor object meshes (LostArtefacts#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm86 authored Apr 22, 2024
1 parent 86d6eff commit 559d370
Show file tree
Hide file tree
Showing 43 changed files with 616 additions and 1,233 deletions.
Binary file modified Deps/TRGE.Coord.dll
Binary file not shown.
80 changes: 40 additions & 40 deletions TREnvironmentEditor/Model/Types/Mirroring/EMMirrorFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,28 +1051,28 @@ private static void MirrorTextures(TR1Level level)
TRMesh mesh = TRMeshUtilities.GetMesh(level, staticMesh.Mesh);

// Flip the faces and store texture references
foreach (TRFace4 f in mesh.TexturedRectangles)
foreach (TRMeshFace face in mesh.TexturedRectangles)
{
Swap(f.Vertices, 0, 3);
Swap(f.Vertices, 1, 2);
textureReferences.Add(f.Texture);
face.SwapVertices(0, 3);
face.SwapVertices(1, 2);
textureReferences.Add(face.Texture);
}

foreach (TRFace4 f in mesh.ColouredRectangles)
foreach (TRMeshFace face in mesh.ColouredRectangles)
{
Swap(f.Vertices, 0, 3);
Swap(f.Vertices, 1, 2);
face.SwapVertices(0, 3);
face.SwapVertices(1, 2);
}

foreach (TRFace3 f in mesh.TexturedTriangles)
foreach (TRMeshFace face in mesh.TexturedTriangles)
{
Swap(f.Vertices, 0, 2);
textureReferences.Add(f.Texture);
face.SwapVertices(0, 2);
textureReferences.Add(face.Texture);
}

foreach (TRFace3 f in mesh.ColouredTriangles)
foreach (TRMeshFace face in mesh.ColouredTriangles)
{
Swap(f.Vertices, 0, 2);
face.SwapVertices(0, 2);
}
}
}
Expand Down Expand Up @@ -1132,28 +1132,28 @@ private static void MirrorTextures(TR2Level level)
TRMesh mesh = TRMeshUtilities.GetMesh(level, staticMesh.Mesh);

// Flip the faces and store texture references
foreach (TRFace4 f in mesh.TexturedRectangles)
foreach (TRMeshFace face in mesh.TexturedRectangles)
{
Swap(f.Vertices, 0, 3);
Swap(f.Vertices, 1, 2);
textureReferences.Add(f.Texture);
face.SwapVertices(0, 3);
face.SwapVertices(1, 2);
textureReferences.Add(face.Texture);
}

foreach (TRFace4 f in mesh.ColouredRectangles)
foreach (TRMeshFace face in mesh.ColouredRectangles)
{
Swap(f.Vertices, 0, 3);
Swap(f.Vertices, 1, 2);
face.SwapVertices(0, 3);
face.SwapVertices(1, 2);
}

foreach (TRFace3 f in mesh.TexturedTriangles)
foreach (TRMeshFace face in mesh.TexturedTriangles)
{
Swap(f.Vertices, 0, 2);
textureReferences.Add(f.Texture);
face.SwapVertices(0, 2);
textureReferences.Add(face.Texture);
}

foreach (TRFace3 f in mesh.ColouredTriangles)
foreach (TRMeshFace face in mesh.ColouredTriangles)
{
Swap(f.Vertices, 0, 2);
face.SwapVertices(0, 2);
}
}
}
Expand Down Expand Up @@ -1204,28 +1204,28 @@ private static void MirrorTextures(TR3Level level)
TRMesh mesh = TRMeshUtilities.GetMesh(level, staticMesh.Mesh);

// Flip the faces and store texture references
foreach (TRFace4 f in mesh.TexturedRectangles)
foreach (TRMeshFace face in mesh.TexturedRectangles)
{
Swap(f.Vertices, 0, 3);
Swap(f.Vertices, 1, 2);
textureReferences.Add((ushort)(f.Texture & 0x0fff));
face.SwapVertices(0, 3);
face.SwapVertices(1, 2);
textureReferences.Add((ushort)(face.Texture & 0x0fff));
}

foreach (TRFace4 f in mesh.ColouredRectangles)
foreach (TRMeshFace face in mesh.ColouredRectangles)
{
Swap(f.Vertices, 0, 3);
Swap(f.Vertices, 1, 2);
face.SwapVertices(0, 3);
face.SwapVertices(1, 2);
}

foreach (TRFace3 f in mesh.TexturedTriangles)
foreach (TRMeshFace face in mesh.TexturedTriangles)
{
Swap(f.Vertices, 0, 2);
textureReferences.Add((ushort)(f.Texture & 0x0fff));
face.SwapVertices(0, 2);
textureReferences.Add((ushort)(face.Texture & 0x0fff));
}

foreach (TRFace3 f in mesh.ColouredTriangles)
foreach (TRMeshFace face in mesh.ColouredTriangles)
{
Swap(f.Vertices, 0, 2);
face.SwapVertices(0, 2);
}
}
}
Expand Down Expand Up @@ -1275,12 +1275,12 @@ private static void MirrorDependentFaces(IEnumerable<TRModel> models, ISet<ushor

foreach (TRMesh mesh in meshes)
{
foreach (TRFace4 f in mesh.TexturedRectangles)
foreach (TRMeshFace face in mesh.TexturedRectangles)
{
if (textureReferences.Contains(f.Texture))
if (textureReferences.Contains(face.Texture))
{
Swap(f.Vertices, 0, 2);
Swap(f.Vertices, 1, 3);
face.SwapVertices(0, 2);
face.SwapVertices(1, 3);
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions TREnvironmentEditor/Model/Types/Mirroring/EMMirrorModelFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,28 @@ private static ISet<ushort> MirrorMeshes(List<TRMesh> meshes)
}
}

foreach (TRFace4 f in mesh.TexturedRectangles)
foreach (TRMeshFace face in mesh.TexturedRectangles)
{
Swap(f.Vertices, 0, 3);
Swap(f.Vertices, 1, 2);
textureReferences.Add((ushort)(f.Texture & 0x0fff));
face.SwapVertices(0, 3);
face.SwapVertices(1, 2);
textureReferences.Add((ushort)(face.Texture & 0x0fff));
}

foreach (TRFace4 f in mesh.ColouredRectangles)
foreach (TRMeshFace face in mesh.ColouredRectangles)
{
Swap(f.Vertices, 0, 3);
Swap(f.Vertices, 1, 2);
face.SwapVertices(0, 3);
face.SwapVertices(1, 2);
}

foreach (TRFace3 f in mesh.TexturedTriangles)
foreach (TRMeshFace face in mesh.TexturedTriangles)
{
Swap(f.Vertices, 0, 2);
textureReferences.Add((ushort)(f.Texture & 0x0fff));
face.SwapVertices(0, 2);
textureReferences.Add((ushort)(face.Texture & 0x0fff));
}

foreach (TRFace3 f in mesh.ColouredTriangles)
foreach (TRMeshFace face in mesh.ColouredTriangles)
{
Swap(f.Vertices, 0, 2);
face.SwapVertices(0, 2);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,27 @@ private static void MirrorMeshes(IEnumerable<TRMesh> meshes)
}
}

foreach (TRFace4 f in mesh.TexturedRectangles)
foreach (TRMeshFace face in mesh.TexturedRectangles)
{
Swap(f.Vertices, 0, 3);
Swap(f.Vertices, 1, 2);
face.SwapVertices(0, 3);
face.SwapVertices(1, 2);
}

foreach (TRFace4 f in mesh.ColouredRectangles)
foreach (TRMeshFace face in mesh.ColouredRectangles)
{
Swap(f.Vertices, 0, 3);
Swap(f.Vertices, 1, 2);
face.SwapVertices(0, 3);
face.SwapVertices(1, 2);
}

foreach (TRFace3 f in mesh.TexturedTriangles)
foreach (TRMeshFace face in mesh.TexturedTriangles)
{
Swap(f.Vertices, 0, 2);
face.SwapVertices(0, 2);
}

foreach (TRFace3 f in mesh.ColouredTriangles)
foreach (TRMeshFace face in mesh.ColouredTriangles)
{
Swap(f.Vertices, 0, 2);
face.SwapVertices(0, 2);
}
}
}

private static void Swap<T>(T[] arr, int pos1, int pos2)
{
(arr[pos2], arr[pos1]) = (arr[pos1], arr[pos2]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ private static void RemapFaces(List<EMMeshTextureData> data, int maximumTexture,
List<TRMesh> meshes = meshAction.Invoke(textureData.ModelID);
foreach (TRMesh mesh in meshes)
{
foreach (TRFace3 face in mesh.ColouredTriangles)
foreach (TRMeshFace face in mesh.ColouredTriangles)
{
face.Texture = SelectReplacementTexture(textureData, face.Texture, textureData.ColouredFace3, maximumTexture);
}
foreach (TRFace4 face in mesh.ColouredRectangles)
foreach (TRMeshFace face in mesh.ColouredRectangles)
{
face.Texture = SelectReplacementTexture(textureData, face.Texture, textureData.ColouredFace4, maximumTexture);
}
foreach (TRFace3 face in mesh.TexturedTriangles)
foreach (TRMeshFace face in mesh.TexturedTriangles)
{
face.Texture = SelectReplacementTexture(textureData, face.Texture, textureData.TexturedFace3, maximumTexture);
}
foreach (TRFace4 face in mesh.TexturedRectangles)
foreach (TRMeshFace face in mesh.TexturedRectangles)
{
face.Texture = SelectReplacementTexture(textureData, face.Texture, textureData.TexturedFace4, maximumTexture);
}
Expand Down
Loading

0 comments on commit 559d370

Please sign in to comment.