Skip to content

Commit

Permalink
NodeBuilder: remove duplicate code (a TODO item) (mrdoob#27412)
Browse files Browse the repository at this point in the history
* remove duplicate  code

* remove imports

* add switch for standard renderer path

* remove unused import

---------

Co-authored-by: aardgoose <angus.sawyer@email.com>
  • Loading branch information
2 people authored and AdaRoseCannon committed Jan 15, 2024
1 parent bab139b commit 3343949
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 64 deletions.
20 changes: 18 additions & 2 deletions examples/jsm/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import NodeKeywords from './NodeKeywords.js';
import NodeCache from './NodeCache.js';
import ParameterNode from './ParameterNode.js';
import FunctionNode from '../code/FunctionNode.js';
import { createNodeMaterialFromType } from '../materials/NodeMaterial.js';
import { createNodeMaterialFromType, default as NodeMaterial } from '../materials/NodeMaterial.js';
import { NodeUpdateType, defaultBuildStages, shaderStages } from './constants.js';

import {
Expand Down Expand Up @@ -1089,7 +1089,23 @@ class NodeBuilder {

}

build() {
build( convertMaterial = true ) {

const { object, material } = this;

if ( convertMaterial ) {

if ( material !== null ) {

NodeMaterial.fromMaterial( material ).build( this );

} else {

this.addFlow( 'compute', object );

}

}

// setup() -> stage 1: create possible new nodes and returns an output reference node
// analyze() -> stage 2: analyze nodes to possible optimization and validation
Expand Down
22 changes: 1 addition & 21 deletions examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MathNode, GLSLNodeParser, NodeBuilder, NodeMaterial } from '../../../nodes/Nodes.js';
import { MathNode, GLSLNodeParser, NodeBuilder } from '../../../nodes/Nodes.js';

const glslMethods = {
[ MathNode.ATAN2 ]: 'atan'
Expand Down Expand Up @@ -315,26 +315,6 @@ void main() {

}

build() {

// @TODO: Move this code to super.build()

const { object, material } = this;

if ( material !== null ) {

NodeMaterial.fromMaterial( material ).build( this );

} else {

this.addFlow( 'compute', object );

}

return super.build();

}

}

export default GLSL1NodeBuilder;
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ ${this.shader[ getShaderStageProperty( shaderStage ) ]}

build() {

super.build();
super.build( false );

this._addSnippets();
this._addUniforms();
Expand Down
22 changes: 1 addition & 21 deletions examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MathNode, GLSLNodeParser, NodeBuilder, NodeMaterial } from '../../../nodes/Nodes.js';
import { MathNode, GLSLNodeParser, NodeBuilder } from '../../../nodes/Nodes.js';

import UniformBuffer from '../../common/UniformBuffer.js';
import NodeUniformsGroup from '../../common/nodes/NodeUniformsGroup.js';
Expand Down Expand Up @@ -647,26 +647,6 @@ void main() {

}

build() {

// @TODO: Move this code to super.build()

const { object, material } = this;

if ( material !== null ) {

NodeMaterial.fromMaterial( material ).build( this );

} else {

this.addFlow( 'compute', object );

}

return super.build();

}

}

export default GLSLNodeBuilder;
20 changes: 1 addition & 19 deletions examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UniformBuffer from '../../common/UniformBuffer.js';
import StorageBuffer from '../../common/StorageBuffer.js';
import { getVectorLength, getStrideLength } from '../../common/BufferUtils.js';

import { NodeBuilder, CodeNode, NodeMaterial } from '../../../nodes/Nodes.js';
import { NodeBuilder, CodeNode } from '../../../nodes/Nodes.js';

import { getFormat } from '../utils/WebGPUTextureUtils.js';

Expand Down Expand Up @@ -127,24 +127,6 @@ class WGSLNodeBuilder extends NodeBuilder {

}

build() {

const { object, material } = this;

if ( material !== null ) {

NodeMaterial.fromMaterial( material ).build( this );

} else {

this.addFlow( 'compute', object );

}

return super.build();

}

needsColorSpaceToLinear( texture ) {

return texture.isVideoTexture === true && texture.colorSpace !== NoColorSpace;
Expand Down

0 comments on commit 3343949

Please sign in to comment.