Garrett Johnson 2 лет назад
Родитель
Сommit
58c2f5a8f4
1 измененных файлов с 7 добавлено и 3 удалено
  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 ) {
 
-		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 );
 
 	}