Fix crash when importing fbx model with convex polygon with duplicated vertices
#3222
This commit is contained in:
@@ -669,16 +669,31 @@ int Triangulate(OpenFbxImporterData& data, const ofbx::GeometryData& geom, const
|
||||
earIndices.Add(indices[i1]);
|
||||
earIndices.Add(indices[i2]);
|
||||
earIndices.Add(indices[i3]);
|
||||
|
||||
// Remove midpoint of the ear from the loop
|
||||
indices.RemoveAtKeepOrder(i2);
|
||||
}
|
||||
|
||||
for (int i = 0; i < earIndices.Count(); i++)
|
||||
triangulatedIndices[i] = polygon.from_vertex + (earIndices[i] % polygon.vertex_count);
|
||||
triangulatedIndices[earIndices.Count() + 0] = polygon.from_vertex + (indices[0] % polygon.vertex_count);
|
||||
triangulatedIndices[earIndices.Count() + 1] = polygon.from_vertex + (indices[1] % polygon.vertex_count);
|
||||
triangulatedIndices[earIndices.Count() + 2] = polygon.from_vertex + (indices[2] % polygon.vertex_count);
|
||||
// Last ear
|
||||
earIndices.Add(indices[0]);
|
||||
earIndices.Add(indices[1]);
|
||||
earIndices.Add(indices[2]);
|
||||
|
||||
// Write any degenerate triangles (eg. if points are duplicated within a list)
|
||||
for (int32 i = 3; i < indices.Count(); i += 3)
|
||||
{
|
||||
earIndices.Add(indices[i + 0]);
|
||||
earIndices.Add(indices[(i + 1) % indices.Count()]);
|
||||
earIndices.Add(indices[(i + 2) % indices.Count()]);
|
||||
}
|
||||
|
||||
return 3 * (polygon.vertex_count - 2);
|
||||
// Copy ears into triangles
|
||||
for (int32 i = 0; i < earIndices.Count(); i++)
|
||||
triangulatedIndices[i] = polygon.from_vertex + (earIndices[i] % polygon.vertex_count);
|
||||
|
||||
// Ensure that we've written enough ears
|
||||
ASSERT(earIndices.Count() == 3 * (polygon.vertex_count - 2));
|
||||
return earIndices.Count();
|
||||
}
|
||||
|
||||
bool ProcessMesh(ModelData& result, OpenFbxImporterData& data, const ofbx::Mesh* aMesh, MeshData& mesh, String& errorMsg, int partitionIndex)
|
||||
@@ -715,6 +730,7 @@ bool ProcessMesh(ModelData& result, OpenFbxImporterData& data, const ofbx::Mesh*
|
||||
mesh.Positions.Get()[j] = ToFloat3(positions.get(triangulatedIndices[j]));
|
||||
numIndicesTotal += numIndices;
|
||||
}
|
||||
ASSERT(numIndicesTotal == vertexCount);
|
||||
}
|
||||
|
||||
// Indices (dummy index buffer)
|
||||
|
||||
Reference in New Issue
Block a user