forked from LostArtefacts/TR-Rando
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Main level mirroring implemented for TR3, including the minor environment changes needed for awkward doors and suchlike in each level. - Function added to mirror a model, but this is only possible for ones that have only one mesh and no animations (Slot2 in Antarctica for example). - Move slot function implemented for TR3. - Mirroring option made available in UI (no other environment options yet).
- Loading branch information
Showing
23 changed files
with
966 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ public enum EMType | |
|
||
// Models | ||
ImportModel = 141, | ||
MirrorModel = 142, | ||
|
||
// NOOP/Placeholder | ||
NOOP = 1000 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
526 changes: 469 additions & 57 deletions
526
TREnvironmentEditor/Model/Types/Mirroring/EMMirrorFunction.cs
Large diffs are not rendered by default.
Oops, something went wrong.
123 changes: 123 additions & 0 deletions
123
TREnvironmentEditor/Model/Types/Mirroring/EMMirrorModelFunction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using TRLevelReader.Helpers; | ||
using TRLevelReader.Model; | ||
using TRLevelReader.Model.Enums; | ||
using TRModelTransporter.Model.Textures; | ||
|
||
namespace TREnvironmentEditor.Model.Types | ||
{ | ||
public class EMMirrorModelFunction : BaseEMFunction | ||
{ | ||
public uint[] ModelIDs { get; set; } | ||
|
||
public override void ApplyToLevel(TR2Level level) | ||
{ | ||
List<TRMesh> meshes = new List<TRMesh>(); | ||
foreach (uint modelID in ModelIDs) | ||
{ | ||
TRMesh[] modelMeshes = TRMeshUtilities.GetModelMeshes(level, (TR2Entities)modelID); | ||
if (modelMeshes == null || modelMeshes.Length > 1) | ||
{ | ||
throw new NotSupportedException("Only models with single meshes can be mirrored."); | ||
} | ||
|
||
meshes.Add(modelMeshes[0]); | ||
} | ||
|
||
MirrorObjectTextures(MirrorMeshes(meshes), level.ObjectTextures); | ||
} | ||
|
||
public override void ApplyToLevel(TR3Level level) | ||
{ | ||
List<TRMesh> meshes = new List<TRMesh>(); | ||
foreach (uint modelID in ModelIDs) | ||
{ | ||
TRMesh[] modelMeshes = TRMeshUtilities.GetModelMeshes(level, (TR3Entities)modelID); | ||
if (modelMeshes == null || modelMeshes.Length > 1) | ||
{ | ||
throw new NotSupportedException("Only models with single meshes can be mirrored."); | ||
} | ||
|
||
meshes.Add(modelMeshes[0]); | ||
} | ||
|
||
MirrorObjectTextures(MirrorMeshes(meshes), level.ObjectTextures); | ||
} | ||
|
||
private ISet<ushort> MirrorMeshes(List<TRMesh> meshes) | ||
{ | ||
ISet<ushort> textureReferences = new HashSet<ushort>(); | ||
|
||
foreach (TRMesh mesh in meshes) | ||
{ | ||
foreach (TRVertex vert in mesh.Vertices) | ||
{ | ||
vert.X *= -1; | ||
} | ||
|
||
if (mesh.Normals != null) | ||
{ | ||
foreach (TRVertex norm in mesh.Normals) | ||
{ | ||
norm.X *= -1; | ||
} | ||
} | ||
|
||
foreach (TRFace4 f in mesh.TexturedRectangles) | ||
{ | ||
Swap(f.Vertices, 0, 3); | ||
Swap(f.Vertices, 1, 2); | ||
textureReferences.Add((ushort)(f.Texture & 0x0fff)); | ||
} | ||
|
||
foreach (TRFace4 f in mesh.ColouredRectangles) | ||
{ | ||
Swap(f.Vertices, 0, 3); | ||
Swap(f.Vertices, 1, 2); | ||
} | ||
|
||
foreach (TRFace3 f in mesh.TexturedTriangles) | ||
{ | ||
Swap(f.Vertices, 0, 2); | ||
textureReferences.Add((ushort)(f.Texture & 0x0fff)); | ||
} | ||
|
||
foreach (TRFace3 f in mesh.ColouredTriangles) | ||
{ | ||
Swap(f.Vertices, 0, 2); | ||
} | ||
} | ||
|
||
return textureReferences; | ||
} | ||
|
||
private void MirrorObjectTextures(ISet<ushort> textureReferences, TRObjectTexture[] objectTextures) | ||
{ | ||
foreach (ushort textureRef in textureReferences) | ||
{ | ||
IndexedTRObjectTexture texture = new IndexedTRObjectTexture | ||
{ | ||
Texture = objectTextures[textureRef] | ||
}; | ||
|
||
if (texture.IsTriangle) | ||
{ | ||
Swap(texture.Texture.Vertices, 0, 2); | ||
} | ||
else | ||
{ | ||
Swap(texture.Texture.Vertices, 0, 3); | ||
Swap(texture.Texture.Vertices, 1, 2); | ||
} | ||
} | ||
} | ||
|
||
private static void Swap<T>(T[] arr, int pos1, int pos2) | ||
{ | ||
T temp = arr[pos1]; | ||
arr[pos1] = arr[pos2]; | ||
arr[pos2] = temp; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
TRRandomizerCore/Resources/TR3/Environment/NEVADA.TR2-Environment.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"Mirrored": [ | ||
{ | ||
"Comments": "Convert two of the planes to the other kind.", | ||
"EMType": 45, | ||
"EntityIndex": 8, | ||
"NewEntityType": 351 | ||
}, | ||
{ | ||
"EMType": 45, | ||
"EntityIndex": 113, | ||
"NewEntityType": 351 | ||
} | ||
] | ||
} |
16 changes: 16 additions & 0 deletions
16
TRRandomizerCore/Resources/TR3/Environment/ROOFS.TR2-Environment.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"Mirrored": [ | ||
{ | ||
"Comments": "Move door #34 otherwise Lara can't pass.", | ||
"EMType": 44, | ||
"EntityIndex": 34, | ||
"TargetLocation": { | ||
"X": 48640, | ||
"Y": -8448, | ||
"Z": 36352, | ||
"Room": 43, | ||
"Angle": -32768 | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.