Scene

Пакет: @aspose/3d (v24.12.0)

Scene є кореневим контейнером для 3D графа сцени у @aspose/3d. Він містить ієрархію вузлів, метадані та кліпи анімації, і забезпечує основний I/O інтерфейс для завантаження та збереження 3D файлів.

export class Scene extends SceneObject

Enumerations

A3DObject ← SceneObject ← Scene

Enumerations

Завантажте файл 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}`);

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

Завантажує 3D‑файл за шляхом до файлу або Buffer у сцену, замінюючи будь‑який існуючий вміст.

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

Enumerations

fileOrStream string | Buffer

Шлях до вихідного файлу або Buffer що містить необроблені дані файлу.

options LoadOptions (необов’язково)

Параметри завантаження, специфічні для формату. Передайте undefined для використання значень за замовчуванням.

Enumerations

void

Enumerations

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


---

### openFromBuffer(buffer, options?)

Завантажує 3D‑файл з пам’яті `Buffer`. Це переважний варіант перевантаження, коли дані файлу вже прочитані в пам’ять.

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

Enumerations

buffer Buffer

Node.js Buffer що містить повний вміст файлу.

Параметри завантаження, специфічні для формату.

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

Зберігає сцену у файл. Формат визначається за розширенням файлу, або ви можете передати формат-специфічний SaveOptions екземпляр (або FileFormat singleton) як другий аргумент.

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

Enumerations

fileOrStream string

Шлях до файлу призначення. Розширення визначає формат виводу (наприклад,)., .glb → GLB, .gltf → glTF JSON, .stl → STL).

formatOrOptions FileFormat | SaveOptions (необов’язково)

Або одиничний формат (наприклад,., GltfFormat.getInstance()) SaveOptions підклас.

options SaveOptions (необов’язково)

Параметри збереження, специфічні для формату, коли FileFormat передається як другий аргумент.

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)

Створює новий іменований кліп анімації та додає його до сцени `animationClips` колекції.

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

Enumerations

name string

Описова назва нового анімаційного кліпу.

Enumerations

AnimationClip

Новостворений AnimationClip екземпляр.

Enumerations

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

 Українська