Scene

Pakke: @aspose/3d (v24.12.0)

Scene er rotbeholderen for en 3D-scengraf i @aspose/3d. Den holder nodehierarkiet, metadata og animasjonsklipp, og gir det primære I/O-grensesnittet for lasting og lagring av 3D-filer.

export class Scene extends SceneObject

BoundingBoxExtent

Quaternion representerer en rotasjon som en enhetskvaternion (w, x, y, z) og tilbyr fabrikkmetoder, sfærisk interpolasjon og konvertering til Euler‑vinkler og Matrix4.

BoundingBoxExtent

Quaternion brukes gjennom hele @aspose/3d‑API‑et for å representere rotasjoner uten gimbal‑lås. Det er typen som returneres av Transform.rotation og GlobalTransform.rotation. Identitets‑kvaternionen (1, 0, 0, 0) representerer ingen rotasjon. Quaternion eksporteres fra understien @aspose/3d/utilities.

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}`);

BoundingBoxExtent

NameTypeAccessDescription
VERSION``ReadGets the version.
rootNodeNodeReadGets the root node.
subScenesScene[]ReadGets the sub scenes.
libraryCustomObject[]ReadGets the library.
assetInfoAssetInfoRead/WriteGets the asset info.
animationClipsAnimationClip[]ReadGets the animation clips.
currentAnimationClip`AnimationClipnull`Read/Write
posesany[]ReadGets the poses.
SignatureDescription
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)AnimationClipCreates a new animation clip with the given name
getAnimationClip(name: string) → `AnimationClipnull`
open(fileOrStream: any, options: any)Loads scene data from a file path or stream using options
`openFromBuffer(buffer: BufferUint8Array, options: any)`
save(fileOrStream: any, formatOrOptions: any, options: any)Writes the scene to a file or stream
saveToBuffer(format: string, _options: any)BufferReturns 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)SceneLoads a scene from the specified file and returns the scene
toString()string

BoundingBoxExtent

open(fileOrStream, options?)

Laster en 3D-fil fra en filsti eller en Buffer inn i scenen, og erstatter eventuelt eksisterende innhold.

open(fileOrStream: string | Buffer, options?: LoadOptions): void

BoundingBoxExtent

fileOrStream string | Buffer

Stien til kildefilen, eller en Buffer som inneholder de rå fildataene.

options LoadOptions (valgfritt)

Formatspesifikke lastingsalternativer. Pass undefined for å bruke standardverdier.

BoundingBoxExtent

void

BoundingBoxExtent

const scene = new Scene(); scene.open(‘input.fbx’); console.log(Loaded scene with root node: ${scene.rootNode.name});


---

### openFromBuffer(buffer, options?)

Laster en 3D‑fil fra minnet `Buffer`. Dette er den foretrukne overbelastingen når fildataene allerede er lest inn i minnet.

```typescript
openFromBuffer(buffer: Buffer, options?: LoadOptions): void

BoundingBoxExtent

buffer Buffer

En Node.js Buffer som inneholder hele filinnholdet.

Formatspesifikke lastingsalternativer.

BoundingBoxExtent

void

BoundingBoxExtent

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?)

Lagrer scenen til en fil. Formatet blir utledet fra filendelsen, eller du kan sende inn et formatspesifikt SaveOptions instans (eller en FileFormat singleton) som det andre argumentet.

save(fileOrStream: string, formatOrOptions?: FileFormat | SaveOptions, options?: SaveOptions): void

BoundingBoxExtent

fileOrStream string

Destinasjonsfilens sti. Endelsen bestemmer utdataformatet (f.eks., .glb → GLB, .gltf → glTF JSON, .stl → STL).

formatOrOptions FileFormat | SaveOptions (valgfritt)

Enten en format‑singleton (f.eks., GltfFormat.getInstance()) SaveOptions subklasse.

options SaveOptions (valgfritt)

Formatspesifikke lagringsalternativer når en FileFormat sendes som det andre argumentet.

BoundingBoxExtent

void

BoundingBoxExtent

const scene = new Scene(); scene.open(‘input.obj’);

// Format inferred from extension scene.save(‘output.glb’); console.log(‘Scene saved as GLB.’);


---

### createAnimationClip(name)

Oppretter et nytt navngitt animasjonsklipp og legger det til scenens `animationClips` samling.

```typescript
createAnimationClip(name: string): AnimationClip

BoundingBoxExtent

name string

Returnerer den inverse kvaternionen. Kaster en feil hvis kvaternionen har null lengde.

BoundingBoxExtent

AnimationClip

Den nyopprettede AnimationClip instansen.

BoundingBoxExtent

const scene = new Scene(); const clip = scene.createAnimationClip(‘WalkCycle’); console.log(Created clip: ${clip.name}); console.log(Total clips: ${scene.animationClips.length});

 Norsk