Skip to content

Commit

Permalink
Hash check obj faces using strings
Browse files Browse the repository at this point in the history
  • Loading branch information
KillzXGaming committed Oct 22, 2020
1 parent fca6c39 commit 5e80ca8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion KclLibrary/ObjModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public void Load(Stream stream)

ObjMesh currentMesh = new ObjMesh("Mesh");

HashSet<string> faceHashes = new HashSet<string>();

Dictionary<ObjFace, int> faceDupes = new Dictionary<ObjFace, int>();
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
Expand Down Expand Up @@ -177,13 +179,17 @@ public void Load(Stream stream)
if (args.Length != 4)
throw new Exception("Obj must be trianglulated!");

int[] indices = new int[3 * 2]; //3 faces, position and normal indices

// Only support triangles for now.
ObjFace face = new ObjFace() { Vertices = new ObjVertex[3] };
face.Material = currentMaterial;
for (int i = 0; i < face.Vertices.Length; i++)
{
string[] vertexArgs = args[i + 1].Split(_vertexSeparators, StringSplitOptions.None);
face.Vertices[i].Position = Positions[Int32.Parse(vertexArgs[0]) - 1];
int positionIndex = Int32.Parse(vertexArgs[0]) - 1;

face.Vertices[i].Position = Positions[positionIndex];

if (float.IsNaN(face.Vertices[i].Position.X) ||
float.IsNaN(face.Vertices[i].Position.Y) ||
Expand All @@ -203,6 +209,12 @@ public void Load(Stream stream)
}
}

string faceStr = face.ToString();
if (faceHashes.Contains(faceStr))
continue;

faceHashes.Add(faceStr);

if (face.Vertices != null)
currentMesh.Faces.Add(face);
continue;
Expand Down

0 comments on commit 5e80ca8

Please sign in to comment.