Class Node

Package: @aspose/3d (v24.12.0)

Node represents a named element in the scene graph hierarchy. Each node has a local transform, can hold child nodes, and carries zero or more Entity objects such as meshes, cameras, or lights.

export class Node extends SceneObject

Inheritance

A3DObject ← SceneObject ← Node

Examples

Create a parent node, attach two child nodes to it, and traverse the full hierarchy by name.

import { Scene, Node } from '@aspose/3d';

const scene = new Scene();
const root = scene.rootNode;

const vehicle = root.createChildNode('vehicle');
const body = vehicle.createChildNode('body');
const wheel = vehicle.createChildNode('wheel_front_left');

function traverse(node: Node, depth = 0): void {
  console.log(' '.repeat(depth * 2) + node.name);
  for (const child of node.childNodes) {
    traverse(child, depth + 1);
  }
}

traverse(root);
// Output:
//   vehicle
//     body
//     wheel_front_left

Properties

PropertyTypeDescription
namestringThe name of this node. Used to identify the node within the scene graph.
parentNodeNode | nullThe parent node in the hierarchy. null for the root node.
childNodesNode[]An array of direct child nodes attached to this node.
entitiesEntity[]The list of entities (meshes, cameras, lights, etc.) attached to this node.
materialsMaterial[]The list of materials associated with this node.
transformTransformThe local transform of this node, with translation: Vector3, rotation: Quaternion, and scaling: Vector3 components.
globalTransformGlobalTransformRead-only. The world-space transform, computed by multiplying all ancestor transforms up to the root.
visiblebooleanWhether this node and its subtree are rendered. Default is true.
excludedbooleanWhen true, the node and its subtree are excluded from export. Default is false.
entityEntity | undefinedConvenience getter and setter for the first entity in the entities array. Returns undefined if no entities are attached.

Methods

addChildNode(node)

Appends an existing Node instance as a direct child of this node.

addChildNode(node: Node): void

Parameters

node Node

The node to attach. The node is reparented from its current parent to this node.

Returns

void

Examples

import { Scene, Node } from '@aspose/3d';

const scene = new Scene();
const parent = scene.rootNode.createChildNode('parent');
const child = new Node('child');
parent.addChildNode(child);
console.log(`Children of parent: ${parent.childNodes.length}`); // 1

createChildNode(name?, entity?, material?)

Creates a new Node, optionally with a name, an entity, and a material, and appends it as a child of this node.

createChildNode(name?: string, entity?: Entity, material?: Material): Node

Parameters

name string (optional)

The name for the new child node.

entity Entity (optional)

An entity to attach to the new node, for example a Mesh instance.

material Material (optional)

A material to associate with the new node.

Returns

Node

The newly created child node.

Examples

import { Scene } from '@aspose/3d';
import { Mesh } from '@aspose/3d/entities';

const scene = new Scene();
const mesh = new Mesh();
// ... populate mesh ...
const meshNode = scene.rootNode.createChildNode('geometry', mesh);
console.log(`Node name: ${meshNode.name}`);
console.log(`Entities attached: ${meshNode.entities.length}`);

evaluateGlobalTransform(withGeometricTransform)

Computes and returns the world-space transformation matrix for this node. Pass true to include the geometric transform offset stored on the node (used by some FBX exporters).

evaluateGlobalTransform(withGeometricTransform: boolean): Matrix4

Parameters

withGeometricTransform boolean

When true, includes the geometric transform in the result.

Returns

Matrix4

The 4×4 world-space transformation matrix.

Examples

import { Scene } from '@aspose/3d';

const scene = new Scene();
scene.open('model.fbx');
const node = scene.rootNode.childNodes[0];
const matrix = node.evaluateGlobalTransform(false);
console.log('World transform matrix computed.');

getBoundingBox()

Calculates the axis-aligned bounding box of this node and all its descendants in world space.

getBoundingBox(): BoundingBox

Returns

BoundingBox

The axis-aligned bounding box enclosing all geometry under this node.

Examples

import { Scene } from '@aspose/3d';

const scene = new Scene();
scene.open('model.obj');
const bbox = scene.rootNode.getBoundingBox();
console.log(`Min: ${JSON.stringify(bbox.minimum)}`);
console.log(`Max: ${JSON.stringify(bbox.maximum)}`);

merge(node)

Merges the content of another node (its entities, materials, and children) into this node and removes the source node from the scene.

merge(node: Node): void

Parameters

node Node

The source node whose content is merged into this node.

Returns

void

Examples

import { Scene } from '@aspose/3d';

const scene = new Scene();
scene.open('multi_part.fbx');

const root = scene.rootNode;
if (root.childNodes.length >= 2) {
  root.childNodes[0].merge(root.childNodes[1]);
  console.log(`Children after merge: ${root.childNodes.length}`);
}