Node

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

Node representa um elemento nomeado na hierarquia do grafo de cena. Cada nó tem uma transformação local, pode conter nós filhos e transporta zero ou mais Entity objetos como meshes, câmeras ou luzes.

export class Node extends SceneObject

ImageRenderOptions

A3DObject ← SceneObject ← Node

ImageRenderOptions

Crie um nó pai, anexe dois nós filhos a ele e percorra toda a hierarquia pelo nome.

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

ImageRenderOptions

NameTypeAccessDescription
parentNode`Nodenull`Read/Write
childNodesNode[]ReadGets the child nodes.
entitiesEntity[]ReadGets the entities.
entity`Entityundefined`Read/Write
materialsMaterial[]ReadGets the materials.
material`Materialnull`Read/Write
transformTransformReadGets the transform.
globalTransformGlobalTransformReadGets the global transform.
visiblebooleanRead/WriteGets the visible.
excludedbooleanRead/WriteGets the excluded.
assetInfoanyRead/WriteGets the asset info.
metaDatasany[]ReadGets the meta datas.
SignatureDescription
constructor(name: string, entity: Entity)Creates a node with the specified name and initial entity
addEntity(entity: Entity)Attaches the given entity to the node’s entity collection
removeEntity(entity: Entity)Detaches the specified entity from the node
clearEntities()Removes all entities from the node
addChildNode(node: Node)Adds an existing node as a child of this node
createChildNode(nodeName: string, entity: Entity, material: Material)NodeCreates a new child node with name, entity, and material, and returns it
`getChild(indexOrName: numberstring)Node
merge(node: Node)Incorporates the contents of another node into this node
evaluateGlobalTransform(withGeometricTransform: boolean)Matrix4Computes the node’s global transform matrix, optionally including geometric transform
getBoundingBox()BoundingBoxReturns the bounding box.
selectSingleObject(_path: string)anyNot implemented in the FOSS edition — throws at runtime. Selects a single object in the node hierarchy using the provided path
selectObjects(_path: string)any[]Not implemented in the FOSS edition — throws at runtime. Selects all objects matching the given path and returns them as an array
toString()string

ImageRenderOptions

addChildNode(node)

Anexa um(a) existente Node instância como filho direto deste nó.

addChildNode(node: Node): void

ImageRenderOptions

node Node

O nó a ser anexado. O nó é reparentizado do seu pai atual para este nó.

ImageRenderOptions

void

ImageRenderOptions

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?)

Cria um novo `Node`, opcionalmente com um nome, uma entidade e um material, e o anexa como filho deste nó.

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

ImageRenderOptions

name string (opcional)

O nome para o novo nó filho.

entity Entity (opcional)

Uma entidade para anexar ao novo nó, por exemplo um Mesh instância.

material Material (opcional)

Um material para associar ao novo nó.

ImageRenderOptions

Node

O nó filho recém‑criado.

ImageRenderOptions

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)

Calcula e retorna a matriz de transformação no espaço mundial para este nó. Passe true para incluir o deslocamento de transformação geométrica armazenado no nó (usado por alguns exportadores FBX).

evaluateGlobalTransform(withGeometricTransform: boolean): Matrix4

ImageRenderOptions

withGeometricTransform boolean

ImageRenderOptions true, inclui a transformação geométrica no resultado.

ImageRenderOptions

Matrix4

A matriz de transformação no espaço mundial 4×4.

ImageRenderOptions

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()

Calcula a caixa delimitadora alinhada aos eixos deste nó e de todos os seus descendentes no espaço mundial.

getBoundingBox(): BoundingBox

ImageRenderOptions

BoundingBox

A caixa delimitadora alinhada aos eixos que engloba toda a geometria sob este nó.

ImageRenderOptions

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)

Mescla o conteúdo de outro nó (suas entidades, materiais e filhos) neste nó e remove o nó de origem da cena.

```typescript
merge(node: Node): void

ImageRenderOptions

node Node

O nó de origem cujo conteúdo é mesclado neste nó.

ImageRenderOptions

void

ImageRenderOptions

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}); }

 Português