Skip to content

Commit

Permalink
WebGLNodeBuilder: Fix Multi-Material (mrdoob#26841)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunag authored Sep 27, 2023
1 parent bf7a89e commit 688b749
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions examples/jsm/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ const toFloat = ( value ) => {

class NodeBuilder {

constructor( object, renderer, parser, scene = null ) {
constructor( object, renderer, parser, scene = null, material = null ) {

this.object = object;
this.material = ( object && object.material ) || null;
this.material = material || ( object && object.material ) || null;
this.geometry = ( object && object.geometry ) || null;
this.renderer = renderer;
this.parser = parser;
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ function getShaderStageProperty( shaderStage ) {

class WebGLNodeBuilder extends NodeBuilder {

constructor( object, renderer, shader ) {
constructor( object, renderer, shader, material = null ) {

super( object, renderer, new GLSLNodeParser() );
super( object, renderer, new GLSLNodeParser(), null, material );

this.shader = shader;
this.slots = { vertex: [], fragment: [] };
Expand Down
16 changes: 14 additions & 2 deletions examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ export const nodeFrame = new NodeFrame();

Material.prototype.onBuild = function ( object, parameters, renderer ) {

if ( object.material.isNodeMaterial === true ) {
if ( Array.isArray( object.material ) ) {

builders.set( this, new WebGLNodeBuilder( object, renderer, parameters ).build() );
for ( const material of object.material ) {

if ( material.isNodeMaterial === true ) {

builders.set( material, new WebGLNodeBuilder( object, renderer, parameters, material ).build() );

}

}

} else if ( object.material.isNodeMaterial === true ) {

builders.set( object.material, new WebGLNodeBuilder( object, renderer, parameters ).build() );

}

Expand Down

0 comments on commit 688b749

Please sign in to comment.