|
|
@@ -2939,13 +2939,41 @@ class NodeBuilder {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Central build method which controls the build for the given object.
|
|
|
- *
|
|
|
- * @return {NodeBuilder} A reference to this node builder.
|
|
|
+ * Prebuild the node builder.
|
|
|
*/
|
|
|
- build() {
|
|
|
+ prebuild() {
|
|
|
+
|
|
|
+ const { object, renderer, material } = this;
|
|
|
+
|
|
|
+ // < renderer.contextNode >
|
|
|
+
|
|
|
+ if ( renderer.contextNode.isContextNode === true ) {
|
|
|
+
|
|
|
+ this.context = { ...this.context, ...renderer.contextNode.getFlowContextData() };
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ error( 'NodeBuilder: "renderer.contextNode" must be an instance of `context()`.' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // < material.contextNode >
|
|
|
|
|
|
- const { object, material, renderer } = this;
|
|
|
+ if ( material && material.contextNode ) {
|
|
|
+
|
|
|
+ if ( material.contextNode.isContextNode === true ) {
|
|
|
+
|
|
|
+ this.context = { ...this.context, ...material.contextNode.getFlowContextData() };
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ error( 'NodeBuilder: "material.contextNode" must be an instance of `context()`.' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // < nodeMaterial >
|
|
|
|
|
|
if ( material !== null ) {
|
|
|
|
|
|
@@ -2953,7 +2981,7 @@ class NodeBuilder {
|
|
|
|
|
|
if ( nodeMaterial === null ) {
|
|
|
|
|
|
- error( `NodeMaterial: Material "${ material.type }" is not compatible.` );
|
|
|
+ error( `NodeBuilder: Material "${ material.type }" is not compatible.` );
|
|
|
|
|
|
nodeMaterial = new NodeMaterial();
|
|
|
|
|
|
@@ -2967,6 +2995,17 @@ class NodeBuilder {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Central build method which controls the build for the given object.
|
|
|
+ *
|
|
|
+ * @return {NodeBuilder} A reference to this node builder.
|
|
|
+ */
|
|
|
+ build() {
|
|
|
+
|
|
|
+ this.prebuild();
|
|
|
+
|
|
|
// setup() -> stage 1: create possible new nodes and/or return an output reference node
|
|
|
// analyze() -> stage 2: analyze nodes to possible optimization and validation
|
|
|
// generate() -> stage 3: generate shader
|
|
|
@@ -3025,27 +3064,7 @@ class NodeBuilder {
|
|
|
*/
|
|
|
async buildAsync() {
|
|
|
|
|
|
- const { object, material, renderer } = this;
|
|
|
-
|
|
|
- if ( material !== null ) {
|
|
|
-
|
|
|
- let nodeMaterial = renderer.library.fromMaterial( material );
|
|
|
-
|
|
|
- if ( nodeMaterial === null ) {
|
|
|
-
|
|
|
- error( `NodeMaterial: Material "${ material.type }" is not compatible.` );
|
|
|
-
|
|
|
- nodeMaterial = new NodeMaterial();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- nodeMaterial.build( this );
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- this.addFlow( 'compute', object );
|
|
|
-
|
|
|
- }
|
|
|
+ this.prebuild();
|
|
|
|
|
|
// setup() -> stage 1: create possible new nodes and/or return an output reference node
|
|
|
// analyze() -> stage 2: analyze nodes to possible optimization and validation
|