📄 InputNode.js
¶
📊 Analysis Summary¶
Metric | Count |
---|---|
🔧 Functions | 6 |
🧱 Classes | 1 |
📦 Imports | 4 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 src/nodes/core/InputNode.js
📦 Imports¶
Name | Source |
---|---|
Node |
./Node.js |
getValueType |
./NodeUtils.js |
getValueFromType |
./NodeUtils.js |
arrayBufferToBase64 |
./NodeUtils.js |
Functions¶
InputNode.getNodeType(): string
¶
Returns: string
Calls:
getValueType (from ./NodeUtils.js)
Code
InputNode.getInputType(builder: NodeBuilder): string
¶
JSDoc:
/**
* 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 different 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.
*/
Parameters:
builder
NodeBuilder
Returns: string
Calls:
this.getNodeType
InputNode.setPrecision(precision: "high" | "low" | "medium"): InputNode
¶
JSDoc:
/**
* 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.
*/
Parameters:
precision
"high" | "low" | "medium"
Returns: InputNode
InputNode.serialize(data: any): void
¶
Parameters:
data
any
Returns: void
Calls:
super.serialize
this.value.toArray
getValueType (from ./NodeUtils.js)
arrayBufferToBase64 (from ./NodeUtils.js)
Code
serialize( data ) {
super.serialize( data );
data.value = this.value;
if ( this.value && this.value.toArray ) data.value = this.value.toArray();
data.valueType = getValueType( this.value );
data.nodeType = this.nodeType;
if ( data.valueType === 'ArrayBuffer' ) data.value = arrayBufferToBase64( data.value );
data.precision = this.precision;
}
InputNode.deserialize(data: any): void
¶
Parameters:
data
any
Returns: void
Calls:
super.deserialize
Array.isArray
getValueFromType (from ./NodeUtils.js)
this.value.fromArray
Code
deserialize( data ) {
super.deserialize( data );
this.nodeType = data.nodeType;
this.value = Array.isArray( data.value ) ? getValueFromType( data.valueType, ...data.value ) : data.value;
this.precision = data.precision || null;
if ( this.value && this.value.fromArray ) this.value = this.value.fromArray( data.value );
}
InputNode.generate(): void
¶
Returns: void
Calls:
console.warn
Classes¶
InputNode
¶
Class Code
class InputNode extends Node {
static get type() {
return 'InputNode';
}
/**
* Constructs a new input node.
*
* @param {any} value - The value of this node. This can be 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 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;
}
getNodeType( /*builder*/ ) {
if ( this.nodeType === null ) {
return getValueType( this.value );
}
return this.nodeType;
}
/**
* 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 different 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;
return this;
}
serialize( data ) {
super.serialize( data );
data.value = this.value;
if ( this.value && this.value.toArray ) data.value = this.value.toArray();
data.valueType = getValueType( this.value );
data.nodeType = this.nodeType;
if ( data.valueType === 'ArrayBuffer' ) data.value = arrayBufferToBase64( data.value );
data.precision = this.precision;
}
deserialize( data ) {
super.deserialize( data );
this.nodeType = data.nodeType;
this.value = Array.isArray( data.value ) ? getValueFromType( data.valueType, ...data.value ) : data.value;
this.precision = data.precision || null;
if ( this.value && this.value.fromArray ) this.value = this.value.fromArray( data.value );
}
generate( /*builder, output*/ ) {
console.warn( 'Abstract function.' );
}
}
Methods¶
getNodeType(): string
¶
Code
getInputType(builder: NodeBuilder): string
¶
setPrecision(precision: "high" | "low" | "medium"): InputNode
¶
serialize(data: any): void
¶
Code
serialize( data ) {
super.serialize( data );
data.value = this.value;
if ( this.value && this.value.toArray ) data.value = this.value.toArray();
data.valueType = getValueType( this.value );
data.nodeType = this.nodeType;
if ( data.valueType === 'ArrayBuffer' ) data.value = arrayBufferToBase64( data.value );
data.precision = this.precision;
}
deserialize(data: any): void
¶
Code
deserialize( data ) {
super.deserialize( data );
this.nodeType = data.nodeType;
this.value = Array.isArray( data.value ) ? getValueFromType( data.valueType, ...data.value ) : data.value;
this.precision = data.precision || null;
if ( this.value && this.value.fromArray ) this.value = this.value.fromArray( data.value );
}