Node
Paket: @aspose/3d (v24.12.0)
Düğüm, sahne grafiği hiyerarşisinde adlandırılmış bir öğeyi temsil eder. Her düğümün yerel dönüşümü vardır, alt düğümler tutabilir ve sıfır veya daha fazla Entity örgüler, kameralar veya ışıklar gibi nesneler.
export class Node extends SceneObjectEnumerations
A3DObject ← SceneObject ← Node
Enumerations
Bir üst düğüm oluşturun, ona iki alt düğüm ekleyin ve tam hiyerarşiyi isimle dolaşın.
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
Enumerations
| 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 |
Enumerations
addChildNode(node)
Mevcut birini ekler. Node instance’ı bu düğümün doğrudan çocuğu olarak ekler.
addChildNode(node: Node): voidEnumerations
node Node
Eklenecek düğüm. Düğüm, mevcut ebeveyninden bu düğüme yeniden ebeveynlenir.
Enumerations
void
Enumerations
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?)
Yeni bir `Node`, isteğe bağlı olarak bir ad, bir entity ve bir material ile ve bunu bu düğümün çocuğu olarak ekler.
```typescript
createChildNode(name?: string, entity?: Entity, material?: Material): NodeEnumerations
name string (optional)
Yeni alt düğüm için ad.
entity Entity (optional)
Yeni düğüme eklenecek bir entity, örneğin bir Mesh instance.
material Material (optional)
Yeni düğümle ilişkilendirilecek bir malzeme.
Enumerations
Node
Yeni oluşturulan alt düğüm.
Enumerations
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)
Bu düğüm için world-space dönüşüm matrisini hesaplar ve döndürür. Pass true geometric transform offset’ini dahil etmek için (bazı FBX dışa aktarıcıları tarafından kullanılır).
evaluateGlobalTransform(withGeometricTransform: boolean): Matrix4Enumerations
withGeometricTransform boolean
Enumerations true, sonuçta geometric transform’u içerir.
Enumerations
Matrix4
4×4 dünya uzayı dönüşüm matrisi.
Enumerations
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()
Bu düğümün ve tüm alt düğümlerinin dünya uzayındaki eksen hizalı sınırlayıcı kutusunu hesaplar.
getBoundingBox(): BoundingBoxEnumerations
BoundingBox
Bu düğüm altındaki tüm geometrileri kapsayan eksen hizalı sınırlayıcı kutu.
Enumerations
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)
Başka bir düğümün içeriğini (varlıklarını, malzemelerini ve alt düğümlerini) bu düğüme birleştirir ve kaynak düğümü sahneden kaldırır.
```typescript
merge(node: Node): voidEnumerations
node Node
İçeriği bu düğüme birleştirilen kaynak düğüm.
Enumerations
void
Enumerations
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});
}