Class Node
Pacchetto: @aspose/3d (v24.12.0)
Un nodo rappresenta un elemento nominato nella gerarchia del grafo della scena. Ogni nodo ha una trasformazione locale, può contenere nodi figli e trasporta zero o più Entity oggetti come mesh, telecamere o luci.
export class Node extends SceneObjectImageRenderOptions
A3DObject ← SceneObject ← Node
ImageRenderOptions
Crea un nodo genitore, collega due nodi figli ad esso e attraversa l’intera gerarchia per 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
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
name | string | Il nome di questo nodo. Usato per identificare il nodo all’interno del grafo della scena. |
parentNode | `Node | null` |
childNodes | Node[] | Un array di nodi figli diretti collegati a questo nodo. |
entities | Entity[] | L’elenco delle entità (mesh, telecamere, luci, ecc.) collegate a questo nodo. |
materials | Material[] | L’elenco dei materiali associati a questo nodo. |
transform | Transform | La trasformazione locale di questo nodo, con translation: Vector3, rotation: Quaternion, e scaling: Vector3 componenti. |
globalTransform | GlobalTransform | Sola lettura. La trasformazione nello spazio mondiale, calcolata moltiplicando tutte le trasformazioni dei genitori fino alla radice. |
visible | boolean | Indica se questo nodo e il suo sottoalbero vengono renderizzati. Il valore predefinito è true. |
excluded | boolean | ImageRenderOptions true, il nodo e il suo sottoalbero sono esclusi dall’esportazione. Il valore predefinito è false. |
entity | `Entity | undefined` |
ImageRenderOptions
addChildNode(node)
Aggiunge un elemento esistente Node istanza come figlio diretto di questo nodo.
addChildNode(node: Node): voidImageRenderOptions
node Node
Il nodo da collegare. Il nodo viene riassegnato dal suo genitore attuale a questo nodo.
ImageRenderOptions
void
ImageRenderOptions
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?)
Crea un nuovo Node, opzionalmente con un nome, un’entità e un materiale, e lo aggiunge come figlio di questo nodo.
createChildNode(name?: string, entity?: Entity, material?: Material): NodeImageRenderOptions
name string (opzionale)
Il nome per il nuovo nodo figlio.
entity Entity (opzionale)
Un’entità da collegare al nuovo nodo, ad esempio un Mesh istanza.
material Material (opzionale)
Un materiale da associare al nuovo nodo.
ImageRenderOptions
Node
Il nodo figlio appena creato.
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)
Calcola e restituisce la matrice di trasformazione nello spazio mondiale per questo nodo. Passa true per includere l’offset di trasformazione geometrica memorizzato sul nodo (usato da alcuni esportatori FBX).
evaluateGlobalTransform(withGeometricTransform: boolean): Matrix4ImageRenderOptions
withGeometricTransform boolean
ImageRenderOptions true, include la trasformazione geometrica nel risultato.
ImageRenderOptions
Matrix4
La matrice di trasformazione nello spazio mondiale 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()
Calcola la bounding box allineata agli assi di questo nodo e di tutti i suoi discendenti nello spazio mondiale.
getBoundingBox(): BoundingBoxImageRenderOptions
BoundingBox
La bounding box allineata agli assi che racchiude tutta la geometria sotto questo nodo.
ImageRenderOptions
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)
Unisce il contenuto di un altro nodo (le sue entità, i materiali e i figli) in questo nodo e rimuove il nodo sorgente dalla scena.
merge(node: Node): voidImageRenderOptions
node Node
Il nodo sorgente il cui contenuto viene unito a questo nodo.
ImageRenderOptions
void
ImageRenderOptions
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}`);
}