Class Scene
แพคเกจ: @aspose/3d (v24.12.0)
Scene คือคอนเทนเนอร์รากสำหรับกราฟฉาก 3D ใน @aspose/3d. มันเก็บลำดับชั้นของโหนด, เมตาดาต้า, และคลิปแอนิเมชัน, และให้ส่วนต่อประสาน I/O หลักสำหรับการโหลดและบันทึกไฟล์ 3D.
export class Scene extends SceneObjectProperties
A3DObject ← SceneObject ← Scene
Properties
โหลดไฟล์ OBJ และพิมพ์จำนวนโหนดลูกในรากของกราฟฉาก.
import { Scene } from '@aspose/3d';
const scene = new Scene();
scene.open('model.obj');
function countNodes(node: any): number {
let total = 1;
for (const child of node.childNodes) {
total += countNodes(child);
}
return total;
}
const nodeCount = countNodes(scene.rootNode);
console.log(`Total nodes in scene: ${nodeCount}`);Properties
| Properties | Properties | Properties |
|---|---|---|
rootNode | Node | โหนดรากของกราฟฉาก. เรขาคณิต, แสง, กล้อง, และวัตถุอื่น ๆ ทั้งหมดจะถูกแนบอยู่ใต้โหนดนี้. |
assetInfo | AssetInfo | เมตาดาต้าเกี่ยวกับแอสเซท, รวมถึงผู้สร้าง, เวลาในการสร้าง, ข้อมูลหน่วย, และระบบพิกัด. |
animationClips | AnimationClip[] | คอลเลกชันของคลิปแอนิเมชันที่กำหนดในฉาก. แต่ละคลิปมีโค้งแอนิเมชันสำหรับโหนดและคุณสมบัติของพวกมัน. |
subScenes | Scene[] | ซับซีนที่ฝังอยู่ภายในฉากนี้. ใช้โดยฟอร์แมตเช่น FBX ที่รองรับลำดับชั้นของฉาก. หมายเหตุ: คุณสมบัตินี้ยังไม่ได้รับการยืนยันใน API ปัจจุบันและอาจไม่พร้อมใช้งาน. |
Properties
open(fileOrStream, options?)
โหลดไฟล์ 3D จากเส้นทางไฟล์หรือ Buffer เข้าไปในฉาก, แทนที่เนื้อหาที่มีอยู่ทั้งหมด.
open(fileOrStream: string | Buffer, options?: LoadOptions): voidProperties
fileOrStream string | Buffer
เส้นทางไปยังไฟล์ต้นฉบับ, หรือ Buffer ที่มีข้อมูลไฟล์ดิบ.
options LoadOptions (ไม่บังคับ)
ตัวเลือกการโหลดตามรูปแบบ. ส่ง undefined เพื่อใช้ค่าเริ่มต้น.
Properties
void
Properties
import { Scene } from '@aspose/3d';
const scene = new Scene();
scene.open('input.fbx');
console.log(`Loaded scene with root node: ${scene.rootNode.name}`);openFromBuffer(buffer, options?)
โหลดไฟล์ 3D จากหน่วยความจำใน‑memory Buffer. นี่คือการ overload ที่แนะนำเมื่อข้อมูลไฟล์ได้ถูกอ่านเข้าหน่วยความจำแล้ว.
openFromBuffer(buffer: Buffer, options?: LoadOptions): voidProperties
buffer Buffer
อ็อบเจกต์ Node.js Buffer ซึ่งบรรจุเนื้อหาไฟล์ทั้งหมด.
options LoadOptions (ไม่บังคับ)
ตัวเลือกการโหลดที่เฉพาะเจาะจงตามรูปแบบ.
Properties
void
Properties
import { Scene } from '@aspose/3d';
import { readFileSync } from 'fs';
const data = readFileSync('model.glb');
const scene = new Scene();
scene.openFromBuffer(data);
console.log(`Animation clips: ${scene.animationClips.length}`);save(fileOrStream, formatOrOptions?, options?)
บันทึกฉากลงในไฟล์ รูปแบบจะถูกสรุปจากนามสกุลไฟล์ หรือคุณสามารถส่งอ็อบเจกต์ที่ระบุรูปแบบเฉพาะ SaveOptions อินสแตนซ์ (หรือ FileFormat singleton) เป็นอาร์กิวเมนต์ที่สอง.
save(fileOrStream: string, formatOrOptions?: FileFormat | SaveOptions, options?: SaveOptions): voidProperties
fileOrStream string
เส้นทางไฟล์ปลายทาง นามสกุลจะกำหนดรูปแบบผลลัพธ์ (เช่น,., .glb → GLB, .gltf → glTF JSON, .stl → STL).
formatOrOptions FileFormat | SaveOptions (ไม่บังคับ)
หรือ singleton ของรูปแบบ (เช่น,., GltfFormat.getInstance()) SaveOptions ซับคลาส.
options SaveOptions (ไม่บังคับ)
ตัวเลือกการบันทึกเฉพาะรูปแบบเมื่อ FileFormat ถูกส่งเป็นอาร์กิวเมนต์ที่สอง.
Properties
void
Properties
import { Scene } from '@aspose/3d';
const scene = new Scene();
scene.open('input.obj');
// Format inferred from extension
scene.save('output.glb');
console.log('Scene saved as GLB.');createAnimationClip(name)
สร้างคลิปแอนิเมชันที่มีชื่อใหม่และเพิ่มเข้าไปใน animationClips คอลเลกชัน.
createAnimationClip(name: string): AnimationClipProperties
name string
ชื่อที่อธิบายลักษณะของคลิปแอนิเมชันใหม่.
Properties
AnimationClip
ที่สร้างใหม่ AnimationClip อินสแตนซ์.
Properties
import { Scene } from '@aspose/3d';
const scene = new Scene();
const clip = scene.createAnimationClip('WalkCycle');
console.log(`Created clip: ${clip.name}`);
console.log(`Total clips: ${scene.animationClips.length}`);