Scene Rendering and Export

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() or scene.save(). Calling scene.save('output.fbx', opts) will not invoke the FBX exporter — the .fbx extension is not recognized by the save dispatcher and the call will fall back to OBJ output. Use the FbxExporter class directly if you need FBX I/O. The format support table marks FBX as No* 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

FormatExtensionMaterialsAnimationSingle FileBest For
glTF.glb / .gltfPBR (glTF 2.0)YesGLB: yes; glTF: noWeb, games, general delivery
STL.stlNoNoYes3D printing, geometry-only
FBX.fbxPhong/PBRNo*No*Importer/exporter exist but not wired into auto-detection
COLLADA.daeYesYesYesCross-DCC exchange
3MF.3mfColor/materialNoYesModern 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

SymptomCauseFix
Output GLB opens as JSON in viewerbinaryMode left as falseSet opts.binaryMode = true
Textures missing in output GLBbinaryMode not setSet opts.binaryMode = true for self-contained GLB
STL file has no color in slicerSTL format does not support colorUse 3MF for color data
saveToBuffer returns empty bufferFormat string argument missing or wrongPass the format string, e.g. 'glb', 'stl', or 'obj'
FBX opens without animation in BlenderSource file (OBJ/STL) has no animationAnimation only carries through if present in the source
Output file is very largeSource OBJ has many duplicate verticesGLB binary output already deduplicates; check source asset quality

See Also

 English