From fcc15a731fb6355d5682cf25153162b7bbcf6f4b Mon Sep 17 00:00:00 2001 From: Christopher Lees Date: Fri, 4 Sep 2026 15:33:54 +0100 Subject: [PATCH 1/2] Change: Add TriFace, TriFace2 to CSV B3D parser --- .../OpenBveApi/Objects/ObjectTypes/StaticObject.cs | 12 ++++++------ .../Formats.OpenBve/Enums/CSVB3D/CSVB3DKey.cs | 4 ++++ source/Plugins/Object.CsvB3d/Plugin.NewParser.cs | 9 +++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/source/OpenBveApi/Objects/ObjectTypes/StaticObject.cs b/source/OpenBveApi/Objects/ObjectTypes/StaticObject.cs index a99c30953..54afb8e98 100644 --- a/source/OpenBveApi/Objects/ObjectTypes/StaticObject.cs +++ b/source/OpenBveApi/Objects/ObjectTypes/StaticObject.cs @@ -12,7 +12,7 @@ namespace OpenBveApi.Objects public class StaticObject : UnifiedObject { /// Whether the object is optimized - private bool isOptimized; + public bool Optimized; /// The mesh of the object public Mesh Mesh; /// The starting track position, for static objects only. @@ -47,7 +47,7 @@ public StaticObject(HostInterface host) EndingTrackDistance = EndingTrackDistance, Dynamic = Dynamic, Mesh = {Vertices = new VertexTemplate[Mesh.Vertices.Length]}, - isOptimized = isOptimized + Optimized = Optimized }; // vertices for (int j = 0; j < Mesh.Vertices.Length; j++) @@ -89,7 +89,7 @@ public override UnifiedObject Clone() EndingTrackDistance = EndingTrackDistance, Dynamic = Dynamic, Mesh = {Vertices = new VertexTemplate[Mesh.Vertices.Length]}, - isOptimized = isOptimized + Optimized = Optimized }; // vertices for (int j = 0; j < Mesh.Vertices.Length; j++) @@ -136,7 +136,7 @@ public override UnifiedObject Mirror() } mirrorResult.Mesh.Faces[i].Flip(); } - mirrorResult.isOptimized = isOptimized; + mirrorResult.Optimized = Optimized; return mirrorResult; } @@ -589,11 +589,11 @@ public override void CreateObject(Vector3 position, Transformation worldTransfor /// public override void OptimizeObject(bool preserveVerticies, int faceThreshold, bool vertexCulling) { - if (isOptimized) + if (Optimized) { return; } - isOptimized = true; + Optimized = true; int m = Mesh.Materials.Length; int f = Mesh.Faces.Length; diff --git a/source/Plugins/Formats.OpenBve/Enums/CSVB3D/CSVB3DKey.cs b/source/Plugins/Formats.OpenBve/Enums/CSVB3D/CSVB3DKey.cs index 9f63cea2a..c67849188 100644 --- a/source/Plugins/Formats.OpenBve/Enums/CSVB3D/CSVB3DKey.cs +++ b/source/Plugins/Formats.OpenBve/Enums/CSVB3D/CSVB3DKey.cs @@ -12,9 +12,13 @@ public enum CSVB3DKey /// Adds a new 1-sided face Face, AddFace = Face, + /// Adds a new 1-sided face consisting of triangles + TriFace, /// Adds a new 2-sided face Face2, AddFace2 = Face2, + /// Adds a new 2-sided face consisting of triangles + TriFace2, /// Sets the color of all preceding faces in the MeshBuilder Color, SetColor = Color, diff --git a/source/Plugins/Object.CsvB3d/Plugin.NewParser.cs b/source/Plugins/Object.CsvB3d/Plugin.NewParser.cs index 2de49d0a0..63dac8ca6 100644 --- a/source/Plugins/Object.CsvB3d/Plugin.NewParser.cs +++ b/source/Plugins/Object.CsvB3d/Plugin.NewParser.cs @@ -73,6 +73,8 @@ internal static StaticObject ReadObject(string fileName, Encoding textEncoding) currentMeshBuilder.Vertices.Add(subBlock.GetNextVertex(out Vector3 currentNormal)); currentNormals.Add(currentNormal); break; + case CSVB3DKey.TriFace: + case CSVB3DKey.TriFace2: case CSVB3DKey.Face: case CSVB3DKey.Face2: if (subBlock.TryGetNextVertexIndexArray(out int[] faceVertices, Plugin.enabledHacks.BveTsHacks)) @@ -100,6 +102,13 @@ internal static StaticObject ReadObject(string fileName, Encoding textEncoding) (f.Vertices[l - 2], f.Vertices[l - 1]) = (f.Vertices[l - 1], f.Vertices[l - 2]); } + if (key == CSVB3DKey.TriFace || key == CSVB3DKey.TriFace2) + { + // if we're using TriFace, assume the exporter has optimised + f.Flags |= FaceFlags.Triangles; + staticObject.Optimized = true; + } + if (key == CSVB3DKey.Face2) { f.Flags |= FaceFlags.Face2Mask; From 55805313327fb207d690ed27d34521dd7356f02b Mon Sep 17 00:00:00 2001 From: Christopher Lees Date: Fri, 4 Sep 2026 15:58:34 +0100 Subject: [PATCH 2/2] Missing CSV variants --- source/Plugins/Formats.OpenBve/Enums/CSVB3D/CSVB3DKey.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/Plugins/Formats.OpenBve/Enums/CSVB3D/CSVB3DKey.cs b/source/Plugins/Formats.OpenBve/Enums/CSVB3D/CSVB3DKey.cs index c67849188..78d73e4cb 100644 --- a/source/Plugins/Formats.OpenBve/Enums/CSVB3D/CSVB3DKey.cs +++ b/source/Plugins/Formats.OpenBve/Enums/CSVB3D/CSVB3DKey.cs @@ -14,11 +14,13 @@ public enum CSVB3DKey AddFace = Face, /// Adds a new 1-sided face consisting of triangles TriFace, + AddTriFace = TriFace, /// Adds a new 2-sided face Face2, AddFace2 = Face2, /// Adds a new 2-sided face consisting of triangles TriFace2, + AddTriFace2 = TriFace2, /// Sets the color of all preceding faces in the MeshBuilder Color, SetColor = Color,