Class Node
Gói: @aspose/3d (v24.12.0)
Node đại diện cho một phần tử có tên trong cấu trúc đồ thị cảnh. Mỗi node có một biến đổi cục bộ, có thể chứa các node con, và mang theo không hoặc nhiều Entity đối tượng như meshes, cameras hoặc lights.
export class Node extends SceneObjectEnumerations
A3DObject ← SceneObject ← Node
Enumerations
Tạo một node cha, gắn hai node con vào nó, và duyệt toàn bộ cấu trúc theo tê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
| Enumerations | Enumerations | Enumerations |
|---|---|---|
name | string | Tên của node này. Được dùng để xác định node trong đồ thị cảnh. |
parentNode | `Node | null` |
childNodes | Node[] | Mảng các node con trực tiếp được gắn vào node này. |
entities | Entity[] | Danh sách các thực thể (meshes, cameras, lights, v.v.) được gắn vào node này. |
materials | Material[] | Danh sách các vật liệu liên kết với node này. |
transform | Transform | Biến đổi cục bộ của node này, với translation: Vector3, rotation: Quaternion, và scaling: Vector3 các thành phần. |
globalTransform | GlobalTransform | Chỉ đọc. Biến đổi không gian thế giới, được tính bằng cách nhân tất cả các biến đổi của các tổ tiên lên tới node gốc. |
visible | boolean | Cho biết node này và các node con của nó có được render hay không. Mặc định là true. |
excluded | boolean | Enumerations true, nút và cây con của nó sẽ bị loại trừ khỏi việc xuất. Mặc định là false. |
entity | `Entity | undefined` |
Enumerations
addChildNode(node)
Thêm một đối tượng hiện có Node instance làm con trực tiếp của nút này.
addChildNode(node: Node): voidEnumerations
node Node
Node cần gắn. Node sẽ được chuyển cha từ cha hiện tại sang node này.
Enumerations
void
Enumerations
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?)
Tạo một mới Node, tùy chọn với tên, một entity và một material, và thêm nó làm con của nút này.
createChildNode(name?: string, entity?: Entity, material?: Material): NodeEnumerations
name string (tùy chọn)
Tên cho node con mới.
entity Entity (tùy chọn)
Một entity để gắn vào nút mới, ví dụ một Mesh instance.
material Material (tùy chọn)
Một vật liệu để gắn với nút mới.
Enumerations
Node
Nút con mới được tạo.
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)
Tính toán và trả về ma trận biến đổi không gian thế giới cho nút này. Truyền true để bao gồm độ dịch biến đổi hình học được lưu trên nút (được một số bộ xuất FBX sử dụng).
evaluateGlobalTransform(withGeometricTransform: boolean): Matrix4Enumerations
withGeometricTransform boolean
Enumerations true, bao gồm biến đổi hình học trong kết quả.
Enumerations
Matrix4
Ma trận biến đổi không gian thế giới 4×4.
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()
Tính toán hộp bao trục trục của nút này và tất cả các nút con của nó trong không gian thế giới.
getBoundingBox(): BoundingBoxEnumerations
BoundingBox
Hộp bao trục trục bao quanh tất cả hình học dưới nút này.
Enumerations
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)
Hợp nhất nội dung của một nút khác (các thực thể, vật liệu và các nút con của nó) vào nút này và loại bỏ nút nguồn khỏi cảnh.
merge(node: Node): voidEnumerations
node Node
Nút nguồn mà nội dung của nó được hợp nhất vào nút này.
Enumerations
void
Enumerations
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}`);
}