소스 검색

some revisions details in descriptions

- rename Node.parse() to Node.analyze()
- rename Node.buildCode() to Node.flow()
- rename Node.eval to Node.parse
- move NodeBuilder.optimize to NodeBuilder.context.ignoreCache
sunag 6 년 전
부모
커밋
7d92d5564f

+ 3 - 3
examples/js/nodes/core/ConstNode.js

@@ -10,7 +10,7 @@ function ConstNode( src, useDefine ) {
 
 	TempNode.call( this );
 
-	this.eval( src || ConstNode.PI, useDefine );
+	this.parse( src || ConstNode.PI, useDefine );
 
 }
 
@@ -31,7 +31,7 @@ ConstNode.prototype.getType = function ( builder ) {
 
 };
 
-ConstNode.prototype.eval = function ( src, useDefine ) {
+ConstNode.prototype.parse = function ( src, useDefine ) {
 
 	this.src = src || '';
 
@@ -100,7 +100,7 @@ ConstNode.prototype.copy = function ( source ) {
 
 	TempNode.prototype.copy.call( this, source );
 
-	this.eval( source.src, source.useDefine );
+	this.parse( source.src, source.useDefine );
 
 };
 

+ 4 - 4
examples/js/nodes/core/FunctionNode.js

@@ -15,7 +15,7 @@ function FunctionNode( src, includes, extensions, keywords, type ) {
 
 	TempNode.call( this, type );
 
-	this.eval( src, includes, extensions, keywords );
+	this.parse( src, includes, extensions, keywords );
 
 }
 
@@ -117,7 +117,7 @@ FunctionNode.prototype.generate = function ( builder, output ) {
 
 		}
 
-		if ( prop != reference ) {
+		if ( prop !== reference ) {
 
 			src = src.substring( 0, match.index + offset ) + reference + src.substring( match.index + prop.length + offset );
 
@@ -151,7 +151,7 @@ FunctionNode.prototype.generate = function ( builder, output ) {
 
 };
 
-FunctionNode.prototype.eval = function ( src, includes, extensions, keywords ) {
+FunctionNode.prototype.parse = function ( src, includes, extensions, keywords ) {
 
 	this.src = src || '';
 
@@ -222,7 +222,7 @@ FunctionNode.prototype.copy = function ( source ) {
 	this.isMethod = source.isMethod;
 	this.useKeywords = source.useKeywords;
 
-	this.eval( source.src, source.includes, source.extensions, source.keywords );
+	this.parse( source.src, source.includes, source.extensions, source.keywords );
 
 	if ( source.type !== undefined ) this.type = source.type;
 

+ 14 - 12
examples/js/nodes/core/Node.js

@@ -20,11 +20,11 @@ Node.prototype = {
 
 	isNode: true,
 
-	parse: function ( builder, settings ) {
+	analyze: function ( builder, settings ) {
 
 		settings = settings || {};
 
-		builder.parsing = true;
+		builder.analyzing = true;
 
 		this.build( builder.addFlow( settings.slot, settings.cache, settings.context ), 'v4' );
 
@@ -33,32 +33,34 @@ Node.prototype = {
 
 		builder.removeFlow();
 
-		builder.parsing = false;
+		builder.analyzing = false;
 
 	},
 
-	parseAndBuildCode: function ( builder, output, settings ) {
+	analyzeAndFlow: function ( builder, output, settings ) {
 
 		settings = settings || {};
 
-		this.parse( builder, settings );
+		this.analyze( builder, settings );
 
-		return this.buildCode( builder, output, settings );
+		return this.flow( builder, output, settings );
 
 	},
 
-	buildCode: function ( builder, output, settings ) {
+	flow: function ( builder, output, settings ) {
 
 		settings = settings || {};
 
-		var data = { result: this.build( builder.addFlow( settings.slot, settings.cache, settings.context ), output ) };
+		builder.addFlow( settings.slot, settings.cache, settings.context )
 
-		data.code = builder.clearNodeCode();
-		data.extra = builder.context.extra;
+		var flow = {};
+		flow.result = this.build( builder, output );
+		flow.code = builder.clearNodeCode();
+		flow.extra = builder.context.extra;
 
 		builder.removeFlow();
 
-		return data;
+		return flow;
 
 	},
 
@@ -68,7 +70,7 @@ Node.prototype = {
 
 		var data = builder.getNodeData( uuid || this );
 
-		if ( builder.parsing ) {
+		if ( builder.analyzing ) {
 
 			this.appendDepsNode( builder, data, output );
 

+ 1 - 2
examples/js/nodes/core/NodeBuilder.js

@@ -142,8 +142,7 @@ function NodeBuilder() {
 
 	// --
 
-	this.parsing = false;
-	this.optimize = true;
+	this.analyzing = false;
 
 }
 

+ 2 - 2
examples/js/nodes/core/StructNode.js

@@ -11,7 +11,7 @@ function StructNode( src ) {
 
 	TempNode.call( this );
 
-	this.eval( src );
+	this.parse( src );
 
 }
 
@@ -55,7 +55,7 @@ StructNode.prototype.generate = function ( builder, output ) {
 
 };
 
-StructNode.prototype.eval = function ( src ) {
+StructNode.prototype.parse = function ( src ) {
 
 	this.src = src || '';
 

+ 2 - 2
examples/js/nodes/core/TempNode.js

@@ -38,7 +38,7 @@ TempNode.prototype.build = function ( builder, output, uuid, ns ) {
 		var data = builder.getNodeData( uuid ),
 			type = data.output || this.getType( builder );
 
-		if ( builder.parsing ) {
+		if ( builder.analyzing ) {
 
 			if ( ( data.deps || 0 ) > 0 || this.getLabel() ) {
 
@@ -56,7 +56,7 @@ TempNode.prototype.build = function ( builder, output, uuid, ns ) {
 
 			return data.name;
 
-		} else if ( ! this.getLabel() && ( ! this.getShared( builder, type ) || ( ! builder.optimize || data.deps === 1 ) ) ) {
+		} else if ( ! this.getLabel() && ( ! this.getShared( builder, type ) || ( builder.context.ignoreCache || data.deps === 1 ) ) ) {
 
 			return Node.prototype.build.call( this, builder, output, uuid );
 

+ 28 - 28
examples/js/nodes/materials/nodes/PhongNode.js

@@ -30,7 +30,7 @@ PhongNode.prototype.build = function ( builder ) {
 
 	if ( builder.isShader( 'vertex' ) ) {
 
-		var position = this.position ? this.position.parseAndBuildCode( builder, 'v3', { cache: 'position' } ) : undefined;
+		var position = this.position ? this.position.analyzeAndFlow( builder, 'v3', { cache: 'position' } ) : undefined;
 
 		builder.mergeUniform( THREE.UniformsUtils.merge( [
 
@@ -101,49 +101,49 @@ PhongNode.prototype.build = function ( builder ) {
 
 	} else {
 
-		// parse all nodes to reuse generate codes
+		// analyze all nodes to reuse generate codes
 
-		if ( this.mask ) this.mask.parse( builder );
+		if ( this.mask ) this.mask.analyze( builder );
 
-		this.color.parse( builder, { slot: 'color' } );
-		this.specular.parse( builder );
-		this.shininess.parse( builder );
+		this.color.analyze( builder, { slot: 'color' } );
+		this.specular.analyze( builder );
+		this.shininess.analyze( builder );
 
-		if ( this.alpha ) this.alpha.parse( builder );
+		if ( this.alpha ) this.alpha.analyze( builder );
 
-		if ( this.normal ) this.normal.parse( builder );
+		if ( this.normal ) this.normal.analyze( builder );
 
-		if ( this.light ) this.light.parse( builder, { cache: 'light' } );
+		if ( this.light ) this.light.analyze( builder, { cache: 'light' } );
 
-		if ( this.ao ) this.ao.parse( builder );
-		if ( this.ambient ) this.ambient.parse( builder );
-		if ( this.shadow ) this.shadow.parse( builder );
-		if ( this.emissive ) this.emissive.parse( builder, { slot: 'emissive' } );
+		if ( this.ao ) this.ao.analyze( builder );
+		if ( this.ambient ) this.ambient.analyze( builder );
+		if ( this.shadow ) this.shadow.analyze( builder );
+		if ( this.emissive ) this.emissive.analyze( builder, { slot: 'emissive' } );
 
-		if ( this.environment ) this.environment.parse( builder, { slot: 'environment' } );
-		if ( this.environmentAlpha && this.environment ) this.environmentAlpha.parse( builder );
+		if ( this.environment ) this.environment.analyze( builder, { slot: 'environment' } );
+		if ( this.environmentAlpha && this.environment ) this.environmentAlpha.analyze( builder );
 
 		// build code
 
-		var mask = this.mask ? this.mask.buildCode( builder, 'b' ) : undefined;
+		var mask = this.mask ? this.mask.flow( builder, 'b' ) : undefined;
 
-		var color = this.color.buildCode( builder, 'c', { slot: 'color' } );
-		var specular = this.specular.buildCode( builder, 'c' );
-		var shininess = this.shininess.buildCode( builder, 'f' );
+		var color = this.color.flow( builder, 'c', { slot: 'color' } );
+		var specular = this.specular.flow( builder, 'c' );
+		var shininess = this.shininess.flow( builder, 'f' );
 
-		var alpha = this.alpha ? this.alpha.buildCode( builder, 'f' ) : undefined;
+		var alpha = this.alpha ? this.alpha.flow( builder, 'f' ) : undefined;
 
-		var normal = this.normal ? this.normal.buildCode( builder, 'v3' ) : undefined;
+		var normal = this.normal ? this.normal.flow( builder, 'v3' ) : undefined;
 
-		var light = this.light ? this.light.buildCode( builder, 'v3', { cache: 'light' } ) : undefined;
+		var light = this.light ? this.light.flow( builder, 'v3', { cache: 'light' } ) : undefined;
 
-		var ao = this.ao ? this.ao.buildCode( builder, 'f' ) : undefined;
-		var ambient = this.ambient ? this.ambient.buildCode( builder, 'c' ) : undefined;
-		var shadow = this.shadow ? this.shadow.buildCode( builder, 'c' ) : undefined;
-		var emissive = this.emissive ? this.emissive.buildCode( builder, 'c', { slot: 'emissive' } ) : undefined;
+		var ao = this.ao ? this.ao.flow( builder, 'f' ) : undefined;
+		var ambient = this.ambient ? this.ambient.flow( builder, 'c' ) : undefined;
+		var shadow = this.shadow ? this.shadow.flow( builder, 'c' ) : undefined;
+		var emissive = this.emissive ? this.emissive.flow( builder, 'c', { slot: 'emissive' } ) : undefined;
 
-		var environment = this.environment ? this.environment.buildCode( builder, 'c', { slot: 'environment' } ) : undefined;
-		var environmentAlpha = this.environmentAlpha && this.environment ? this.environmentAlpha.buildCode( builder, 'f' ) : undefined;
+		var environment = this.environment ? this.environment.flow( builder, 'c', { slot: 'environment' } ) : undefined;
+		var environmentAlpha = this.environmentAlpha && this.environment ? this.environmentAlpha.flow( builder, 'f' ) : undefined;
 
 		builder.requires.transparent = alpha != undefined;
 

+ 1 - 1
examples/js/nodes/materials/nodes/RawNode.js

@@ -18,7 +18,7 @@ RawNode.prototype.nodeType = "Raw";
 
 RawNode.prototype.generate = function ( builder ) {
 
-	var data = this.value.parseAndBuildCode( builder, this.type ),
+	var data = this.value.analyzeAndFlow( builder, this.type ),
 		code = data.code + '\n';
 
 	if ( builder.isShader( 'vertex' ) ) {

+ 8 - 8
examples/js/nodes/materials/nodes/SpriteNode.js

@@ -29,7 +29,7 @@ SpriteNode.prototype.build = function ( builder ) {
 
 	if ( builder.isShader( 'vertex' ) ) {
 
-		var position = this.position ? this.position.parseAndBuildCode( builder, 'v3', { cache: 'position' } ) : undefined;
+		var position = this.position ? this.position.analyzeAndFlow( builder, 'v3', { cache: 'position' } ) : undefined;
 
 		builder.mergeUniform( THREE.UniformsUtils.merge( [
 			THREE.UniformsLib.fog
@@ -121,19 +121,19 @@ SpriteNode.prototype.build = function ( builder ) {
 			"#include <logdepthbuf_fragment>"
 		].join( "\n" ) );
 
-		// parse all nodes to reuse generate codes
+		// analyze all nodes to reuse generate codes
 
-		if ( this.mask ) this.mask.parse( builder );
+		if ( this.mask ) this.mask.analyze( builder );
 
-		if ( this.alpha ) this.alpha.parse( builder );
+		if ( this.alpha ) this.alpha.analyze( builder );
 
-		this.color.parse( builder, { slot: 'color' } );
+		this.color.analyze( builder, { slot: 'color' } );
 
 		// build code
 
-		var mask = this.mask ? this.mask.buildCode( builder, 'b' ) : undefined,
-			alpha = this.alpha ? this.alpha.buildCode( builder, 'f' ) : undefined,
-			color = this.color.buildCode( builder, 'c', { slot: 'color' } ),
+		var mask = this.mask ? this.mask.flow( builder, 'b' ) : undefined,
+			alpha = this.alpha ? this.alpha.flow( builder, 'f' ) : undefined,
+			color = this.color.flow( builder, 'c', { slot: 'color' } ),
 			output = [];
 
 		if ( mask ) {

+ 33 - 33
examples/js/nodes/materials/nodes/StandardNode.js

@@ -33,7 +33,7 @@ StandardNode.prototype.build = function ( builder ) {
 
 	if ( builder.isShader( 'vertex' ) ) {
 
-		var position = this.position ? this.position.parseAndBuildCode( builder, 'v3', { cache: 'position' } ) : undefined;
+		var position = this.position ? this.position.analyzeAndFlow( builder, 'v3', { cache: 'position' } ) : undefined;
 
 		builder.mergeUniform( THREE.UniformsUtils.merge( [
 
@@ -115,59 +115,59 @@ StandardNode.prototype.build = function ( builder ) {
 
 		var useClearCoat = ! builder.isDefined( 'STANDARD' );
 
-		// parse all nodes to reuse generate codes
+		// analyze all nodes to reuse generate codes
 
-		if ( this.mask ) this.mask.parse( builder );
+		if ( this.mask ) this.mask.analyze( builder );
 
-		this.color.parse( builder, { slot: 'color', context: contextGammaOnly } );
-		this.roughness.parse( builder );
-		this.metalness.parse( builder );
+		this.color.analyze( builder, { slot: 'color', context: contextGammaOnly } );
+		this.roughness.analyze( builder );
+		this.metalness.analyze( builder );
 
-		if ( this.alpha ) this.alpha.parse( builder );
+		if ( this.alpha ) this.alpha.analyze( builder );
 
-		if ( this.normal ) this.normal.parse( builder );
+		if ( this.normal ) this.normal.analyze( builder );
 
-		if ( this.clearCoat ) this.clearCoat.parse( builder );
-		if ( this.clearCoatRoughness ) this.clearCoatRoughness.parse( builder );
+		if ( this.clearCoat ) this.clearCoat.analyze( builder );
+		if ( this.clearCoatRoughness ) this.clearCoatRoughness.analyze( builder );
 
-		if ( this.reflectivity ) this.reflectivity.parse( builder );
+		if ( this.reflectivity ) this.reflectivity.analyze( builder );
 
-		if ( this.light ) this.light.parse( builder, { cache: 'light' } );
+		if ( this.light ) this.light.analyze( builder, { cache: 'light' } );
 
-		if ( this.ao ) this.ao.parse( builder );
-		if ( this.ambient ) this.ambient.parse( builder );
-		if ( this.shadow ) this.shadow.parse( builder );
-		if ( this.emissive ) this.emissive.parse( builder, { slot: 'emissive' } );
+		if ( this.ao ) this.ao.analyze( builder );
+		if ( this.ambient ) this.ambient.analyze( builder );
+		if ( this.shadow ) this.shadow.analyze( builder );
+		if ( this.emissive ) this.emissive.analyze( builder, { slot: 'emissive' } );
 
-		if ( this.environment ) this.environment.parse( builder, { cache: 'env', context: contextEnvironment, slot: 'environment' } ); // isolate environment from others inputs ( see TextureNode, CubeTextureNode )
+		if ( this.environment ) this.environment.analyze( builder, { cache: 'env', context: contextEnvironment, slot: 'environment' } ); // isolate environment from others inputs ( see TextureNode, CubeTextureNode )
 
 		// build code
 
-		var mask = this.mask ? this.mask.buildCode( builder, 'b' ) : undefined;
+		var mask = this.mask ? this.mask.flow( builder, 'b' ) : undefined;
 
-		var color = this.color.buildCode( builder, 'c', { slot: 'color', context: contextGammaOnly } );
-		var roughness = this.roughness.buildCode( builder, 'f' );
-		var metalness = this.metalness.buildCode( builder, 'f' );
+		var color = this.color.flow( builder, 'c', { slot: 'color', context: contextGammaOnly } );
+		var roughness = this.roughness.flow( builder, 'f' );
+		var metalness = this.metalness.flow( builder, 'f' );
 
-		var alpha = this.alpha ? this.alpha.buildCode( builder, 'f' ) : undefined;
+		var alpha = this.alpha ? this.alpha.flow( builder, 'f' ) : undefined;
 
-		var normal = this.normal ? this.normal.buildCode( builder, 'v3' ) : undefined;
+		var normal = this.normal ? this.normal.flow( builder, 'v3' ) : undefined;
 
-		var clearCoat = this.clearCoat ? this.clearCoat.buildCode( builder, 'f' ) : undefined;
-		var clearCoatRoughness = this.clearCoatRoughness ? this.clearCoatRoughness.buildCode( builder, 'f' ) : undefined;
+		var clearCoat = this.clearCoat ? this.clearCoat.flow( builder, 'f' ) : undefined;
+		var clearCoatRoughness = this.clearCoatRoughness ? this.clearCoatRoughness.flow( builder, 'f' ) : undefined;
 
-		var reflectivity = this.reflectivity ? this.reflectivity.buildCode( builder, 'f' ) : undefined;
+		var reflectivity = this.reflectivity ? this.reflectivity.flow( builder, 'f' ) : undefined;
 
-		var light = this.light ? this.light.buildCode( builder, 'v3', { cache: 'light' } ) : undefined;
+		var light = this.light ? this.light.flow( builder, 'v3', { cache: 'light' } ) : undefined;
 
-		var ao = this.ao ? this.ao.buildCode( builder, 'f' ) : undefined;
-		var ambient = this.ambient ? this.ambient.buildCode( builder, 'c' ) : undefined;
-		var shadow = this.shadow ? this.shadow.buildCode( builder, 'c' ) : undefined;
-		var emissive = this.emissive ? this.emissive.buildCode( builder, 'c', { slot: 'emissive' } ) : undefined;
+		var ao = this.ao ? this.ao.flow( builder, 'f' ) : undefined;
+		var ambient = this.ambient ? this.ambient.flow( builder, 'c' ) : undefined;
+		var shadow = this.shadow ? this.shadow.flow( builder, 'c' ) : undefined;
+		var emissive = this.emissive ? this.emissive.flow( builder, 'c', { slot: 'emissive' } ) : undefined;
 
-		var environment = this.environment ? this.environment.buildCode( builder, 'c', { cache: 'env', context: contextEnvironment, slot: 'environment' } ) : undefined;
+		var environment = this.environment ? this.environment.flow( builder, 'c', { cache: 'env', context: contextEnvironment, slot: 'environment' } ) : undefined;
 
-		var clearCoatEnv = useClearCoat && environment ? this.environment.buildCode( builder, 'c', { cache: 'clearCoat', context: contextEnvironment, slot: 'environment' } ) : undefined;
+		var clearCoatEnv = useClearCoat && environment ? this.environment.flow( builder, 'c', { cache: 'clearCoat', context: contextEnvironment, slot: 'environment' } ) : undefined;
 
 		builder.requires.transparent = alpha !== undefined;