Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible Fix for faceVertexCount logic #136

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions source/xatlas/xatlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9087,23 +9087,25 @@ AddMeshError AddMesh(Atlas *atlas, const MeshDecl &meshDecl, uint32_t meshCountH
uint32_t warningCount = 0;
internal::Array<uint32_t> triIndices;
internal::Triangulator triangulator;
uint32_t currentFaceStartIndex = 0;
for (uint32_t face = 0; face < faceCount; face++) {
// Decode face indices.
const uint32_t faceVertexCount = meshDecl.faceVertexCount ? (uint32_t)meshDecl.faceVertexCount[face] : 3;
uint32_t polygon[UINT8_MAX];
for (uint32_t i = 0; i < faceVertexCount; i++) {
if (hasIndices) {
polygon[i] = DecodeIndex(meshDecl.indexFormat, meshDecl.indexData, meshDecl.indexOffset, face * faceVertexCount + i);
polygon[i] = DecodeIndex(meshDecl.indexFormat, meshDecl.indexData, meshDecl.indexOffset, currentFaceStartIndex + i);
// Check if any index is out of range.
if (polygon[i] >= meshDecl.vertexCount) {
mesh->~Mesh();
XA_FREE(mesh);
return AddMeshError::IndexOutOfRange;
}
} else {
polygon[i] = face * faceVertexCount + i;
polygon[i] = currentFaceStartIndex + i;
}
}
currentFaceStartIndex += faceVertexCount;
// Ignore faces with degenerate or zero length edges.
bool ignore = false;
for (uint32_t i = 0; i < faceVertexCount; i++) {
Expand Down