|
@@ -3,12 +3,12 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
THREE.NodeMaterial = function( vertex, fragment ) {
|
|
THREE.NodeMaterial = function( vertex, fragment ) {
|
|
-
|
|
|
|
|
|
+
|
|
THREE.ShaderMaterial.call( this );
|
|
THREE.ShaderMaterial.call( this );
|
|
-
|
|
|
|
|
|
+
|
|
this.vertex = vertex || new THREE.RawNode( new THREE.PositionNode( THREE.PositionNode.PROJECTION ) );
|
|
this.vertex = vertex || new THREE.RawNode( new THREE.PositionNode( THREE.PositionNode.PROJECTION ) );
|
|
this.fragment = fragment || new THREE.RawNode( new THREE.ColorNode( 0xFF0000 ) );
|
|
this.fragment = fragment || new THREE.RawNode( new THREE.ColorNode( 0xFF0000 ) );
|
|
-
|
|
|
|
|
|
+
|
|
};
|
|
};
|
|
|
|
|
|
THREE.NodeMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
|
|
THREE.NodeMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
|
|
@@ -27,168 +27,176 @@ THREE.NodeMaterial.Type = {
|
|
};
|
|
};
|
|
|
|
|
|
THREE.NodeMaterial.GetShortcuts = function( prop, name ) {
|
|
THREE.NodeMaterial.GetShortcuts = function( prop, name ) {
|
|
-
|
|
|
|
|
|
+
|
|
return {
|
|
return {
|
|
- get: function () { return this[prop][name]; },
|
|
|
|
- set: function ( val ) { this[prop][name] = val; }
|
|
|
|
|
|
+ get: function() {
|
|
|
|
+
|
|
|
|
+ return this[ prop ][ name ];
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+ set: function( val ) {
|
|
|
|
+
|
|
|
|
+ this[ prop ][ name ] = val;
|
|
|
|
+
|
|
|
|
+ }
|
|
};
|
|
};
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
THREE.NodeMaterial.Shortcuts = function( proto, prop, list ) {
|
|
THREE.NodeMaterial.Shortcuts = function( proto, prop, list ) {
|
|
-
|
|
|
|
|
|
+
|
|
var shortcuts = {};
|
|
var shortcuts = {};
|
|
-
|
|
|
|
- for(var i = 0; i < list.length; ++i) {
|
|
|
|
-
|
|
|
|
- var name = list[i];
|
|
|
|
-
|
|
|
|
- shortcuts[name] = this.GetShortcuts( prop, name );
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ for ( var i = 0; i < list.length; ++ i ) {
|
|
|
|
+
|
|
|
|
+ var name = list[ i ];
|
|
|
|
+
|
|
|
|
+ shortcuts[ name ] = this.GetShortcuts( prop, name );
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Object.defineProperties( proto, shortcuts );
|
|
Object.defineProperties( proto, shortcuts );
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
THREE.NodeMaterial.prototype.updateAnimation = function( delta ) {
|
|
THREE.NodeMaterial.prototype.updateAnimation = function( delta ) {
|
|
-
|
|
|
|
- for(var i = 0; i < this.requestUpdate.length; ++i) {
|
|
|
|
|
|
|
|
- this.requestUpdate[i].updateAnimation( delta );
|
|
|
|
-
|
|
|
|
|
|
+ for ( var i = 0; i < this.requestUpdate.length; ++ i ) {
|
|
|
|
+
|
|
|
|
+ this.requestUpdate[ i ].updateAnimation( delta );
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
};
|
|
};
|
|
|
|
|
|
THREE.NodeMaterial.prototype.build = function() {
|
|
THREE.NodeMaterial.prototype.build = function() {
|
|
-
|
|
|
|
|
|
+
|
|
var vertex, fragment;
|
|
var vertex, fragment;
|
|
-
|
|
|
|
|
|
+
|
|
this.defines = {};
|
|
this.defines = {};
|
|
- this.uniforms = {};
|
|
|
|
-
|
|
|
|
- this.nodeData = {};
|
|
|
|
-
|
|
|
|
|
|
+ this.uniforms = {};
|
|
|
|
+
|
|
|
|
+ this.nodeData = {};
|
|
|
|
+
|
|
this.vertexUniform = [];
|
|
this.vertexUniform = [];
|
|
this.fragmentUniform = [];
|
|
this.fragmentUniform = [];
|
|
-
|
|
|
|
|
|
+
|
|
this.vertexTemps = [];
|
|
this.vertexTemps = [];
|
|
this.fragmentTemps = [];
|
|
this.fragmentTemps = [];
|
|
-
|
|
|
|
|
|
+
|
|
this.uniformList = [];
|
|
this.uniformList = [];
|
|
-
|
|
|
|
|
|
+
|
|
this.consts = [];
|
|
this.consts = [];
|
|
this.functions = [];
|
|
this.functions = [];
|
|
-
|
|
|
|
|
|
+
|
|
this.requestUpdate = [];
|
|
this.requestUpdate = [];
|
|
-
|
|
|
|
|
|
+
|
|
this.requestAttrib = {
|
|
this.requestAttrib = {
|
|
- uv:[],
|
|
|
|
- color:[]
|
|
|
|
|
|
+ uv: [],
|
|
|
|
+ color: []
|
|
};
|
|
};
|
|
-
|
|
|
|
|
|
+
|
|
this.needsColor = false;
|
|
this.needsColor = false;
|
|
this.needsLight = false;
|
|
this.needsLight = false;
|
|
this.needsPosition = false;
|
|
this.needsPosition = false;
|
|
this.needsTransparent = false;
|
|
this.needsTransparent = false;
|
|
-
|
|
|
|
|
|
+
|
|
this.vertexPars = '';
|
|
this.vertexPars = '';
|
|
this.fragmentPars = '';
|
|
this.fragmentPars = '';
|
|
-
|
|
|
|
|
|
+
|
|
this.vertexCode = '';
|
|
this.vertexCode = '';
|
|
this.fragmentCode = '';
|
|
this.fragmentCode = '';
|
|
-
|
|
|
|
|
|
+
|
|
this.vertexNode = '';
|
|
this.vertexNode = '';
|
|
this.fragmentNode = '';
|
|
this.fragmentNode = '';
|
|
-
|
|
|
|
- var builder = new THREE.BuilderNode(this);
|
|
|
|
-
|
|
|
|
- vertex = this.vertex.build( builder.setShader('vertex'), 'v4' );
|
|
|
|
- fragment = this.fragment.build( builder.setShader('fragment'), 'v4' );
|
|
|
|
-
|
|
|
|
- if (this.requestAttrib.uv[0]) {
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ var builder = new THREE.BuilderNode( this );
|
|
|
|
+
|
|
|
|
+ vertex = this.vertex.build( builder.setShader( 'vertex' ), 'v4' );
|
|
|
|
+ fragment = this.fragment.build( builder.setShader( 'fragment' ), 'v4' );
|
|
|
|
+
|
|
|
|
+ if ( this.requestAttrib.uv[ 0 ] ) {
|
|
|
|
+
|
|
this.addVertexPars( 'varying vec2 vUv;' );
|
|
this.addVertexPars( 'varying vec2 vUv;' );
|
|
this.addFragmentPars( 'varying vec2 vUv;' );
|
|
this.addFragmentPars( 'varying vec2 vUv;' );
|
|
-
|
|
|
|
|
|
+
|
|
this.addVertexCode( 'vUv = uv;' );
|
|
this.addVertexCode( 'vUv = uv;' );
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (this.requestAttrib.uv[1]) {
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ if ( this.requestAttrib.uv[ 1 ] ) {
|
|
|
|
+
|
|
this.addVertexPars( 'varying vec2 vUv2; attribute vec2 uv2;' );
|
|
this.addVertexPars( 'varying vec2 vUv2; attribute vec2 uv2;' );
|
|
this.addFragmentPars( 'varying vec2 vUv2;' );
|
|
this.addFragmentPars( 'varying vec2 vUv2;' );
|
|
-
|
|
|
|
|
|
+
|
|
this.addVertexCode( 'vUv2 = uv2;' );
|
|
this.addVertexCode( 'vUv2 = uv2;' );
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (this.requestAttrib.color[0]) {
|
|
|
|
|
|
+
|
|
|
|
+ if ( this.requestAttrib.color[ 0 ] ) {
|
|
|
|
|
|
this.addVertexPars( 'varying vec4 vColor; attribute vec4 color;' );
|
|
this.addVertexPars( 'varying vec4 vColor; attribute vec4 color;' );
|
|
this.addFragmentPars( 'varying vec4 vColor;' );
|
|
this.addFragmentPars( 'varying vec4 vColor;' );
|
|
-
|
|
|
|
|
|
+
|
|
this.addVertexCode( 'vColor = color;' );
|
|
this.addVertexCode( 'vColor = color;' );
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (this.requestAttrib.color[1]) {
|
|
|
|
|
|
+
|
|
|
|
+ if ( this.requestAttrib.color[ 1 ] ) {
|
|
|
|
|
|
this.addVertexPars( 'varying vec4 vColor2; attribute vec4 color2;' );
|
|
this.addVertexPars( 'varying vec4 vColor2; attribute vec4 color2;' );
|
|
this.addFragmentPars( 'varying vec4 vColor2;' );
|
|
this.addFragmentPars( 'varying vec4 vColor2;' );
|
|
-
|
|
|
|
|
|
+
|
|
this.addVertexCode( 'vColor2 = color2;' );
|
|
this.addVertexCode( 'vColor2 = color2;' );
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (this.requestAttrib.position) {
|
|
|
|
|
|
+
|
|
|
|
+ if ( this.requestAttrib.position ) {
|
|
|
|
|
|
this.addVertexPars( 'varying vec3 vPosition;' );
|
|
this.addVertexPars( 'varying vec3 vPosition;' );
|
|
this.addFragmentPars( 'varying vec3 vPosition;' );
|
|
this.addFragmentPars( 'varying vec3 vPosition;' );
|
|
-
|
|
|
|
|
|
+
|
|
this.addVertexCode( 'vPosition = transformed;' );
|
|
this.addVertexCode( 'vPosition = transformed;' );
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (this.requestAttrib.worldPosition) {
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ if ( this.requestAttrib.worldPosition ) {
|
|
|
|
+
|
|
// for future update replace from the native "varying vec3 vWorldPosition" for optimization
|
|
// for future update replace from the native "varying vec3 vWorldPosition" for optimization
|
|
-
|
|
|
|
|
|
+
|
|
this.addVertexPars( 'varying vec3 vWPosition;' );
|
|
this.addVertexPars( 'varying vec3 vWPosition;' );
|
|
this.addFragmentPars( 'varying vec3 vWPosition;' );
|
|
this.addFragmentPars( 'varying vec3 vWPosition;' );
|
|
-
|
|
|
|
|
|
+
|
|
this.addVertexCode( 'vWPosition = worldPosition.xyz;' );
|
|
this.addVertexCode( 'vWPosition = worldPosition.xyz;' );
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (this.requestAttrib.normal) {
|
|
|
|
|
|
+
|
|
|
|
+ if ( this.requestAttrib.normal ) {
|
|
|
|
|
|
this.addVertexPars( 'varying vec3 vObjectNormal;' );
|
|
this.addVertexPars( 'varying vec3 vObjectNormal;' );
|
|
this.addFragmentPars( 'varying vec3 vObjectNormal;' );
|
|
this.addFragmentPars( 'varying vec3 vObjectNormal;' );
|
|
-
|
|
|
|
|
|
+
|
|
this.addVertexCode( 'vObjectNormal = normal;' );
|
|
this.addVertexCode( 'vObjectNormal = normal;' );
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (this.requestAttrib.worldNormal) {
|
|
|
|
|
|
+
|
|
|
|
+ if ( this.requestAttrib.worldNormal ) {
|
|
|
|
|
|
this.addVertexPars( 'varying vec3 vWNormal;' );
|
|
this.addVertexPars( 'varying vec3 vWNormal;' );
|
|
this.addFragmentPars( 'varying vec3 vWNormal;' );
|
|
this.addFragmentPars( 'varying vec3 vWNormal;' );
|
|
-
|
|
|
|
|
|
+
|
|
this.addVertexCode( 'vWNormal = ( modelMatrix * vec4( objectNormal, 0.0 ) ).xyz;' );
|
|
this.addVertexCode( 'vWNormal = ( modelMatrix * vec4( objectNormal, 0.0 ) ).xyz;' );
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
this.lights = this.needsLight;
|
|
this.lights = this.needsLight;
|
|
this.transparent = this.needsTransparent;
|
|
this.transparent = this.needsTransparent;
|
|
-
|
|
|
|
|
|
+
|
|
this.vertexShader = [
|
|
this.vertexShader = [
|
|
this.vertexPars,
|
|
this.vertexPars,
|
|
this.getCodePars( this.vertexUniform, 'uniform' ),
|
|
this.getCodePars( this.vertexUniform, 'uniform' ),
|
|
- this.getIncludes(this.consts['vertex']),
|
|
|
|
- this.getIncludes(this.functions['vertex']),
|
|
|
|
|
|
+ this.getIncludes( this.consts[ 'vertex' ] ),
|
|
|
|
+ this.getIncludes( this.functions[ 'vertex' ] ),
|
|
'void main(){',
|
|
'void main(){',
|
|
this.getCodePars( this.vertexTemps ),
|
|
this.getCodePars( this.vertexTemps ),
|
|
vertex,
|
|
vertex,
|
|
@@ -199,115 +207,120 @@ THREE.NodeMaterial.prototype.build = function() {
|
|
this.fragmentShader = [
|
|
this.fragmentShader = [
|
|
this.fragmentPars,
|
|
this.fragmentPars,
|
|
this.getCodePars( this.fragmentUniform, 'uniform' ),
|
|
this.getCodePars( this.fragmentUniform, 'uniform' ),
|
|
- this.getIncludes(this.consts['fragment']),
|
|
|
|
- this.getIncludes(this.functions['fragment']),
|
|
|
|
|
|
+ this.getIncludes( this.consts[ 'fragment' ] ),
|
|
|
|
+ this.getIncludes( this.functions[ 'fragment' ] ),
|
|
'void main(){',
|
|
'void main(){',
|
|
this.getCodePars( this.fragmentTemps ),
|
|
this.getCodePars( this.fragmentTemps ),
|
|
this.fragmentCode,
|
|
this.fragmentCode,
|
|
fragment,
|
|
fragment,
|
|
'}'
|
|
'}'
|
|
].join( "\n" );
|
|
].join( "\n" );
|
|
-
|
|
|
|
|
|
+
|
|
this.needsUpdate = true;
|
|
this.needsUpdate = true;
|
|
this.dispose(); // force update
|
|
this.dispose(); // force update
|
|
-
|
|
|
|
|
|
+
|
|
return this;
|
|
return this;
|
|
|
|
+
|
|
};
|
|
};
|
|
|
|
|
|
-THREE.NodeMaterial.prototype.define = function(name, value) {
|
|
|
|
|
|
+THREE.NodeMaterial.prototype.define = function( name, value ) {
|
|
|
|
|
|
- this.defines[name] = value == undefined ? 1 : value;
|
|
|
|
|
|
+ this.defines[ name ] = value == undefined ? 1 : value;
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
-THREE.NodeMaterial.prototype.isDefined = function(name) {
|
|
|
|
|
|
+THREE.NodeMaterial.prototype.isDefined = function( name ) {
|
|
|
|
|
|
- return this.defines[name] != undefined;
|
|
|
|
|
|
+ return this.defines[ name ] != undefined;
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
THREE.NodeMaterial.prototype.mergeUniform = function( uniforms ) {
|
|
THREE.NodeMaterial.prototype.mergeUniform = function( uniforms ) {
|
|
-
|
|
|
|
- for (var name in uniforms) {
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ for ( var name in uniforms ) {
|
|
|
|
+
|
|
this.uniforms[ name ] = uniforms[ name ];
|
|
this.uniforms[ name ] = uniforms[ name ];
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
};
|
|
};
|
|
|
|
|
|
THREE.NodeMaterial.prototype.createUniform = function( value, type, needsUpdate ) {
|
|
THREE.NodeMaterial.prototype.createUniform = function( value, type, needsUpdate ) {
|
|
-
|
|
|
|
|
|
+
|
|
var index = this.uniformList.length;
|
|
var index = this.uniformList.length;
|
|
-
|
|
|
|
|
|
+
|
|
var uniform = {
|
|
var uniform = {
|
|
type : type,
|
|
type : type,
|
|
value : value,
|
|
value : value,
|
|
needsUpdate : needsUpdate,
|
|
needsUpdate : needsUpdate,
|
|
name : 'nVu' + index
|
|
name : 'nVu' + index
|
|
};
|
|
};
|
|
-
|
|
|
|
- this.uniformList.push(uniform);
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ this.uniformList.push( uniform );
|
|
|
|
+
|
|
return uniform;
|
|
return uniform;
|
|
-
|
|
|
|
|
|
+
|
|
};
|
|
};
|
|
|
|
|
|
THREE.NodeMaterial.prototype.getVertexTemp = function( uuid, type ) {
|
|
THREE.NodeMaterial.prototype.getVertexTemp = function( uuid, type ) {
|
|
-
|
|
|
|
- if (!this.vertexTemps[ uuid ]) {
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ if ( ! this.vertexTemps[ uuid ] ) {
|
|
|
|
+
|
|
var index = this.vertexTemps.length,
|
|
var index = this.vertexTemps.length,
|
|
name = 'nVt' + index,
|
|
name = 'nVt' + index,
|
|
data = { name : name, type : type };
|
|
data = { name : name, type : type };
|
|
-
|
|
|
|
|
|
+
|
|
this.vertexTemps.push( data );
|
|
this.vertexTemps.push( data );
|
|
- this.vertexTemps[uuid] = data;
|
|
|
|
-
|
|
|
|
|
|
+ this.vertexTemps[ uuid ] = data;
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- return this.vertexTemps[uuid];
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ return this.vertexTemps[ uuid ];
|
|
|
|
+
|
|
};
|
|
};
|
|
|
|
|
|
THREE.NodeMaterial.prototype.getIncludes = function( incs ) {
|
|
THREE.NodeMaterial.prototype.getIncludes = function( incs ) {
|
|
-
|
|
|
|
- function sortByPosition(a, b){
|
|
|
|
|
|
+
|
|
|
|
+ function sortByPosition( a, b ) {
|
|
|
|
+
|
|
return b.deps - a.deps;
|
|
return b.deps - a.deps;
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
return function( incs ) {
|
|
return function( incs ) {
|
|
-
|
|
|
|
- if (!incs) return '';
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ if ( ! incs ) return '';
|
|
|
|
+
|
|
var code = '';
|
|
var code = '';
|
|
- var incs = incs.sort(sortByPosition);
|
|
|
|
-
|
|
|
|
- for(var i = 0; i < incs.length; i++) {
|
|
|
|
-
|
|
|
|
- code += incs[i].node.src + '\n';
|
|
|
|
-
|
|
|
|
|
|
+ var incs = incs.sort( sortByPosition );
|
|
|
|
+
|
|
|
|
+ for ( var i = 0; i < incs.length; i ++ ) {
|
|
|
|
+
|
|
|
|
+ code += incs[ i ].node.src + '\n';
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
return code;
|
|
return code;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|
|
}();
|
|
}();
|
|
|
|
|
|
THREE.NodeMaterial.prototype.getFragmentTemp = function( uuid, type ) {
|
|
THREE.NodeMaterial.prototype.getFragmentTemp = function( uuid, type ) {
|
|
-
|
|
|
|
- if (!this.fragmentTemps[ uuid ]) {
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ if ( ! this.fragmentTemps[ uuid ] ) {
|
|
|
|
+
|
|
var index = this.fragmentTemps.length,
|
|
var index = this.fragmentTemps.length,
|
|
name = 'nVt' + index,
|
|
name = 'nVt' + index,
|
|
data = { name : name, type : type };
|
|
data = { name : name, type : type };
|
|
-
|
|
|
|
|
|
+
|
|
this.fragmentTemps.push( data );
|
|
this.fragmentTemps.push( data );
|
|
- this.fragmentTemps[uuid] = data;
|
|
|
|
-
|
|
|
|
|
|
+ this.fragmentTemps[ uuid ] = data;
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- return this.fragmentTemps[uuid];
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ return this.fragmentTemps[ uuid ];
|
|
|
|
+
|
|
};
|
|
};
|
|
|
|
|
|
THREE.NodeMaterial.prototype.addVertexPars = function( code ) {
|
|
THREE.NodeMaterial.prototype.addVertexPars = function( code ) {
|
|
@@ -343,9 +356,9 @@ THREE.NodeMaterial.prototype.addVertexNode = function( code ) {
|
|
THREE.NodeMaterial.prototype.clearVertexNode = function() {
|
|
THREE.NodeMaterial.prototype.clearVertexNode = function() {
|
|
|
|
|
|
var code = this.fragmentNode;
|
|
var code = this.fragmentNode;
|
|
-
|
|
|
|
|
|
+
|
|
this.fragmentNode = '';
|
|
this.fragmentNode = '';
|
|
-
|
|
|
|
|
|
+
|
|
return code;
|
|
return code;
|
|
|
|
|
|
};
|
|
};
|
|
@@ -359,9 +372,9 @@ THREE.NodeMaterial.prototype.addFragmentNode = function( code ) {
|
|
THREE.NodeMaterial.prototype.clearFragmentNode = function() {
|
|
THREE.NodeMaterial.prototype.clearFragmentNode = function() {
|
|
|
|
|
|
var code = this.fragmentNode;
|
|
var code = this.fragmentNode;
|
|
-
|
|
|
|
|
|
+
|
|
this.fragmentNode = '';
|
|
this.fragmentNode = '';
|
|
-
|
|
|
|
|
|
+
|
|
return code;
|
|
return code;
|
|
|
|
|
|
};
|
|
};
|
|
@@ -371,20 +384,21 @@ THREE.NodeMaterial.prototype.getCodePars = function( pars, prefix ) {
|
|
prefix = prefix || '';
|
|
prefix = prefix || '';
|
|
|
|
|
|
var code = '';
|
|
var code = '';
|
|
-
|
|
|
|
- for (var i = 0, l = pars.length; i < l; ++i) {
|
|
|
|
-
|
|
|
|
- var parsType = pars[i].type;
|
|
|
|
- var parsName = pars[i].name;
|
|
|
|
- var parsValue = pars[i].value;
|
|
|
|
-
|
|
|
|
- if (parsType == 't' && parsValue instanceof THREE.CubeTexture) parsType = 'tc';
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ for ( var i = 0, l = pars.length; i < l; ++ i ) {
|
|
|
|
+
|
|
|
|
+ var parsType = pars[ i ].type;
|
|
|
|
+ var parsName = pars[ i ].name;
|
|
|
|
+ var parsValue = pars[ i ].value;
|
|
|
|
+
|
|
|
|
+ if ( parsType == 't' && parsValue instanceof THREE.CubeTexture ) parsType = 'tc';
|
|
|
|
+
|
|
var type = THREE.NodeMaterial.Type[ parsType ];
|
|
var type = THREE.NodeMaterial.Type[ parsType ];
|
|
-
|
|
|
|
- if (type == undefined) throw new Error( "Node pars " + parsType + " not found." );
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ if ( type == undefined ) throw new Error( "Node pars " + parsType + " not found." );
|
|
|
|
+
|
|
code += prefix + ' ' + type + ' ' + parsName + ';\n';
|
|
code += prefix + ' ' + type + ' ' + parsName + ';\n';
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
return code;
|
|
return code;
|
|
@@ -394,12 +408,12 @@ THREE.NodeMaterial.prototype.getCodePars = function( pars, prefix ) {
|
|
THREE.NodeMaterial.prototype.getVertexUniform = function( value, type, needsUpdate ) {
|
|
THREE.NodeMaterial.prototype.getVertexUniform = function( value, type, needsUpdate ) {
|
|
|
|
|
|
var uniform = this.createUniform( value, type, needsUpdate );
|
|
var uniform = this.createUniform( value, type, needsUpdate );
|
|
-
|
|
|
|
- this.vertexUniform.push(uniform);
|
|
|
|
- this.vertexUniform[uniform.name] = uniform;
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ this.vertexUniform.push( uniform );
|
|
|
|
+ this.vertexUniform[ uniform.name ] = uniform;
|
|
|
|
+
|
|
this.uniforms[ uniform.name ] = uniform;
|
|
this.uniforms[ uniform.name ] = uniform;
|
|
-
|
|
|
|
|
|
+
|
|
return uniform;
|
|
return uniform;
|
|
|
|
|
|
};
|
|
};
|
|
@@ -407,61 +421,61 @@ THREE.NodeMaterial.prototype.getVertexUniform = function( value, type, needsUpda
|
|
THREE.NodeMaterial.prototype.getFragmentUniform = function( value, type, needsUpdate ) {
|
|
THREE.NodeMaterial.prototype.getFragmentUniform = function( value, type, needsUpdate ) {
|
|
|
|
|
|
var uniform = this.createUniform( value, type, needsUpdate );
|
|
var uniform = this.createUniform( value, type, needsUpdate );
|
|
-
|
|
|
|
- this.fragmentUniform.push(uniform);
|
|
|
|
- this.fragmentUniform[uniform.name] = uniform;
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ this.fragmentUniform.push( uniform );
|
|
|
|
+ this.fragmentUniform[ uniform.name ] = uniform;
|
|
|
|
+
|
|
this.uniforms[ uniform.name ] = uniform;
|
|
this.uniforms[ uniform.name ] = uniform;
|
|
-
|
|
|
|
|
|
+
|
|
return uniform;
|
|
return uniform;
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
THREE.NodeMaterial.prototype.getDataNode = function( uuid ) {
|
|
THREE.NodeMaterial.prototype.getDataNode = function( uuid ) {
|
|
|
|
|
|
- return this.nodeData[uuid] = this.nodeData[uuid] || {};
|
|
|
|
|
|
+ return this.nodeData[ uuid ] = this.nodeData[ uuid ] || {};
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
THREE.NodeMaterial.prototype.include = function( shader, node ) {
|
|
THREE.NodeMaterial.prototype.include = function( shader, node ) {
|
|
-
|
|
|
|
|
|
+
|
|
var includes;
|
|
var includes;
|
|
-
|
|
|
|
- node = typeof node === 'string' ? THREE.LibNode.get(node) : node;
|
|
|
|
-
|
|
|
|
- if (node instanceof THREE.FunctionNode) {
|
|
|
|
-
|
|
|
|
- for (var i = 0; i < node.includes.length; i++) {
|
|
|
|
-
|
|
|
|
- this.include( shader, node.includes[i] );
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ node = typeof node === 'string' ? THREE.LibNode.get( node ) : node;
|
|
|
|
+
|
|
|
|
+ if ( node instanceof THREE.FunctionNode ) {
|
|
|
|
+
|
|
|
|
+ for ( var i = 0; i < node.includes.length; i ++ ) {
|
|
|
|
+
|
|
|
|
+ this.include( shader, node.includes[ i ] );
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- includes = this.functions[shader] = this.functions[shader] || [];
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ includes = this.functions[ shader ] = this.functions[ shader ] || [];
|
|
|
|
+
|
|
}
|
|
}
|
|
- else if (node instanceof THREE.ConstNode) {
|
|
|
|
-
|
|
|
|
- includes = this.consts[shader] = this.consts[shader] || [];
|
|
|
|
-
|
|
|
|
|
|
+ else if ( node instanceof THREE.ConstNode ) {
|
|
|
|
+
|
|
|
|
+ includes = this.consts[ shader ] = this.consts[ shader ] || [];
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (includes[node.name] === undefined) {
|
|
|
|
-
|
|
|
|
- for (var ext in node.extensions) {
|
|
|
|
-
|
|
|
|
- this.extensions[ext] = true;
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ if ( includes[ node.name ] === undefined ) {
|
|
|
|
+
|
|
|
|
+ for ( var ext in node.extensions ) {
|
|
|
|
+
|
|
|
|
+ this.extensions[ ext ] = true;
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- includes[node.name] = {
|
|
|
|
|
|
+
|
|
|
|
+ includes[ node.name ] = {
|
|
node : node,
|
|
node : node,
|
|
deps : 1
|
|
deps : 1
|
|
};
|
|
};
|
|
-
|
|
|
|
- includes.push(includes[node.name]);
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ includes.push( includes[ node.name ] );
|
|
|
|
+
|
|
}
|
|
}
|
|
- else ++includes[node.name].deps;
|
|
|
|
|
|
+ else ++ includes[ node.name ].deps;
|
|
|
|
|
|
-};
|
|
|
|
|
|
+};
|