Browse Source

Merge pull request #21118 from Mugen87/dev51

Examples: Clean up.
Mr.doob 4 years ago
parent
commit
7c98985f7f

+ 2 - 2
examples/jsm/renderers/nodes/core/Node.js

@@ -18,13 +18,13 @@ class Node {
 
 	update( /*frame*/ ) {
 
-		console.warn( "Abstract function." );
+		console.warn( 'Abstract function.' );
 
 	}
 
 	generate( /*builder, output*/ ) {
 
-		console.warn( "Abstract function." );
+		console.warn( 'Abstract function.' );
 
 	}
 

+ 10 - 10
examples/jsm/renderers/nodes/core/NodeBuilder.js

@@ -53,7 +53,7 @@ class NodeBuilder {
 
 	}
 
-	getTexture( textureProperty, uvSnippet ) {
+	getTexture( /* textureProperty, uvSnippet */ ) {
 
 
 
@@ -67,7 +67,7 @@ class NodeBuilder {
 		if ( type === 'vec4' ) return `vec4( ${value.x}, ${value.y}, ${value.z}, ${value.w} )`;
 		if ( type === 'color' ) return `vec3( ${value.r}, ${value.g}, ${value.b} )`;
 
-		throw new Error(`Type '${type}' not found in generate constant attempt.`);
+		throw new Error( `Type '${type}' not found in generate constant attempt.` );
 
 	}
 
@@ -187,7 +187,7 @@ class NodeBuilder {
 
 	flowNode( node, output ) {
 
-		let flowData = {};
+		const flowData = {};
 		flowData.result = node.build( this, output );
 
 		return flowData;
@@ -200,7 +200,7 @@ class NodeBuilder {
 
 		let code = '';
 
-		for ( let name in defines ) {
+		for ( const name in defines ) {
 
 			code += `#define ${name} ${defines[ name ]}\n`;
 
@@ -228,7 +228,7 @@ class NodeBuilder {
 
 		let snippet = '';
 
-		for ( let uniform of uniforms ) {
+		for ( const uniform of uniforms ) {
 
 			snippet += `${uniform.type} ${uniform.name}; `;
 
@@ -280,15 +280,15 @@ class NodeBuilder {
 		const shaderStages = [ 'vertex', 'fragment' ];
 		const shaderData = {};
 
-		for ( let shaderStage of shaderStages ) {
+		for ( const shaderStage of shaderStages ) {
 
 			this.shaderStage = shaderStage;
 
-			let slots = this.slots[ shaderStage ];
+			const slots = this.slots[ shaderStage ];
 
-			for ( let slot of slots ) {
+			for ( const slot of slots ) {
 
-				let flowData = this.flowNode( slot.node, slot.output );
+				const flowData = this.flowNode( slot.node, slot.output );
 
 				this.define( shaderStage, `NODE_${slot.name}`, flowData.result );
 
@@ -298,7 +298,7 @@ class NodeBuilder {
 
 		this.shaderStage = null;
 
-		for ( let shaderStage of shaderStages ) {
+		for ( const shaderStage of shaderStages ) {
 
 			this.define( shaderStage, 'NODE_HEADER_UNIFORMS', this.getUniformsHeaderSnippet( shaderStage ) );
 			this.define( shaderStage, 'NODE_HEADER_ATTRIBUTES', this.getAttributesHeaderSnippet( shaderStage ) );

+ 3 - 7
examples/jsm/renderers/webgpu/WebGPUBindings.js

@@ -1,7 +1,5 @@
 import WebGPUUniformsGroup from './WebGPUUniformsGroup.js';
-import { FloatUniform, Matrix3Uniform, Matrix4Uniform } from './WebGPUUniform.js';
-import WebGPUSampler from './WebGPUSampler.js';
-import { WebGPUSampledTexture } from './WebGPUSampledTexture.js';
+import { Matrix3Uniform, Matrix4Uniform } from './WebGPUUniform.js';
 
 class WebGPUBindings {
 
@@ -39,7 +37,7 @@ class WebGPUBindings {
 
 			// each material defines an array of bindings (ubos, textures, samplers etc.)
 
-			let bindings = this.composeBindings( object, nodeBuilder.getBindings( 'fragment' ) );
+			const bindings = this.composeBindings( object, nodeBuilder.getBindings( 'fragment' ) );
 
 			// setup (static) binding layout and (dynamic) binding group
 
@@ -136,7 +134,6 @@ class WebGPUBindings {
 
 			} else if ( binding.isSampler ) {
 
-				const material = object.material;
 				const texture = binding.texture;
 
 				textures.updateSampler( texture );
@@ -152,7 +149,6 @@ class WebGPUBindings {
 
 			} else if ( binding.isSampledTexture ) {
 
-				const material = object.material;
 				const texture = binding.texture;
 
 				const forceUpdate = textures.updateTexture( texture );
@@ -264,7 +260,7 @@ class WebGPUBindings {
 
 	composeBindings( object, uniforms ) {
 
-		let bindings = [];
+		const bindings = [];
 
 		// UBOs
 

+ 1 - 1
examples/jsm/renderers/webgpu/WebGPURenderPipelines.js

@@ -22,7 +22,7 @@ class WebGPURenderPipelines {
 
 		this.pipelines = new WeakMap();
 		this.shaderAttributes = new WeakMap();
-		
+
 		this.shaderModules = {
 			vertex: new Map(),
 			fragment: new Map()

+ 6 - 6
examples/jsm/renderers/webgpu/WebGPUUniform.js

@@ -19,11 +19,11 @@ class WebGPUUniform {
 		this.value = value;
 
 	}
-	
+
 	getValue() {
-		
+
 		return this.value;
-		
+
 	}
 
 }
@@ -40,11 +40,11 @@ class FloatUniform extends WebGPUUniform {
 		Object.defineProperty( this, 'isFloatUniform', { value: true } );
 
 	}
-	
+
 	getValue() {
-		
+
 		return this.nodeUniform.value;
-		
+
 	}
 
 }

+ 12 - 12
examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js

@@ -183,12 +183,12 @@ class WebGPUNodeBuilder extends NodeBuilder {
 		let attributeIndex = this.attributeIndex;
 		let varyIndex = this.varyIndex;
 
-		for ( let name in attributes ) {
+		for ( const name in attributes ) {
 
-			let attribute = attributes[ name ];
+			const attribute = attributes[ name ];
 
-			let type = attribute.type;
-			let property = attribute.property;
+			const type = attribute.type;
+			const property = attribute.property;
 
 			if ( shaderStage === 'vertex' ) {
 
@@ -207,17 +207,17 @@ class WebGPUNodeBuilder extends NodeBuilder {
 
 	}
 
-	getAttributesBodySnippet( shaderStage ) {
+	getAttributesBodySnippet( /* shaderStage */ ) {
 
 		let snippet = '';
 
 		const attributes = this.attributes;
 
-		for ( let name in attributes ) {
+		for ( const name in attributes ) {
 
-			let attribute = attributes[ name ];
+			const attribute = attributes[ name ];
 
-			let property = attribute.property;
+			const property = attribute.property;
 
 			snippet += `${property} = ${name};`;
 
@@ -236,7 +236,7 @@ class WebGPUNodeBuilder extends NodeBuilder {
 
 		let bindingIndex = this.bindingIndex;
 
-		for ( let uniform of uniforms ) {
+		for ( const uniform of uniforms ) {
 
 			if ( uniform.type === 'texture' ) {
 
@@ -245,7 +245,7 @@ class WebGPUNodeBuilder extends NodeBuilder {
 
 			} else {
 
-				let vectorType = this.getVectorType( uniform.type );
+				const vectorType = this.getVectorType( uniform.type );
 
 				groupSnippet += `uniform ${vectorType} ${uniform.name};`;
 
@@ -266,9 +266,9 @@ class WebGPUNodeBuilder extends NodeBuilder {
 	composeShaderCode( code, snippet ) {
 
 		// use regex maybe for security?
-		const versionStrIndex = code.indexOf( "\n" );
+		const versionStrIndex = code.indexOf( '\n' );
 
-		let finalCode = code.substr( 0, versionStrIndex ) + "\n\n";
+		let finalCode = code.substr( 0, versionStrIndex ) + '\n\n';
 
 		finalCode += snippet;
 

+ 1 - 1
examples/jsm/renderers/webgpu/nodes/WebGPUNodeUniformsGroup.js

@@ -26,4 +26,4 @@ class WebGPUNodeUniformsGroup extends WebGPUUniformsGroup {
 
 }
 
-export default WebGPUUniformsGroup;
+export default WebGPUNodeUniformsGroup;

+ 2 - 2
examples/jsm/renderers/webgpu/nodes/WebGPUNodes.js

@@ -41,7 +41,7 @@ class WebGPUNodes {
 
 	}
 
-	update( object, camera ) {
+	update( object/*, camera*/ ) {
 
 		const material = object.material;
 
@@ -49,7 +49,7 @@ class WebGPUNodes {
 
 		this.nodeFrame.material = object.material;
 
-		for ( let node of nodeBuilder.updateNodes ) {
+		for ( const node of nodeBuilder.updateNodes ) {
 
 			this.nodeFrame.updateNode( node );
 

+ 3 - 3
examples/webgpu_rtt.html

@@ -23,7 +23,7 @@
 			import Vector2Node from './jsm/renderers/nodes/inputs/Vector2Node.js';
 
 			let camera, scene, renderer;
-			let mouse = new THREE.Vector2();
+			const mouse = new THREE.Vector2();
 
 			let cameraFX, sceneFX, textureRenderer;
 
@@ -83,9 +83,9 @@
 
 				const geometryFX = new THREE.PlaneGeometry( 2, 2 );
 
-				// @TODO Until NodeMaterial is available just copy the beauty pass to screen
+				// modulate the final color based on the mouse position
 
-				const screenFXNode = new OperatorNode( '+', new Vector2Node( mouse ), new Vector2Node( new THREE.Vector2( .5, .5 ) ).setConst( true ) );
+				const screenFXNode = new OperatorNode( '+', new Vector2Node( mouse ), new Vector2Node( new THREE.Vector2( 0.5, 0.5 ) ).setConst( true ) );
 
 				const materialFX = new THREE.MeshBasicMaterial();
 				materialFX.colorNode = new OperatorNode( '*', new TextureNode( textureRenderer.getTexture() ), screenFXNode );

+ 1 - 2
examples/webgpu_sandbox.html

@@ -22,7 +22,6 @@
 			import AttributeNode from './jsm/renderers/nodes/core/AttributeNode.js';
 			import FloatNode from './jsm/renderers/nodes/inputs/FloatNode.js';
 			import Vector2Node from './jsm/renderers/nodes/inputs/Vector2Node.js';
-			import Vector3Node from './jsm/renderers/nodes/inputs/Vector3Node.js';
 			import ColorNode from './jsm/renderers/nodes/inputs/ColorNode.js';
 			import TextureNode from './jsm/renderers/nodes/inputs/TextureNode.js';
 			import UVNode from './jsm/renderers/nodes/accessors/UVNode.js';
@@ -73,7 +72,7 @@
 				const timerNode = new TimerNode();
 
 				// birection speed
-				const timerScaleNode = new OperatorNode( '*', timerNode, new Vector2Node( new THREE.Vector2( - .5, .1 ) ).setConst( true ) );
+				const timerScaleNode = new OperatorNode( '*', timerNode, new Vector2Node( new THREE.Vector2( - 0.5, 0.1 ) ).setConst( true ) );
 				const animateUV = new OperatorNode( '+', new UVNode(), timerScaleNode );
 
 				materialBox.colorNode = new TextureNode( texture, animateUV );