Skip to content

Documentation / scene / BaseGraphNode

Abstract Class: BaseGraphNode ​

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

Abstract base class for graph nodes

Remarks ​

Provides common functionality for all graph node types:

  • Input/output slot storage
  • Error state management
  • Basic validation logic
  • Change event emission

Subclasses must implement:

  • getType(): Define output type logic
  • Optionally override validate() for custom validation
  • Optionally override toString() for code generation

Example ​

typescript
class MultiplyNode extends BaseGraphNode {
  constructor() {
    super();
    this._inputs = [
      { id: 0, name: 'a', type: ['float', 'vec2', 'vec3'], required: true },
      { id: 1, name: 'b', type: ['float', 'vec2', 'vec3'], required: true }
    ];
    this._outputs = [
      { id: 0, name: 'result' }
    ];
  }

  protected getType(id?: number): string {
    // Return type based on input types
    return this._inputs[0].inputNode?.getOutputType(0) ?? 'float';
  }

  toString(): string {
    return `${this.getType()} result = a * b;`;
  }
}

Extends ​

  • Observable<{ changed: []; }>

Extended by ​

Implements ​

Constructors ​

Constructor ​

new BaseGraphNode(): BaseGraphNode

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

Creates a new BaseGraphNode instance

Returns ​

BaseGraphNode

Remarks ​

Initializes empty input/output arrays and error state. Subclasses should populate _inputs and _outputs in their constructor.

Overrides ​

Observable<{ changed: [] }>.constructor

Properties ​

_inputs ​

protected _inputs: GraphNodeInput[]

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

Internal storage for input slot definitions


_outputs ​

protected _outputs: GraphNodeOutput[]

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

Internal storage for output slot definitions


_error ​

protected _error: string

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

Internal storage for error message

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

Implementation of ​

IGraphNode.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

Implementation of ​

IGraphNode.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

Implementation of ​

IGraphNode.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

Implementation of ​

IGraphNode.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

Implementation of ​

IGraphNode.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

Implementation of ​

IGraphNode.on

Inherited from ​

Observable.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

Implementation of ​

IGraphNode.once

Inherited from ​

Observable.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

Implementation of ​

IGraphNode.off

Inherited from ​

Observable.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

Implementation of ​

IGraphNode.dispatchEvent

Inherited from ​

Observable.dispatchEvent


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.

Implementation of ​

IGraphNode.getOutputType


toString() ​

toString(): string

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

Generates a string representation of the node

Returns ​

string

Empty string by default

Remarks ​

Subclasses should override this to return valid shader code or a meaningful description of the node's operation.

Implementation of ​

IGraphNode.toString


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.

Implementation of ​

IGraphNode.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.

Implementation of ​

IGraphNode.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);

getType() ​

abstract protected getType(_id?): string

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

Gets the type name for a specific output slot

Parameters ​

_id? ​

number

The output slot ID (optional)

Returns ​

string

The type name (e.g., 'float', 'vec3', 'mat4')

Remarks ​

Must be implemented by subclasses to define type resolution logic. The type may depend on connected input types.

Example ​

typescript
protected getType(_id?: number): string {
  // Return type based on first input
  const inputType = this._inputs[0]?.inputNode?.getOutputType(this._inputs[0].inputId ?? 0);
  return inputType ?? 'float';
}

validate() ​

protected validate(): string

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

Validates the node's current state

Returns ​

string

Error message string, or empty string if valid

Remarks ​

Default implementation checks if all required inputs are connected. Subclasses can override to add custom validation logic like:

  • Type compatibility checking
  • Value range validation
  • Configuration validation

Example ​

typescript
protected validate(): string {
  const baseError = super.validate();
  if (baseError) return baseError;

  // Custom validation
  const type1 = this._inputs[0].inputNode?.getOutputType(0);
  const type2 = this._inputs[1].inputNode?.getOutputType(0);
  if (type1 !== type2) {
    return 'Input types must match';
  }

  return '';
}

Released under the MIT License.