Node

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

节点表示场景图层次结构中的命名元素。每个节点都有本地变换,能够容纳子节点,并携带零个或多个 Entity 对象,例如网格、相机或灯光。.

export class Node extends SceneObject

Properties

A3DObject ← SceneObject ← Node

Properties

创建一个父节点,向其附加两个子节点,并通过名称遍历完整层次结构。.

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

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

Properties

addChildNode(node)

追加一个已有的 Node 实例作为此节点的直接子节点。.

addChildNode(node: Node): void

Properties

node Node

要附加的节点。该节点会从当前父节点重新归属到此节点。.

Properties

void

Properties

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

创建一个新的 `Node`,,可选地带有名称、实体和材质,并将其追加为此节点的子节点。.

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

Properties

name string (可选)

新子节点的名称。.

entity Entity (可选)

要附加到新节点的实体,例如一个 Mesh 实例。.

material Material (可选)

用于关联新节点的材质。.

Properties

Node

新创建的子节点。.

Properties

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)

计算并返回此节点的世界空间变换矩阵。传递 true 以包含存储在节点上的几何变换偏移(某些 FBX 导出器使用)。.

evaluateGlobalTransform(withGeometricTransform: boolean): Matrix4

Properties

withGeometricTransform boolean

Properties true,,在结果中包含几何变换。.

Properties

Matrix4

4×4 的世界空间变换矩阵。.

Properties

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

计算此节点及其所有子节点在世界空间中的轴对齐包围盒。.

getBoundingBox(): BoundingBox

Properties

BoundingBox

包含此节点下所有几何体的轴对齐包围盒。.

Properties

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)

将另一个节点的内容(其实体、材质和子节点)合并到此节点,并从场景中移除源节点。.

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

Properties

node Node

其内容被合并到此节点的源节点。.

Properties

void

Properties

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

 中文