浏览代码

add sampleFaceIndex function (#25970)

Garrett Johnson 2 年之前
父节点
当前提交
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 );
 
 	}