Parcourir la source

TSL: Analyze lights and auto generate cache (#28509)

* analyze lights, auto generate cache

* new cache for new function generator
sunag il y a 1 an
Parent
commit
d2a7e15762

+ 6 - 0
examples/jsm/nodes/core/ContextNode.js

@@ -20,6 +20,12 @@ class ContextNode extends Node {
 
 	}
 
+	analyze( builder ) {
+
+		this.node.build( builder );
+
+	}
+
 	setup( builder ) {
 
 		const previousContext = builder.getContext();

+ 7 - 0
examples/jsm/nodes/core/NodeBuilder.js

@@ -911,7 +911,9 @@ class NodeBuilder {
 
 		const previousFlow = this.flow;
 		const previousVars = this.vars;
+		const previousCache = this.cache;
 		const previousBuildStage = this.buildStage;
+		const previousStack = this.stack;
 
 		const flow = {
 			code: ''
@@ -919,6 +921,8 @@ class NodeBuilder {
 
 		this.flow = flow;
 		this.vars = {};
+		this.cache = new NodeCache();
+		this.stack = stack();
 
 		for ( const buildStage of defaultBuildStages ) {
 
@@ -932,6 +936,9 @@ class NodeBuilder {
 
 		this.flow = previousFlow;
 		this.vars = previousVars;
+		this.cache = previousCache;
+		this.stack = previousStack;
+
 		this.setBuildStage( previousBuildStage );
 
 		return flow;

+ 17 - 0
examples/jsm/nodes/lighting/LightsNode.js

@@ -53,6 +53,18 @@ class LightsNode extends Node {
 
 	}
 
+	analyze( builder ) {
+
+		const properties = builder.getDataFromNode( this );
+
+		for ( const node of properties.nodes ) {
+
+			node.build( builder );
+
+		}
+
+	}
+
 	setup( builder ) {
 
 		const context = builder.context;
@@ -70,6 +82,11 @@ class LightsNode extends Node {
 
 			//
 
+			const properties = builder.getDataFromNode( this );
+			properties.nodes = stack.nodes;
+
+			//
+
 			lightingModel.start( context, stack, builder );
 
 			// lights