Skip to content

Documentation / scene / GenericMathNode

Abstract Class: GenericMathNode ​

Defined in: libs/scene/src/utility/blueprint/common/math.ts:1025

Abstract base class for generic mathematical function nodes

Remarks ​

Provides a flexible framework for shader math functions that:

  • Accept N arguments of specified types
  • Perform type validation and inference
  • Support both uniform input types and mixed types

Type handling:

  • By default, all inputs must be the same type (float, vec2, vec3, or vec4)
  • explicitInTypes allows specific inputs to accept only certain types
  • additionalInTypes allows specific inputs to accept additional mixed types
  • originTypes specifies type casting requirements

The output type is either:

  • Explicitly specified via outType
  • Inferred from the common input type

Example ​

typescript
// Simple function with uniform types (all float or all vec3, etc.)
class AddNode extends GenericMathNode {
  constructor() {
    super('add', 2); // 2 arguments, output type = input type
  }
}

// Function with explicit output type
class LengthNode extends GenericMathNode {
  constructor() {
    super('length', 1, 'float'); // 1 argument, always outputs float
  }
}

// Function with mixed input types
class MulNode extends GenericMathNode {
  constructor() {
    // Allow scalar multiplication: vec * float or float * vec
    super('mul', 2, null, null, null, { '1': ['float'], '2': ['float'] });
  }
}

Extends ​

Extended by ​

Constructors ​

Constructor ​

new GenericMathNode(func, numArgs, outType?, inTypes?, explicitInTypes?, additionalInTypes?, originTypes?): GenericMathNode

Defined in: libs/scene/src/utility/blueprint/common/math.ts:1049

Creates a new generic math node

Parameters ​

func ​

string

The shader function name

numArgs ​

number

Number of input arguments

outType? ​

string

Explicit output type (null to infer from inputs)

inTypes? ​

string[]

Default allowed input types (defaults to all vector types)

explicitInTypes? ​

Nullable<Record<number, string[]>>

Per-slot type restrictions

additionalInTypes? ​

Nullable<Record<number, string[]>>

Per-slot additional allowed types

originTypes? ​

string[]

Per-slot type casting requirements

Returns ​

GenericMathNode

Remarks ​

Creates input slots named 'a', 'b', 'c', etc. based on numArgs. All inputs are required by default.

Overrides ​

BaseGraphNode.constructor

Properties ​

func ​

readonly func: string

Defined in: libs/scene/src/utility/blueprint/common/math.ts:1027

The shader function name (e.g., 'sin', 'add', 'normalize')


outType ​

readonly outType: string

Defined in: libs/scene/src/utility/blueprint/common/math.ts:1029

The explicit output type, if specified (otherwise inferred from inputs)


explicitInTypes ​

readonly explicitInTypes: Nullable<Record<number, string[]>>

Defined in: libs/scene/src/utility/blueprint/common/math.ts:1031

Maps input slot IDs to allowed types for that specific slot


additionalInTypes ​

readonly additionalInTypes: Nullable<Record<number, string[]>>

Defined in: libs/scene/src/utility/blueprint/common/math.ts:1033

Maps input slot IDs to additional allowed types beyond the common type


_inputs ​

protected _inputs: GraphNodeInput[]

Defined in: libs/scene/src/utility/blueprint/node.ts:336

Internal storage for input slot definitions

Inherited from ​

BaseGraphNode._inputs


_outputs ​

protected _outputs: GraphNodeOutput[]

Defined in: libs/scene/src/utility/blueprint/node.ts:338

Internal storage for output slot definitions

Inherited from ​

BaseGraphNode._outputs


_error ​

protected _error: string

Defined in: libs/scene/src/utility/blueprint/node.ts:340

Internal storage for error message

Inherited from ​

BaseGraphNode._error

Accessors ​

isUniform ​

Get Signature ​

get isUniform(): boolean

Defined in: libs/scene/src/utility/blueprint/node.ts:357

Whether this node contains uniform value/texture

Returns ​

boolean

Whether this node has uniform value

Inherited from ​

BaseGraphNode.isUniform


paramName ​

Get Signature ​

get paramName(): string

Defined in: libs/scene/src/utility/blueprint/node.ts:363

Uniform parameter name

Returns ​

string

Uniform parameter name

Inherited from ​

BaseGraphNode.paramName


inputs ​

Get Signature ​

get inputs(): GraphNodeInput[]

Defined in: libs/scene/src/utility/blueprint/node.ts:380

Gets the input slot definitions array

Returns ​

GraphNodeInput[]

Array of input slot definitions

Inherited from ​

SpriteBlockNode.inputs


outputs ​

Get Signature ​

get outputs(): GraphNodeOutput[]

