Skip to content

Node: Document more modules. #30000

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

Merged
merged 7 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions src/nodes/core/AssignNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import TempNode from '../core/TempNode.js';
import { addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';
import { vectorComponents } from '../core/constants.js';

/**
* These node represents an assing operation. Meaning a node is assigned
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assing?!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* to anohter node.
*
* @augments TempNode
*/
class AssignNode extends TempNode {

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

}

/**
* Constructs a new assign node.
*
* @param {Node} targetNode - The target node.
* @param {Node} sourceNode - The source type.
*/
constructor( targetNode, sourceNode ) {

super();

/**
* The target node.
*
* @type {Node}
*/
this.targetNode = targetNode;

/**
* The source node.
*
* @type {Node}
*/
this.sourceNode = sourceNode;

}

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

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

}

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

const { targetNode } = this;

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

const targetLength = builder.getTypeLength( targetNode.node.getNodeType( builder ) );
const assignDiferentVector = vectorComponents.join( '' ).slice( 0, targetLength ) !== targetNode.components;
const assignDifferentVector = vectorComponents.join( '' ).slice( 0, targetLength ) !== targetNode.components;

return assignDiferentVector;
return assignDifferentVector;

}

Expand Down
33 changes: 33 additions & 0 deletions src/nodes/core/AttributeNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Node from './Node.js';
import { nodeObject, varying } from '../tsl/TSLBase.js';

/**
* Base class for representing shader attributes as nodes.
*
* @augments Node
*/
class AttributeNode extends Node {

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

}

/**
* Constructs a new attribute node.
*
* @param {String} attributeName - The name of the attribute.
* @param {String?} nodeType - The node type.
*/
constructor( attributeName, nodeType = null ) {

super( nodeType );

/**
* `AttributeNode` sets this property to `true` by default.
*
* @type {Boolean}
* @default true
*/
this.global = true;

this._attributeName = attributeName;
Expand Down Expand Up @@ -51,6 +68,14 @@ class AttributeNode extends Node {

}

/**
* Sets the attribute name to the given value. The method can be
* overwritten in derived classes if the final name must be computed
* analytically.
*
* @param {String} attributeName - The name of the attribute.
* @return {AttributeNode} A reference to this node.
*/
setAttributeName( attributeName ) {

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

}

/**
* Returns the attribute name of this node. The method can be
* overwritten in derived classes if the final name must be computed
* analytically.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {String} The attribute name.
*/
getAttributeName( /*builder*/ ) {

return this._attributeName;
Expand Down
26 changes: 24 additions & 2 deletions src/nodes/core/BypassNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Node from './Node.js';
import { addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';

/**
* TODO: Explain the purpose of this module.
*
* @augments Node
*/
class BypassNode extends Node {

static get type() {
Expand All @@ -9,13 +14,30 @@ class BypassNode extends Node {

}

constructor( returnNode, callNode ) {
/**
* Constructs a new bypass node.
*
* @param {Node} outputNode - The output node.
* @param {Node} callNode - The call node.
*/
constructor( outputNode, callNode ) {

super();

this.isBypassNode = true;

this.outputNode = returnNode;
/**
* The output node.
*
* @type {Node}
*/
this.outputNode = outputNode;

/**
* The call node.
*
* @type {Node}
*/
this.callNode = callNode;

}
Expand Down
32 changes: 32 additions & 0 deletions src/nodes/core/CacheNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import Node from './Node.js';
import { addMethodChaining, nodeObject } from '../tsl/TSLCore.js';

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

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

}

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

super();

/**
* The node that should be cached.
*
* @type {Node}
*/
this.node = node;

/**
* Whether this node refers to a shared parent cache or not.
*
* @type {Boolean}
* @default true
*/
this.parent = parent;

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isCacheNode = true;

}
Expand Down
24 changes: 24 additions & 0 deletions src/nodes/core/ConstNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import InputNode from './InputNode.js';

/**
* Class for representing a constant value in the shader.
*
* @augments InputNode
*/
class ConstNode extends InputNode {

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

}

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

super( value, nodeType );

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isConstNode = true;

}

/**
* Generates the shader string of the value with the current node builder.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {String} The generated value as a shader string.
*/
generateConst( builder ) {

return builder.generateConst( this.getNodeType( builder ), this.value );
Expand Down
48 changes: 48 additions & 0 deletions src/nodes/core/InputNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Node from './Node.js';
import { getValueType, getValueFromType, arrayBufferToBase64 } from './NodeUtils.js';

/**
* Base class for representing data input nodes.
*
* @augments Node
*/
class InputNode extends Node {

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

}

/**
* Constructs a new input node.
*
* @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).
* @param {String?} nodeType - The node type. If no explicit type is defined, the node tries to derive the type from its value.
*/
constructor( value, nodeType = null ) {

super( nodeType );

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isInputNode = true;

/**
* The value of this node. This can be a any JS primitive, functions, array buffers or even three.js objects (vector, matrices, colors).
*
* @type {Any}
*/
this.value = value;

/**
* The precision of the value in the shader.
*
* @type {('low'|'medium'|'high')?}
* @default null
*/
this.precision = null;

}
Expand All @@ -32,12 +62,30 @@ class InputNode extends Node {

}

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

return this.getNodeType( builder );

}

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

this.precision = precision;
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/core/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ class Node extends EventDispatcher {
/**
* Whether this node is global or not. This property is relevant for the internal
* node caching system. All nodes which should be declared just once should
* set this flag to `true` (a typical example is `AttributeNode`).
* set this flag to `true` (a typical example is {@link AttributeNode}).
*
* @type {Boolean}
* @default false
*/
this.global = false;

/**
* This flag can be used for type testing (whether a given object is of type `Node` or not).
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
Expand Down
Loading