Skip to content

Commit 682d9b1

Browse files
MeshAlgo::distributePoints : Support density primvar values over 1
It's now easier to support this than not, and I don't see any good reason not to, and we're updating the distribution a little anyway by fixing precision issues and removing duplicates, so now seems like a good time.
1 parent 3bb898d commit 682d9b1

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

src/IECoreScene/MeshAlgoDistributePoints.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,7 @@ void distributePointsInTriangle(
384384
densityInterpolation, densityView, vertexIds, faceIdx,
385385
cornerDensities[0], cornerDensities[1], cornerDensities[2]
386386
);
387-
float maxDensity = std::max( std::max( cornerDensities[0], cornerDensities[1] ), cornerDensities[2] );
388-
389-
// This matches previous behaviour where a density primvar value over 1.0 does nothing, because it
390-
// cannot increase the number of points generated. Maybe this is valuable as a safety mechanism?
391-
// We could just delete this line, and then densities greater than 1 would work how you would expect.
392-
maxDensity = std::min( 1.0f, std::max( 0.0f, maxDensity ) );
387+
float maxDensity = std::max( 0.0f, std::max( std::max( cornerDensities[0], cornerDensities[1] ), cornerDensities[2] ) );
393388

394389
// Apply the max density from the primvar to the density passed in to PointDistribution
395390
finalDensity *= maxDensity;
@@ -466,7 +461,7 @@ PointsPrimitivePtr MeshAlgo::distributePoints( const MeshPrimitive *mesh, float
466461
PrimitiveVariable::IndexedView<float> densityView;
467462
if( densityVar.interpolation == PrimitiveVariable::Constant )
468463
{
469-
density *= std::min( 1.0f, std::max( 0.0f, (IECore::runTimeCast<FloatData>(densityVar.data.get()))->readable() ) );
464+
density *= std::max( 0.0f, (IECore::runTimeCast<FloatData>(densityVar.data.get()))->readable() );
470465
}
471466
else
472467
{

test/IECoreScene/MeshAlgoDistributePointsTest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,9 @@ def pointTest( self, mesh, points, density, error=0.05, checkDuplicates = True )
112112
for f in range( 0, mesh.verticesPerFace.size() ) :
113113
if "density" in mesh :
114114
if mesh["density"].interpolation == IECoreScene.PrimitiveVariable.Interpolation.Constant:
115-
# For consistency, no primitive variable may increase the density, only decrease it.
116-
# At least currently, we could just fix this now.
117-
density = min( 1, mesh["density"].data.value ) * origDensity
115+
density = mesh["density"].data.value * origDensity
118116
else:
119-
density = min( 1, mesh["density"].data[f] ) * origDensity
117+
density = mesh["density"].data[f] * origDensity
120118
self.assertLessEqual( abs( pointsPerFace[f] - density * mesh['faceArea'].data[f] ), density * error + len(positions) * error * error )
121119

122120
def testSimple( self ) :

0 commit comments

Comments
 (0)