NodeBuilder.html.md 33 KB

NodeBuilder

Base class for builders which generate a shader program based on a 3D object and its node material definition.

Constructor

new NodeBuilder( object : Object3D, renderer : Renderer, parser : NodeParser )

Constructs a new node builder.

object

The 3D object.

renderer

The current renderer.

parser

A reference to a node parser.

Properties

.activeStacks : Array.

The active stack nodes.

.attributes : Array.

This array holds the node attributes of this builder created via AttributeNode.

.bindGroups : Array.

Reference to the array of bind groups.

.bindings : Object

This dictionary holds the bindings for each shader stage.

.bindingsIndexes : Object

This dictionary maintains the binding indices per bind group.

.bufferAttributes : Array.

This array holds the node attributes of this builder created via BufferAttributeNode.

.buildStage : 'setup' | 'analyze' | 'generate'

The current build stage.

.cache : NodeCache

The builder's cache.

.camera : Camera

The camera the 3D object is rendered with.

Default is null.

.chaining : Array.

A chain of nodes. Used to check recursive calls in node-graph.

.clippingContext : ClippingContext

The current clipping context.

.codes : Object.>

This dictionary holds the (native) node codes of this builder. The codes are maintained in an array for each shader stage.

.computeShader : string

The generated compute shader.

.context : Object

The builder's context.

.currentFunctionNode : FunctionNode

Reference to the current function node.

Default is null.

.currentNode : Node

A reference the current node which is the last node in the chain of nodes.

.declarations : Object

This dictionary holds the declarations for each shader stage.

.environmentNode : Node

A reference to the current environment node.

Default is null.

.flow : Object

Current code flow. All code generated in this stack will be stored in .flow.

.flowCode : Object.

Nodes code from .flowNodes.

.flowNodes : Object.>

Nodes used in the primary flow of code generation.

.fnCall : Node

The current TSL function(Fn) call node.

Default is null.

.fogNode : Node

A reference to the current fog node.

Default is null.

.fragmentShader : string

The generated fragment shader.

.geometry : BufferGeometry

The geometry of the 3D object.

.globalCache : NodeCache

Since the NodeBuilder#cache might be temporarily overwritten by other caches, this member retains the reference to the builder's own cache.

Default is this.cache.

.hashNodes : Object.

A dictionary that assigns each node to a unique hash.

.lightsNode : LightsNode

A reference to the current lights node.

Default is null.

.material : Material

The material of the 3D object.

.nodes : Array.

A list of all nodes the builder is processing for this 3D object.

.object : Object3D

The 3D object.

.observer : NodeMaterialObserver

A reference to a node material observer.

Default is null.

.parser : NodeParser

A reference to a node parser.

.renderer : Renderer

The current renderer.

.scene : Scene

The scene the 3D object belongs to.

Default is null.

.sequentialNodes : Array.

A list of all sequential nodes.

.shaderStage : 'vertex' | 'fragment' | 'compute' | 'any'

The current shader stage.

.stack : StackNode

The current stack. This reflects the current process in the code block hierarchy, it is useful to know if the current process is inside a conditional for example.

.stacks : Array.

List of stack nodes. The current stack hierarchy is stored in an array.

.structs : Object

This dictionary holds the output structs of the builder. The structs are maintained in an array for each shader stage.

.subBuild

Returns the current sub-build layer.

.subBuildFn : string

The current sub-build TSL function(Fn).

Default is null.

.subBuildLayers : Array.

The sub-build layers.

Default is [].

.tab : string

A tab value. Used for shader string generation.

Default is '\t'.

.types : Object

This dictionary holds the types of the builder.

.uniforms : Object

This dictionary holds the node uniforms of the builder. The uniforms are maintained in an array for each shader stage.

.updateAfterNodes : Array.

A list of all nodes which Node#updateAfter method should be executed.

.updateBeforeNodes : Array.

A list of all nodes which Node#updateBefore method should be executed.

.updateNodes : Array.

A list of all nodes which Node#update method should be executed.

.vars : Object.|number)>

This dictionary holds the node variables of this builder. The variables are maintained in an array for each shader stage. This dictionary is also used to count the number of variables according to their type (const, vars).

.varyings : Array.

This array holds the node varyings of this builder.

.vertexShader : string

The generated vertex shader.

Methods

.addChain( node : Node )

Adds the given node to the internal node chain. This is used to check recursive calls in node-graph.

node

The node to add.

.addContext( context : Object ) : Object

Adds context data to the builder's current context.

context

The context to add.

Returns: The previous context.

.addFlow( shaderStage : 'vertex' | 'fragment' | 'compute', node : Node ) : Node

Adds the Node to a target flow so that it can generate code in the 'generate' process.

shaderStage

The shader stage.

node

The node to add.

Returns: The node.

.addFlowCode( code : string ) : NodeBuilder

Adds a code to the current code flow.

code

Shader code.

Returns: A reference to this node builder.

.addFlowCodeHierarchy( node : Node, nodeBlock : Node )

Adds a code flow based on the code-block hierarchy. This is used so that code-blocks like If,Else create their variables locally if the Node is only used inside one of these conditionals in the current shader stage.

node

The node to add.

nodeBlock

Node-based code-block. Usually 'ConditionalNode'.

.addFlowTab() : NodeBuilder

