diff --git a/KclLibrary/CollisonFile/KCLFile.cs b/KclLibrary/CollisonFile/KCLFile.cs index 2be1ba5..6ac1be8 100644 --- a/KclLibrary/CollisonFile/KCLFile.cs +++ b/KclLibrary/CollisonFile/KCLFile.cs @@ -114,9 +114,26 @@ public ObjModel CreateGenericModel() { ObjModel objModel = new ObjModel(); + Dictionary meshes = new Dictionary(); + var mesh = new ObjMesh($"Mesh"); objModel.Meshes.Add(mesh); + bool spltByMaterial = true; + + foreach (KCLModel model in Models) + { + //Distinct check. Some cases prisims have a unique ID + //Only split when they don't each have their own. + var distinctPrisms = model.Prisms + .GroupBy(p => p.CollisionFlags) + .Select(g => g.First()) + .ToList().Count; + + if (distinctPrisms == model.Prisms.Length) + spltByMaterial = false; + } + foreach (KCLModel model in Models) { foreach (var face in model.Prisms) { @@ -134,7 +151,16 @@ public ObjModel CreateGenericModel() }; } - mesh.Faces.Add(objFace); + if (spltByMaterial) + { + if (!meshes.ContainsKey(objFace.Material)) { + meshes.Add(objFace.Material, new ObjMesh(objFace.Material)); + objModel.Meshes.Add(meshes[objFace.Material]); + } + meshes[objFace.Material].Faces.Add(objFace); + } + else + mesh.Faces.Add(objFace); } } return objModel;