Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions src/materials/nodes/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { modelViewMatrix } from '../../nodes/accessors/ModelNode.js';
import { vertexColor } from '../../nodes/accessors/VertexColorNode.js';
import { premultiplyAlpha } from '../../nodes/display/BlendModes.js';
import { subBuild } from '../../nodes/core/SubBuildNode.js';
import { error } from '../../utils.js';

/**
* Base class for all node materials.
Expand Down Expand Up @@ -485,32 +484,6 @@ class NodeMaterial extends Material {
const renderer = builder.renderer;
const renderTarget = renderer.getRenderTarget();

// < CONTEXT >

if ( renderer.contextNode.isContextNode === true ) {

builder.context = { ...builder.context, ...renderer.contextNode.getFlowContextData() };

} else {

error( 'NodeMaterial: "renderer.contextNode" must be an instance of `context()`.' );

}

if ( this.contextNode !== null ) {

if ( this.contextNode.isContextNode === true ) {

builder.context = { ...builder.context, ...this.contextNode.getFlowContextData() };

} else {

error( 'NodeMaterial: "material.contextNode" must be an instance of `context()`.' );

}

}

// < VERTEX STAGE >

builder.addStack();
Expand Down
73 changes: 46 additions & 27 deletions src/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2939,21 +2939,49 @@ 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 ) {

let nodeMaterial = renderer.library.fromMaterial( material );

if ( nodeMaterial === null ) {

error( `NodeMaterial: Material "${ material.type }" is not compatible.` );
error( `NodeBuilder: Material "${ material.type }" is not compatible.` );

nodeMaterial = new NodeMaterial();

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading