Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeBuilder: remove duplicate code (a TODO item) #27412

Merged
merged 4 commits into from
Jan 4, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -124,24 +124,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