Skip to content

Commit

Permalink
Use rondreas/quad-support xatlas
Browse files Browse the repository at this point in the history
  • Loading branch information
iffyloop committed Sep 26, 2024
1 parent 5962272 commit 4a5e18e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ int main(int argc, char *argv[])
outFile << "v " << pos[0] << " " << pos[1] << " " << pos[2] << "\n";
outFile << "vt " << vertex.uv[0] / static_cast<float>(atlas->width) << " " << vertex.uv[1] / static_cast<float>(atlas->height) << "\n";
}
std::size_t currentFaceIndex = 0;
std::size_t totalFaceIndex = 0;
for (std::size_t i = 0; i < outFacesNumVertices.size(); ++i)
{
outFile << "f";
const std::size_t index = atlas->meshes[0].indexArray[currentFaceIndex];
for (std::size_t j = 0; j < outFacesNumVertices[i]; ++j)
{
const std::size_t index = atlas->meshes[0].indexArray[totalFaceIndex] + 1;
outFile << " " << index << "/" << index;
++totalFaceIndex;
}
outFile << "\n";
++currentFaceIndex;
}

std::cout << "AutoRemesher done!\n";
Expand Down
16 changes: 11 additions & 5 deletions thirdparty/xatlas/source/xatlas/xatlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9083,28 +9083,27 @@ AddMeshError AddMesh(Atlas *atlas, const MeshDecl &meshDecl, uint32_t meshCountH
meshPolygonMapping->triangleToPolygonMap.reserve(meshDecl.faceCount);
meshPolygonMapping->triangleToPolygonIndicesMap.reserve(meshDecl.indexCount);
}
uint32_t firstIndex = 0;
const uint32_t kMaxWarnings = 50;
uint32_t warningCount = 0;
internal::Array<uint32_t> triIndices;
internal::Triangulator triangulator;
uint32_t allFacesI = 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, allFacesI);
polygon[i] = DecodeIndex(meshDecl.indexFormat, meshDecl.indexData, meshDecl.indexOffset, firstIndex + 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] = allFacesI;
polygon[i] = face * faceVertexCount + i;
}
++allFacesI;
}
// Ignore faces with degenerate or zero length edges.
bool ignore = false;
Expand Down Expand Up @@ -9193,10 +9192,17 @@ AddMeshError AddMesh(Atlas *atlas, const MeshDecl &meshDecl, uint32_t meshCountH
if (meshPolygonMapping)
meshPolygonMapping->triangleToPolygonMap.push_back(face);
}
// For each triangle index, store original index location
if (meshPolygonMapping) {
for (uint32_t i = 0; i < triIndices.size(); i++)
meshPolygonMapping->triangleToPolygonIndicesMap.push_back(triIndices[i]);
{
uint32_t polygonIndex = 0;
for (polygonIndex; polygonIndex < faceVertexCount; polygonIndex++)
if (triIndices[i] == polygon[polygonIndex]) break;
meshPolygonMapping->triangleToPolygonIndicesMap.push_back(firstIndex+polygonIndex);
}
}
firstIndex += faceVertexCount;
}
if (warningCount > kMaxWarnings)
XA_PRINT(" %u additional warnings truncated\n", warningCount - kMaxWarnings);
Expand Down

0 comments on commit 4a5e18e

Please sign in to comment.