Skip to content

Commit 90d8a86

Browse files
committed
subdiv: add setting 'mergeBefore' (which applies MergeOnDistance before subdividing
1 parent 80e8aa4 commit 90d8a86

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

include/slg/shapes/subdiv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class SubdivShape : public Shape {
3434
const u_int maxLevel,
3535
const float maxEdgeScreenSize,
3636
const bool enhanced,
37+
const bool merge_before, // Apply merge on distance beforehands
3738
const float sharpnessThresholdRadians,
3839
const float creaseWeight
3940
);
@@ -46,6 +47,7 @@ class SubdivShape : public Shape {
4647
luxrays::ExtTriangleMeshRef srcMesh,
4748
const u_int maxLevel,
4849
const bool enhanced,
50+
const bool merge_before,
4951
const float sharpnessThresholdRadians,
5052
const float creaseWeight
5153
);

src/slg/scene/parseshapes.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ ExtTriangleMeshUPtr Scene::CreateShape(const string &shapeName, const Properties
341341
Property(propName + ".enhanced")(false)
342342
).Get<bool>();
343343

344+
// Apply merge on distance beforehand
345+
const bool mergeBefore = props.Get(
346+
Property(propName + ".mergebefore")(false)
347+
).Get<bool>();
348+
344349
const float sharpnessThresholdRadians = props.Get(Property(propName + ".sharpnessthreshold")(0.512)).Get<double>();
345350
const float creaseWeight = props.Get(Property(propName + ".creaseweight")(10.0)).Get<double>();
346351

@@ -351,6 +356,7 @@ ExtTriangleMeshUPtr Scene::CreateShape(const string &shapeName, const Properties
351356
maxLevel,
352357
maxEdgeScreenSize,
353358
subdivEnhanced,
359+
mergeBefore,
354360
sharpnessThresholdRadians,
355361
creaseWeight
356362
);

src/slg/shapes/subdiv.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,7 @@ SubdivShape::SubdivShape(
15411541
const u_int maxLevel,
15421542
const float maxEdgeScreenSize,
15431543
const bool enhanced,
1544+
const bool merge_before,
15441545
const float sharpnessThresholdRadians,
15451546
const float creaseWeight
15461547
) {
@@ -1556,10 +1557,11 @@ SubdivShape::SubdivShape(
15561557
if (maxLevel > 0) {
15571558

15581559
// Merge vertices on distance
1559-
auto srcMeshPtr = MergeOnDistanceShape::ApplyMergeOnDistance(
1560-
rawSrcMesh, std::numeric_limits<float>::min(), true
1561-
);
1562-
auto& srcMesh = *srcMeshPtr;
1560+
auto srcMeshPtr = merge_before ?
1561+
MergeOnDistanceShape::ApplyMergeOnDistance(
1562+
rawSrcMesh, std::numeric_limits<float>::min(), true
1563+
) : nullptr;
1564+
auto& srcMesh = merge_before ? *srcMeshPtr : rawSrcMesh;
15631565

15641566
if (camera && (maxEdgeScreenSize > 0.f)) {
15651567
SDL_LOG("Subdividing shape " << srcMesh.GetName()
@@ -1594,6 +1596,7 @@ SubdivShape::SubdivShape(
15941596
*mesh,
15951597
optimizedLevel,
15961598
enhanced,
1599+
merge_before,
15971600
sharpnessThresholdRadians,
15981601
creaseWeight
15991602
);
@@ -1610,7 +1613,7 @@ SubdivShape::SubdivShape(
16101613
} else {
16111614
SDL_LOG("Subdividing shape " << srcMesh.GetName() << " at level: " << maxLevel);
16121615

1613-
mesh = ApplySubdiv(srcMesh, maxLevel, enhanced, sharpnessThresholdRadians, creaseWeight);
1616+
mesh = ApplySubdiv(srcMesh, maxLevel, enhanced, merge_before, sharpnessThresholdRadians, creaseWeight);
16141617
}
16151618
} else {
16161619
// Nothing to do, just make a copy
@@ -1687,6 +1690,7 @@ ExtTriangleMeshUPtr SubdivShape::ApplySubdiv(
16871690
ExtTriangleMeshRef srcMesh,
16881691
const u_int maxLevel,
16891692
const bool enhanced,
1693+
const bool merge_before,
16901694
const float sharpnessThresholdRadians,
16911695
const float creaseWeight
16921696
) {

0 commit comments

Comments
 (0)