Scene

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

Scene é o contêiner raiz para um grafo de cena 3D em @aspose/3d. Ele contém a hierarquia de nós, metadados e clipes de animação, e fornece a interface principal de E/S para carregar e salvar arquivos 3D.

export class Scene extends SceneObject

ImageRenderOptions

A3DObject ← SceneObject ← Scene

ImageRenderOptions

Carregue um arquivo OBJ e imprima o número de nós filhos na raiz do grafo de cena.

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

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

ImageRenderOptions

open(fileOrStream, options?)

Carrega um arquivo 3D a partir de um caminho de arquivo ou um Buffer para a cena, substituindo qualquer conteúdo existente.

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

ImageRenderOptions

fileOrStream string | Buffer

O caminho para o arquivo de origem, ou um Buffer contendo os dados brutos do arquivo.

options LoadOptions (opcional)

Opções de carregamento específicas do formato. Passe undefined para usar os padrões.

ImageRenderOptions

void

ImageRenderOptions

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


---

### openFromBuffer(buffer, options?)

Carrega um arquivo 3D a partir de uma memória `Buffer`. Esta é a sobrecarga preferida quando os dados do arquivo já foram lidos para a memória.

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

ImageRenderOptions

buffer Buffer

Um Node.js Buffer contendo o conteúdo completo do arquivo.

Opções de carregamento específicas de formato.

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

Salva a cena em um arquivo. O formato é inferido a partir da extensão do arquivo, ou você pode passar um específico de formato SaveOptions instância (ou um FileFormat singleton) como segundo argumento.

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

ImageRenderOptions

fileOrStream string

O caminho do arquivo de destino. A extensão determina o formato de saída (por exemplo,., .glb → GLB, .gltf → glTF JSON, .stl → STL).

formatOrOptions FileFormat | SaveOptions (opcional)

Um singleton de formato (por exemplo,., GltfFormat.getInstance()) ou um específico de formato SaveOptions subclasse.

options SaveOptions (opcional)

Opções de salvamento específicas de formato quando um FileFormat é passado como o segundo argumento.

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)

Cria um novo clipe de animação nomeado e o adiciona ao `animationClips` coleção.

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

ImageRenderOptions

name string

Um nome descritivo para o novo clipe de animação.

ImageRenderOptions

AnimationClip

O recém-criado AnimationClip instância.

ImageRenderOptions

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

 Português