summaryrefslogtreecommitdiff
path: root/thirdparty/thekla_atlas
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/thekla_atlas')
-rw-r--r--thirdparty/thekla_atlas/nvmesh/param/Atlas.cpp4
-rw-r--r--thirdparty/thekla_atlas/nvmesh/param/Atlas.h3
-rw-r--r--thirdparty/thekla_atlas/nvmesh/param/AtlasPacker.cpp12
3 files changed, 17 insertions, 2 deletions
diff --git a/thirdparty/thekla_atlas/nvmesh/param/Atlas.cpp b/thirdparty/thekla_atlas/nvmesh/param/Atlas.cpp
index 4e41e76695..98f92cef96 100644
--- a/thirdparty/thekla_atlas/nvmesh/param/Atlas.cpp
+++ b/thirdparty/thekla_atlas/nvmesh/param/Atlas.cpp
@@ -38,6 +38,7 @@ using namespace nv;
/// Ctor.
Atlas::Atlas()
{
+ failed=false;
}
// Dtor.
@@ -100,6 +101,7 @@ void Atlas::extractCharts(const HalfEdge::Mesh * mesh)
void Atlas::computeCharts(const HalfEdge::Mesh * mesh, const SegmentationSettings & settings, const Array<uint> & unchartedMaterialArray)
{
+ failed=false;
MeshCharts * meshCharts = new MeshCharts(mesh);
meshCharts->computeCharts(settings, unchartedMaterialArray);
addMeshCharts(meshCharts);
@@ -235,6 +237,8 @@ float Atlas::packCharts(int quality, float texelsPerUnit, bool blockAlign, bool
{
AtlasPacker packer(this);
packer.packCharts(quality, texelsPerUnit, blockAlign, conservative);
+ if (hasFailed())
+ return 0;
return packer.computeAtlasUtilization();
}
diff --git a/thirdparty/thekla_atlas/nvmesh/param/Atlas.h b/thirdparty/thekla_atlas/nvmesh/param/Atlas.h
index 8b478207e3..0398bd905c 100644
--- a/thirdparty/thekla_atlas/nvmesh/param/Atlas.h
+++ b/thirdparty/thekla_atlas/nvmesh/param/Atlas.h
@@ -64,9 +64,12 @@ namespace nv
// Pack charts in the smallest possible rectangle.
float packCharts(int quality, float texelArea, bool blockAlign, bool conservative);
+ bool setFailed() { failed = true; }
+ bool hasFailed() const { return failed; }
private:
+ bool failed;
Array<MeshCharts *> m_meshChartsArray;
};
diff --git a/thirdparty/thekla_atlas/nvmesh/param/AtlasPacker.cpp b/thirdparty/thekla_atlas/nvmesh/param/AtlasPacker.cpp
index f2156899ae..5ce452cb9e 100644
--- a/thirdparty/thekla_atlas/nvmesh/param/AtlasPacker.cpp
+++ b/thirdparty/thekla_atlas/nvmesh/param/AtlasPacker.cpp
@@ -152,7 +152,7 @@ AtlasPacker::~AtlasPacker()
}
// This should compute convex hull and use rotating calipers to find the best box. Currently it uses a brute force method.
-static void computeBoundingBox(Chart * chart, Vector2 * majorAxis, Vector2 * minorAxis, Vector2 * minCorner, Vector2 * maxCorner)
+static bool computeBoundingBox(Chart * chart, Vector2 * majorAxis, Vector2 * minorAxis, Vector2 * minCorner, Vector2 * maxCorner)
{
// Compute list of boundary points.
Array<Vector2> points(16);
@@ -184,6 +184,9 @@ static void computeBoundingBox(Chart * chart, Vector2 * majorAxis, Vector2 * min
#if 1
Array<Vector2> hull;
+ if (points.size()==0) {
+ return false;
+ }
convexHull(points, hull, 0.00001f);
@@ -373,6 +376,8 @@ static void computeBoundingBox(Chart * chart, Vector2 * majorAxis, Vector2 * min
}
}*/
#endif
+
+ return true;
}
@@ -431,7 +436,10 @@ void AtlasPacker::packCharts(int quality, float texelsPerUnit, bool blockAligned
// Compute bounding box of chart.
Vector2 majorAxis, minorAxis, origin, end;
- computeBoundingBox(chart, &majorAxis, &minorAxis, &origin, &end);
+ if (!computeBoundingBox(chart, &majorAxis, &minorAxis, &origin, &end)) {
+ m_atlas->setFailed();
+ return;
+ }
nvCheck(isFinite(majorAxis) && isFinite(minorAxis) && isFinite(origin));