Bläddra i källkod

Examples: Clean up.

Mr.doob 5 år sedan
förälder
incheckning
9006b8320b

+ 10 - 3
examples/js/misc/GPUComputationRenderer.js

@@ -1,7 +1,5 @@
 console.warn( "THREE.GPUComputationRenderer: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation." );
 /**
- * @author yomboprime https://github.com/yomboprime
- *
  * GPUComputationRenderer, based on SimulationRenderer by zz85
  *
  * The GPUComputationRenderer uses the concept of variables. These variables are RGBA float textures that hold 4 floats
@@ -104,6 +102,8 @@ THREE.GPUComputationRenderer = function ( sizeX, sizeY, renderer ) {
 
 	this.currentTextureIndex = 0;
 
+	var dataType = THREE.FloatType;
+
 	var scene = new THREE.Scene();
 
 	var camera = new THREE.Camera();
@@ -119,6 +119,13 @@ THREE.GPUComputationRenderer = function ( sizeX, sizeY, renderer ) {
 	scene.add( mesh );
 
 
+	this.setDataType = function ( type ) {
+
+		dataType = type;
+		return this;
+
+	};
+
 	this.addVariable = function ( variableName, computeFragmentShader, initialValueTexture ) {
 
 		var material = this.createShaderMaterial( computeFragmentShader );
@@ -311,7 +318,7 @@ THREE.GPUComputationRenderer = function ( sizeX, sizeY, renderer ) {
 			minFilter: minFilter,
 			magFilter: magFilter,
 			format: THREE.RGBAFormat,
-			type: ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) ? THREE.HalfFloatType : THREE.FloatType,
+			type: dataType,
 			stencilBuffer: false,
 			depthBuffer: false
 		} );

+ 0 - 2
examples/jsm/misc/GPUComputationRenderer.js

@@ -1,6 +1,4 @@
 /**
- * @author yomboprime https://github.com/yomboprime
- *
  * GPUComputationRenderer, based on SimulationRenderer by zz85
  *
  * The GPUComputationRenderer uses the concept of variables. These variables are RGBA float textures that hold 4 floats

+ 7 - 2
examples/webgl_gpgpu_birds.html

@@ -484,7 +484,9 @@
 				gpuCompute = new GPUComputationRenderer( WIDTH, WIDTH, renderer );
 
 				if ( isSafari() ) {
+
 					gpuCompute.setDataType( THREE.HalfFloatType );
+
 				}
 
 				var dtPosition = gpuCompute.createTexture();
@@ -519,16 +521,19 @@
 				positionVariable.wrapT = THREE.RepeatWrapping;
 
 				var error = gpuCompute.init();
+
 				if ( error !== null ) {
 
-				    console.error( error );
+					console.error( error );
 
 				}
 
 			}
 
 			function isSafari() {
-				return !!navigator.userAgent.match(/Safari/i) && !navigator.userAgent.match(/Chrome/i);
+
+				return !! navigator.userAgent.match( /Safari/i ) && ! navigator.userAgent.match( /Chrome/i );
+
 			}
 
 			function initBirds() {

+ 5 - 1
examples/webgl_gpgpu_birds_gltf.html

@@ -432,7 +432,9 @@
 				gpuCompute = new GPUComputationRenderer( WIDTH, WIDTH, renderer );
 
 				if ( isSafari() ) {
+
 					gpuCompute.setDataType( THREE.HalfFloatType );
+
 				}
 
 				var dtPosition = gpuCompute.createTexture();
@@ -477,7 +479,9 @@
 			}
 
 			function isSafari() {
-				return !!navigator.userAgent.match(/Safari/i) && !navigator.userAgent.match(/Chrome/i);
+
+				return !! navigator.userAgent.match( /Safari/i ) && ! navigator.userAgent.match( /Chrome/i );
+
 			}
 
 			function initBirds() {

+ 5 - 1
examples/webgl_gpgpu_protoplanet.html

@@ -317,7 +317,9 @@
 				gpuCompute = new GPUComputationRenderer( WIDTH, WIDTH, renderer );
 
 				if ( isSafari() ) {
+
 					gpuCompute.setDataType( THREE.HalfFloatType );
+
 				}
 
 				var dtPosition = gpuCompute.createTexture();
@@ -347,7 +349,9 @@
 			}
 
 			function isSafari() {
-				return !!navigator.userAgent.match(/Safari/i) && !navigator.userAgent.match(/Chrome/i);
+
+				return !! navigator.userAgent.match( /Safari/i ) && ! navigator.userAgent.match( /Chrome/i );
+
 			}
 
 			function restartSimulation() {

+ 6 - 1
examples/webgl_gpgpu_water.html

@@ -445,7 +445,9 @@
 				gpuCompute = new GPUComputationRenderer( WIDTH, WIDTH, renderer );
 
 				if ( isSafari() ) {
+
 					gpuCompute.setDataType( THREE.HalfFloatType );
+
 				}
 
 				var heightmap0 = gpuCompute.createTexture();
@@ -497,7 +499,9 @@
 			}
 
 			function isSafari() {
-				return !!navigator.userAgent.match(/Safari/i) && !navigator.userAgent.match(/Chrome/i);
+
+				return !! navigator.userAgent.match( /Safari/i ) && ! navigator.userAgent.match( /Chrome/i );
+
 			}
 
 			function fillTexture( texture ) {
@@ -516,6 +520,7 @@
 						mult *= 1.25;
 
 					}
+
 					return r;
 
 				}