From 688b7499dba1f5a440cb405583124b40ff00c57b Mon Sep 17 00:00:00 2001 From: sunag Date: Wed, 27 Sep 2023 13:42:29 -0300 Subject: [PATCH] WebGLNodeBuilder: Fix Multi-Material (#26841) --- examples/jsm/nodes/core/NodeBuilder.js | 4 ++-- .../webgl-legacy/nodes/WebGLNodeBuilder.js | 4 ++-- .../renderers/webgl-legacy/nodes/WebGLNodes.js | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/examples/jsm/nodes/core/NodeBuilder.js b/examples/jsm/nodes/core/NodeBuilder.js index df23915a0a74bb..68da8a5ccdf318 100644 --- a/examples/jsm/nodes/core/NodeBuilder.js +++ b/examples/jsm/nodes/core/NodeBuilder.js @@ -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; diff --git a/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js b/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js index 33ec3255613f32..2f963cec5adaa1 100644 --- a/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +++ b/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js @@ -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: [] }; diff --git a/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js b/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js index 2825b7335103ab..4e8509d3347dd1 100644 --- a/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +++ b/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js @@ -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() ); }