Skip to content

Commit

Permalink
fix: PrimKey needs to check equality for each material list element
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed Apr 20, 2021
1 parent 587cee9 commit e3d3bc1
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions UnityGLTF/Assets/UnityGLTF/Runtime/Scripts/GLTFSceneExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,41 @@ private struct ImageInfo

protected struct PrimKey
{
public bool Equals(PrimKey other)
{
if (!Equals(Mesh, other.Mesh)) return false;
if (Materials == null && other.Materials == null) return true;
if (!(Materials != null && other.Materials != null)) return false;
if (!Equals(Materials.Length, other.Materials.Length)) return false;
for (var i = 0; i < Materials.Length; i++)
{
if (!Equals(Materials[i], other.Materials[i])) return false;
}

return true;
}

public override bool Equals(object obj)
{
return obj is PrimKey other && Equals(other);
}

public override int GetHashCode()
{
unchecked
{
var code = (Mesh != null ? Mesh.GetHashCode() : 0) * 397;
if (Materials != null)
{
code = code ^ Materials.Length.GetHashCode() * 397;
foreach (var mat in Materials)
code = (code ^ (mat != null ? mat.GetHashCode() : 0)) * 397;
}

return code;
}
}

public Mesh Mesh;
public Material[] Materials;
}
Expand Down

0 comments on commit e3d3bc1

Please sign in to comment.