Scene
Paket: @aspose/3d (v24.12.0)
Scene je koreni kontejner za 3D graf scene u @aspose/3d. On drži hijerarhiju čvorova, metapodatke i animacione klipove, i pruža primarni I/O interfejs za učitavanje i čuvanje 3D datoteka.
export class Scene extends SceneObjectA3DObject ← SceneObject ← Scene
Učitaj OBJ fajl i prikaži broj podčvorova u korenu grafa scene.
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}`);| 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 |
open(fileOrStream, options?)
Učita 3D fajl sa putanje do fajla ili Buffer u scenu, zamenjujući sav postojeći sadržaj.
open(fileOrStream: string | Buffer, options?: LoadOptions): voidfileOrStream string | Buffer
Putanja do izvornog fajla, ili Buffer koja sadrži sirove podatke fajla.
options LoadOptions (opciono)
Opcije učitavanja specifične za format. Prosledite undefined za korišćenje podrazumevanih vrednosti.
void
const scene = new Scene();
scene.open(‘input.fbx’);
console.log(Loaded scene with root node: ${scene.rootNode.name});
---
### openFromBuffer(buffer, options?)
Učitava 3D fajl iz memorije `Buffer`. Ovo je preferirano preopterećenje kada su podaci fajla već učitani u memoriju.
```typescript
openFromBuffer(buffer: Buffer, options?: LoadOptions): voidbuffer Buffer
Jedan Node.js Buffer sadrži kompletan sadržaj fajla.
Opcije učitavanja specifične za format.
void
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?)
Sačuva scenu u fajl. Format se zaključuje iz ekstenzije fajla, ili možete proslediti format‑specifičan SaveOptions instancu (ili a FileFormat singleton) kao drugi argument.
save(fileOrStream: string, formatOrOptions?: FileFormat | SaveOptions, options?: SaveOptions): voidfileOrStream string
Putanja odredišnog fajla. Ekstenzija određuje izlazni format (npr.,)., .glb → GLB, .gltf → glTF JSON, .stl → STL).
formatOrOptions FileFormat | SaveOptions (opcionalno)
Bilo da je format singleton (npr., GltfFormat.getInstance()) ili specifičan za format SaveOptions podklasu.
options SaveOptions (opcionalno)
Opcije za čuvanje specifične za format kada je FileFormat prosleđen kao drugi argument.
void
const scene = new Scene(); scene.open(‘input.obj’);
// Format inferred from extension scene.save(‘output.glb’); console.log(‘Scene saved as GLB.’);
---
### createAnimationClip(name)
Kreira novi imenovani animacioni klip i dodaje ga u scenu `animationClips` kolekciju.
```typescript
createAnimationClip(name: string): AnimationClipname string
Opisno ime za novi animacioni klip.
AnimationClip
Novo kreirani AnimationClip instancu.
const scene = new Scene();
const clip = scene.createAnimationClip(‘WalkCycle’);
console.log(Created clip: ${clip.name});
console.log(Total clips: ${scene.animationClips.length});