Scene
Paket: @aspose/3d (v24.12.0)
Scene är den rotbehållare för ett 3D-scen‑graf i @aspose/3d. Den innehåller nodhierarkin, metadata och animationsklipp, och tillhandahåller det primära I/O‑gränssnittet för att läsa in och spara 3D‑filer.
export class Scene extends SceneObjectImageRenderOptions
A3DObject ← SceneObject ← Scene
ImageRenderOptions
Läs in en OBJ‑fil och skriv ut antalet barnnoder i rotens scengraf.
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?)
Läser in en 3D‑fil från en filsökväg eller en Buffer i scenen, vilket ersätter eventuellt befintligt innehåll.
open(fileOrStream: string | Buffer, options?: LoadOptions): voidImageRenderOptions
fileOrStream string | Buffer
Sökvägen till källfilen, eller en Buffer som innehåller de råa fildata.
options LoadOptions (valfritt)
Format-specifika laddningsalternativ. Pass undefined för att använda standardvärden.
ImageRenderOptions
void
ImageRenderOptions
const scene = new Scene();
scene.open(‘input.fbx’);
console.log(Loaded scene with root node: ${scene.rootNode.name});
---
### openFromBuffer(buffer, options?)
Laddar en 3D-fil från minnet `Buffer`. Detta är den föredragna överlagringen när fildatan redan har lästs in i minnet.
```typescript
openFromBuffer(buffer: Buffer, options?: LoadOptions): voidImageRenderOptions
buffer Buffer
En Node.js Buffer som innehåller hela filinnehållet.
Format-specifika laddningsalternativ.
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?)
Sparar scenen till en fil. Formatet härleds från filändelsen, eller så kan du skicka ett format‑specifikt SaveOptions instans (eller en FileFormat singleton) som det andra argumentet.
save(fileOrStream: string, formatOrOptions?: FileFormat | SaveOptions, options?: SaveOptions): voidImageRenderOptions
fileOrStream string
Destinationsfilens sökväg. Filändelsen bestämmer utdataformatet (t.ex., .glb → GLB, .gltf → glTF JSON, .stl → STL).
formatOrOptions FileFormat | SaveOptions (valfritt)
Antingen en format‑singleton (t.ex., GltfFormat.getInstance()) SaveOptions subklass.
options SaveOptions (valfritt)
Formatspecifika sparalternativ när en FileFormat skickas som det andra argumentet.
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)
Skapar ett nytt namngivet animationsklipp och lägger till det i scenens `animationClips` samling.
```typescript
createAnimationClip(name: string): AnimationClipImageRenderOptions
name string
Ett beskrivande namn för det nya animationsklippet.
ImageRenderOptions
AnimationClip
Det nyss skapade AnimationClip instans.
ImageRenderOptions
const scene = new Scene();
const clip = scene.createAnimationClip(‘WalkCycle’);
console.log(Created clip: ${clip.name});
console.log(Total clips: ${scene.animationClips.length});