Scene

Pakej: @aspose/3d (v24.12.0)

Scene adalah kontena akar untuk graf adegan 3D dalam @aspose/3d. Ia menyimpan hierarki nod, metadata, dan klip animasi, serta menyediakan antara muka I/O utama untuk memuatkan dan menyimpan fail 3D.

export class Scene extends SceneObject

ColladaSaveOptions

Rujukan untuk semua kelas pilihan muat naik dan simpan khusus format dalam @aspose/3d, meliputi glTF, OBJ, STL, dan FBX.

ColladaSaveOptions

Muatkan fail OBJ dan cetak bilangan nod anak dalam akar graf 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}`);

ColladaSaveOptions

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

ColladaSaveOptions

open(fileOrStream, options?)

Muatkan fail 3D dari laluan fail atau Buffer ke dalam adegan, menggantikan sebarang kandungan sedia ada.

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

ColladaSaveOptions

fileOrStream string | Buffer

Laluan ke fail sumber, atau Buffer yang mengandungi data fail mentah.

options LoadOptions (pilihan)

Pilihan muat khusus format. Lepas undefined untuk menggunakan nilai lalai.

ColladaSaveOptions

void

ColladaSaveOptions

const scene = new Scene(); scene.open(‘input.fbx’); console.log(Loaded scene with root node: ${scene.rootNode.name});


---

### openFromBuffer(buffer, options?)

Muatkan fail 3D dari memori dalam `Buffer`. Ini adalah overload yang disukai apabila data fail telah dibaca ke dalam memori.

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

ColladaSaveOptions

buffer Buffer

Sebuah Node.js Buffer yang mengandungi keseluruhan kandungan fail.

Pilihan muat khusus format.

ColladaSaveOptions

void

ColladaSaveOptions

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 dalam fail. Format dikesan daripada sambungan fail, atau anda boleh menghantar format khusus SaveOptions instans (atau satu FileFormat singleton) sebagai argumen kedua.

save(fileOrStream: string, formatOrOptions?: FileFormat | SaveOptions, options?: SaveOptions): void

ColladaSaveOptions

fileOrStream string

Laluan fail destinasi. Sambungan menentukan format output (contohnya,., .glb → GLB, .gltf → glTF JSON, .stl → STL).

formatOrOptions FileFormat | SaveOptions (pilihan)

Sama ada satu entiti format (contohnya,., GltfFormat.getInstance()) atau format khusus SaveOptions subkelas.

options SaveOptions (pilihan)

Pilihan simpan khusus format apabila a FileFormat diberikan sebagai argumen kedua.

ColladaSaveOptions

void

ColladaSaveOptions

const scene = new Scene(); scene.open(‘input.obj’);

// Format inferred from extension scene.save(‘output.glb’); console.log(‘Scene saved as GLB.’);


---

### createAnimationClip(name)

Mencipta klip animasi bernama baru dan menambahkannya ke koleksi scene `animationClips` koleksi.

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

ColladaSaveOptions

name string

Nama deskriptif untuk klip animasi baru.

ColladaSaveOptions

AnimationClip

Yang baru dicipta AnimationClip instans.

ColladaSaveOptions

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

 Bahasa Melayu