From b603dddae26b86c178773a76dacf04ac850acb70 Mon Sep 17 00:00:00 2001 From: igorseabra4 Date: Thu, 7 May 2020 10:55:23 -0300 Subject: [PATCH] ... --- IndustrialPark/Models/Model_IO_Assimp.cs | 21 ++++++++++++--------- IndustrialPark/SharpDX/SharpRenderer.cs | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/IndustrialPark/Models/Model_IO_Assimp.cs b/IndustrialPark/Models/Model_IO_Assimp.cs index ca9674c9..5956d3ac 100644 --- a/IndustrialPark/Models/Model_IO_Assimp.cs +++ b/IndustrialPark/Models/Model_IO_Assimp.cs @@ -102,7 +102,7 @@ public static RWSection[] CreateDFFFromAssimp(string fileName, bool flipUVs, boo (flipUVs ? PostProcessSteps.FlipUVs : 0); Scene scene = new AssimpContext().ImportFile(fileName, pps); - + int vertexCount = scene.Meshes.Sum(m => m.VertexCount); int triangleCount = scene.Meshes.Sum(m => m.FaceCount); @@ -117,7 +117,7 @@ public static RWSection[] CreateDFFFromAssimp(string fileName, bool flipUVs, boo materialStruct = new MaterialStruct_0001() { unusedFlags = 0, - color = ignoreMeshColors ? + color = ignoreMeshColors ? new RenderWareFile.Color(255, 255, 255, 255) : new RenderWareFile.Color( (byte)(m.ColorDiffuse.R * 255), @@ -154,27 +154,27 @@ public static RWSection[] CreateDFFFromAssimp(string fileName, bool flipUVs, boo } : null, materialExtension = new Extension_0003(), }); - + List vertices = new List(); List normals = new List(); List textCoords = new List(); List vertexColors = new List(); List triangles = new List(); - + foreach (var m in scene.Meshes) { int totalVertices = vertices.Count; foreach (Vector3D v in m.Vertices) vertices.Add(new Vertex3(v.X, v.Y, v.Z)); - + foreach (Vector3D v in m.Normals) normals.Add(new Vertex3(v.X, v.Y, v.Z)); if (m.HasTextureCoords(0)) foreach (Vector3D v in m.TextureCoordinateChannels[0]) textCoords.Add(new Vertex2(v.X, v.Y)); - else + else for (int i = 0; i < m.VertexCount; i++) textCoords.Add(new Vertex2(0, 0)); @@ -391,7 +391,7 @@ public static RWSection[] CreateDFFFromAssimp(string fileName, bool flipUVs, boo clumpExtension = new Extension_0003() }; - + return new RWSection[] { clump }; } @@ -428,7 +428,7 @@ public static void ExportAssimp(string fileName, RWSection[] bspFile, bool flipU PostProcessSteps.PreTransformVertices | PostProcessSteps.RemoveRedundantMaterials | PostProcessSteps.Triangulate | - PostProcessSteps.ValidateDataStructure| + PostProcessSteps.ValidateDataStructure | (flipUVs ? PostProcessSteps.FlipUVs : 0)); } @@ -453,7 +453,10 @@ private static void WorldToScene(Scene scene, World_000B world, string textureEx Name = mat.materialStruct.isTextured != 0 ? "mat_" + mat.texture.diffuseTextureName.stringString : default, }); - scene.Meshes.Add(new Mesh(PrimitiveType.Triangle) { MaterialIndex = i, Name = "mesh_" + + scene.Meshes.Add(new Mesh(PrimitiveType.Triangle) + { + MaterialIndex = i, + Name = "mesh_" + (mat.materialStruct.isTextured != 0 ? mat.texture.diffuseTextureName.stringString : ("default_" + i.ToString())) }); } diff --git a/IndustrialPark/SharpDX/SharpRenderer.cs b/IndustrialPark/SharpDX/SharpRenderer.cs index eef6aa47..f2ce768d 100644 --- a/IndustrialPark/SharpDX/SharpRenderer.cs +++ b/IndustrialPark/SharpDX/SharpRenderer.cs @@ -524,6 +524,7 @@ public void RunMainLoop(Panel Panel) tintedShader.Dispose(); foreach (SharpMesh mesh in RenderWareModelFile.completeMeshList) + if (mesh != null) mesh.Dispose(); device.Dispose();