Browse Source

Add a `getRandomNumber` function to MeshSurfaceSampler so it can be overridden

Garrett Johnson 4 years ago
parent
commit
1bf8fc8ba8
1 changed files with 9 additions and 3 deletions
  1. 9 3
      examples/jsm/math/MeshSurfaceSampler.js

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

@@ -104,11 +104,17 @@ var MeshSurfaceSampler = ( function () {
 
 
 		},
 		},
 
 
+		getRandomNumber: function () {
+
+			return Math.random();
+
+		},
+
 		sample: function ( targetPosition, targetNormal ) {
 		sample: function ( targetPosition, targetNormal ) {
 
 
 			var cumulativeTotal = this.distribution[ this.distribution.length - 1 ];
 			var cumulativeTotal = this.distribution[ this.distribution.length - 1 ];
 
 
-			var faceIndex = this.binarySearch( Math.random() * cumulativeTotal );
+			var faceIndex = this.binarySearch( this.getRandomNumber() * cumulativeTotal );
 
 
 			return this.sampleFace( faceIndex, targetPosition, targetNormal );
 			return this.sampleFace( faceIndex, targetPosition, targetNormal );
 
 
@@ -150,8 +156,8 @@ var MeshSurfaceSampler = ( function () {
 
 
 		sampleFace: function ( faceIndex, targetPosition, targetNormal ) {
 		sampleFace: function ( faceIndex, targetPosition, targetNormal ) {
 
 
-			var u = Math.random();
-			var v = Math.random();
+			var u = this.getRandomNumber();
+			var v = this.getRandomNumber();
 
 
 			if ( u + v > 1 ) {
 			if ( u + v > 1 ) {