Scene
Pakiet: @aspose/3d (v24.12.0)
Scene jest głównym kontenerem dla grafu sceny 3D w @aspose/3d. Przechowuje hierarchię węzłów, metadane oraz klipy animacji i zapewnia podstawowy interfejs I/O do ładowania i zapisywania plików 3D.
export class Scene extends SceneObjectImageRenderOptions
A3DObject ← SceneObject ← Scene
ImageRenderOptions
Wczytaj plik OBJ i wypisz liczbę węzłów potomnych w korzeniu grafu sceny.
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}`);ImageRenderOptions
| Name | Type | Access | Description |
|---|---|---|---|
VERSION | `` | Read | Gets the version. |
rootNode | Node | Read | Gets the root node. |
subScenes | Scene[] | Read | Gets the sub scenes. |
library | CustomObject[] | Read | Gets the library. |
assetInfo | AssetInfo | Read/Write | Gets the asset info. |
animationClips | AnimationClip[] | Read | Gets the animation clips. |
currentAnimationClip | `AnimationClip | null` | Read/Write |
poses | any[] | Read | Gets the poses. |
| Signature | Description |
|---|---|
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) → AnimationClip | Creates a new animation clip with the given name |
getAnimationClip(name: string) → `AnimationClip | null` |
open(fileOrStream: any, options: any) | Loads scene data from a file path or stream using options |
| `openFromBuffer(buffer: Buffer | Uint8Array, options: any)` |
save(fileOrStream: any, formatOrOptions: any, options: any) | Writes the scene to a file or stream |
saveToBuffer(format: string, _options: any) → Buffer | Returns 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) → Scene | Loads a scene from the specified file and returns the scene |
toString() → string |
ImageRenderOptions
open(fileOrStream, options?)
Ładuje plik 3D ze ścieżki pliku lub a Buffer do sceny, zastępując istniejącą zawartość.
open(fileOrStream: string | Buffer, options?: LoadOptions): voidImageRenderOptions
fileOrStream string | Buffer
Ścieżka do pliku źródłowego lub a Buffer zawierająca surowe dane pliku.
options LoadOptions (opcjonalnie)
Opcje ładowania specyficzne dla formatu. Przekaż undefined aby użyć wartości domyślnych.
ImageRenderOptions
void
ImageRenderOptions
const scene = new Scene();
scene.open(‘input.fbx’);
console.log(Loaded scene with root node: ${scene.rootNode.name});
---
### openFromBuffer(buffer, options?)
Ładuje plik 3D z pamięci `Buffer`. Jest to preferowane przeciążenie, gdy dane pliku zostały już wczytane do pamięci.
```typescript
openFromBuffer(buffer: Buffer, options?: LoadOptions): voidImageRenderOptions
buffer Buffer
Node.js Buffer zawierający pełną zawartość pliku.
Opcje ładowania specyficzne dla formatu.
ImageRenderOptions
void
ImageRenderOptions
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?)
Zapisuje scenę do pliku. Format jest wywnioskowany z rozszerzenia pliku, lub możesz przekazać specyficzny dla formatu SaveOptions instancję (lub FileFormat singleton) jako drugi argument.
save(fileOrStream: string, formatOrOptions?: FileFormat | SaveOptions, options?: SaveOptions): voidImageRenderOptions
fileOrStream string
Ścieżka docelowego pliku. Rozszerzenie określa format wyjściowy (np., .glb → GLB, .gltf → glTF JSON, .stl → STL).
formatOrOptions FileFormat | SaveOptions (opcjonalnie)
Albo pojedynczy format (np., GltfFormat.getInstance()) lub specyficzny dla formatu SaveOptions podklasa.
options SaveOptions (opcjonalnie)
Opcje zapisu specyficzne dla formatu, gdy FileFormat jest przekazywany jako drugi argument.
ImageRenderOptions
void
ImageRenderOptions
const scene = new Scene(); scene.open(‘input.obj’);
// Format inferred from extension scene.save(‘output.glb’); console.log(‘Scene saved as GLB.’);
---
### createAnimationClip(name)
Tworzy nowy nazwany klip animacji i dodaje go do sceny `animationClips` kolekcji.
```typescript
createAnimationClip(name: string): AnimationClipImageRenderOptions
name string
Opisowa nazwa nowego klipu animacji.
ImageRenderOptions
AnimationClip
Nowo utworzony AnimationClip instancja.
ImageRenderOptions
const scene = new Scene();
const clip = scene.createAnimationClip(‘WalkCycle’);
console.log(Created clip: ${clip.name});
console.log(Total clips: ${scene.animationClips.length});