Parcourir la source

add sampleFaceIndex function (#25970)

Garrett Johnson il y a 2 ans
Parent
commit
58c2f5a8f4
1 fichiers modifiés avec 7 ajouts et 3 suppressions
  1. 7 3
      examples/jsm/math/MeshSurfaceSampler.js

+ 7 - 3
examples/jsm/math/MeshSurfaceSampler.js

@@ -108,11 +108,15 @@ class MeshSurfaceSampler {
 
 
 	sample( targetPosition, targetNormal, targetColor ) {
 	sample( targetPosition, targetNormal, targetColor ) {
 
 
-		const cumulativeTotal = this.distribution[ this.distribution.length - 1 ];
+		const faceIndex = this.sampleFaceIndex();
+		return this.sampleFace( faceIndex, targetPosition, targetNormal, targetColor );
+
+	}
 
 
-		const faceIndex = this.binarySearch( this.randomFunction() * cumulativeTotal );
+	sampleFaceIndex() {
 
 
-		return this.sampleFace( faceIndex, targetPosition, targetNormal, targetColor );
+		const cumulativeTotal = this.distribution[ this.distribution.length - 1 ];
+		return this.binarySearch( this.randomFunction() * cumulativeTotal );
 
 
 	}
 	}