Add tab in the code that will be generated so that other snippets respect the current tabulation. Typically used in codes with If,Else.

Returns: A reference to this node builder.

.addInclude( node : Node ) : void

Includes a node in the current function node.

node

The node to include.

.addLineFlowCode( code : string, node : Node ) : NodeBuilder

Add a inline-code to the current flow.

code

The code to add.

node

Optional Node, can help the system understand if the Node is part of a code-block.

Default is null.

Returns: A reference to this node builder.

.addLineFlowCodeBlock( node : Node, code : string, nodeBlock : Node )

Add a inline-code to the current flow code-block.

node

The node to add.

code

The code to add.

nodeBlock

Current ConditionalNode

.addNode( node : Node )

Adds a node to this builder.

node

The node to add.

.addSequentialNode( node : Node )

It is used to add Nodes that will be used as FRAME and RENDER events, and need to follow a certain sequence in the calls to work correctly. This function should be called after 'setup()' in the 'build()' process to ensure that the child nodes are processed first.

node

The node to add.

.addStack() : StackNode

Adds a stack node to the internal stack.

Returns: The added stack node.

.addSubBuild( subBuild : SubBuildNode )

Adds a sub-build layer to the node builder.

subBuild

The sub-build layer to add.

.build() : NodeBuilder

Central build method which controls the build for the given object.

Returns: A reference to this node builder.

.buildCode() (abstract)

Controls the code build of the shader stages.

.buildFunctionCode( shaderNode : ShaderNodeInternal ) : string (abstract)

Builds the given shader node.

shaderNode

The shader node.

Returns: The function code.

.buildFunctionNode( shaderNode : ShaderNodeInternal ) : FunctionNode

Returns the native shader operator name for a given generic name. It is a similar type of method like NodeBuilder#getMethod.

shaderNode

The shader node to build the function node with.

Returns: The build function node.

.buildUpdateNodes()

Checks the update types of nodes

.changeComponentType( type : string, newComponentType : string ) : string

For a given type this method changes the component type to the given value. E.g. vec4 should be changed to the new component type uint which results in uvec4.

type

The type.

newComponentType

The new component type.

Returns: The new type.

.createCubeRenderTarget( size : number, options : Object ) : CubeRenderTarget

Factory method for creating an instance of CubeRenderTarget with the given dimensions and options.

size

The size of the cube render target.

options

The options of the cube render target.

Returns: The cube render target.

.createRenderTarget( width : number, height : number, options : Object ) : RenderTarget

Factory method for creating an instance of RenderTarget with the given dimensions and options.

width

The width of the render target.

height

The height of the render target.

options

The options of the render target.

Returns: The render target.

.flowBuildStage( node : Node, buildStage : string, output : Node | string ) : Node | string

Executes the node in a specific build stage.

This function can be used to arbitrarily execute the specified build stage outside of the standard build process. For instance, if a node's type depends on properties created by the 'setup' stage, then flowBuildStage(node, 'setup') can be used to execute the setup build stage and access its generated nodes before the standard build process begins.

node

The node to execute.

buildStage

The build stage to execute the node in.

output

Expected output type. For example 'vec3'.

Default is null.

Returns: The result of the node build.

.flowChildNode( node : Node, output : string ) : Object

Generates a code flow based on a child Node.

node

The node to execute.

output

Expected output type. For example 'vec3'.

Default is null.

Returns: The code flow.

.flowNode( node : Node ) : Object

Executes the node flow based on a root node to generate the final shader code.

node

The node to execute.

Returns: The code flow.

.flowNodeFromShaderStage( shaderStage : 'vertex' | 'fragment' | 'compute' | 'any', node : Node, output : string, propertyName : string ) : Object | Node

Executes a flow of code in a different stage.

Some nodes like varying() have the ability to compute code in vertex-stage and return the value in fragment-stage even if it is being executed in an input fragment.

shaderStage

The shader stage.

node

The node to execute.

output

Expected output type. For example 'vec3'.

Default is null.

propertyName

The property name to assign the result.

Default is null.

Returns: The code flow or node.build() result.

.flowShaderNode( shaderNode : ShaderNodeInternal ) : Object

Generates a code flow based on a TSL function: Fn().

shaderNode

A function code will be generated based on the input.

.flowStagesNode( node : Node, output : string ) : Object

Runs the node flow through all the steps of creation, 'setup', 'analyze', 'generate'.

node

The node to execute.

output

Expected output type. For example 'vec3'.

Default is null.

.format( snippet : string, fromType : string, toType : string ) : string

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<f32>( 1.0 )".

snippet

The shader snippet.

fromType

The source type.

toType

The target type.

Returns: The updated shader string.

.generateArray( type : string, count : number, values : Array. ) : string

Generates the array shader string for the given type and value.

type

The type.

count

The count.

values

The default values.

Default is null.

Returns: The generated value as a shader string.

.generateArrayDeclaration( type : string, count : number ) : string

Generates the array declaration string.

type

The type.

count

The count.

Returns: The generated value as a shader string.

.generateConst( type : string, value : any ) : string

Generates the shader string for the given type and value.

type

The type.

value

The value.

Default is null.

Returns: The generated value as a shader string.

.generateStruct( type : string, membersLayout : Array.

粤ICP备19079148号