Scene

แพคเกจ: @aspose/3d (v24.12.0)

Scene คือคอนเทนเนอร์รากสำหรับกราฟฉาก 3D ใน @aspose/3d. มันเก็บลำดับชั้นของโหนด, เมตาดาต้า, และคลิปแอนิเมชัน, และให้ส่วนต่อประสาน I/O หลักสำหรับการโหลดและบันทึกไฟล์ 3D.

export class Scene extends SceneObject

Properties

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

NameTypeAccessDescription
VERSION``ReadGets the version.
rootNodeNodeReadGets the root node.
subScenesScene[]ReadGets the sub scenes.
libraryCustomObject[]ReadGets the library.
assetInfoAssetInfoRead/WriteGets the asset info.
animationClipsAnimationClip[]ReadGets the animation clips.
currentAnimationClip`AnimationClipnull`Read/Write
posesany[]ReadGets the poses.
SignatureDescription
constructor()Creates a scene containing the specified entity
constructor(entity: Entity)
constructor(parentScene: Scene, name: string)
constructor()
clear()Removes all nodes, assets and animation data from the scene
createAnimationClip(name: string)AnimationClipCreates a new animation clip with the given name
getAnimationClip(name: string) → `AnimationClipnull`
open(fileOrStream: any, options: any)Loads scene data from a file path or stream using options
`openFromBuffer(buffer: BufferUint8Array, options: any)`
save(fileOrStream: any, formatOrOptions: any, options: any)Writes the scene to a file or stream
saveToBuffer(format: string, _options: any)BufferReturns a Buffer containing the scene in the given format
render(_camera: any, _file_name_or_bitmap: any, _size: any, _format: any, _options: any)Not implemented in the FOSS edition — throws at runtime. Renders the scene with the camera to an image
fromFile(fileName: string)SceneLoads a scene from the specified file and returns the scene
toString()string

Properties

open(fileOrStream, options?)

โหลดไฟล์ 3D จากเส้นทางไฟล์หรือ Buffer เข้าไปในฉาก, แทนที่เนื้อหาที่มีอยู่ทั้งหมด.

open(fileOrStream: string | Buffer, options?: LoadOptions): void

Properties

fileOrStream string | Buffer

เส้นทางไปยังไฟล์ต้นฉบับ, หรือ Buffer ที่มีข้อมูลไฟล์ดิบ.

options LoadOptions (ไม่บังคับ)

ตัวเลือกการโหลดตามรูปแบบ. ส่ง undefined เพื่อใช้ค่าเริ่มต้น.

Properties

void

Properties

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 ที่แนะนำเมื่อข้อมูลไฟล์ได้ถูกอ่านเข้าหน่วยความจำแล้ว.

```typescript
openFromBuffer(buffer: Buffer, options?: LoadOptions): void

Properties

buffer Buffer

อ็อบเจกต์ Node.js Buffer ซึ่งบรรจุเนื้อหาไฟล์ทั้งหมด.

ตัวเลือกการโหลดที่เฉพาะเจาะจงตามรูปแบบ.

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): void

Properties

fileOrStream string

เส้นทางไฟล์ปลายทาง นามสกุลจะกำหนดรูปแบบผลลัพธ์ (เช่น,., .glb → GLB, .gltf → glTF JSON, .stl → STL).

formatOrOptions FileFormat | SaveOptions (ไม่บังคับ)

หรือ singleton ของรูปแบบ (เช่น,., GltfFormat.getInstance()) SaveOptions ซับคลาส.

options SaveOptions (ไม่บังคับ)

ตัวเลือกการบันทึกเฉพาะรูปแบบเมื่อ FileFormat ถูกส่งเป็นอาร์กิวเมนต์ที่สอง.

Properties

void

Properties

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` คอลเลกชัน.

```typescript
createAnimationClip(name: string): AnimationClip

Properties

name string

ชื่อที่อธิบายลักษณะของคลิปแอนิเมชันใหม่.

Properties

AnimationClip

ที่สร้างใหม่ AnimationClip อินสแตนซ์.

Properties

const scene = new Scene(); const clip = scene.createAnimationClip(‘WalkCycle’); console.log(Created clip: ${clip.name}); console.log(Total clips: ${scene.animationClips.length});

 ภาษาไทย