From 994c1939e1dcb4a8188f397a2961c57ecf3e8f55 Mon Sep 17 00:00:00 2001 From: VirtualBrightPlayz Date: Sat, 26 Nov 2022 09:44:19 -0700 Subject: [PATCH] fix model baking --- CBRE.Editor/Compiling/Lightmap/Lightmapper.cs | 24 +++++++++---------- CBRE.Providers/Map/RMeshProvider.cs | 6 +++-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/CBRE.Editor/Compiling/Lightmap/Lightmapper.cs b/CBRE.Editor/Compiling/Lightmap/Lightmapper.cs index e270a8570..d103b0638 100644 --- a/CBRE.Editor/Compiling/Lightmap/Lightmapper.cs +++ b/CBRE.Editor/Compiling/Lightmap/Lightmapper.cs @@ -125,19 +125,19 @@ public Lightmapper(Document document) { TextureU = (decimal)(x.TextureU), TextureV = (decimal)(x.TextureV), }); - tFace.Vertices.Clear(); - tFace.Vertices.AddRange(verts); - /*for (int i = 0; i < mesh.Vertices.Count - 1; i+=2) { - tFace.Vertices.Add(verts.ElementAt(i+0)); + for (int i = 0; i < mesh.Vertices.Count; i+=3) { + tFace.Vertices.Clear(); + tFace.Vertices.Add(verts.ElementAt(i)); tFace.Vertices.Add(verts.ElementAt(i+1)); - }*/ - tFace.Plane = new DataStructures.Geometric.Plane(tFace.Vertices[0].Location, tFace.Vertices[1].Location, tFace.Vertices[2].Location); - tFace.Vertices.ForEach(v => { v.LMU = -500.0f; v.LMV = -500.0f; }); - tFace.UpdateBoundingBox(); - LMFace face = new LMFace(tFace.Clone()); - BoxF faceBox = new BoxF(face.BoundingBox.Start - new Vector3F(3.0f, 3.0f, 3.0f), face.BoundingBox.End + new Vector3F(3.0f, 3.0f, 3.0f)); - // opaqueFaces.Add(face); - modelFaces.Add(face); + tFace.Vertices.Add(verts.ElementAt(i+2)); + tFace.Plane = new DataStructures.Geometric.Plane(tFace.Vertices[0].Location, tFace.Vertices[1].Location, tFace.Vertices[2].Location); + tFace.Vertices.ForEach(v => { v.LMU = -500.0f; v.LMV = -500.0f; }); + tFace.UpdateBoundingBox(); + LMFace face = new LMFace(tFace.Clone()); + BoxF faceBox = new BoxF(face.BoundingBox.Start - new Vector3F(3.0f, 3.0f, 3.0f), face.BoundingBox.End + new Vector3F(3.0f, 3.0f, 3.0f)); + // opaqueFaces.Add(face); + modelFaces.Add(face); + } } } } diff --git a/CBRE.Providers/Map/RMeshProvider.cs b/CBRE.Providers/Map/RMeshProvider.cs index 7b0449c5b..d40c07aba 100644 --- a/CBRE.Providers/Map/RMeshProvider.cs +++ b/CBRE.Providers/Map/RMeshProvider.cs @@ -90,11 +90,13 @@ public static void SaveToFile(string path, DataStructures.MapObjects.Map map, Te new Vector3F(fv.Location.XZY()), new Vector2F((float)fv.TextureU, (float)fv.TextureV), new Vector2F((float)fv.LMU, (float)fv.LMV), Color.FromArgb(0xff, (byte)(fv.Color.X * 255f), (byte)(fv.Color.Y * 255f), (byte)(fv.Color.Z * 255f))))); + /* for (int i = 0; i < vertices.Count; i+=3) { triangles.Add(new RMesh.RMesh.Triangle((ushort)i, (ushort)(i+1), (ushort)(i+2))); } - /*triangles.AddRange(face.GetTriangleIndices().Chunk(3).Select(c => new RMesh.RMesh.Triangle( - (ushort)(c[0] + indexOffset), (ushort)(c[1] + indexOffset), (ushort)(c[2] + indexOffset))));*/ + */ + triangles.AddRange(face.GetTriangleIndices().Chunk(3).Select(c => new RMesh.RMesh.Triangle( + (ushort)(c[0] + indexOffset), (ushort)(c[1] + indexOffset), (ushort)(c[2] + indexOffset)))); indexOffset += face.Vertices.Count; if (face.Texture.Name.ToLowerInvariant() == "tooltextures/invisible_collision") {