Skip to content

Commit f81793c

Browse files
authored
Node: Document more modules. (#30000)
* Node: Document more modules. * Node: More docs. * Node: More docs. * Docs: Minor fix. * Docs: More fixes. * Docs: Fix TODOs. * Update AssignNode.js
1 parent c9e64a1 commit f81793c

15 files changed

+502
-14
lines changed

src/nodes/core/AssignNode.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import TempNode from '../core/TempNode.js';
22
import { addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';
33
import { vectorComponents } from '../core/constants.js';
44

5+
/**
6+
* These node represents an assing operation. Meaning a node is assigned
7+
* to another node.
8+
*
9+
* @augments TempNode
10+
*/
511
class AssignNode extends TempNode {
612

713
static get type() {
@@ -10,15 +16,38 @@ class AssignNode extends TempNode {
1016

1117
}
1218

19+
/**
20+
* Constructs a new assign node.
21+
*
22+
* @param {Node} targetNode - The target node.
23+
* @param {Node} sourceNode - The source type.
24+
*/
1325
constructor( targetNode, sourceNode ) {
1426

1527
super();
1628

29+
/**
30+
* The target node.
31+
*
32+
* @type {Node}
33+
*/
1734
this.targetNode = targetNode;
35+
36+
/**
37+
* The source node.
38+
*
39+
* @type {Node}
40+
*/
1841
this.sourceNode = sourceNode;
1942

2043
}
2144

45+
/**
46+
* Whether this node is used more than once in contextx of other nodes. This method
47+
* is overwritten since it always returns `false` (assigns are unique).
48+
*
49+
* @return {Boolean} A flag that inidiactes if there is more than one dependency to other nodes. Always `false`.
50+
*/
2251
hasDependencies() {
2352

2453
return false;
@@ -31,16 +60,23 @@ class AssignNode extends TempNode {
3160

3261
}
3362

63+
/**
64+
* Whehter a split is required when assigning source to target. This can happen when the component length of
65+
* target and source data type does not match.
66+
*
67+
* @param {NodeBuilder} builder - The current node builder.
68+
* @return {Boolean} Whehter a split is required when assigning source to target.
69+
*/
3470
needsSplitAssign( builder ) {
3571

3672
const { targetNode } = this;
3773

3874
if ( builder.isAvailable( 'swizzleAssign' ) === false && targetNode.isSplitNode && targetNode.components.length > 1 ) {
3975

4076
const targetLength = builder.getTypeLength( targetNode.node.getNodeType( builder ) );
41-
const assignDiferentVector = vectorComponents.join( '' ).slice( 0, targetLength ) !== targetNode.components;
77+
const assignDifferentVector = vectorComponents.join( '' ).slice( 0, targetLength ) !== targetNode.components;
4278

43-
return assignDiferentVector;
79+
return assignDifferentVector;
4480

4581
}
4682

src/nodes/core/AttributeNode.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import Node from './Node.js';
22
import { nodeObject, varying } from '../tsl/TSLBase.js';
33

4+
/**
5+
* Base class for representing shader attributes as nodes.
6+
*
7+
* @augments Node
8+
*/
49
class AttributeNode extends Node {
510

611
static get type() {
@@ -9,10 +14,22 @@ class AttributeNode extends Node {
914

1015
}
1116

17+
/**
18+
* Constructs a new attribute node.
19+
*
20+
* @param {String} attributeName - The name of the attribute.
21+
* @param {String?} nodeType - The node type.
22+
*/
1223
constructor( attributeName, nodeType = null ) {
1324

1425
super( nodeType );
1526

27+
/**
28+
* `AttributeNode` sets this property to `true` by default.
29+
*
30+
* @type {Boolean}
31+
* @default true
32+
*/
1633
this.global = true;
1734

1835
this._attributeName = attributeName;
@@ -51,6 +68,14 @@ class AttributeNode extends Node {
5168

5269
}
5370

71+
/**
72+
* Sets the attribute name to the given value. The method can be
73+
* overwritten in derived classes if the final name must be computed
74+
* analytically.
75+
*
76+
* @param {String} attributeName - The name of the attribute.
77+
* @return {AttributeNode} A reference to this node.
78+
*/
5479
setAttributeName( attributeName ) {
5580

5681
this._attributeName = attributeName;
@@ -59,6 +84,14 @@ class AttributeNode extends Node {
5984

6085
}
6186

87+
/**
88+
* Returns the attribute name of this node. The method can be
89+
* overwritten in derived classes if the final name must be computed
90+
* analytically.
91+
*
92+
* @param {NodeBuilder} builder - The current node builder.
93+
* @return {String} The attribute name.
94+
*/
6295
getAttributeName( /*builder*/ ) {
6396

6497
return this._attributeName;

src/nodes/core/BypassNode.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import Node from './Node.js';
22
import { addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';
33

4+
/**
5+
* The class generates the code of a given node but returns another node in the output.
6+
* This can be used to call a method or node that does not return a value, i.e.
7+
* type `void` on an input where returning a value is required. Example:
8+
*
9+
* ```js
10+
* material.colorNode = myColor.bypass( runVoidFn() )
11+
*```
12+
*
13+
* @augments Node
14+
*/
415
class BypassNode extends Node {
516

617
static get type() {
@@ -9,13 +20,37 @@ class BypassNode extends Node {
920

1021
}
1122

12-
constructor( returnNode, callNode ) {
23+
/**
24+
* Constructs a new bypass node.
25+
*
26+
* @param {Node} outputNode - The output node.
27+
* @param {Node} callNode - The call node.
28+
*/
29+
constructor( outputNode, callNode ) {
1330

1431
super();
1532

33+
/**
34+
* This flag can be used for type testing.
35+
*
36+
* @type {Boolean}
37+
* @readonly
38+
* @default true
39+
*/
1640
this.isBypassNode = true;
1741

18-
this.outputNode = returnNode;
42+
/**
43+
* The output node.
44+
*
45+
* @type {Node}
46+
*/
47+
this.outputNode = outputNode;
48+
49+
/**
50+
* The call node.
51+
*
52+
* @type {Node}
53+
*/
1954
this.callNode = callNode;
2055

2156
}

src/nodes/core/CacheNode.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import Node from './Node.js';
22
import { addMethodChaining, nodeObject } from '../tsl/TSLCore.js';
33

4+
/**
5+
* This node can be used as a cache management component for another node.
6+
* Caching is in general used by default in {@link NodeBuilder} but this node
7+
* allows the usage of a shared parent cache during the build process.
8+
*
9+
* @augments Node
10+
*/
411
class CacheNode extends Node {
512

613
static get type() {
@@ -9,13 +16,38 @@ class CacheNode extends Node {
916

1017
}
1118

19+
/**
20+
* Constructs a new cache node.
21+
*
22+
* @param {Node} node - The node that should be cached.
23+
* @param {Boolean} [parent=true] - Whether this node refers to a shared parent cache or not.
24+
*/
1225
constructor( node, parent = true ) {
1326

1427
super();
1528

29+
/**
30+
* The node that should be cached.
31+
*
32+
* @type {Node}
33+
*/
1634
this.node = node;
35+
36+
/**
37+
* Whether this node refers to a shared parent cache or not.
38+
*
39+
* @type {Boolean}
40+
* @default true
41+
*/
1742
this.parent = parent;
1843

44+
/**
45+
* This flag can be used for type testing.
46+
*
47+
* @type {Boolean}
48+
* @readonly
49+
* @default true
50+
*/
1951
this.isCacheNode = true;
2052

2153
}

src/nodes/core/ConstNode.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import InputNode from './InputNode.js';
22

3+
/**
4+
* Class for representing a constant value in the shader.
5+
*
6+
* @augments InputNode
7+
*/
38
class ConstNode extends InputNode {
49

510
static get type() {
@@ -8,14 +13,33 @@ class ConstNode extends InputNode {
813

914
}
1015

16+
/**
17+
* Constructs a new input node.
18+
*
19+
* @param {Any} value - The value of this node. Usually a JS primitive or three.js object (vector, matrix, color).
20+
* @param {String?} nodeType - The node type. If no explicit type is defined, the node tries to derive the type from its value.
21+
*/
1122
constructor( value, nodeType = null ) {
1223

1324
super( value, nodeType );
1425

26+
/**
27+
* This flag can be used for type testing.
28+
*
29+
* @type {Boolean}
30+
* @readonly
31+
* @default true
32+
*/
1533
this.isConstNode = true;
1634

1735
}
1836

37+
/**
38+
* Generates the shader string of the value with the current node builder.
39+
*
40+
* @param {NodeBuilder} builder - The current node builder.
41+
* @return {String} The generated value as a shader string.
42+
*/
1943
generateConst( builder ) {
2044

2145
return builder.generateConst( this.getNodeType( builder ), this.value );

src/nodes/core/InputNode.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import Node from './Node.js';
22
import { getValueType, getValueFromType, arrayBufferToBase64 } from './NodeUtils.js';
33

4+
/**
5+
* Base class for representing data input nodes.
6+
*
7+
* @augments Node
8+
*/
49
class InputNode extends Node {
510

611
static get type() {
@@ -9,13 +14,38 @@ class InputNode extends Node {
914

1015
}
1116

17+
/**
18+
* Constructs a new input node.
19+
*
20+
* @param {Any} value - The value of this node. This can be a any JS primitive, functions, array buffers or even three.js objects (vector, matrices, colors).
21+
* @param {String?} nodeType - The node type. If no explicit type is defined, the node tries to derive the type from its value.
22+
*/
1223
constructor( value, nodeType = null ) {
1324

1425
super( nodeType );
1526

27+
/**
28+
* This flag can be used for type testing.
29+
*
30+
* @type {Boolean}
31+
* @readonly
32+
* @default true
33+
*/
1634
this.isInputNode = true;
1735

36+
/**
37+
* The value of this node. This can be a any JS primitive, functions, array buffers or even three.js objects (vector, matrices, colors).
38+
*
39+
* @type {Any}
40+
*/
1841
this.value = value;
42+
43+
/**
44+
* The precision of the value in the shader.
45+
*
46+
* @type {('low'|'medium'|'high')?}
47+
* @default null
48+
*/
1949
this.precision = null;
2050

2151
}
@@ -32,12 +62,30 @@ class InputNode extends Node {
3262

3363
}
3464

65+
/**
66+
* Returns the input type of the node which is by default the node type. Derived modules
67+
* might overwrite this method and use a fixed type or compute one analytically.
68+
*
69+
* A typical example for differnt input and node types are textures. The input type of a
70+
* normal RGBA texture is `texture` whereas its node type is `vec4`.
71+
*
72+
* @param {NodeBuilder} builder - The current node builder.
73+
* @return {String} The input type.
74+
*/
3575
getInputType( builder ) {
3676

3777
return this.getNodeType( builder );
3878

3979
}
4080

81+
/**
82+
* Sets the precision to the given value. The method can be
83+
* overwritten in derived classes if the final precision must be computed
84+
* analytically.
85+
*
86+
* @param {('low'|'medium'|'high')} precision - The precision of the input value in the shader.
87+
* @return {InputNode} A reference to this node.
88+
*/
4189
setPrecision( precision ) {
4290

4391
this.precision = precision;

src/nodes/core/Node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ class Node extends EventDispatcher {
8080
/**
8181
* Whether this node is global or not. This property is relevant for the internal
8282
* node caching system. All nodes which should be declared just once should
83-
* set this flag to `true` (a typical example is `AttributeNode`).
83+
* set this flag to `true` (a typical example is {@link AttributeNode}).
8484
*
8585
* @type {Boolean}
8686
* @default false
8787
*/
8888
this.global = false;
8989

9090
/**
91-
* This flag can be used for type testing (whether a given object is of type `Node` or not).
91+
* This flag can be used for type testing.
9292
*
9393
* @type {Boolean}
9494
* @readonly

0 commit comments

Comments
 (0)