Scene

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

Scene est le conteneur racine d’un graphe de scène 3D dans @aspose/3d. Il contient la hiérarchie des nœuds, les métadonnées et les clips d’animation, et fournit l’interface d’E/S principale pour le chargement et l’enregistrement des fichiers 3D.

export class Scene extends SceneObject

ColladaSaveOptions

Renvoie true si le point ou la boîte englobante fourni(e) est entièrement à l’intérieur de cette boîte. Accepte un objet point {x, y, z}, un Vector3, ou un autre BoundingBox.

ColladaSaveOptions

Chargez un fichier OBJ et affichez le nombre de nœuds enfants à la racine du graphe de scène.

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

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

ColladaSaveOptions

open(fileOrStream, options?)

Charge un fichier 3D à partir d’un chemin de fichier ou d’un Buffer dans la scène, en remplaçant tout le contenu existant.

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

ColladaSaveOptions

fileOrStream string | Buffer

Le chemin vers le fichier source, ou un Buffer contenant les données brutes du fichier.

options LoadOptions (optionnel)

Options de chargement spécifiques au format. Passez undefined pour utiliser les valeurs par défaut.

ColladaSaveOptions

void

ColladaSaveOptions

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


---

### openFromBuffer(buffer, options?)

Charge un fichier 3D à partir d'une source en mémoire `Buffer`. C’est la surcharge préférée lorsque les données du fichier ont déjà été lues en mémoire.

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

ColladaSaveOptions

buffer Buffer

Un Node.js Buffer contenant le contenu complet du fichier.

options LoadOptions (facultatif)

Options de chargement spécifiques au format.

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

Enregistre la scène dans un fichier. Le format est déduit de l’extension du fichier, ou vous pouvez passer un format spécifique SaveOptions instance (ou un FileFormat singleton) comme deuxième argument.

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

ColladaSaveOptions

fileOrStream string

Le chemin du fichier de destination. L’extension détermine le format de sortie (par ex., .glb → GLB, .gltf → glTF JSON, .stl → STL).

formatOrOptions FileFormat | SaveOptions (facultatif)

Soit un singleton de format (par ex., GltfFormat.getInstance()) SaveOptions ou un format‑spécifique subclass.

options SaveOptions (facultatif)

Options d’enregistrement spécifiques au format lorsqu’un FileFormat est passé en tant que deuxième argument.

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)

Crée un nouveau clip d’animation nommé et l’ajoute à la scène’s `animationClips` collection.

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

ColladaSaveOptions

name string

Un nom descriptif pour le nouveau clip d’animation.

ColladaSaveOptions

AnimationClip

Le nouvellement créé 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});

 Français