Class Node
แพคเกจ: @aspose/3d (v24.12.0)
Node แทนองค์ประกอบที่มีชื่อในโครงสร้างกราฟของฉาก แต่ละ node มีการแปลงเชิงท้องถิ่น สามารถบรรจุ node ลูกได้ และสามารถบรรทุกศูนย์หรือมากกว่า Entity วัตถุเช่น meshes, กล้อง, หรือไฟ.
export class Node extends SceneObjectProperties
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
| Properties | Properties | Properties |
|---|---|---|
name | string | ชื่อของ node นี้ ใช้เพื่อระบุ node ภายในกราฟของฉาก. |
parentNode | `Node | null` |
childNodes | Node[] | อาร์เรย์ของ node ลูกโดยตรงที่แนบกับ node นี้. |
entities | Entity[] | รายการของเอนทิตี้ (meshes, กล้อง, ไฟ ฯลฯ) ที่แนบกับ node นี้. |
materials | Material[] | รายการของวัสดุที่เชื่อมโยงกับ node นี้. |
transform | Transform | การแปลงเชิงท้องถิ่นของ node นี้, พร้อมกับ translation: Vector3, rotation: Quaternion, และ scaling: Vector3 คอมโพเนนต์. |
globalTransform | GlobalTransform | อ่านอย่างเดียว การแปลงในอวกาศโลก, คำนวณโดยการคูณการแปลงของบรรพบุรุษทั้งหมดจนถึงราก. |
visible | boolean | ว่าการเรนเดอร์ node นี้และ subtree ของมันหรือไม่ ค่าเริ่มต้นคือ true. |
excluded | boolean | Properties true, โหนดและส่วนย่อยของมันจะถูกยกเว้นจากการส่งออก ค่าเริ่มต้นคือ false. |
entity | `Entity | undefined` |
Properties
addChildNode(node)
เพิ่มอ็อบเจ็กต์ที่มีอยู่แล้ว Node instance เป็นลูกโดยตรงของโหนดนี้.
addChildNode(node: Node): voidProperties
node Node
โหนดที่ต้องการแนบ โหนดนี้จะถูกเปลี่ยนพาเรนท์จากพาเรนท์ปัจจุบันไปยังโหนดนี้.
Properties
void
Properties
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?)
สร้างใหม่ Node, โดยอาจมีชื่อ, entity, และ material, แล้วผนวกเป็นลูกของโหนดนี้.
createChildNode(name?: string, entity?: Entity, material?: Material): NodeProperties
name string (optional)
ชื่อของโหนดลูกใหม่.
entity Entity (optional)
เอนทิตี้ที่จะผูกกับโหนดใหม่, ตัวอย่างเช่น a Mesh instance.
material Material (optional)
วัสดุที่เชื่อมโยงกับโหนดใหม่.
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): Matrix4Properties
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(): BoundingBoxProperties
BoundingBox
กล่องขอบเขตที่จัดแนวตามแกนซึ่งล้อมรอบเรขาคณิตทั้งหมดภายใต้โหนดนี้.
Properties
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)
รวมเนื้อหาของโหนดอื่น (เอนทิตี, วัสดุ, และโหนดลูก) เข้ากับโหนดนี้และลบโหนดต้นทางออกจากฉาก.
merge(node: Node): voidProperties
node Node
โหนดต้นทางที่เนื้อหาถูกผสานเข้ากับโหนดนี้.
Properties
void
Properties
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}`);
}