Scene
Paketti: @aspose/3d (v24.12.0)
Scene on 3D-skenegraafin juurikontti @aspose/3d. Se pitää sisällään solmuhierarkian, metadata ja animaatioklipit, ja tarjoaa ensisijaisen I/O-rajapinnan 3D-tiedostojen lataamiseen ja tallentamiseen.
export class Scene extends SceneObjectColladaSaveOptions
A3DObject ← SceneObject ← Scene
ColladaSaveOptions
Lataa OBJ‑tiedosto ja tulosta lapsisolmujen määrä kohtausgraafin juuressa.
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?)
Lataa 3D‑tiedoston tiedostopolusta tai Buffer kohtaan, korvaten kaikki olemassa oleva sisältö.
open(fileOrStream: string | Buffer, options?: LoadOptions): voidColladaSaveOptions
fileOrStream string | Buffer
Polku lähdetiedostoon, tai a Buffer sisältäen raakadatatiedoston.
options LoadOptions (valinnainen)
Formaattiin liittyvät latausasetukset. Ohita undefined käyttääksesi oletusasetuksia.
ColladaSaveOptions
void
ColladaSaveOptions
const scene = new Scene();
scene.open(‘input.fbx’);
console.log(Loaded scene with root node: ${scene.rootNode.name});
---
### openFromBuffer(buffer, options?)
Lataa 3D-tiedoston muistista `Buffer`. Tämä on suositeltu ylikuormitus, kun tiedoston data on jo luettu muistiin.
```typescript
openFromBuffer(buffer: Buffer, options?: LoadOptions): voidColladaSaveOptions
buffer Buffer
Node.js Buffer joka sisältää koko tiedoston sisällön.
Formaattikohtaiset latausasetukset.
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?)
Tallentaa kohtauksen tiedostoon. Tiedostomuoto päätellään tiedostopäätteestä, tai voit antaa formaattiin perustuvan SaveOptions instanssin (tai FileFormat singletonin) toisena argumenttina.
save(fileOrStream: string, formatOrOptions?: FileFormat | SaveOptions, options?: SaveOptions): voidColladaSaveOptions
fileOrStream string
Kohdetiedoston polku. Tiedostopääte määrittää tulostusmuodon (esim., .glb → GLB, .gltf → glTF JSON, .stl → STL).
formatOrOptions FileFormat | SaveOptions (valinnainen)
Joko formaatin yksittäinen instanssi (esim., GltfFormat.getInstance()) tai formaattiin perustuva SaveOptions aliluokka.
options SaveOptions (valinnainen)
Formaattiin perustuvat tallennusasetukset, kun FileFormat annetaan toisena argumenttina.
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)
Luo uuden nimetty animaatioleikkeen ja lisää sen kohtauksen `animationClips` kokoelmaan.
```typescript
createAnimationClip(name: string): AnimationClipColladaSaveOptions
name string
Kuvaava nimi uudelle animaatioklippille.
ColladaSaveOptions
AnimationClip
Uudeksi luotu AnimationClip instanssi.
ColladaSaveOptions
const scene = new Scene();
const clip = scene.createAnimationClip(‘WalkCycle’);
console.log(Created clip: ${clip.name});
console.log(Total clips: ${scene.animationClips.length});