Class Scene

Class Scene

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

Scene 是 3D 场景图的根容器,位于 @aspose/3d. 它保存节点层次结构、元数据和动画剪辑,并提供用于加载和保存 3D 文件的主要 I/O 接口。.

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

PropertiesPropertiesProperties
rootNodeNode场景图的根节点。所有几何体、灯光、相机以及其他对象都附加在此节点下。.
assetInfoAssetInfo关于资产的元数据,包括创建者、创建时间、单位信息和坐标系。.
animationClipsAnimationClip[]场景中定义的动画剪辑集合。每个剪辑包含节点及其属性的动画曲线。.
subScenesScene[]嵌入此场景的子场景。用于支持场景层次结构的格式,如 FBX。. 注意:: 此属性在当前 API 表面未确认,可能不可用。.

Properties

open(fileOrStream, options?)

从文件路径或 Buffer 加载到场景中,替换任何已有内容。.

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

Properties

fileOrStream string | Buffer

源文件的路径,或一个 Buffer 包含原始文件数据。.

options LoadOptions (可选)

特定格式的加载选项。传入 undefined 以使用默认值。.

Properties

void

Properties

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

从内存中加载 3D 文件 Buffer.。这是首选的重载方式,当文件数据已经读取到内存中时。.

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

Properties

buffer Buffer

一个 Node.js Buffer 包含完整文件内容。.

options LoadOptions (可选)

特定格式的加载选项。.

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 单例) 作为第二个参数。.

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

Properties

fileOrStream string

目标文件路径。扩展名决定输出格式(例如,., .glb → GLB, .gltf → glTF JSON,, .stl → STL).

formatOrOptions FileFormat | SaveOptions (可选)

可以是格式单例(例如,., GltfFormat.getInstance()) SaveOptions 子类。.

options SaveOptions (可选)

特定格式的保存选项,当 a FileFormat 作为第二个参数传入时。.

Properties

void

Properties

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)

创建一个新的具名动画剪辑并将其添加到场景的 animationClips 集合中。.

createAnimationClip(name: string): AnimationClip

Properties

name string

新动画剪辑的描述性名称。.

Properties

AnimationClip

新创建的 AnimationClip 实例。.

Properties

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