Skip to content

Commit dda58fa

Browse files
committed
Introduce NodeHandler
1 parent a60450e commit dda58fa

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

src/nodes/Nodes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export { default as UniformNode, uniform } from './core/UniformNode.js';
3434
export { default as VaryingNode, varying } from './core/VaryingNode.js';
3535
export { default as OutputStructNode, outputStruct } from './core/OutputStructNode.js';
3636
export { default as MRTNode, mrt } from './core/MRTNode.js';
37+
export { default as NodeHandler } from './core/NodeHandler.js';
3738

3839
import * as NodeUtils from './core/NodeUtils.js';
3940
export { NodeUtils };

src/nodes/core/NodeBuilder.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,14 @@ class NodeBuilder {
572572

573573
}
574574

575+
handle( name, node ) {
576+
577+
const handler = this.renderer.nodeHandler;
578+
579+
return handler !== null ? handler.handle( name, node, this ) : node;
580+
581+
}
582+
575583
getPropertyName( node/*, shaderStage*/ ) {
576584

577585
return node.name;

src/nodes/core/NodeHandler.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class NodeHandler {
2+
3+
constructor() {
4+
5+
this.handlers = [];
6+
7+
}
8+
9+
onHandle( name, callback ) {
10+
11+
this.handlers[ name ] = callback;
12+
13+
return this;
14+
15+
}
16+
17+
handle( name, node, builder ) {
18+
19+
const callback = this.handlers[ name ];
20+
21+
if ( callback !== undefined ) {
22+
23+
node = callback( node, builder );
24+
25+
}
26+
27+
return node || null;
28+
29+
}
30+
31+
}
32+
33+
export default NodeHandler;

src/nodes/materials/NodeMaterial.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,14 +415,26 @@ class NodeMaterial extends Material {
415415

416416
}
417417

418+
// AO
419+
420+
let aoNode = null;
421+
418422
if ( this.aoNode !== null || builder.material.aoMap ) {
419423

420-
const aoNode = this.aoNode !== null ? this.aoNode : materialAOMap;
424+
aoNode = this.aoNode !== null ? this.aoNode : materialAOMap;
425+
426+
}
427+
428+
aoNode = builder.handle( 'ao', aoNode );
429+
430+
if ( aoNode !== null ) {
421431

422432
materialLightsNode.push( new AONode( aoNode ) );
423433

424434
}
425435

436+
//
437+
426438
let lightsN = this.lightsNode || builder.lightsNode;
427439

428440
if ( materialLightsNode.length > 0 ) {

src/renderers/common/Renderer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ class Renderer {
135135

136136
// backwards compatibility
137137

138+
this.nodeHandler = null;
139+
138140
this.shadowMap = {
139141
enabled: false,
140142
type: null

0 commit comments

Comments
 (0)