Scene

Gói: @aspose/3d (v24.12.0)

Scene là bộ chứa gốc cho đồ thị cảnh 3D trong @aspose/3d. Nó chứa cấu trúc cây các nút, siêu dữ liệu và các clip hoạt hình, và cung cấp giao diện I/O chính để tải và lưu các tệp 3D.

export class Scene extends SceneObject

Enumerations

A3DObject ← SceneObject ← Scene

Enumerations

Tải một tệp OBJ và in ra số lượng node con trong gốc của đồ thị cảnh.

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}`);

Enumerations

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

Enumerations

open(fileOrStream, options?)

Tải một tệp 3D từ đường dẫn tệp hoặc một Buffer vào cảnh, thay thế bất kỳ nội dung hiện có nào.

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

Enumerations

fileOrStream string | Buffer

Đường dẫn tới tệp nguồn, hoặc một Buffer chứa dữ liệu tệp thô.

options LoadOptions (tùy chọn)

Các tùy chọn tải theo định dạng. Pass undefined để sử dụng mặc định.

Enumerations

void

Enumerations

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


---

### openFromBuffer(buffer, options?)

Tải một tệp 3D từ bộ nhớ trong `Buffer`. Đây là phiên bản ưu tiên khi dữ liệu tệp đã được đọc vào bộ nhớ.

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

Enumerations

buffer Buffer

Một Node.js Buffer chứa toàn bộ nội dung tệp.

Các tùy chọn tải đặc thù cho định dạng.

Enumerations

void

Enumerations

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?)

Lưu cảnh vào một tệp. Định dạng được suy ra từ phần mở rộng tệp, hoặc bạn có thể truyền một định dạng‑cụ thể SaveOptions đối tượng (hoặc một FileFormat đối tượng đơn) làm đối số thứ hai.

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

Enumerations

fileOrStream string

Đường dẫn tệp đích. Phần mở rộng xác định định dạng đầu ra (ví dụ,., .glb → GLB, .gltf → glTF JSON, .stl → STL).

formatOrOptions FileFormat | SaveOptions (tùy chọn)

Hoặc một đối tượng đơn định dạng (ví dụ,., GltfFormat.getInstance()) SaveOptions lớp con.

options SaveOptions (tùy chọn)

Các tùy chọn lưu theo định dạng khi một FileFormat được truyền làm đối số thứ hai.

Enumerations

void

Enumerations

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

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


---

### createAnimationClip(name)

Tạo một đoạn hoạt hình có tên mới và thêm nó vào `animationClips` bộ sưu tập của scene.

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

Enumerations

name string

Một tên mô tả cho clip hoạt hình mới.

Enumerations

AnimationClip

Đối tượng mới được tạo AnimationClip đối tượng.

Enumerations

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

 Tiếng Việt