Scene Rendering and Export
@aspose/3d is a processing and conversion library, and it does not perform GPU rendering or produce image files. “Rendering” in the context of this library means exporting a scene to a format that a downstream renderer, game engine, or viewer can consume.
This page covers all export paths: file-based saving, in-memory buffer output, format-specific options, and how to prepare scenes for common downstream targets (Three.js, Babylon.js, model viewers, and game engines).
Basic Export
Call scene.save() with a file path. The library infers the output format from the file extension:
import { Scene } from '@aspose/3d';
const scene = new Scene();
scene.open('input.obj'); // use a supported format (OBJ, glTF, GLB, STL, 3MF, COLLADA)
scene.save('output.glb'); // GLB (binary glTF)
scene.save('output.stl'); // STL
scene.save('output.dae'); // COLLADA
scene.save('output.3mf'); // 3MF
Exporting to GLB (Recommended for Web and Games)
GLB (binary glTF 2.0) is a single self-contained file that embeds all mesh data, materials, and textures. It is the recommended output format for web viewers (Three.js, Babylon.js, model-viewer) and game engines (Godot, Unity via importer):
import { Scene } from '@aspose/3d';
import { GltfSaveOptions } from '@aspose/3d/formats/gltf';
const scene = new Scene();
scene.open('source.obj');
const opts = new GltfSaveOptions();
opts.binaryMode = true; // produce .glb instead of .gltf + .bin
scene.save('output.glb', opts);
console.log('GLB export complete');Set binaryMode = true to produce a self-contained GLB file. When false, the output is a .gltf JSON file with a separate .bin buffer sidecar.
Exporting to glTF (JSON Format for Inspection)
The JSON variant (.gltf + .bin) is useful during development because the JSON is human-readable:
import { Scene } from '@aspose/3d';
import { GltfSaveOptions } from '@aspose/3d/formats/gltf';
const scene = new Scene();
scene.open('input.dae'); // COLLADA is fully supported; FBX is not wired into scene.open()
const opts = new GltfSaveOptions();
opts.binaryMode = false; // JSON + .bin sidecar
scene.save('output.gltf', opts);Exporting to STL (3D Printing Workflows)
STL is geometry-only (no materials, no animation). It is the standard exchange format for 3D printing slicers:
import { Scene } from '@aspose/3d';
import { StlSaveOptions } from '@aspose/3d/formats/stl';
const scene = new Scene();
scene.open('model.obj');
const opts = new StlSaveOptions();
opts.binaryMode = true; // binary STL is more compact than ASCII
scene.save('output.stl', opts);Set binaryMode = false to produce ASCII STL, which is text-readable but larger.
Exporting to FBX (DCC Tool Workflows)
Note: FBX importer and exporter classes exist in the library, but FBX format auto-detection is not wired into
scene.open()orscene.save(). Callingscene.save('output.fbx', opts)will not invoke the FBX exporter — the.fbxextension is not recognized by the save dispatcher and the call will fall back to OBJ output. Use theFbxExporterclass directly if you need FBX I/O. The format support table marks FBX asNo*for this reason.
If you need to export to a format accepted by Blender, Maya, or Unreal Engine, use GLB or COLLADA instead — both are fully wired into scene.save():
import { Scene } from '@aspose/3d';
import { GltfSaveOptions } from '@aspose/3d/formats/gltf';
const scene = new Scene();
scene.open('input.dae');
// GLB is fully supported and widely accepted by DCC tools
const opts = new GltfSaveOptions();
opts.binaryMode = true;
scene.save('output.glb', opts);In-Memory Export with saveToBuffer()
For serverless functions, HTTP responses, and streaming pipelines, export directly to a Buffer without writing to disk:
import { Scene } from '@aspose/3d';
import { GltfSaveOptions } from '@aspose/3d/formats/gltf';
function convertToGlbBuffer(inputPath: string): Buffer {
const scene = new Scene();
scene.open(inputPath);
const opts = new GltfSaveOptions();
opts.binaryMode = true;
return scene.saveToBuffer('glb', opts);
}
// Express.js / HTTP response example
// const glbBuffer = convertToGlbBuffer('model.obj');
// res.setHeader('Content-Type', 'model/gltf-binary');
// res.send(glbBuffer);
saveToBuffer() takes a format string as the first argument (e.g. 'glb', 'stl', 'obj') and the same options objects as save().
Combining openFromBuffer() and saveToBuffer()
A fully in-memory conversion pipeline with no disk I/O at any stage:
import { Scene } from '@aspose/3d';
import { ObjLoadOptions } from '@aspose/3d/formats/obj';
import { GltfSaveOptions } from '@aspose/3d/formats/gltf';
function objBufferToGlbBuffer(objData: Buffer): Buffer {
const scene = new Scene();
const loadOpts = new ObjLoadOptions();
loadOpts.enableMaterials = true;
scene.openFromBuffer(objData, loadOpts);
const saveOpts = new GltfSaveOptions();
saveOpts.binaryMode = true;
return scene.saveToBuffer('glb', saveOpts);
}Preparing Scenes for Specific Renderers
Three.js / Babylon.js (Web)
These renderers natively load GLB files. Export with binaryMode = true. If textures are referenced from the source OBJ, ensure the .mtl and image files are co-located when loading.
model-viewer (Web Component)
Accepts .glb directly. Same export settings as Three.js.
Godot Engine
Import GLB via Godot’s importer (Project → Import). Use binaryMode = true. Godot supports PBR materials from glTF 2.0 natively.
Blender
For the best import fidelity use glTF (output.gltf + output.bin) or GLB (output.glb). Blender’s glTF 2.0 importer handles PBR materials and animation. Note: FBX output via scene.save() is not supported — FBX format auto-detection is not wired into the save dispatcher.
3D Printing (Slicers: Cura, PrusaSlicer, Bambu Studio)
Export to STL or 3MF. Use 3MF when you need color or material metadata preserved. Use STL for maximum compatibility.
Export Format Comparison
| Format | Extension | Materials | Animation | Single File | Best For |
|---|---|---|---|---|---|
| glTF | .glb / .gltf | PBR (glTF 2.0) | Yes | GLB: yes; glTF: no | Web, games, general delivery |
| STL | .stl | No | No | Yes | 3D printing, geometry-only |
| FBX | .fbx | Phong/PBR | No* | No* | Importer/exporter exist but not wired into auto-detection |
| COLLADA | .dae | Yes | Yes | Yes | Cross-DCC exchange |
| 3MF | .3mf | Color/material | No | Yes | Modern 3D printing |
Choose glTF (GLB) for web delivery, 3MF for print workflows requiring color metadata, and STL for maximum geometry compatibility with older tools.
Common Export Issues
| Symptom | Cause | Fix |
|---|---|---|
| Output GLB opens as JSON in viewer | binaryMode left as false | Set opts.binaryMode = true |
| Textures missing in output GLB | binaryMode not set | Set opts.binaryMode = true for self-contained GLB |
| STL file has no color in slicer | STL format does not support color | Use 3MF for color data |
saveToBuffer returns empty buffer | Format string argument missing or wrong | Pass the format string, e.g. 'glb', 'stl', or 'obj' |
| FBX opens without animation in Blender | Source file (OBJ/STL) has no animation | Animation only carries through if present in the source |
| Output file is very large | Source OBJ has many duplicate vertices | GLB binary output already deduplicates; check source asset quality |
See Also
- Model Loading: loading 3D files from disk and buffers
- Scene Graph: building and modifying the scene before export
- Format Support: complete read/write matrix
- API Overview: all classes and enumerations