Scene
Csomag: @aspose/3d (v24.12.0)
A Scene a 3D jelenetgráf gyökérkonténere a @aspose/3d. Tartalmazza a csomópont-hierarchiát, a metaadatokat és az animációs klipeket, és biztosítja az elsődleges I/O felületet a 3D fájlok betöltéséhez és mentéséhez.
export class Scene extends SceneObjectColladaSaveOptions
A3DObject ← SceneObject ← Scene
ColladaSaveOptions
Töltsön be egy OBJ fájlt, és írja ki a gyermekcsomópontok számát a jelenetgrafikon gyökerében.
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?)
Betölt egy 3D fájlt egy fájl útvonalról vagy egy Buffer a jelenetbe, felülírva a meglévő tartalmat.
open(fileOrStream: string | Buffer, options?: LoadOptions): voidColladaSaveOptions
fileOrStream string | Buffer
A forrásfájl elérési útja, vagy egy Buffer amely a nyers fájl adatokat tartalmazza.
options LoadOptions (opcionális)
Formátum-specifikus betöltési beállítások. Pass undefined az alapértelmezettek használatához.
ColladaSaveOptions
void
ColladaSaveOptions
const scene = new Scene();
scene.open(‘input.fbx’);
console.log(Loaded scene with root node: ${scene.rootNode.name});
---
### openFromBuffer(buffer, options?)
Betölti a 3D fájlt a memóriában lévőből `Buffer`. Ez a preferált túlterhelés, amikor a fájl adatai már be vannak olvasva a memóriába.
```typescript
openFromBuffer(buffer: Buffer, options?: LoadOptions): voidColladaSaveOptions
buffer Buffer
Egy Node.js Buffer amely a teljes fájl tartalmát tartalmazza.
Formátum-specifikus betöltési beállítások.
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?)
Mentse a jelenetet egy fájlba. A formátum a fájl kiterjesztéséből kerül meghatározásra, vagy megadhat egy formátum-specifikus SaveOptions példányt (vagy egy FileFormat singletont) a második argumentumként.
save(fileOrStream: string, formatOrOptions?: FileFormat | SaveOptions, options?: SaveOptions): voidColladaSaveOptions
fileOrStream string
A célfájl elérési útja. A kiterjesztés határozza meg a kimeneti formátumot (például,., .glb → GLB, .gltf → glTF JSON, .stl → STL).
formatOrOptions FileFormat | SaveOptions (opcionális)
Vagy egy formátum singleton (például,., GltfFormat.getInstance()) SaveOptions al osztály.
options SaveOptions (opcionális)
Formátum-specifikus mentési beállítások, amikor egy FileFormat második argumentumként van átadva.
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)
Létrehoz egy új, névvel ellátott animációs klipet, és hozzáadja a jelenet `animationClips` gyűjteményéhez.
```typescript
createAnimationClip(name: string): AnimationClipColladaSaveOptions
name string
A leíró név az új animációs kliphez.
ColladaSaveOptions
AnimationClip
Az újonnan létrehozott AnimationClip példány.
ColladaSaveOptions
const scene = new Scene();
const clip = scene.createAnimationClip(‘WalkCycle’);
console.log(Created clip: ${clip.name});
console.log(Total clips: ${scene.animationClips.length});