Scene
Pachet: @aspose/3d (v24.12.0)
Scene este containerul rădăcină pentru un graf de scenă 3D în @aspose/3d. Acesta conține ierarhia nodurilor, metadatele și clipurile de animație și oferă interfața principală I/O pentru încărcarea și salvarea fișierelor 3D.
export class Scene extends SceneObjectImageRenderOptions
A3DObject ← SceneObject ← Scene
ImageRenderOptions
Încarcă un fișier OBJ și afișează numărul de noduri copil din rădăcina grafului de scenă.
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?)
Încarcă un fișier 3D dintr-o cale de fișier sau un Buffer în scenă, înlocuind orice conținut existent.
open(fileOrStream: string | Buffer, options?: LoadOptions): voidImageRenderOptions
fileOrStream string | Buffer
Calea către fișierul sursă, sau un Buffer care conține datele brute ale fișierului.
options LoadOptions (opțional)
Opțiuni de încărcare specifice formatului. Transmite undefined pentru a folosi valorile implicite.
ImageRenderOptions
void
ImageRenderOptions
const scene = new Scene();
scene.open(‘input.fbx’);
console.log(Loaded scene with root node: ${scene.rootNode.name});
---
### openFromBuffer(buffer, options?)
Încarcă un fișier 3D dintr-un în memorie `Buffer`. Aceasta este suprasarcina preferată când datele fișierului au fost deja citite în memorie.
```typescript
openFromBuffer(buffer: Buffer, options?: LoadOptions): voidImageRenderOptions
buffer Buffer
Un Node.js Buffer care conține conținutul complet al fișierului.
Opțiuni de încărcare specifice formatului.
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?)
Salvează scena într-un fișier. Formatul este dedus din extensia fișierului, sau poți furniza un format specific SaveOptions instanță (sau o FileFormat singleton) ca al doilea argument.
save(fileOrStream: string, formatOrOptions?: FileFormat | SaveOptions, options?: SaveOptions): voidImageRenderOptions
fileOrStream string
Calea fișierului de destinație. Extensia determină formatul de ieșire (de ex., .glb → GLB, .gltf → glTF JSON, .stl → STL).
formatOrOptions FileFormat | SaveOptions (opțional)
Fie un singleton de format (de ex., GltfFormat.getInstance()) sau un format-specific SaveOptions subclasă.
options SaveOptions (opțional)
Opțiuni de salvare Format-specific când un FileFormat este transmis ca al doilea 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)
Creează un nou clip de animație denumit și îl adaugă la scenei `animationClips` colecție.
```typescript
createAnimationClip(name: string): AnimationClipImageRenderOptions
name string
Un nume descriptiv pentru noul clip de animație.
ImageRenderOptions
AnimationClip
Nou creat AnimationClip instanță.
ImageRenderOptions
const scene = new Scene();
const clip = scene.createAnimationClip(‘WalkCycle’);
console.log(Created clip: ${clip.name});
console.log(Total clips: ${scene.animationClips.length});