Defined in: libs/scene/src/utility/blueprint/node.ts:384

Gets the output slot definitions array

Returns ​

GraphNodeOutput[]

Array of output slot definitions

Inherited from ​

BaseGraphNode.outputs


error ​

Get Signature ​

get error(): string

Defined in: libs/scene/src/utility/blueprint/node.ts:388

Gets the current error message

Returns ​

string

Set Signature ​

set error(str): void

Defined in: libs/scene/src/utility/blueprint/node.ts:391

Current error message, empty string if no error

Parameters ​
str ​

string

Returns ​

void

Current error message, empty string if no error

Inherited from ​

BaseGraphNode.error

Methods ​

on() ​

on<K>(type, listener, context?): void

Defined in: libs/base/dist/index.d.ts:630

IEventTarget.on

Type Parameters ​

K ​

K extends "changed"

Parameters ​

type ​

K

listener ​

EventListener<{ changed: []; }, K>

context? ​

unknown

Returns ​

void

Inherited from ​

BaseGraphNode.on


once() ​

once<K>(type, listener, context?): void

Defined in: libs/base/dist/index.d.ts:634

IEventTarget.once

Type Parameters ​

K ​

K extends "changed"

Parameters ​

type ​

K

listener ​

EventListener<{ changed: []; }, K>

context? ​

unknown

Returns ​

void

Inherited from ​

BaseGraphNode.once


off() ​

off<K>(type, listener?, context?): void

Defined in: libs/base/dist/index.d.ts:638

IEventTarget.off

Type Parameters ​

K ​

K extends "changed"

Parameters ​

type ​

K

listener? ​

EventListener<{ changed: []; }>

context? ​

unknown

Returns ​

void

Inherited from ​

BaseGraphNode.off


dispatchEvent() ​

dispatchEvent<K>(type, ...args): void

Defined in: libs/base/dist/index.d.ts:642

IEventTarget.dispatchEvent

Type Parameters ​

K ​

K extends "changed"

Parameters ​

type ​

K

args ​

...object[K]

Returns ​

void

Inherited from ​

BaseGraphNode.dispatchEvent


toString() ​

toString(): string

Defined in: libs/scene/src/utility/blueprint/common/math.ts:1085

Generates a string representation of this node

Returns ​

string

The function name

Overrides ​

BaseGraphNode.toString


validate() ​

protected validate(): string

Defined in: libs/scene/src/utility/blueprint/common/math.ts:1099

Validates the node state and input type compatibility

Returns ​

string

Error message if invalid, empty string if valid

Remarks ​

Ensures all inputs:

  • Have determinable types
  • Have allowed types for their slot
  • Share a common type (unless explicitly or additionally typed)

Overrides ​

BaseGraphNode.validate


getType() ​

protected getType(): string

Defined in: libs/scene/src/utility/blueprint/common/math.ts:1135

Gets the output type based on input types

Returns ​

string

The output type, or empty string if invalid

Remarks ​

Returns the explicit output type if specified, otherwise infers the common type from non-explicit, non-additional inputs.

Overrides ​

BaseGraphNode.getType


getOutputType() ​

getOutputType(id): string

Defined in: libs/scene/src/utility/blueprint/node.ts:376

Gets the output type for a specific output slot

Parameters ​

id ​

number

The output slot ID

Returns ​

string

The type name of the output

Remarks ​

Default implementation delegates to the abstract getType() method. Can be overridden for more complex type logic.

Inherited from ​

BaseGraphNode.getOutputType


check() ​

check(): void

Defined in: libs/scene/src/utility/blueprint/node.ts:413

Validates the node and updates error state

Returns ​

void

Remarks ​

Calls the validate() method and stores the result in _error. Emits a 'changed' event if the error state changes.

Inherited from ​

BaseGraphNode.check


reset() ​

reset(): void

Defined in: libs/scene/src/utility/blueprint/node.ts:422

Clears the error state

Returns ​

void

Remarks ​

Sets _error to an empty string.

Inherited from ​

BaseGraphNode.reset


setInput() ​

setInput(id, node, inputId): void

Defined in: libs/scene/src/utility/blueprint/node.ts:443

Connects an input slot to another node's output

Parameters ​

id ​

number

The input slot ID to connect

node ​

BaseGraphNode

The source node to connect from

inputId ​

number

The output slot ID of the source node

Returns ​

void

Throws ​

Error if the input slot with the given ID doesn't exist

Example ​

typescript
const addNode = new AddNode();
const constantNode = new ConstantNode(5.0);

// Connect constantNode's output 0 to addNode's input 0
addNode.setInput(0, constantNode, 0);

Inherited from ​

BaseGraphNode.setInput

Released under the MIT License.