From dec1707a4e479f0e79d114c90b551efeed4bdd6b Mon Sep 17 00:00:00 2001 From: sunag Date: Sun, 4 Feb 2018 18:25:50 -0200 Subject: [PATCH 01/13] InputNode readonly option --- examples/js/loaders/NodeMaterialLoader.js | 7 +++++ examples/js/nodes/InputNode.js | 33 +++++++++++++++-------- examples/js/nodes/inputs/ColorNode.js | 8 ++++++ examples/js/nodes/inputs/FloatNode.js | 10 +++++++ examples/js/nodes/inputs/IntNode.js | 8 ++++++ examples/js/nodes/inputs/Matrix3Node.js | 8 ++++++ examples/js/nodes/inputs/Matrix4Node.js | 8 ++++++ examples/js/nodes/inputs/Vector2Node.js | 8 ++++++ examples/js/nodes/inputs/Vector3Node.js | 8 ++++++ examples/js/nodes/inputs/Vector4Node.js | 8 ++++++ examples/webgl_materials_nodes.html | 17 ++++++++++++ 11 files changed, 112 insertions(+), 11 deletions(-) diff --git a/examples/js/loaders/NodeMaterialLoader.js b/examples/js/loaders/NodeMaterialLoader.js index 4a42f8705dfb22..d3841637c1d11b 100644 --- a/examples/js/loaders/NodeMaterialLoader.js +++ b/examples/js/loaders/NodeMaterialLoader.js @@ -125,8 +125,15 @@ Object.assign( THREE.NodeMaterialLoader.prototype, { this.names[ object.name ] = object; + } else { + + // ignore "uniform" shader input ( for optimization ) + object.readonly = true; + } + if ( node.readonly !== undefined ) object.readonly = node.readonly; + this.nodes[ uuid ] = object; } diff --git a/examples/js/nodes/InputNode.js b/examples/js/nodes/InputNode.js index 4f3153d977e1d5..38c1b3986c2e18 100644 --- a/examples/js/nodes/InputNode.js +++ b/examples/js/nodes/InputNode.js @@ -9,6 +9,8 @@ THREE.InputNode = function ( type, params ) { THREE.TempNode.call( this, type, params ); + this.readonly = false; + }; THREE.InputNode.prototype = Object.create( THREE.TempNode.prototype ); @@ -21,27 +23,36 @@ THREE.InputNode.prototype.generate = function ( builder, output, uuid, type, ns, uuid = builder.getUuid( uuid || this.getUuid() ); type = type || this.getType( builder ); - var data = material.getDataNode( uuid ); + var data = material.getDataNode( uuid ), + readonly = this.readonly && this.generateReadonly !== undefined; - if ( builder.isShader( 'vertex' ) ) { + if ( readonly ) { - if ( ! data.vertex ) { + return this.generateReadonly( builder, output, uuid, type, ns, needsUpdate ); - data.vertex = material.createVertexUniform( type, this.value, ns, needsUpdate ); + } else { - } + if ( builder.isShader( 'vertex' ) ) { - return builder.format( data.vertex.name, type, output ); + if ( ! data.vertex ) { - } else { + data.vertex = material.createVertexUniform( type, this.value, ns, needsUpdate ); - if ( ! data.fragment ) { + } - data.fragment = material.createFragmentUniform( type, this.value, ns, needsUpdate ); + return builder.format( data.vertex.name, type, output ); - } + } else { - return builder.format( data.fragment.name, type, output ); + if ( ! data.fragment ) { + + data.fragment = material.createFragmentUniform( type, this.value, ns, needsUpdate ); + + } + + return builder.format( data.fragment.name, type, output ); + + } } diff --git a/examples/js/nodes/inputs/ColorNode.js b/examples/js/nodes/inputs/ColorNode.js index 300eaeeca3c6ff..497f077a334751 100644 --- a/examples/js/nodes/inputs/ColorNode.js +++ b/examples/js/nodes/inputs/ColorNode.js @@ -16,6 +16,12 @@ THREE.ColorNode.prototype.nodeType = "Color"; THREE.NodeMaterial.addShortcuts( THREE.ColorNode.prototype, 'value', [ 'r', 'g', 'b' ] ); +THREE.ColorNode.prototype.generateReadonly = function ( builder, output, uuid, type, ns, needsUpdate ) { + + return builder.format( "vec3( " + this.r + ", " + this.g + ", " + this.b + " )", type, output ); + +}; + THREE.ColorNode.prototype.toJSON = function ( meta ) { var data = this.getJSONNode( meta ); @@ -28,6 +34,8 @@ THREE.ColorNode.prototype.toJSON = function ( meta ) { data.g = this.g; data.b = this.b; + if ( this.readyonly === true ) data.readyonly = true; + } return data; diff --git a/examples/js/nodes/inputs/FloatNode.js b/examples/js/nodes/inputs/FloatNode.js index 39c9722e756390..0ac081d10f4aff 100644 --- a/examples/js/nodes/inputs/FloatNode.js +++ b/examples/js/nodes/inputs/FloatNode.js @@ -29,6 +29,14 @@ Object.defineProperties( THREE.FloatNode.prototype, { } } ); +THREE.FloatNode.prototype.generateReadonly = function ( builder, output, uuid, type, ns, needsUpdate ) { + + var value = this.number; + + return builder.format( ~~value !== value ? value : value + ".0", type, output ); + +}; + THREE.FloatNode.prototype.toJSON = function ( meta ) { var data = this.getJSONNode( meta ); @@ -39,6 +47,8 @@ THREE.FloatNode.prototype.toJSON = function ( meta ) { data.number = this.number; + if ( this.readyonly === true ) data.readyonly = true; + } return data; diff --git a/examples/js/nodes/inputs/IntNode.js b/examples/js/nodes/inputs/IntNode.js index 6048b6bcf0daa3..f05ecfb9849231 100644 --- a/examples/js/nodes/inputs/IntNode.js +++ b/examples/js/nodes/inputs/IntNode.js @@ -29,6 +29,12 @@ Object.defineProperties( THREE.IntNode.prototype, { } } ); +THREE.IntNode.prototype.generateReadonly = function ( builder, output, uuid, type, ns, needsUpdate ) { + + return builder.format( this.number, type, output ); + +}; + THREE.IntNode.prototype.toJSON = function ( meta ) { var data = this.getJSONNode( meta ); @@ -39,6 +45,8 @@ THREE.IntNode.prototype.toJSON = function ( meta ) { data.number = this.number; + if ( this.readyonly === true ) data.readyonly = true; + } return data; diff --git a/examples/js/nodes/inputs/Matrix3Node.js b/examples/js/nodes/inputs/Matrix3Node.js index 43dff8887944ae..7fd2f56d452593 100644 --- a/examples/js/nodes/inputs/Matrix3Node.js +++ b/examples/js/nodes/inputs/Matrix3Node.js @@ -14,6 +14,12 @@ THREE.Matrix3Node.prototype = Object.create( THREE.InputNode.prototype ); THREE.Matrix3Node.prototype.constructor = THREE.Matrix3Node; THREE.Matrix3Node.prototype.nodeType = "Matrix3"; +THREE.Matrix3Node.prototype.generateReadonly = function ( builder, output, uuid, type, ns, needsUpdate ) { + + return builder.format( "mat3( " + this.value.elements.joint( ", " ) + " )", type, output ); + +}; + THREE.Matrix3Node.prototype.toJSON = function ( meta ) { var data = this.getJSONNode( meta ); @@ -24,6 +30,8 @@ THREE.Matrix3Node.prototype.toJSON = function ( meta ) { data.elements = this.value.elements.concat(); + if ( this.readyonly === true ) data.readyonly = true; + } return data; diff --git a/examples/js/nodes/inputs/Matrix4Node.js b/examples/js/nodes/inputs/Matrix4Node.js index 3ccb698e5e4756..cc56b8b2283201 100644 --- a/examples/js/nodes/inputs/Matrix4Node.js +++ b/examples/js/nodes/inputs/Matrix4Node.js @@ -14,6 +14,12 @@ THREE.Matrix4Node.prototype = Object.create( THREE.InputNode.prototype ); THREE.Matrix4Node.prototype.constructor = THREE.Matrix4Node; THREE.Matrix4Node.prototype.nodeType = "Matrix4"; +THREE.Matrix4Node.prototype.generateReadonly = function ( builder, output, uuid, type, ns, needsUpdate ) { + + return builder.format( "mat4( " + this.value.elements.joint( ", " ) + " )", type, output ); + +}; + THREE.Matrix4Node.prototype.toJSON = function ( meta ) { var data = this.getJSONNode( meta ); @@ -24,6 +30,8 @@ THREE.Matrix4Node.prototype.toJSON = function ( meta ) { data.elements = this.value.elements.concat(); + if ( this.readyonly === true ) data.readyonly = true; + } return data; diff --git a/examples/js/nodes/inputs/Vector2Node.js b/examples/js/nodes/inputs/Vector2Node.js index 31e052254a890c..752135e3f0bbeb 100644 --- a/examples/js/nodes/inputs/Vector2Node.js +++ b/examples/js/nodes/inputs/Vector2Node.js @@ -16,6 +16,12 @@ THREE.Vector2Node.prototype.nodeType = "Vector2"; THREE.NodeMaterial.addShortcuts( THREE.Vector2Node.prototype, 'value', [ 'x', 'y' ] ); +THREE.Vector2Node.prototype.generateReadonly = function ( builder, output, uuid, type, ns, needsUpdate ) { + + return builder.format( "vec2( " + this.x + ", " + this.y + " )", type, output ); + +}; + THREE.Vector2Node.prototype.toJSON = function ( meta ) { var data = this.getJSONNode( meta ); @@ -27,6 +33,8 @@ THREE.Vector2Node.prototype.toJSON = function ( meta ) { data.x = this.x; data.y = this.y; + if ( this.readyonly === true ) data.readyonly = true; + } return data; diff --git a/examples/js/nodes/inputs/Vector3Node.js b/examples/js/nodes/inputs/Vector3Node.js index 9550315012ee97..72587495901b44 100644 --- a/examples/js/nodes/inputs/Vector3Node.js +++ b/examples/js/nodes/inputs/Vector3Node.js @@ -17,6 +17,12 @@ THREE.Vector3Node.prototype.nodeType = "Vector3"; THREE.NodeMaterial.addShortcuts( THREE.Vector3Node.prototype, 'value', [ 'x', 'y', 'z' ] ); +THREE.Vector3Node.prototype.generateReadonly = function ( builder, output, uuid, type, ns, needsUpdate ) { + + return builder.format( "vec3( " + this.x + ", " + this.y + ", " + this.z + " )", type, output ); + +}; + THREE.Vector3Node.prototype.toJSON = function ( meta ) { var data = this.getJSONNode( meta ); @@ -29,6 +35,8 @@ THREE.Vector3Node.prototype.toJSON = function ( meta ) { data.y = this.y; data.z = this.z; + if ( this.readyonly === true ) data.readyonly = true; + } return data; diff --git a/examples/js/nodes/inputs/Vector4Node.js b/examples/js/nodes/inputs/Vector4Node.js index c01a7fe84402be..48667167963800 100644 --- a/examples/js/nodes/inputs/Vector4Node.js +++ b/examples/js/nodes/inputs/Vector4Node.js @@ -16,6 +16,12 @@ THREE.Vector4Node.prototype.nodeType = "Vector4"; THREE.NodeMaterial.addShortcuts( THREE.Vector4Node.prototype, 'value', [ 'x', 'y', 'z', 'w' ] ); +THREE.Vector4Node.prototype.generateReadonly = function ( builder, output, uuid, type, ns, needsUpdate ) { + + return builder.format( "vec4( " + this.x + ", " + this.y + ", " + this.z + ", " + this.w + " )", type, output ); + +}; + THREE.Vector4Node.prototype.toJSON = function ( meta ) { var data = this.getJSONNode( meta ); @@ -29,6 +35,8 @@ THREE.Vector4Node.prototype.toJSON = function ( meta ) { data.z = this.z; data.w = this.w; + if ( this.readyonly === true ) data.readyonly = true; + } return data; diff --git a/examples/webgl_materials_nodes.html b/examples/webgl_materials_nodes.html index 3100fa6775c2ae..c983539e0d1813 100644 --- a/examples/webgl_materials_nodes.html +++ b/examples/webgl_materials_nodes.html @@ -256,6 +256,7 @@ 'misc / firefly': 'firefly', 'misc / reserved-keywords': 'reserved-keywords', 'misc / varying': 'varying', + 'misc / readonly': 'readonly', 'misc / custom-attribute': 'custom-attribute' } ).onFinishChange( function () { @@ -2019,6 +2020,22 @@ break; + case 'readonly': + + mtl = new THREE.PhongNodeMaterial(); + + mtl.color = new THREE.ColorNode( 0xFFFFFF ); + mtl.specular = new THREE.FloatNode( .5 ); + mtl.shininess = new THREE.FloatNode( 15 ); + + // not use "uniform" input ( for optimization ) + // instead use explicit declaration example: + // vec3( 1.0, 1.0, 1.0 ) instead "uniform vec3" + // but not allow change the value after build the shader material + mtl.color.readonly = mtl.specular.readonly = mtl.shininess.readonly = true; + + break; + case 'triangle-blur': // MATERIAL From 6ac7c94fc2250c771edab16efb301b21e44a7d37 Mon Sep 17 00:00:00 2001 From: sunag Date: Sun, 4 Feb 2018 18:26:31 -0200 Subject: [PATCH 02/13] NodeFrame: rename updateFrame to updateNode --- examples/js/nodes/NodeFrame.js | 2 +- examples/js/nodes/NodeMaterial.js | 2 +- examples/webgl_loader_nodes.html | 2 +- examples/webgl_materials_nodes.html | 2 +- examples/webgl_mirror_nodes.html | 2 +- examples/webgl_postprocessing_nodes.html | 2 +- examples/webgl_sprites_nodes.html | 6 +++--- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/js/nodes/NodeFrame.js b/examples/js/nodes/NodeFrame.js index b48509a3d78221..7c0a2ebffe5be9 100644 --- a/examples/js/nodes/NodeFrame.js +++ b/examples/js/nodes/NodeFrame.js @@ -21,7 +21,7 @@ THREE.NodeFrame.prototype.update = function ( delta ) { }; -THREE.NodeFrame.prototype.updateFrame = function ( node ) { +THREE.NodeFrame.prototype.updateNode = function ( node ) { if ( node.frameId === this.frameId ) return this; diff --git a/examples/js/nodes/NodeMaterial.js b/examples/js/nodes/NodeMaterial.js index 1c77347f45856b..670f7ffbb00ac0 100644 --- a/examples/js/nodes/NodeMaterial.js +++ b/examples/js/nodes/NodeMaterial.js @@ -72,7 +72,7 @@ THREE.NodeMaterial.prototype.updateFrame = function ( frame ) { for ( var i = 0; i < this.updaters.length; ++ i ) { - frame.updateFrame( this.updaters[ i ] ); + frame.updateNode( this.updaters[ i ] ); } diff --git a/examples/webgl_loader_nodes.html b/examples/webgl_loader_nodes.html index 6f45abc6b3b64b..a612ec77f51d63 100644 --- a/examples/webgl_loader_nodes.html +++ b/examples/webgl_loader_nodes.html @@ -274,7 +274,7 @@ var delta = clock.getDelta(); // update material animation and/or gpu calcs (pre-renderer) - if ( mesh.material instanceof THREE.NodeMaterial ) frame.update( delta ).updateFrame( mesh.material ); + if ( mesh.material instanceof THREE.NodeMaterial ) frame.update( delta ).updateNode( mesh.material ); renderer.render( scene, camera ); diff --git a/examples/webgl_materials_nodes.html b/examples/webgl_materials_nodes.html index c983539e0d1813..d4ed1406236b1f 100644 --- a/examples/webgl_materials_nodes.html +++ b/examples/webgl_materials_nodes.html @@ -2391,7 +2391,7 @@ //mesh.rotation.z += .01; // update material animation and/or gpu calcs (pre-renderer) - frame.update( delta ).updateFrame( mesh.material ); + frame.update( delta ).updateNode( mesh.material ); // render to texture for sss/translucent material only if ( rtTexture ) { diff --git a/examples/webgl_mirror_nodes.html b/examples/webgl_mirror_nodes.html index 938d2c69808b64..d974e6d7f904dd 100644 --- a/examples/webgl_mirror_nodes.html +++ b/examples/webgl_mirror_nodes.html @@ -325,7 +325,7 @@ smallSphere.rotation.y = ( Math.PI / 2 ) - timer * 0.1; smallSphere.rotation.z = timer * 0.8; - frame.update( delta ).updateFrame( groundMirrorMaterial ); + frame.update( delta ).updateNode( groundMirrorMaterial ); render(); diff --git a/examples/webgl_postprocessing_nodes.html b/examples/webgl_postprocessing_nodes.html index 38c3664d82248e..6694cd4d04713f 100644 --- a/examples/webgl_postprocessing_nodes.html +++ b/examples/webgl_postprocessing_nodes.html @@ -591,7 +591,7 @@ object.rotation.x += 0.005; object.rotation.y += 0.01; - frame.update( delta ).updateFrame( nodepass.node ); + frame.update( delta ).updateNode( nodepass.node ); composer.render(); diff --git a/examples/webgl_sprites_nodes.html b/examples/webgl_sprites_nodes.html index 6a7e024eced753..54e5913980412a 100644 --- a/examples/webgl_sprites_nodes.html +++ b/examples/webgl_sprites_nodes.html @@ -302,9 +302,9 @@ // update material animation and/or gpu calcs (pre-renderer) frame.update( delta ) - .updateFrame( sprite1.material ) - .updateFrame( sprite2.material ) - .updateFrame( sprite3.material ); + .updateNode( sprite1.material ) + .updateNode( sprite2.material ) + .updateNode( sprite3.material ); // rotate sprite sprite3.rotation.z -= Math.PI * .005; From 1042ada6d9c48791bfde31471a770df45d472225 Mon Sep 17 00:00:00 2001 From: sunag Date: Mon, 5 Feb 2018 13:41:25 -0200 Subject: [PATCH 03/13] fix names --- examples/js/nodes/inputs/ColorNode.js | 2 +- examples/js/nodes/inputs/FloatNode.js | 2 +- examples/js/nodes/inputs/IntNode.js | 2 +- examples/js/nodes/inputs/Matrix3Node.js | 4 ++-- examples/js/nodes/inputs/Matrix4Node.js | 4 ++-- examples/js/nodes/inputs/Vector2Node.js | 2 +- examples/js/nodes/inputs/Vector3Node.js | 2 +- examples/js/nodes/inputs/Vector4Node.js | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/js/nodes/inputs/ColorNode.js b/examples/js/nodes/inputs/ColorNode.js index 497f077a334751..255b55716e8abf 100644 --- a/examples/js/nodes/inputs/ColorNode.js +++ b/examples/js/nodes/inputs/ColorNode.js @@ -34,7 +34,7 @@ THREE.ColorNode.prototype.toJSON = function ( meta ) { data.g = this.g; data.b = this.b; - if ( this.readyonly === true ) data.readyonly = true; + if ( this.readonly === true ) data.readonly = true; } diff --git a/examples/js/nodes/inputs/FloatNode.js b/examples/js/nodes/inputs/FloatNode.js index 0ac081d10f4aff..fadd556385cb5e 100644 --- a/examples/js/nodes/inputs/FloatNode.js +++ b/examples/js/nodes/inputs/FloatNode.js @@ -47,7 +47,7 @@ THREE.FloatNode.prototype.toJSON = function ( meta ) { data.number = this.number; - if ( this.readyonly === true ) data.readyonly = true; + if ( this.readonly === true ) data.readonly = true; } diff --git a/examples/js/nodes/inputs/IntNode.js b/examples/js/nodes/inputs/IntNode.js index f05ecfb9849231..48e90ed3fb5e2d 100644 --- a/examples/js/nodes/inputs/IntNode.js +++ b/examples/js/nodes/inputs/IntNode.js @@ -45,7 +45,7 @@ THREE.IntNode.prototype.toJSON = function ( meta ) { data.number = this.number; - if ( this.readyonly === true ) data.readyonly = true; + if ( this.readonly === true ) data.readonly = true; } diff --git a/examples/js/nodes/inputs/Matrix3Node.js b/examples/js/nodes/inputs/Matrix3Node.js index 7fd2f56d452593..19d795d61f9fe0 100644 --- a/examples/js/nodes/inputs/Matrix3Node.js +++ b/examples/js/nodes/inputs/Matrix3Node.js @@ -16,7 +16,7 @@ THREE.Matrix3Node.prototype.nodeType = "Matrix3"; THREE.Matrix3Node.prototype.generateReadonly = function ( builder, output, uuid, type, ns, needsUpdate ) { - return builder.format( "mat3( " + this.value.elements.joint( ", " ) + " )", type, output ); + return builder.format( "mat3( " + this.value.elements.join( ", " ) + " )", type, output ); }; @@ -30,7 +30,7 @@ THREE.Matrix3Node.prototype.toJSON = function ( meta ) { data.elements = this.value.elements.concat(); - if ( this.readyonly === true ) data.readyonly = true; + if ( this.readonly === true ) data.readonly = true; } diff --git a/examples/js/nodes/inputs/Matrix4Node.js b/examples/js/nodes/inputs/Matrix4Node.js index cc56b8b2283201..fa9ca859fa33a9 100644 --- a/examples/js/nodes/inputs/Matrix4Node.js +++ b/examples/js/nodes/inputs/Matrix4Node.js @@ -16,7 +16,7 @@ THREE.Matrix4Node.prototype.nodeType = "Matrix4"; THREE.Matrix4Node.prototype.generateReadonly = function ( builder, output, uuid, type, ns, needsUpdate ) { - return builder.format( "mat4( " + this.value.elements.joint( ", " ) + " )", type, output ); + return builder.format( "mat4( " + this.value.elements.join( ", " ) + " )", type, output ); }; @@ -30,7 +30,7 @@ THREE.Matrix4Node.prototype.toJSON = function ( meta ) { data.elements = this.value.elements.concat(); - if ( this.readyonly === true ) data.readyonly = true; + if ( this.readonly === true ) data.readonly = true; } diff --git a/examples/js/nodes/inputs/Vector2Node.js b/examples/js/nodes/inputs/Vector2Node.js index 752135e3f0bbeb..593f565f978cad 100644 --- a/examples/js/nodes/inputs/Vector2Node.js +++ b/examples/js/nodes/inputs/Vector2Node.js @@ -33,7 +33,7 @@ THREE.Vector2Node.prototype.toJSON = function ( meta ) { data.x = this.x; data.y = this.y; - if ( this.readyonly === true ) data.readyonly = true; + if ( this.readonly === true ) data.readonly = true; } diff --git a/examples/js/nodes/inputs/Vector3Node.js b/examples/js/nodes/inputs/Vector3Node.js index 72587495901b44..62e7d403fdea76 100644 --- a/examples/js/nodes/inputs/Vector3Node.js +++ b/examples/js/nodes/inputs/Vector3Node.js @@ -35,7 +35,7 @@ THREE.Vector3Node.prototype.toJSON = function ( meta ) { data.y = this.y; data.z = this.z; - if ( this.readyonly === true ) data.readyonly = true; + if ( this.readonly === true ) data.readonly = true; } diff --git a/examples/js/nodes/inputs/Vector4Node.js b/examples/js/nodes/inputs/Vector4Node.js index 48667167963800..b67fc4b3dd146e 100644 --- a/examples/js/nodes/inputs/Vector4Node.js +++ b/examples/js/nodes/inputs/Vector4Node.js @@ -35,7 +35,7 @@ THREE.Vector4Node.prototype.toJSON = function ( meta ) { data.z = this.z; data.w = this.w; - if ( this.readyonly === true ) data.readyonly = true; + if ( this.readonly === true ) data.readonly = true; } From ec725721488b7706588157a74ee387ed39e5ca43 Mon Sep 17 00:00:00 2001 From: sunag Date: Mon, 5 Feb 2018 13:42:40 -0200 Subject: [PATCH 04/13] text --- examples/webgl_materials_nodes.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/webgl_materials_nodes.html b/examples/webgl_materials_nodes.html index d4ed1406236b1f..f4075967c3fcc3 100644 --- a/examples/webgl_materials_nodes.html +++ b/examples/webgl_materials_nodes.html @@ -2029,7 +2029,7 @@ mtl.shininess = new THREE.FloatNode( 15 ); // not use "uniform" input ( for optimization ) - // instead use explicit declaration example: + // instead use explicit declaration, for example: // vec3( 1.0, 1.0, 1.0 ) instead "uniform vec3" // but not allow change the value after build the shader material mtl.color.readonly = mtl.specular.readonly = mtl.shininess.readonly = true; From e7fcf56985e4d1b7f6f6c0f5483ee3d0fbe9d85f Mon Sep 17 00:00:00 2001 From: sunag Date: Mon, 5 Feb 2018 13:48:02 -0200 Subject: [PATCH 05/13] text --- examples/webgl_materials_nodes.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/webgl_materials_nodes.html b/examples/webgl_materials_nodes.html index f4075967c3fcc3..e0f7b7ee78d0b1 100644 --- a/examples/webgl_materials_nodes.html +++ b/examples/webgl_materials_nodes.html @@ -2031,7 +2031,7 @@ // not use "uniform" input ( for optimization ) // instead use explicit declaration, for example: // vec3( 1.0, 1.0, 1.0 ) instead "uniform vec3" - // but not allow change the value after build the shader material + // if readonly is true not allow change the value after build the shader material mtl.color.readonly = mtl.specular.readonly = mtl.shininess.readonly = true; break; From 9474471d2b612b8641eb8bba4ffad8bd6297317d Mon Sep 17 00:00:00 2001 From: sunag Date: Mon, 5 Feb 2018 13:52:35 -0200 Subject: [PATCH 06/13] text --- examples/webgl_materials_nodes.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/webgl_materials_nodes.html b/examples/webgl_materials_nodes.html index e0f7b7ee78d0b1..650139dc927a05 100644 --- a/examples/webgl_materials_nodes.html +++ b/examples/webgl_materials_nodes.html @@ -2022,6 +2022,8 @@ case 'readonly': + // MATERIAL + mtl = new THREE.PhongNodeMaterial(); mtl.color = new THREE.ColorNode( 0xFFFFFF ); From 43db54b5330e2f9cc32e5fd97b71ba32076842ca Mon Sep 17 00:00:00 2001 From: sunag Date: Mon, 5 Feb 2018 18:00:20 -0200 Subject: [PATCH 07/13] speed vs readability --- examples/js/nodes/inputs/FloatNode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/js/nodes/inputs/FloatNode.js b/examples/js/nodes/inputs/FloatNode.js index fadd556385cb5e..0b2e0bc4f1b74e 100644 --- a/examples/js/nodes/inputs/FloatNode.js +++ b/examples/js/nodes/inputs/FloatNode.js @@ -33,7 +33,7 @@ THREE.FloatNode.prototype.generateReadonly = function ( builder, output, uuid, t var value = this.number; - return builder.format( ~~value !== value ? value : value + ".0", type, output ); + return builder.format( Math.floor( value ) !== value ? value : value + ".0", type, output ); }; From c955d3ae8cd9b6aa6cf39f56308291cb7e823141 Mon Sep 17 00:00:00 2001 From: sunag Date: Tue, 6 Feb 2018 13:10:57 -0200 Subject: [PATCH 08/13] timeSscale is first argument in TimerNode --- examples/js/nodes/utils/TimerNode.js | 4 ++-- examples/webgl_sprites_nodes.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/js/nodes/utils/TimerNode.js b/examples/js/nodes/utils/TimerNode.js index b559ec5044a15c..05fcb9d8f2e5c9 100644 --- a/examples/js/nodes/utils/TimerNode.js +++ b/examples/js/nodes/utils/TimerNode.js @@ -2,12 +2,12 @@ * @author sunag / http://www.sunag.com.br/ */ -THREE.TimerNode = function ( scope, scale ) { +THREE.TimerNode = function ( scale, scope ) { THREE.FloatNode.call( this ); - this.scope = scope || THREE.TimerNode.GLOBAL; this.scale = scale !== undefined ? scale : 1; + this.scope = scope || THREE.TimerNode.GLOBAL; }; diff --git a/examples/webgl_sprites_nodes.html b/examples/webgl_sprites_nodes.html index 54e5913980412a..367c2207ec12fb 100644 --- a/examples/webgl_sprites_nodes.html +++ b/examples/webgl_sprites_nodes.html @@ -215,7 +215,7 @@ // horizontal zigzag sprite sprite2.material.transform = new THREE.OperatorNode( new THREE.OperatorNode( - new THREE.Math1Node( new THREE.TimerNode( 0, 3 ), THREE.Math1Node.SIN ), // 3 is speed (time scale) + new THREE.Math1Node( new THREE.TimerNode( 3 ), THREE.Math1Node.SIN ), // 3 is speed (time scale) new THREE.Vector2Node( .3, 0 ), // horizontal scale (position) THREE.OperatorNode.MUL ), From d6e1c5fd8aad332eec2f3357e5ae0cf8402b2613 Mon Sep 17 00:00:00 2001 From: sunag Date: Tue, 6 Feb 2018 13:47:47 -0200 Subject: [PATCH 09/13] TimerNode.timeScale optional - share "uniform" input if is used on more time with others TimerNode --- examples/js/nodes/utils/TimerNode.js | 18 +++++++++++++++--- examples/webgl_loader_nodes.html | 4 ++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/examples/js/nodes/utils/TimerNode.js b/examples/js/nodes/utils/TimerNode.js index 05fcb9d8f2e5c9..3b5eeecdb8c90e 100644 --- a/examples/js/nodes/utils/TimerNode.js +++ b/examples/js/nodes/utils/TimerNode.js @@ -9,6 +9,8 @@ THREE.TimerNode = function ( scale, scope ) { this.scale = scale !== undefined ? scale : 1; this.scope = scope || THREE.TimerNode.GLOBAL; + this.timeScale = this.scale !== 1; + }; THREE.TimerNode.GLOBAL = 'global'; @@ -19,25 +21,34 @@ THREE.TimerNode.prototype = Object.create( THREE.FloatNode.prototype ); THREE.TimerNode.prototype.constructor = THREE.TimerNode; THREE.TimerNode.prototype.nodeType = "Timer"; +THREE.TimerNode.prototype.isUnique = function ( builder ) { + + // share TimerNode "uniform" input if is used on more time with others TimerNode + return this.timeScale && ( this.scope === THREE.TimerNode.GLOBAL || this.scope === THREE.TimerNode.DELTA ); + +}; + THREE.TimerNode.prototype.updateFrame = function ( frame ) { + var scale = this.timeScale ? this.scale : 1; + switch( this.scope ) { case THREE.TimerNode.LOCAL: - this.number += frame.delta * this.scale; + this.number += frame.delta * scale; break; case THREE.TimerNode.DELTA: - this.number = frame.delta * this.scale; + this.number = frame.delta * scale; break; default: - this.number = frame.time * this.scale; + this.number = frame.time * scale; } @@ -53,6 +64,7 @@ THREE.TimerNode.prototype.toJSON = function ( meta ) { data.scope = this.scope; data.scale = this.scale; + data.timeScale = this.timeScale; } diff --git a/examples/webgl_loader_nodes.html b/examples/webgl_loader_nodes.html index a612ec77f51d63..d907084df31d1a 100644 --- a/examples/webgl_loader_nodes.html +++ b/examples/webgl_loader_nodes.html @@ -243,6 +243,10 @@ if (time) { + time.timeScale = true; + + loader.material.build(); + addGui( 'timeScale', time.scale, function ( val ) { time.scale = val; From d0c23311257d9f7649ff5d007c48859a8a86c6ee Mon Sep 17 00:00:00 2001 From: sunag Date: Tue, 6 Feb 2018 13:49:04 -0200 Subject: [PATCH 10/13] text --- examples/webgl_loader_nodes.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/webgl_loader_nodes.html b/examples/webgl_loader_nodes.html index d907084df31d1a..df33fb084e7739 100644 --- a/examples/webgl_loader_nodes.html +++ b/examples/webgl_loader_nodes.html @@ -243,9 +243,13 @@ if (time) { - time.timeScale = true; + // enable time scale + time.timeScale = true; + loader.material.build(); + + // gui addGui( 'timeScale', time.scale, function ( val ) { From 298203f55ee020ff9da1583e63c296916179a008 Mon Sep 17 00:00:00 2001 From: sunag Date: Tue, 6 Feb 2018 13:51:35 -0200 Subject: [PATCH 11/13] codestyle --- examples/webgl_loader_nodes.html | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/webgl_loader_nodes.html b/examples/webgl_loader_nodes.html index df33fb084e7739..0377ea125cc197 100644 --- a/examples/webgl_loader_nodes.html +++ b/examples/webgl_loader_nodes.html @@ -224,7 +224,7 @@ } - + function updateMaterial() { if ( mesh.material ) mesh.material.dispose(); @@ -234,31 +234,31 @@ var url = "nodes/" + param.load + ".json"; var library = { - "cloud" : cloud + "cloud": cloud }; var loader = new THREE.NodeMaterialLoader( undefined, library ).load( url, function () { - var time = loader.getObjectByName("time"); - - if (time) { - + var time = loader.getObjectByName( "time" ); + + if ( time ) { + // enable time scale - + time.timeScale = true; loader.material.build(); - + // gui - + addGui( 'timeScale', time.scale, function ( val ) { time.scale = val; - }, false, -2, 2 ); - + }, false, - 2, 2 ); + } - + // set material mesh.material = loader.material; From 18b7bcc37162057d9355a8063af86a78c25c9f36 Mon Sep 17 00:00:00 2001 From: sunag Date: Tue, 6 Feb 2018 13:55:39 -0200 Subject: [PATCH 12/13] fix readonly TimerNode --- examples/js/nodes/InputNode.js | 8 +++++++- examples/js/nodes/utils/TimerNode.js | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/js/nodes/InputNode.js b/examples/js/nodes/InputNode.js index 38c1b3986c2e18..1675464e714676 100644 --- a/examples/js/nodes/InputNode.js +++ b/examples/js/nodes/InputNode.js @@ -16,6 +16,12 @@ THREE.InputNode = function ( type, params ) { THREE.InputNode.prototype = Object.create( THREE.TempNode.prototype ); THREE.InputNode.prototype.constructor = THREE.InputNode; +THREE.InputNode.prototype.isReadonly = function ( builder ) { + + return this.readonly; + +}; + THREE.InputNode.prototype.generate = function ( builder, output, uuid, type, ns, needsUpdate ) { var material = builder.material; @@ -24,7 +30,7 @@ THREE.InputNode.prototype.generate = function ( builder, output, uuid, type, ns, type = type || this.getType( builder ); var data = material.getDataNode( uuid ), - readonly = this.readonly && this.generateReadonly !== undefined; + readonly = this.isReadonly( builder ) && this.generateReadonly !== undefined; if ( readonly ) { diff --git a/examples/js/nodes/utils/TimerNode.js b/examples/js/nodes/utils/TimerNode.js index 3b5eeecdb8c90e..6dcfecf8ee19f4 100644 --- a/examples/js/nodes/utils/TimerNode.js +++ b/examples/js/nodes/utils/TimerNode.js @@ -21,6 +21,12 @@ THREE.TimerNode.prototype = Object.create( THREE.FloatNode.prototype ); THREE.TimerNode.prototype.constructor = THREE.TimerNode; THREE.TimerNode.prototype.nodeType = "Timer"; +THREE.TimerNode.prototype.isReadonly = function ( builder ) { + + return false; + +}; + THREE.TimerNode.prototype.isUnique = function ( builder ) { // share TimerNode "uniform" input if is used on more time with others TimerNode From 5bb2c369a7dc657e8fde27c74d720cd3b371ee3c Mon Sep 17 00:00:00 2001 From: sunag Date: Tue, 6 Feb 2018 14:00:28 -0200 Subject: [PATCH 13/13] fix readonly VelocityNode --- examples/js/nodes/utils/VelocityNode.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/js/nodes/utils/VelocityNode.js b/examples/js/nodes/utils/VelocityNode.js index 8982ba62713076..ed699f3f73fb34 100644 --- a/examples/js/nodes/utils/VelocityNode.js +++ b/examples/js/nodes/utils/VelocityNode.js @@ -19,6 +19,12 @@ THREE.VelocityNode.prototype = Object.create( THREE.Vector3Node.prototype ); THREE.VelocityNode.prototype.constructor = THREE.VelocityNode; THREE.VelocityNode.prototype.nodeType = "Velocity"; +THREE.VelocityNode.prototype.isReadonly = function ( builder ) { + + return false; + +}; + THREE.VelocityNode.prototype.setParams = function ( params ) { switch ( this.params.type ) {