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.fbx');

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.fbx');

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)

FBX output preserves scene hierarchy, mesh data, materials, and animation clips. Use it when the output will be imported into Blender, Maya, or Unreal Engine:

import { Scene } from '@aspose/3d';
import { FbxSaveOptions } from '@aspose/3d/formats/fbx';

const scene = new Scene();
scene.open('input.dae');

const opts = new FbxSaveOptions();
scene.save('output.fbx', 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';

async function convertToGlbBuffer(inputPath: string): Promise<Buffer> {
    const scene = new Scene();
    scene.open(inputPath);

    const opts = new GltfSaveOptions();
    opts.binaryMode = true;

    return scene.saveToBuffer('output.glb', opts);
}

// Express.js / HTTP response example
// const glbBuffer = await convertToGlbBuffer('model.obj');
// res.setHeader('Content-Type', 'model/gltf-binary');
// res.send(glbBuffer);

saveToBuffer() takes the output file name as the first argument (the extension is used for format inference) 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('output.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 FBX (output.fbx) or glTF (output.gltf + output.bin). Blender’s glTF 2.0 importer handles PBR materials; the FBX importer handles animation.

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
GLB.glbPBR (glTF 2.0)YesYesWeb, games, general delivery
glTF.gltfPBR (glTF 2.0)YesNo (+ .bin)Development, inspection
STL.stlNoNoYes3D printing, geometry-only
FBX.fbxPhong/PBRYesYesDCC tools (Maya, Blender, Unreal)
COLLADA.daeYesYesYesCross-DCC exchange
3MF.3mfColor/materialNoYesModern 3D printing

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 bufferExtension argument missing or wrongPass the full filename with extension, e.g. 'output.glb'
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