Scene

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

Scene es el contenedor raíz para un grafo de escena 3D en @aspose/3d. Contiene la jerarquía de nodos, metadatos y clips de animación, y proporciona la interfaz principal de E/S para cargar y guardar archivos 3D.

export class Scene extends SceneObject

ColladaSaveOptions

A3DObject ← SceneObject ← Scene

ColladaSaveOptions

Cargue un archivo OBJ y muestre el número de nodos hijos en la raíz del grafo de escena.

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

Carga un archivo 3D desde una ruta de archivo o un Buffer en la escena, reemplazando cualquier contenido existente.

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

ColladaSaveOptions

fileOrStream string | Buffer

La ruta al archivo fuente, o un Buffer que contiene los datos brutos del archivo.

options LoadOptions (opcional)

Opciones de carga específicas del formato. Pase undefined para usar los valores predeterminados.

ColladaSaveOptions

void

ColladaSaveOptions

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


---

### openFromBuffer(buffer, options?)

Carga un archivo 3D desde una fuente en memoria `Buffer`. Esta es la sobrecarga preferida cuando los datos del archivo ya se han leído en memoria.

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

ColladaSaveOptions

buffer Buffer

Un Node.js Buffer que contiene el contenido completo del archivo.

Opciones de carga específicas del formato.

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

Guarda la escena en un archivo. El formato se infiere de la extensión del archivo, o puedes pasar un formato específico SaveOptions instancia (o una FileFormat singleton) como segundo argumento.

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

ColladaSaveOptions

fileOrStream string

La ruta del archivo de destino. La extensión determina el formato de salida (p. ej., .glb → GLB, .gltf → glTF JSON, .stl → STL).

formatOrOptions FileFormat | SaveOptions (opcional)

Ya sea un singleton de formato (p. ej., GltfFormat.getInstance()) o un formato específico SaveOptions subclase.

options SaveOptions (opcional)

Opciones de guardado específicas del formato cuando un FileFormat se pasa como segundo argumento.

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)

Crea un nuevo clip de animación con nombre y lo agrega a la escena `animationClips` colección.

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

ColladaSaveOptions

name string

Un nombre descriptivo para el nuevo clip de animación.

ColladaSaveOptions

AnimationClip

El recién creado AnimationClip instancia.

ColladaSaveOptions

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

 Español