Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputNode readonly option #13250

Merged
merged 13 commits into from
Feb 7, 2018
7 changes: 7 additions & 0 deletions examples/js/loaders/NodeMaterialLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Expand Down
39 changes: 28 additions & 11 deletions examples/js/nodes/InputNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,56 @@ THREE.InputNode = function ( type, params ) {

THREE.TempNode.call( this, type, params );

this.readonly = false;

};

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;

uuid = builder.getUuid( uuid || this.getUuid() );
type = type || this.getType( builder );

var data = material.getDataNode( uuid );
var data = material.getDataNode( uuid ),
readonly = this.isReadonly( builder ) && 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 {

if ( ! data.fragment ) {

data.fragment = material.createFragmentUniform( type, this.value, ns, needsUpdate );

return builder.format( data.fragment.name, type, output );
}

return builder.format( data.fragment.name, type, output );

}

}

Expand Down
2 changes: 1 addition & 1 deletion examples/js/nodes/NodeFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion examples/js/nodes/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );

}

Expand Down
8 changes: 8 additions & 0 deletions examples/js/nodes/inputs/ColorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -28,6 +34,8 @@ THREE.ColorNode.prototype.toJSON = function ( meta ) {
data.g = this.g;
data.b = this.b;

if ( this.readonly === true ) data.readonly = true;

}

return data;
Expand Down
10 changes: 10 additions & 0 deletions examples/js/nodes/inputs/FloatNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( Math.floor( value ) !== value ? value : value + ".0", type, output );

};

THREE.FloatNode.prototype.toJSON = function ( meta ) {

var data = this.getJSONNode( meta );
Expand All @@ -39,6 +47,8 @@ THREE.FloatNode.prototype.toJSON = function ( meta ) {

data.number = this.number;

if ( this.readonly === true ) data.readonly = true;

}

return data;
Expand Down
8 changes: 8 additions & 0 deletions examples/js/nodes/inputs/IntNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -39,6 +45,8 @@ THREE.IntNode.prototype.toJSON = function ( meta ) {

data.number = this.number;

if ( this.readonly === true ) data.readonly = true;

}

return data;
Expand Down
8 changes: 8 additions & 0 deletions examples/js/nodes/inputs/Matrix3Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.join( ", " ) + " )", type, output );

};

THREE.Matrix3Node.prototype.toJSON = function ( meta ) {

var data = this.getJSONNode( meta );
Expand All @@ -24,6 +30,8 @@ THREE.Matrix3Node.prototype.toJSON = function ( meta ) {

data.elements = this.value.elements.concat();

if ( this.readonly === true ) data.readonly = true;

}

return data;
Expand Down
8 changes: 8 additions & 0 deletions examples/js/nodes/inputs/Matrix4Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.join( ", " ) + " )", type, output );

};

THREE.Matrix4Node.prototype.toJSON = function ( meta ) {

var data = this.getJSONNode( meta );
Expand All @@ -24,6 +30,8 @@ THREE.Matrix4Node.prototype.toJSON = function ( meta ) {

data.elements = this.value.elements.concat();

if ( this.readonly === true ) data.readonly = true;

}

return data;
Expand Down
8 changes: 8 additions & 0 deletions examples/js/nodes/inputs/Vector2Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -27,6 +33,8 @@ THREE.Vector2Node.prototype.toJSON = function ( meta ) {
data.x = this.x;
data.y = this.y;

if ( this.readonly === true ) data.readonly = true;

}

return data;
Expand Down
8 changes: 8 additions & 0 deletions examples/js/nodes/inputs/Vector3Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -29,6 +35,8 @@ THREE.Vector3Node.prototype.toJSON = function ( meta ) {
data.y = this.y;
data.z = this.z;

if ( this.readonly === true ) data.readonly = true;

}

return data;
Expand Down
8 changes: 8 additions & 0 deletions examples/js/nodes/inputs/Vector4Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -29,6 +35,8 @@ THREE.Vector4Node.prototype.toJSON = function ( meta ) {
data.z = this.z;
data.w = this.w;

if ( this.readonly === true ) data.readonly = true;

}

return data;
Expand Down
28 changes: 23 additions & 5 deletions examples/js/nodes/utils/TimerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
* @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;

this.timeScale = this.scale !== 1;

};

Expand All @@ -19,25 +21,40 @@ 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
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;

}

Expand All @@ -53,6 +70,7 @@ THREE.TimerNode.prototype.toJSON = function ( meta ) {

data.scope = this.scope;
data.scale = this.scale;
data.timeScale = this.timeScale;

}

Expand Down
6 changes: 6 additions & 0 deletions examples/js/nodes/utils/VelocityNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
Loading