Class 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

EnumerationsEnumerationsEnumerations
rootNodeNodeNút gốc của đồ thị cảnh. Tất cả hình học, đèn, máy ảnh và các đối tượng khác được gắn dưới nút này.
assetInfoAssetInfoSiêu dữ liệu về tài sản, bao gồm người tạo, thời gian tạo, thông tin đơn vị và hệ tọa độ.
animationClipsAnimationClip[]Bộ sưu tập các clip hoạt hình được định nghĩa trong cảnh. Mỗi clip chứa các đường cong hoạt hình cho các nút và thuộc tính của chúng.
subScenesScene[]Các cảnh phụ được nhúng trong cảnh này. Được sử dụng bởi các định dạng như FBX hỗ trợ cấu trúc cảnh. Lưu ý: Thuộc tính này chưa được xác nhận trong API hiện tại và có thể không khả dụng.

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

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

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ớ.

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

Enumerations

buffer Buffer

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

options LoadOptions (tùy chọn)

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

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)

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.

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

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}`);
 Tiếng Việt