Skip to content

Commit

Permalink
OBJ : Split prisms by meshes.
Browse files Browse the repository at this point in the history
  • Loading branch information
KillzXGaming committed Oct 24, 2020
1 parent 5e80ca8 commit ea897e3
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion KclLibrary/CollisonFile/KCLFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,26 @@ public ObjModel CreateGenericModel()
{
ObjModel objModel = new ObjModel();

Dictionary<string, ObjMesh> meshes = new Dictionary<string, ObjMesh>();

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)
{
Expand All @@ -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;
Expand Down

0 comments on commit ea897e3

Please sign in to comment.