From e8dbbd986e94bf486bd6d3a098dc9a47fc8f9ad7 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Tue, 3 Dec 2024 11:45:57 +0100 Subject: [PATCH] NodeBuilder: More docs. --- src/nodes/core/NodeBuilder.js | 607 +++++++++++++++++++++++++++++++++- 1 file changed, 591 insertions(+), 16 deletions(-) diff --git a/src/nodes/core/NodeBuilder.js b/src/nodes/core/NodeBuilder.js index bdf40a6539329e..5ac9840a70f039 100644 --- a/src/nodes/core/NodeBuilder.js +++ b/src/nodes/core/NodeBuilder.js @@ -116,6 +116,7 @@ class NodeBuilder { * The scene the 3D object belongs to. * * @type {Scene?} + * @default null */ this.scene = null; @@ -123,29 +124,125 @@ class NodeBuilder { * The camera the 3D object is rendered with. * * @type {Camera?} + * @default null */ this.camera = null; + /** + * A list of all nodes the builder is processing + * for this 3D object. + * + * @type {Array} + */ this.nodes = []; + + /** + * A list of all sequential nodes. + * + * @type {Array} + */ this.sequentialNodes = []; + + /** + * A list of all nodes which {@link Node#update} method should be executed. + * + * @type {Array} + */ this.updateNodes = []; + + /** + * A list of all nodes which {@link Node#updateBefore} method should be executed. + * + * @type {Array} + */ this.updateBeforeNodes = []; + + /** + * A list of all nodes which {@link Node#updateAfter} method should be executed. + * + * @type {Array} + */ this.updateAfterNodes = []; + + /** + * A dictionary that assigns each node to a unique hash. + * + * @type {Object} + */ this.hashNodes = {}; + /** + * A reference to a node material observer. + * + * @type {NodeMaterialObserver?} + * @default null + */ this.monitor = null; + /** + * A reference to the current lights node. + * + * @type {LightsNode?} + * @default null + */ this.lightsNode = null; + + /** + * A reference to the current environment node. + * + * @type {Node?} + * @default null + */ this.environmentNode = null; + + /** + * A reference to the current fog node. + * + * @type {FogNode?} + * @default null + */ this.fogNode = null; + /** + * The current clipping context. + * + * @type {ClippingContext?} + */ this.clippingContext = null; + /** + * The generated vertex shader. + * + * @type {String?} + */ this.vertexShader = null; + + /** + * The generated fragment shader. + * + * @type {String?} + */ this.fragmentShader = null; + + /** + * The generated compute shader. + * + * @type {String?} + */ this.computeShader = null; + /** + * TODO + * + * @type {Object} + */ this.flowNodes = { vertex: [], fragment: [], compute: [] }; + + /** + * TODO + * + * @type {Object} + */ this.flowCode = { vertex: '', fragment: '', compute: '' }; /** @@ -163,8 +260,26 @@ class NodeBuilder { * @type {Object} */ this.structs = { vertex: [], fragment: [], compute: [], index: 0 }; + + /** + * This dictionary holds the bindings for each shader stage. + * + * @type {Object} + */ this.bindings = { vertex: {}, fragment: {}, compute: {} }; + + /** + * This dictionary maintains the binding indices per bind group. + * + * @type {Object} + */ this.bindingsIndexes = {}; + + /** + * Reference to the array of bind groups. + * + * @type {Array?} + */ this.bindGroups = null; /** @@ -205,19 +320,81 @@ class NodeBuilder { * @type {Object>} */ this.vars = {}; + + /** + * TODO + * + * @type {{code: String}} + */ this.flow = { code: '' }; + + /** + * A chain of nodes. + * + * TODO: Explains purpose of this property. + * + * @type {Array} + */ this.chaining = []; + + /** + * The current stack. + * + * TODO: Explains purpose of this property. + * + * @type {StackNode} + */ this.stack = stack(); + + /** + * List of stack nodes. + * + * TODO: Explains purpose of this property. + * + * @type {Array} + */ this.stacks = []; + + /** + * A tab value. Used for shader string generation. + * + * @type {String} + * @default '\t' + */ this.tab = '\t'; + /** + * Reference to the current function node. + * + * @type {FunctionNode?} + * @default null + */ this.currentFunctionNode = null; + /** + * The builder's context. + * + * @type {Object} + */ this.context = { material: this.material }; + /** + * The builder's cache. + * + * @type {NodeCache} + */ this.cache = new NodeCache(); + + /** + * Since the {@link NodeBuilder#cache} might be temporarily + * overwritten by other caches, this member retains the reference + * to the builder's own cache. + * + * @type {NodeCache} + * @default this.cache + */ this.globalCache = this.cache; this.flowsData = new WeakMap(); @@ -225,7 +402,7 @@ class NodeBuilder { /** * The current shader stage. * - * @type {('vertex'|'fragment'|'compute')?} + * @type {('vertex'|'fragment'|'compute'|'any')?} */ this.shaderStage = null; @@ -236,6 +413,12 @@ class NodeBuilder { */ this.buildStage = null; + /** + * Whether comparison in shader code are generated with methods or not. + * + * @type {Boolean} + * @default false + */ this.useComparisonMethod = false; } @@ -315,6 +498,14 @@ class NodeBuilder { } + /** + * Returns a bind group for the given group name and binding. + * + * @private + * @param {String} groupName - The group name. + * @param {Array} bindings - List of bindings. + * @return {BindGroup} The bind group + */ _getBindGroup( groupName, bindings ) { const bindGroupsCache = this.getBindGroupsCache(); @@ -359,6 +550,13 @@ class NodeBuilder { } + /** + * Returns an array of node uniform groups for the given group name and shader stage. + * + * @param {String} groupName - The group name. + * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage. + * @return {Array} The array of node uniform groups. + */ getBindGroupArray( groupName, shaderStage ) { const bindings = this.bindings[ shaderStage ]; @@ -381,6 +579,13 @@ class NodeBuilder { } + /** + * Returns a list bindings. + * + * TODO: Add more details. + * + * @return {Array} The list of bindings. + */ getBindings() { let bindingsGroups = this.bindGroups; @@ -423,6 +628,9 @@ class NodeBuilder { } + /** + * Sorts the bind groups and updates {@link NodeBuilder#bindingsIndexes}. + */ sortBindingGroups() { const bindingsGroups = this.getBindings(); @@ -440,12 +648,24 @@ class NodeBuilder { } + /** + * The builder maintains each node in a hash-based dictionary. + * This method sets the given node (value) with the given hash (key) into this dictionary. + * + * @param {Node} node - The node to add. + * @param {Number} hash - The hash of the node. + */ setHashNode( node, hash ) { this.hashNodes[ hash ] = node; } + /** + * Adds a node to this builder. + * + * @param {Node} node - The node to add. + */ addNode( node ) { if ( this.nodes.includes( node ) === false ) { @@ -458,6 +678,11 @@ class NodeBuilder { } + /** + * TODO: Describe the difference to `addNode()`. + * + * @param {Node} node - The node to add. + */ addSequentialNode( node ) { if ( this.sequentialNodes.includes( node ) === false ) { @@ -468,6 +693,9 @@ class NodeBuilder { } + /** + * Checks the update types of nodes + */ buildUpdateNodes() { for ( const node of this.nodes ) { @@ -503,12 +731,24 @@ class NodeBuilder { } + /** + * A reference the current node which is the + * last node in the chain of nodes. + * + * @type {Node} + */ get currentNode() { return this.chaining[ this.chaining.length - 1 ]; } + /** + * Whether the given texture is filtered or not. + * + * @param {Texture} texture - The texture to check. + * @return {Boolean} Whether the given texture is filtered or not. + */ isFilteredTexture( texture ) { return ( texture.magFilter === LinearFilter || texture.magFilter === LinearMipmapNearestFilter || texture.magFilter === NearestMipmapLinearFilter || texture.magFilter === LinearMipmapLinearFilter || @@ -516,6 +756,13 @@ class NodeBuilder { } + /** + * Adds the given node to the internal node chain. + * + * TODO: Describe the difference to `addNode()`. + * + * @param {Node} node - The node to add. + */ addChain( node ) { /* @@ -530,6 +777,11 @@ class NodeBuilder { } + /** + * Removes the given node from the internal node chain. + * + * @param {Node} node - The node to remove. + */ removeChain( node ) { const lastChain = this.chaining.pop(); @@ -542,18 +794,40 @@ class NodeBuilder { } + /** + * Returns the native shader method name for a given generic name. E.g. + * the method name `textureDimensions` matches the WGSL name but must be + * resolved to `texureSize` in GLSL. + * + * @abstract + * @param {String} name - The method name to resolve. + * @return {String} The resolved method name. + */ getMethod( method ) { return method; } + /** + * Returns a node for the given hash, see {@link NodeBuilder#setHashNode}. + * + * @param {Number} hash - The hash of the node. + * @return {Node} The found node. + */ getNodeFromHash( hash ) { return this.hashNodes[ hash ]; } + /** + * TODO + * + * @param {('vertex'|'fragment'|'compute')} shaderStage - The shader stage. + * @param {Node} node - The node. + * @return {Node} The node + */ addFlow( shaderStage, node ) { this.flowNodes[ shaderStage ].push( node ); @@ -562,18 +836,33 @@ class NodeBuilder { } + /** + * Sets builder's context. + * + * @param {Object} context - The context to set. + */ setContext( context ) { this.context = context; } + /** + * Returns the builder's current context. + * + * @return {Object} The builder's current context. + */ getContext() { return this.context; } + /** + * TODO + * + * @return {Object} TODO. + */ getSharedContext() { const context = { ...this.context }; @@ -584,18 +873,35 @@ class NodeBuilder { } + /** + * Sets builder's cache. + * + * @param {NodeCache} cache - The cache to set. + */ setCache( cache ) { this.cache = cache; } + /** + * Returns the builder's current cache. + * + * @return {NodeCache} The builder's current cache. + */ getCache() { return this.cache; } + /** + * Returns a cache for the given node. + * + * @param {Node} Node - The node. + * @param {Boolean} [parent=true] - Whether this node refers to a shared parent cache or not. + * @return {NodeCache} The cache. + */ getCacheFromNode( node, parent = true ) { const data = this.getDataFromNode( node ); @@ -605,48 +911,99 @@ class NodeBuilder { } + /** + * Whether the requested feature is available or not. + * + * @abstract + * @param {String} name - The requested feature. + * @return {Boolean} Whether the requested feature is supported or not. + */ isAvailable( /*name*/ ) { return false; } + /** + * Returns the vertexIndex input variable as a native shader string. + * + * @abstract + * @return {String} The instanceIndex shader string. + */ getVertexIndex() { console.warn( 'Abstract function.' ); } + /** + * Returns the instanceIndex input variable as a native shader string. + * + * @abstract + * @return {String} The instanceIndex shader string. + */ getInstanceIndex() { console.warn( 'Abstract function.' ); } + /** + * Returns the drawIndex input variable as a native shader string. + * Only relevant for WebGL and its `WEBGL_multi_draw` extension. + * + * @abstract + * @return {String} The drawIndex shader string. + */ getDrawIndex() { console.warn( 'Abstract function.' ); } + /** + * Returns the frontFacing input variable as a native shader string. + * + * @abstract + * @return {String} The frontFacing shader string. + */ getFrontFacing() { console.warn( 'Abstract function.' ); } + /** + * Returns thefragCoord input variable as a native shader string. + * + * @abstract + * @return {String} The fragCoord shader string. + */ getFragCoord() { console.warn( 'Abstract function.' ); } + /** + * Whether to flip texture data along its vertical axis or not. WebGL needs + * this method evalaute to `true`, WebGPU to `false`. + * + * @abstract + * @return {Boolean} Whether to flip texture data along its vertical axis or not. + */ isFlipY() { return false; } + /** + * Calling this mehod increases the usage count for the given node by one. + * + * @param {Node} Node - The node to increase the usage count for. + * @return {Number} The updated usage count. + */ increaseUsage( node ) { const nodeData = this.getDataFromNode( node ); @@ -656,18 +1013,44 @@ class NodeBuilder { } + /** + * Generates a texture sample shader string for the given texture data. + * + * @abstract + * @param {Texture} texture - The texture. + * @param {String} textureProperty - The texture property name. + * @param {String} uvSnippet - Snippet defining the texture coordinates. + * @return {String} The generated shader string. + */ generateTexture( /* texture, textureProperty, uvSnippet */ ) { console.warn( 'Abstract function.' ); } + /** + * Generates a texture LOD shader string for the given texture data. + * + * @abstract + * @param {Texture} texture - The texture. + * @param {String} textureProperty - The texture property name. + * @param {String} uvSnippet - Snippet defining the texture coordinates. + * @param {String} levelSnippet - Snippet defining the mip level. + * @return {String} The generated shader string. + */ generateTextureLod( /* texture, textureProperty, uvSnippet, levelSnippet */ ) { console.warn( 'Abstract function.' ); } + /** + * Generates the shader string for the given type and value. + * + * @param {String} type - The type. + * @param {Any?} [value=null] - The value. + * @return {String} The generated value as a shader string. + */ generateConst( type, value = null ) { if ( value === null ) { @@ -783,7 +1166,7 @@ class NodeBuilder { * Returns for the given node and shader stage the property name for the shader. * * @param {Node} node - The node. - * @param {('vertex'|'fragment'|'compute')?} shaderStage - The current shader stage. + * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage. * @return {String} The property name. */ getPropertyName( node/*, shaderStage*/ ) { @@ -1039,6 +1422,11 @@ class NodeBuilder { } + /** + * Adds a stack node to the internal stack. + * + * @return {StackNode} The added stack node. + */ addStack() { this.stack = stack( this.stack ); @@ -1050,6 +1438,11 @@ class NodeBuilder { } + /** + * Removes the last stack node from the internal stack. + * + * @return {StackNode} The removed stack node. + */ removeStack() { const lastStack = this.stack; @@ -1061,6 +1454,15 @@ class NodeBuilder { } + /** + * The builder maintains (cached) data for each node during the building process. This method + * can be used to get these data for a specific shader stage and cache. + * + * @param {Node} node - The node to get the data for. + * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage. + * @param {NodeCache?} cache - An optional cache. + * @return {Object} The node data. + */ getDataFromNode( node, shaderStage = this.shaderStage, cache = null ) { cache = cache === null ? ( node.isGlobal( this ) ? this.globalCache : this.cache ) : cache; @@ -1081,6 +1483,13 @@ class NodeBuilder { } + /** + * Returns the properties for the given node and shader stage. + * + * @param {Node} node - The node to get the properties for. + * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage='any'] - The shader stage. + * @return {Object} The node properties. + */ getNodeProperties( node, shaderStage = 'any' ) { const nodeData = this.getDataFromNode( node, shaderStage ); @@ -1089,6 +1498,13 @@ class NodeBuilder { } + /** + * Returns an instance of {@link NodeAttribute} for the given buffer attribute node. + * + * @param {BufferAttributeNode} node - The buffer attribute node. + * @param {String} type - The node type. + * @return {NodeAttribute} The node attribute. + */ getBufferAttributeFromNode( node, type ) { const nodeData = this.getDataFromNode( node ); @@ -1111,6 +1527,14 @@ class NodeBuilder { } + /** + * Returns an instance of {@link StructTypeNode} for the given output struct node. + * + * @param {OutputStructNode} node - The output struct node. + * @param {Array} types - The output struct types. + * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage. + * @return {StructTypeNode} The struct type attribute. + */ getStructTypeFromNode( node, types, shaderStage = this.shaderStage ) { const nodeData = this.getDataFromNode( node, shaderStage ); @@ -1133,6 +1557,15 @@ class NodeBuilder { } + /** + * Returns an instance of {@link NodeUniform} for the given uniform node. + * + * @param {UniformNode} node - The uniform node. + * @param {String} type - The uniform type. + * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage. + * @param {String?} name - The name of the uniform. + * @return {NodeUniform} The node uniform. + */ getUniformFromNode( node, type, shaderStage = this.shaderStage, name = null ) { const nodeData = this.getDataFromNode( node, shaderStage, this.globalCache ); @@ -1155,6 +1588,15 @@ class NodeBuilder { } + /** + * Returns an instance of {@link NodeVar} for the given variable node. + * + * @param {VarNode} node - The variable node. + * @param {String?} name - The variable's name. + * @param {String} [type=node.getNodeType( this )] - The variable's type. + * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage. + * @return {NodeVar} The node variable. + */ getVarFromNode( node, name = null, type = node.getNodeType( this ), shaderStage = this.shaderStage ) { const nodeData = this.getDataFromNode( node, shaderStage ); @@ -1179,6 +1621,14 @@ class NodeBuilder { } + /** + * Returns an instance of {@link NodeVarying} for the given varying node. + * + * @param {(VaryingNode|PropertyNode)} node - The varying node. + * @param {String?} name - The varying's name. + * @param {String} [type=node.getNodeType( this )] - The varying's type. + * @return {NodeVar} The node varying. + */ getVaryingFromNode( node, name = null, type = node.getNodeType( this ) ) { const nodeData = this.getDataFromNode( node, 'any' ); @@ -1204,6 +1654,14 @@ class NodeBuilder { } + /** + * Returns an instance of {@link NodeCode} for the given code node. + * + * @param {CodeNode} node - The code node. + * @param {String} type - The node type. + * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage. + * @return {NodeCode} The node code. + */ getCodeFromNode( node, type, shaderStage = this.shaderStage ) { const nodeData = this.getDataFromNode( node ); @@ -1227,6 +1685,12 @@ class NodeBuilder { } + /** + * TODO + * + * @param {Node} node - TODO. + * @param {Node} nodeBlock - TODO. + */ addFlowCodeHierarchy( node, nodeBlock ) { const { flowCodes, flowCodeBlock } = this.getDataFromNode( node ); @@ -1259,6 +1723,13 @@ class NodeBuilder { } + /** + * TODO + * + * @param {Node} node - TODO. + * @param {String} code - TODO. + * @param {Node} nodeBlock - TODO. + */ addLineFlowCodeBlock( node, code, nodeBlock ) { const nodeData = this.getDataFromNode( node ); @@ -1270,6 +1741,13 @@ class NodeBuilder { } + /** + * TODO + * + * @param {String} code - TODO. + * @param {Node?} [node= null] - TODO. + * @return {NodeBuilder} A reference to this node builder. + */ addLineFlowCode( code, node = null ) { if ( code === '' ) return this; @@ -1294,6 +1772,12 @@ class NodeBuilder { } + /** + * TODO + * + * @param {String} code - TODO. + * @return {NodeBuilder} A reference to this node builder. + */ addFlowCode( code ) { this.flow.code += code; @@ -1302,6 +1786,11 @@ class NodeBuilder { } + /** + * TODO + * + * @return {NodeBuilder} A reference to this node builder. + */ addFlowTab() { this.tab += '\t'; @@ -1310,6 +1799,11 @@ class NodeBuilder { } + /** + * TODO + * + * @return {NodeBuilder} A reference to this node builder. + */ removeFlowTab() { this.tab = this.tab.slice( 0, - 1 ); @@ -1318,12 +1812,25 @@ class NodeBuilder { } + /** + * TODO + * + * @param {Node} node - TODO. + * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage. + * @return {Object} + */ getFlowData( node/*, shaderStage*/ ) { return this.flowsData.get( node ); } + /** + * TODO + * + * @param {Node} node - TODO. + * @return {Object} + */ flowNode( node ) { const output = node.getNodeType( this ); @@ -1336,6 +1843,13 @@ class NodeBuilder { } + /** + * Returns the native shader operator name for a given generic name. + * It is a similar type of method like {@link NodeBuilder#getMethod}. + * + * @param {ShaderNodeInternal} shaderNode - The shader node to build the function node with. + * @return {FunctionNode} The build function node. + */ buildFunctionNode( shaderNode ) { const fn = new FunctionNode(); @@ -1352,6 +1866,12 @@ class NodeBuilder { } + /** + * TODO + * + * @param {ShaderNodeInternal} node - TODO. + * @return {Object} + */ flowShaderNode( shaderNode ) { const layout = shaderNode.layout; @@ -1390,6 +1910,13 @@ class NodeBuilder { } + /** + * TODO + * + * @param {Node} node - TODO. + * @param {String?} output - TODO. + * @return {Object} + */ flowStagesNode( node, output = null ) { const previousFlow = this.flow; @@ -1428,12 +1955,27 @@ class NodeBuilder { } - getFunctionOperator() { + /** + * Returns the native shader operator name for a given generic name. + * It is a similar type of method like {@link NodeBuilder#getMethod}. + * + * @abstract + * @param {String} op - The operator name to resolve. + * @return {String} The resolved operator name. + */ + getFunctionOperator( /* op */ ) { return null; } + /** + * TODO + * + * @param {Node} node - TODO. + * @param {String?} output - TODO. + * @return {Object} + */ flowChildNode( node, output = null ) { const previousFlow = this.flow; @@ -1452,6 +1994,15 @@ class NodeBuilder { } + /** + * TODO + * + * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage. + * @param {Node} node - TODO. + * @param {String?} output - TODO. + * @param {String?} propertyName - TODO. + * @return {Object} + */ flowNodeFromShaderStage( shaderStage, node, output = null, propertyName = null ) { const previousShaderStage = this.shaderStage; @@ -1489,7 +2040,7 @@ class NodeBuilder { * Returns the attribute definitions as a shader string for the given shader stage. * * @abstract - * @param {('vertex'|'fragment'|'compute')?} shaderStage - The current shader stage. + * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage. * @return {String} The attribute code section. */ getAttributes( /*shaderStage*/ ) { @@ -1502,7 +2053,7 @@ class NodeBuilder { * Returns the varying definitions as a shader string for the given shader stage. * * @abstract - * @param {('vertex'|'fragment'|'compute')?} shaderStage - The current shader stage. + * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage. * @return {String} The varying code section. */ getVaryings( /*shaderStage*/ ) { @@ -1527,7 +2078,7 @@ class NodeBuilder { /** * Returns the variable definitions as a shader string for the given shader stage. * - * @param {('vertex'|'fragment'|'compute')?} shaderStage - The current shader stage. + * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage. * @return {String} The variable code section. */ getVars( shaderStage ) { @@ -1554,7 +2105,7 @@ class NodeBuilder { * Returns the uniform definitions as a shader string for the given shader stage. * * @abstract - * @param {('vertex'|'fragment'|'compute')?} shaderStage - The current shader stage. + * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage. * @return {String} The uniform code section. */ getUniforms( /*shaderStage*/ ) { @@ -1566,7 +2117,7 @@ class NodeBuilder { /** * Returns the native code definitions as a shader string for the given shader stage. * - * @param {('vertex'|'fragment'|'compute')?} shaderStage - The current shader stage. + * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage. * @return {String} The native code section. */ getCodes( shaderStage ) { @@ -1589,6 +2140,11 @@ class NodeBuilder { } + /** + * Returns the hash of this node builder. + * + * @return {String} The hash. + */ getHash() { return this.vertexShader + this.fragmentShader + this.computeShader; @@ -1598,7 +2154,7 @@ class NodeBuilder { /** * Sets the current shader stage. * - * @param {('vertex'|'fragment'|'compute')?} shaderStage - The shader stage to set. + * @param {('vertex'|'fragment'|'compute'|'any')?} shaderStage - The shader stage to set. */ setShaderStage( shaderStage ) { @@ -1609,7 +2165,7 @@ class NodeBuilder { /** * Returns the current shader stage. * - * @return {('vertex'|'fragment'|'compute')?} The current shader stage. + * @return {('vertex'|'fragment'|'compute'|'any')?} The current shader stage. */ getShaderStage() { @@ -1729,6 +2285,13 @@ class NodeBuilder { } + /** + * Returns a uniform representation which is later used for UBO generation and rendering. + * + * @param {NodeUniform} uniformNode - The uniform node. + * @param {String} type - The requested type. + * @return {Uniform} The uniform. + */ getNodeUniform( uniformNode, type ) { if ( type === 'float' || type === 'int' || type === 'uint' ) return new NumberNodeUniform( uniformNode ); @@ -1743,12 +2306,16 @@ class NodeBuilder { } - createNodeMaterial( type = 'NodeMaterial' ) { // @deprecated, r168 - - throw new Error( `THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${ type }() instead.` ); - - } - + /** + * Formats the given shader snippet from a given type into another one. E.g. + * this method might be used to convert a simple float string `"1.0"` into a + * `vec3` representation: `"vec3( 1.0 )"`. + * + * @param {String} snippet - The shader snippet. + * @param {String} fromType - The source type. + * @param {String} toType - The target type. + * @return {String} The updated shader string. + */ format( snippet, fromType, toType ) { fromType = this.getVectorType( fromType ); @@ -1840,6 +2407,14 @@ class NodeBuilder { } + // deprecated + + createNodeMaterial( type = 'NodeMaterial' ) { // @deprecated, r168 + + throw new Error( `THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${ type }() instead.` ); + + } + } export default NodeBuilder;