Scene
Paket: @aspose/3d (v24.12.0)
Scene adalah kontainer akar untuk grafik adegan 3D dalam @aspose/3d. Ia menyimpan hierarki node, metadata, dan klip animasi, serta menyediakan antarmuka I/O utama untuk memuat dan menyimpan file 3D.
export class Scene extends SceneObjectBoundingBoxExtent
A3DObject ← SceneObject ← Scene
BoundingBoxExtent
Muat file OBJ dan cetak jumlah node anak di akar grafik adegan.
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}`);BoundingBoxExtent
| Name | Type | Access | Description |
|---|---|---|---|
VERSION | `` | Read | Gets the version. |
rootNode | Node | Read | Gets the root node. |
subScenes | Scene[] | Read | Gets the sub scenes. |
library | CustomObject[] | Read | Gets the library. |
assetInfo | AssetInfo | Read/Write | Gets the asset info. |
animationClips | AnimationClip[] | Read | Gets the animation clips. |
currentAnimationClip | `AnimationClip | null` | Read/Write |
poses | any[] | Read | Gets the poses. |
| Signature | Description |
|---|---|
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) → AnimationClip | Creates a new animation clip with the given name |
getAnimationClip(name: string) → `AnimationClip | null` |
open(fileOrStream: any, options: any) | Loads scene data from a file path or stream using options |
| `openFromBuffer(buffer: Buffer | Uint8Array, options: any)` |
save(fileOrStream: any, formatOrOptions: any, options: any) | Writes the scene to a file or stream |
saveToBuffer(format: string, _options: any) → Buffer | Returns 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) → Scene | Loads a scene from the specified file and returns the scene |
toString() → string |
BoundingBoxExtent
open(fileOrStream, options?)
Memuat file 3D dari jalur file atau sebuah Buffer ke dalam adegan, menggantikan konten yang ada.
open(fileOrStream: string | Buffer, options?: LoadOptions): voidBoundingBoxExtent
fileOrStream string | Buffer
Jalur ke file sumber, atau sebuah Buffer yang berisi data file mentah.
options LoadOptions (opsional)
Opsi pemuatan khusus format. Lewati undefined untuk menggunakan nilai default.
BoundingBoxExtent
void
BoundingBoxExtent
const scene = new Scene();
scene.open(‘input.fbx’);
console.log(Loaded scene with root node: ${scene.rootNode.name});
---
### openFromBuffer(buffer, options?)
Memuat file 3D dari memori `Buffer`. Ini adalah overload yang disarankan ketika data file sudah dibaca ke memori.
```typescript
openFromBuffer(buffer: Buffer, options?: LoadOptions): voidBoundingBoxExtent
buffer Buffer
Sebuah Node.js Buffer yang berisi konten file lengkap.
Examples.
BoundingBoxExtent
void
BoundingBoxExtent
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?)
Menyimpan adegan ke sebuah file. Formatnya diinferrensi dari ekstensi file, atau Anda dapat memberikan sebuah format-spesifik SaveOptions instance (atau sebuah FileFormat singleton) sebagai argumen kedua.
save(fileOrStream: string, formatOrOptions?: FileFormat | SaveOptions, options?: SaveOptions): voidBoundingBoxExtent
fileOrStream string
Jalur file tujuan. Ekstensi menentukan format output (misalnya,., .glb → GLB, .gltf → glTF JSON, .stl → STL).
formatOrOptions FileFormat | SaveOptions (opsional)
Baik sebuah singleton format (misalnya,., GltfFormat.getInstance()) SaveOptions subkelas.
options SaveOptions (opsional)
Opsi penyimpanan spesifik format ketika sebuah FileFormat dilewatkan sebagai argumen kedua.
BoundingBoxExtent
void
BoundingBoxExtent
const scene = new Scene(); scene.open(‘input.obj’);
// Format inferred from extension scene.save(‘output.glb’); console.log(‘Scene saved as GLB.’);
---
### createAnimationClip(name)
Membuat klip animasi bernama baru dan menambahkannya ke scene `animationClips` koleksi.
```typescript
createAnimationClip(name: string): AnimationClipBoundingBoxExtent
name string
Nama deskriptif untuk klip animasi baru.
BoundingBoxExtent
AnimationClip
Yang baru dibuat AnimationClip instance.
BoundingBoxExtent
const scene = new Scene();
const clip = scene.createAnimationClip(‘WalkCycle’);
console.log(Created clip: ${clip.name});
console.log(Total clips: ${scene.animationClips.length});