Scene
Pakotne: @aspose/3d (v24.12.0)
Scene ir saknes konteiners 3D ainas grafam @aspose/3d. Tas satur mezglu hierarhiju, metadatus un animācijas klipus, un nodrošina galveno I/O interfeisu 3D failu ielādēšanai un saglabāšanai.
export class Scene extends SceneObjectColladaSaveOptions
A3DObject ← SceneObject ← Scene
ColladaSaveOptions
Ielādējiet OBJ failu un izdrukājiet bērna mezglu skaitu saknē ainas grafā.
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?)
Ielādē 3D failu no faila ceļa vai Buffer ainas, aizstājot jebkuru esošu saturu.
open(fileOrStream: string | Buffer, options?: LoadOptions): voidColladaSaveOptions
fileOrStream string | Buffer
Ceļš uz avota failu, vai Buffer kas satur neapstrādātos faila datus.
options LoadOptions (pēc izvēles)
Formāta specifiskas ielādes iespējas. Pāriet undefined lai izmantotu noklusējuma vērtības.
ColladaSaveOptions
void
ColladaSaveOptions
const scene = new Scene();
scene.open(‘input.fbx’);
console.log(Loaded scene with root node: ${scene.rootNode.name});
---
### openFromBuffer(buffer, options?)
Ielādē 3D failu no atmiņas `Buffer`. Tas ir vēlamais pārlādētais variants, kad faila dati jau ir nolasīti atmiņā.
```typescript
openFromBuffer(buffer: Buffer, options?: LoadOptions): voidColladaSaveOptions
buffer Buffer
Node.js Buffer kas satur pilnu faila saturu.
Formāta specifiskās ielādes opcijas.
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?)
Saglabā ainu failā. Formāts tiek noteikts no faila paplašinājuma, vai arī varat nodot formāta specifisku SaveOptions instanci (vai FileFormat singleton) kā otro argumentu.
save(fileOrStream: string, formatOrOptions?: FileFormat | SaveOptions, options?: SaveOptions): voidColladaSaveOptions
fileOrStream string
Mērķa faila ceļš. Paplašinājums nosaka izvades formātu (piemēram,., .glb → GLB, .gltf → glTF JSON, .stl → STL).
formatOrOptions FileFormat | SaveOptions (pēc izvēles)
Vai nu formāta vienīgais (piemēram,., GltfFormat.getInstance()) vai formāta specifisks SaveOptions apakšklase.
options SaveOptions (pēc izvēles)
Formāta specifiskās saglabāšanas iespējas, kad a FileFormat tiek nodots kā otrais arguments.
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)
Izveido jaunu nosauktu animācijas klipu un pievieno to scene's `animationClips` kolekcija.
```typescript
createAnimationClip(name: string): AnimationClipColladaSaveOptions
name string
Vector2 un Vector4 — dubultas precizitātes 2‑ un 4‑komponentu vektori, ko izmanto UV koordinātām un homogēnām pozīcijām pakotnē @aspose/3d.
ColladaSaveOptions
AnimationClip
Jaunizveidotais AnimationClip instance.
ColladaSaveOptions
const scene = new Scene();
const clip = scene.createAnimationClip(‘WalkCycle’);
console.log(Created clip: ${clip.name});
console.log(Total clips: ${scene.animationClips.length});