Node
Pakket: @aspose/3d (v24.12.0)
Node vertegenwoordigt een benoemd element in de hiërarchie van de scènegrafiek. Elke node heeft een lokale transformatie, kan kindnodes bevatten en draagt nul of meer Entity objecten zoals meshes, camera’s of lichten.
export class Node extends SceneObjectImageRenderOptions
A3DObject ← SceneObject ← Node
ImageRenderOptions
Maak een bovenliggende node, koppel twee kindnodes eraan, en doorloop de volledige hiërarchie op naam.
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
| Name | Type | Access | Description |
|---|---|---|---|
parentNode | `Node | null` | Read/Write |
childNodes | Node[] | Read | Gets the child nodes. |
entities | Entity[] | Read | Gets the entities. |
entity | `Entity | undefined` | Read/Write |
materials | Material[] | Read | Gets the materials. |
material | `Material | null` | Read/Write |
transform | Transform | Read | Gets the transform. |
globalTransform | GlobalTransform | Read | Gets the global transform. |
visible | boolean | Read/Write | Gets the visible. |
excluded | boolean | Read/Write | Gets the excluded. |
assetInfo | any | Read/Write | Gets the asset info. |
metaDatas | any[] | Read | Gets the meta datas. |
| Signature | Description |
|---|---|
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) → Node | Creates a new child node with name, entity, and material, and returns it |
| `getChild(indexOrName: number | string) → Node |
merge(node: Node) | Incorporates the contents of another node into this node |
evaluateGlobalTransform(withGeometricTransform: boolean) → Matrix4 | Computes the node’s global transform matrix, optionally including geometric transform |
getBoundingBox() → BoundingBox | Returns the bounding box. |
selectSingleObject(_path: string) → any | Not 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)
Voegt een bestaande toe Node instance als direct kind van dit knooppunt.
addChildNode(node: Node): voidImageRenderOptions
node Node
De node om toe te voegen. De node wordt van zijn huidige ouder naar deze node verplaatst.
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?)
Maakt een nieuwe `Node`, eventueel met een naam, een entiteit en een materiaal, en voegt het toe als kind van dit knooppunt.
```typescript
createChildNode(name?: string, entity?: Entity, material?: Material): NodeImageRenderOptions
name string (optioneel)
De naam voor de nieuwe kindnode.
entity Entity (optioneel)
Een entiteit om aan het nieuwe knooppunt te koppelen, bijvoorbeeld een Mesh instance.
material Material (optioneel)
Een materiaal om te koppelen aan het nieuwe knooppunt.
ImageRenderOptions
Node
Het nieuw aangemaakte kindknooppunt.
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)
Berekent en retourneert de wereldruimtetransformatie-matrix voor dit knooppunt. Geef true om de geometrische transformatie-offset die op het knooppunt is opgeslagen op te nemen (gebruikt door sommige FBX-exporteurs).
evaluateGlobalTransform(withGeometricTransform: boolean): Matrix4ImageRenderOptions
withGeometricTransform boolean
ImageRenderOptions true, omvat de geometrische transformatie in het resultaat.
ImageRenderOptions
Matrix4
De 4×4 wereldruimtetransformatie‑matrix.
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()
Berekent de asgeoriënteerde begrenzingsdoos van dit knooppunt en al zijn afstammelingen in de wereldruimte.
getBoundingBox(): BoundingBoxImageRenderOptions
BoundingBox
De asgeoriënteerde begrenzingsdoos die alle geometrie onder dit knooppunt omsluit.
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)
Voegt de inhoud van een ander knooppunt (zijn entiteiten, materialen en kinderen) samen met dit knooppunt en verwijdert het bronknooppunt uit de scène.
```typescript
merge(node: Node): voidImageRenderOptions
node Node
De bronknooppunt waarvan de inhoud wordt samengevoegd met dit knooppunt.
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});
}