mirror of
https://github.com/Relintai/mesh_utils.git
synced 2025-02-04 16:05:55 +01:00
Bit more work on xatlas.
This commit is contained in:
parent
e40a4cea4a
commit
b6940f3799
@ -2395,6 +2395,42 @@ public:
|
|||||||
for (uint32_t i = 0; i < faceCount; i++) {
|
for (uint32_t i = 0; i < faceCount; i++) {
|
||||||
if (isFaceIgnored(i))
|
if (isFaceIgnored(i))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
for (uint32_t j = 0; j < 3; j++) {
|
||||||
|
const uint32_t edge = i * 3 + j;
|
||||||
|
const uint32_t vertex0 = m_indices[edge];
|
||||||
|
const uint32_t vertex1 = m_indices[i * 3 + (j + 1) % 3];
|
||||||
|
|
||||||
|
// If there is an edge with opposite winding to this one, the edge isn't on a boundary. (orig)
|
||||||
|
//I have a boundary where vertices are not joined by indices -> they shouldnt be the same
|
||||||
|
//does xatlas merge verts?
|
||||||
|
|
||||||
|
const uint32_t oppositeEdge = findEdge(vertex1, vertex0);
|
||||||
|
if (oppositeEdge != UINT32_MAX) {
|
||||||
|
m_oppositeEdges[edge] = oppositeEdge;
|
||||||
|
} else {
|
||||||
|
m_boundaryEdges.push_back(edge);
|
||||||
|
m_isBoundaryVertex.set(vertex0);
|
||||||
|
m_isBoundaryVertex.set(vertex1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void createBoundariesOriginal() {
|
||||||
|
const uint32_t edgeCount = m_indices.size();
|
||||||
|
const uint32_t vertexCount = m_positions.size();
|
||||||
|
m_oppositeEdges.resize(edgeCount);
|
||||||
|
m_boundaryEdges.reserve(uint32_t(edgeCount * 0.1f));
|
||||||
|
m_isBoundaryVertex.resize(vertexCount);
|
||||||
|
m_isBoundaryVertex.zeroOutMemory();
|
||||||
|
for (uint32_t i = 0; i < edgeCount; i++)
|
||||||
|
m_oppositeEdges[i] = UINT32_MAX;
|
||||||
|
const uint32_t faceCount = m_indices.size() / 3;
|
||||||
|
for (uint32_t i = 0; i < faceCount; i++) {
|
||||||
|
if (isFaceIgnored(i))
|
||||||
|
continue;
|
||||||
|
|
||||||
for (uint32_t j = 0; j < 3; j++) {
|
for (uint32_t j = 0; j < 3; j++) {
|
||||||
const uint32_t edge = i * 3 + j;
|
const uint32_t edge = i * 3 + j;
|
||||||
const uint32_t vertex0 = m_indices[edge];
|
const uint32_t vertex0 = m_indices[edge];
|
||||||
@ -2426,6 +2462,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If colocals were created, try every permutation.
|
// If colocals were created, try every permutation.
|
||||||
|
/*
|
||||||
if (!m_nextColocalVertex.isEmpty()) {
|
if (!m_nextColocalVertex.isEmpty()) {
|
||||||
uint32_t colocalVertex0 = vertex0;
|
uint32_t colocalVertex0 = vertex0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -2447,7 +2484,7 @@ public:
|
|||||||
if (colocalVertex0 == vertex0)
|
if (colocalVertex0 == vertex0)
|
||||||
break; // Back to start.
|
break; // Back to start.
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
return UINT32_MAX;
|
return UINT32_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4511,7 +4548,7 @@ struct AtlasData {
|
|||||||
const uint32_t edgeCount = mesh->edgeCount();
|
const uint32_t edgeCount = mesh->edgeCount();
|
||||||
edgeDihedralAngles.resize(edgeCount);
|
edgeDihedralAngles.resize(edgeCount);
|
||||||
edgeLengths.resize(edgeCount);
|
edgeLengths.resize(edgeCount);
|
||||||
|
|
||||||
faceAreas.resize(faceCount);
|
faceAreas.resize(faceCount);
|
||||||
//if (options.useInputMeshUvs)
|
//if (options.useInputMeshUvs)
|
||||||
faceUvAreas.resize(faceCount);
|
faceUvAreas.resize(faceCount);
|
||||||
@ -5688,6 +5725,7 @@ public:
|
|||||||
}
|
}
|
||||||
m_unifiedMesh->addFace(unifiedIndices);
|
m_unifiedMesh->addFace(unifiedIndices);
|
||||||
}
|
}
|
||||||
|
printf("cre\n");
|
||||||
m_unifiedMesh->createBoundaries();
|
m_unifiedMesh->createBoundaries();
|
||||||
#if XA_CHECK_T_JUNCTIONS
|
#if XA_CHECK_T_JUNCTIONS
|
||||||
m_tjunctionCount = meshCheckTJunctions(*m_unifiedMesh);
|
m_tjunctionCount = meshCheckTJunctions(*m_unifiedMesh);
|
||||||
@ -5744,6 +5782,7 @@ public:
|
|||||||
}
|
}
|
||||||
m_unifiedMesh->addFace(unifiedIndices);
|
m_unifiedMesh->addFace(unifiedIndices);
|
||||||
}
|
}
|
||||||
|
printf("cre2\n");
|
||||||
m_unifiedMesh->createBoundaries();
|
m_unifiedMesh->createBoundaries();
|
||||||
// Need to store texcoords for backup/restore so packing can be run multiple times.
|
// Need to store texcoords for backup/restore so packing can be run multiple times.
|
||||||
backupTexcoords();
|
backupTexcoords();
|
||||||
@ -6198,6 +6237,7 @@ private:
|
|||||||
mesh->createColocals();
|
mesh->createColocals();
|
||||||
XA_PROFILE_END(createChartGroupMeshColocals)
|
XA_PROFILE_END(createChartGroupMeshColocals)
|
||||||
XA_PROFILE_START(createChartGroupMeshBoundaries)
|
XA_PROFILE_START(createChartGroupMeshBoundaries)
|
||||||
|
printf("cre3\n");
|
||||||
mesh->createBoundaries();
|
mesh->createBoundaries();
|
||||||
mesh->destroyEdgeMap(); // Only needed it for createBoundaries.
|
mesh->destroyEdgeMap(); // Only needed it for createBoundaries.
|
||||||
XA_PROFILE_END(createChartGroupMeshBoundaries)
|
XA_PROFILE_END(createChartGroupMeshBoundaries)
|
||||||
@ -6582,27 +6622,33 @@ struct AddChartTaskArgs {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void runAddChartTask(void *groupUserData, void *taskUserData) {
|
static void runAddChartTask(void *groupUserData, void *taskUserData) {
|
||||||
|
printf("1\n");
|
||||||
XA_PROFILE_START(packChartsAddChartsThread)
|
XA_PROFILE_START(packChartsAddChartsThread)
|
||||||
auto boundingBox = (ThreadLocal<BoundingBox2D> *)groupUserData;
|
auto boundingBox = (ThreadLocal<BoundingBox2D> *)groupUserData;
|
||||||
auto args = (AddChartTaskArgs *)taskUserData;
|
auto args = (AddChartTaskArgs *)taskUserData;
|
||||||
param::Chart *paramChart = args->paramChart;
|
param::Chart *paramChart = args->paramChart;
|
||||||
|
printf("2\n");
|
||||||
XA_PROFILE_START(packChartsAddChartsRestoreTexcoords)
|
XA_PROFILE_START(packChartsAddChartsRestoreTexcoords)
|
||||||
paramChart->restoreTexcoords();
|
paramChart->restoreTexcoords();
|
||||||
XA_PROFILE_END(packChartsAddChartsRestoreTexcoords)
|
XA_PROFILE_END(packChartsAddChartsRestoreTexcoords)
|
||||||
|
printf("3\n");
|
||||||
Mesh *mesh = paramChart->unifiedMesh();
|
Mesh *mesh = paramChart->unifiedMesh();
|
||||||
Chart *chart = args->chart = XA_NEW(MemTag::Default, Chart);
|
Chart *chart = args->chart = XA_NEW(MemTag::Default, Chart);
|
||||||
chart->atlasIndex = -1;
|
chart->atlasIndex = -1;
|
||||||
chart->material = 0;
|
chart->material = 0;
|
||||||
chart->indices = mesh->indices();
|
chart->indices = mesh->indices();
|
||||||
chart->parametricArea = mesh->computeParametricArea();
|
chart->parametricArea = mesh->computeParametricArea();
|
||||||
|
printf("4\n");
|
||||||
if (chart->parametricArea < kAreaEpsilon) {
|
if (chart->parametricArea < kAreaEpsilon) {
|
||||||
// When the parametric area is too small we use a rough approximation to prevent divisions by very small numbers.
|
// When the parametric area is too small we use a rough approximation to prevent divisions by very small numbers.
|
||||||
const Vector2 bounds = paramChart->computeParametricBounds();
|
const Vector2 bounds = paramChart->computeParametricBounds();
|
||||||
chart->parametricArea = bounds.x * bounds.y;
|
chart->parametricArea = bounds.x * bounds.y;
|
||||||
}
|
}
|
||||||
|
printf("5\n");
|
||||||
chart->surfaceArea = mesh->computeSurfaceArea();
|
chart->surfaceArea = mesh->computeSurfaceArea();
|
||||||
chart->vertices = mesh->texcoords();
|
chart->vertices = mesh->texcoords();
|
||||||
chart->boundaryEdges = &mesh->boundaryEdges();
|
chart->boundaryEdges = &mesh->boundaryEdges();
|
||||||
|
printf("6\n");
|
||||||
// Compute bounding box of chart.
|
// Compute bounding box of chart.
|
||||||
BoundingBox2D &bb = boundingBox->get();
|
BoundingBox2D &bb = boundingBox->get();
|
||||||
bb.clear();
|
bb.clear();
|
||||||
@ -6610,11 +6656,13 @@ static void runAddChartTask(void *groupUserData, void *taskUserData) {
|
|||||||
if (mesh->isBoundaryVertex(v))
|
if (mesh->isBoundaryVertex(v))
|
||||||
bb.appendBoundaryVertex(mesh->texcoord(v));
|
bb.appendBoundaryVertex(mesh->texcoord(v));
|
||||||
}
|
}
|
||||||
|
printf("7\n");
|
||||||
bb.compute(mesh->texcoords());
|
bb.compute(mesh->texcoords());
|
||||||
chart->majorAxis = bb.majorAxis;
|
chart->majorAxis = bb.majorAxis;
|
||||||
chart->minorAxis = bb.minorAxis;
|
chart->minorAxis = bb.minorAxis;
|
||||||
chart->minCorner = bb.minCorner;
|
chart->minCorner = bb.minCorner;
|
||||||
chart->maxCorner = bb.maxCorner;
|
chart->maxCorner = bb.maxCorner;
|
||||||
|
printf("8\n");
|
||||||
XA_PROFILE_END(packChartsAddChartsThread)
|
XA_PROFILE_END(packChartsAddChartsThread)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user