Scene
Pacchetto: @aspose/3d (v24.12.0)
Scene è il contenitore radice per un grafo di scena 3D in @aspose/3d. Contiene la gerarchia dei nodi, i metadati e le clip di animazione, e fornisce l’interfaccia I/O principale per il caricamento e il salvataggio di file 3D.
export class Scene extends SceneObjectColladaSaveOptions
A3DObject ← SceneObject ← Scene
ColladaSaveOptions
Carica un file OBJ e stampa il numero di nodi figlio nella radice del grafo di scena.
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}`);ColladaSaveOptions
| 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 |
ColladaSaveOptions
open(fileOrStream, options?)
Carica un file 3D da un percorso file o da un Buffer nella scena, sostituendo qualsiasi contenuto esistente.
open(fileOrStream: string | Buffer, options?: LoadOptions): voidColladaSaveOptions
fileOrStream string | Buffer
Il percorso al file sorgente, o un Buffer contenente i dati grezzi del file.
options LoadOptions (opzionale)
Opzioni di caricamento specifiche del formato. Pass undefined per utilizzare i valori predefiniti.
ColladaSaveOptions
void
ColladaSaveOptions
const scene = new Scene();
scene.open(‘input.fbx’);
console.log(Loaded scene with root node: ${scene.rootNode.name});
---
### openFromBuffer(buffer, options?)
Carica un file 3D da una memoria in‑ram `Buffer`. Questo è il sovraccarico preferito quando i dati del file sono già stati letti in memoria.
```typescript
openFromBuffer(buffer: Buffer, options?: LoadOptions): voidColladaSaveOptions
buffer Buffer
Un Node.js Buffer contenente il contenuto completo del file.
Vector2.parse(input) (static).
ColladaSaveOptions
void
ColladaSaveOptions
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?)
Salva la scena in un file. Il formato è dedotto dall’estensione del file, o è possibile passare un format-specific SaveOptions istanza (o un FileFormat singleton) come secondo argomento.
save(fileOrStream: string, formatOrOptions?: FileFormat | SaveOptions, options?: SaveOptions): voidColladaSaveOptions
fileOrStream string
Il percorso del file di destinazione. L’estensione determina il formato di output (ad es., .glb → GLB, .gltf → glTF JSON, .stl → STL).
formatOrOptions FileFormat | SaveOptions (opzionale)
Sia un singleton di formato (ad es., GltfFormat.getInstance()) SaveOptions sottoclasse.
options SaveOptions (opzionale)
Opzioni di salvataggio specifiche del formato quando un FileFormat viene passato come secondo argomento.
ColladaSaveOptions
void
ColladaSaveOptions
const scene = new Scene(); scene.open(‘input.obj’);
// Format inferred from extension scene.save(‘output.glb’); console.log(‘Scene saved as GLB.’);
---
### createAnimationClip(name)
Crea una nuova clip di animazione con nome e la aggiunge alla `animationClips` collezione.
```typescript
createAnimationClip(name: string): AnimationClipColladaSaveOptions
name string
Accesso basato su indice; key deve essere compreso tra 0 e 3.
ColladaSaveOptions
AnimationClip
Il nuovo creato AnimationClip istanza.
ColladaSaveOptions
const scene = new Scene();
const clip = scene.createAnimationClip(‘WalkCycle’);
console.log(Created clip: ${clip.name});
console.log(Total clips: ${scene.animationClips.length});