Skip to content

Commit 3d97470

Browse files
sunagMugen87
andauthored
NodeBuilder: More docs. (mrdoob#30038)
* more docs * Update StackNode.js --------- Co-authored-by: Michael Herzog <[email protected]>
1 parent 16cb40e commit 3d97470

File tree

2 files changed

+58
-52
lines changed

2 files changed

+58
-52
lines changed

src/nodes/core/NodeBuilder.js

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ class NodeBuilder {
232232
this.computeShader = null;
233233

234234
/**
235-
* TODO
235+
* Nodes used in the primary flow of code generation.
236236
*
237-
* @type {Object}
237+
* @type {Object<String,Array<Node>>}
238238
*/
239239
this.flowNodes = { vertex: [], fragment: [], compute: [] };
240240

241241
/**
242-
* TODO
242+
* Nodes code from `.flowNodes`.
243243
*
244244
* @type {Object<String,String>}
245245
*/
@@ -322,34 +322,33 @@ class NodeBuilder {
322322
this.vars = {};
323323

324324
/**
325-
* TODO
325+
* Current code flow.
326+
* All code generated in this stack will be stored in `.flow`.
326327
*
327328
* @type {{code: String}}
328329
*/
329330
this.flow = { code: '' };
330331

331332
/**
332333
* A chain of nodes.
333-
*
334-
* TODO: Explains purpose of this property.
334+
* Used to check recursive calls in node-graph.
335335
*
336336
* @type {Array<Node>}
337337
*/
338338
this.chaining = [];
339339

340340
/**
341341
* The current stack.
342-
*
343-
* TODO: Explains purpose of this property.
342+
* This reflects the current process in the code block hierarchy,
343+
* it is useful to know if the current process is inside a conditional for example.
344344
*
345345
* @type {StackNode}
346346
*/
347347
this.stack = stack();
348348

349349
/**
350350
* List of stack nodes.
351-
*
352-
* TODO: Explains purpose of this property.
351+
* The current stack hierarchy is stored in an array.
353352
*
354353
* @type {Array<StackNode>}
355354
*/
@@ -580,9 +579,7 @@ class NodeBuilder {
580579
}
581580

582581
/**
583-
* Returns a list bindings.
584-
*
585-
* TODO: Add more details.
582+
* Returns a list bindings of all shader stages separated by groups.
586583
*
587584
* @return {Array<BindGroup>} The list of bindings.
588585
*/
@@ -679,7 +676,8 @@ class NodeBuilder {
679676
}
680677

681678
/**
682-
* TODO: Describe the difference to `addNode()`.
679+
* It is used to add Nodes that will be used as FRAME and RENDER events,
680+
* and need to follow a certain sequence in the calls to work correctly.
683681
*
684682
* @param {Node} node - The node to add.
685683
*/
@@ -758,8 +756,7 @@ class NodeBuilder {
758756

759757
/**
760758
* Adds the given node to the internal node chain.
761-
*
762-
* TODO: Describe the difference to `addNode()`.
759+
* This is used to check recursive calls in node-graph.
763760
*
764761
* @param {Node} node - The node to add.
765762
*/
@@ -822,11 +819,11 @@ class NodeBuilder {
822819
}
823820

824821
/**
825-
* TODO
822+
* Adds the Node to a target flow so that it can generate code in the 'generate' process.
826823
*
827824
* @param {('vertex'|'fragment'|'compute')} shaderStage - The shader stage.
828-
* @param {Node} node - The node.
829-
* @return {Node} The node
825+
* @param {Node} node - The node to add.
826+
* @return {Node} The node.
830827
*/
831828
addFlow( shaderStage, node ) {
832829

@@ -859,9 +856,10 @@ class NodeBuilder {
859856
}
860857

861858
/**
862-
* TODO
859+
* Gets a context used in shader construction that can be shared across different materials.
860+
* This is necessary since the renderer cache can reuse shaders generated in one material and use them in another.
863861
*
864-
* @return {Object} TODO.
862+
* @return {Object} The builder's current context without material.
865863
*/
866864
getSharedContext() {
867865

@@ -1686,10 +1684,13 @@ class NodeBuilder {
16861684
}
16871685

16881686
/**
1689-
* TODO
1687+
* Adds a code flow based on the code-block hierarchy.
1688+
1689+
* This is used so that code-blocks like If,Else create their variables locally if the Node
1690+
* is only used inside one of these conditionals in the current shader stage.
16901691
*
1691-
* @param {Node} node - TODO.
1692-
* @param {Node} nodeBlock - TODO.
1692+
* @param {Node} node - The node to add.
1693+
* @param {Node} nodeBlock - Node-based code-block. Usually 'ConditionalNode'.
16931694
*/
16941695
addFlowCodeHierarchy( node, nodeBlock ) {
16951696

@@ -1724,11 +1725,11 @@ class NodeBuilder {
17241725
}
17251726

17261727
/**
1727-
* TODO
1728+
* Add a inline-code to the current flow code-block.
17281729
*
1729-
* @param {Node} node - TODO.
1730-
* @param {String} code - TODO.
1731-
* @param {Node} nodeBlock - TODO.
1730+
* @param {Node} node - The node to add.
1731+
* @param {String} code - The code to add.
1732+
* @param {Node} nodeBlock - Current ConditionalNode
17321733
*/
17331734
addLineFlowCodeBlock( node, code, nodeBlock ) {
17341735

@@ -1742,10 +1743,10 @@ class NodeBuilder {
17421743
}
17431744

17441745
/**
1745-
* TODO
1746+
* Add a inline-code to the current flow.
17461747
*
1747-
* @param {String} code - TODO.
1748-
* @param {Node?} [node= null] - TODO.
1748+
* @param {String} code - The code to add.
1749+
* @param {Node?} [node= null] - Optional Node, can help the system understand if the Node is part of a code-block.
17491750
* @return {NodeBuilder} A reference to this node builder.
17501751
*/
17511752
addLineFlowCode( code, node = null ) {
@@ -1773,9 +1774,9 @@ class NodeBuilder {
17731774
}
17741775

17751776
/**
1776-
* TODO
1777+
* Adds a code to the current code flow.
17771778
*
1778-
* @param {String} code - TODO.
1779+
* @param {String} code - Shader code.
17791780
* @return {NodeBuilder} A reference to this node builder.
17801781
*/
17811782
addFlowCode( code ) {
@@ -1787,7 +1788,8 @@ class NodeBuilder {
17871788
}
17881789

17891790
/**
1790-
* TODO
1791+
* Add tab in the code that will be generated so that other snippets respect the current tabulation.
1792+
* Typically used in codes with If,Else.
17911793
*
17921794
* @return {NodeBuilder} A reference to this node builder.
17931795
*/
@@ -1800,7 +1802,7 @@ class NodeBuilder {
18001802
}
18011803

18021804
/**
1803-
* TODO
1805+
* Removes a tab.
18041806
*
18051807
* @return {NodeBuilder} A reference to this node builder.
18061808
*/
@@ -1813,9 +1815,9 @@ class NodeBuilder {
18131815
}
18141816

18151817
/**
1816-
* TODO
1818+
* Gets the current flow data based on a Node.
18171819
*
1818-
* @param {Node} node - TODO.
1820+
* @param {Node} node - Node that the flow was started.
18191821
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
18201822
* @return {Object}
18211823
*/
@@ -1826,9 +1828,9 @@ class NodeBuilder {
18261828
}
18271829

18281830
/**
1829-
* TODO
1831+
* Executes the node flow based on a root node to generate the final shader code.
18301832
*
1831-
* @param {Node} node - TODO.
1833+
* @param {Node} node - The node to execute.
18321834
* @return {Object}
18331835
*/
18341836
flowNode( node ) {
@@ -1867,9 +1869,9 @@ class NodeBuilder {
18671869
}
18681870

18691871
/**
1870-
* TODO
1872+
* Generates a code flow based on a TSL function: Fn().
18711873
*
1872-
* @param {ShaderNodeInternal} node - TODO.
1874+
* @param {ShaderNodeInternal} node - A function code will be generated based on the input.
18731875
* @return {Object}
18741876
*/
18751877
flowShaderNode( shaderNode ) {
@@ -1911,10 +1913,10 @@ class NodeBuilder {
19111913
}
19121914

19131915
/**
1914-
* TODO
1916+
* Runs the node flow through all the steps of creation, 'setup', 'analyze', 'generate'.
19151917
*
1916-
* @param {Node} node - TODO.
1917-
* @param {String?} output - TODO.
1918+
* @param {Node} node - The node to execute.
1919+
* @param {String?} output - Expected output type. For example 'vec3'.
19181920
* @return {Object}
19191921
*/
19201922
flowStagesNode( node, output = null ) {
@@ -1970,10 +1972,10 @@ class NodeBuilder {
19701972
}
19711973

19721974
/**
1973-
* TODO
1975+
* Generates a code flow based on a child Node.
19741976
*
1975-
* @param {Node} node - TODO.
1976-
* @param {String?} output - TODO.
1977+
* @param {Node} node - The node to execute.
1978+
* @param {String?} output - Expected output type. For example 'vec3'.
19771979
* @return {Object}
19781980
*/
19791981
flowChildNode( node, output = null ) {
@@ -1995,12 +1997,15 @@ class NodeBuilder {
19951997
}
19961998

19971999
/**
1998-
* TODO
2000+
* Executes a flow of code in a different stage.
2001+
*
2002+
* Some nodes like `varying()` have the ability to compute code in vertex-stage and
2003+
* return the value in fragment-stage even if it is being executed in an input fragment.
19992004
*
20002005
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2001-
* @param {Node} node - TODO.
2002-
* @param {String?} output - TODO.
2003-
* @param {String?} propertyName - TODO.
2006+
* @param {Node} node - The node to execute.
2007+
* @param {String?} output - Expected output type. For example 'vec3'.
2008+
* @param {String?} propertyName - The property name to assign the result.
20042009
* @return {Object}
20052010
*/
20062011
flowNodeFromShaderStage( shaderStage, node, output = null, propertyName = null ) {

src/nodes/core/StackNode.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { select } from '../math/ConditionalNode.js';
33
import { ShaderNode, nodeProxy, getCurrentStack, setCurrentStack } from '../tsl/TSLBase.js';
44

55
/**
6-
* TODO
6+
* Stack is a helper for Nodes that need to produce stack-based code instead of continuous flow.
7+
* They are usually needed in cases like `If`, `Else`.
78
*
89
* @augments Node
910
*/

0 commit comments

Comments
 (0)