Aspose.3D FOSS for Java supports five 3D file formats: OBJ, STL, glTF, GLB, and FBX (import only). This post is a practical, format-by-format guide showing how to load and save each one, what options are available, and how to convert between them.

All examples use the com.aspose.threed.* package:

import com.aspose.threed.*;

Maven dependency:

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-3d-foss</artifactId>
    <version>26.1.0</version>
</dependency>

Format Landscape

Before diving in, here is a quick overview of the four supported formats and their typical use cases.

FormatExtensionImportExportMaterial SupportScene Hierarchy
OBJ.objYesYesBasic (MTL files)Flat
STL.stlYesYesNoneFlat
glTF 2.0.gltfYesYesPBRFull
GLB.glbYesYesPBRFull
FBX.fbxYesNoRichFull

OBJ, STL, glTF, and GLB support both import and export. FBX is supported for import only. GLB (binary glTF) is produced via GltfSaveOptions with setContentType(FileContentType.BINARY).

OBJ: Wavefront Object

OBJ is one of the most widely supported 3D mesh formats. It stores geometry as plain text, with an optional .mtl companion file for materials.

Loading OBJ Files

The simplest approach is to pass the file path directly:

Scene scene = Scene.fromFile("model.obj");

For more control, use ObjLoadOptions:

ObjLoadOptions opts = new ObjLoadOptions();
Scene scene = Scene.fromFile("model.obj", opts);

When the OBJ file references an MTL file (via a mtllib directive), the library will attempt to load material definitions from it automatically. The MTL file should be in the same directory as the OBJ file or at the path specified in the directive.

Saving as OBJ

Scene scene = Scene.fromFile("input.fbx");
scene.save("output.obj");

OBJ Use Cases

  • Exchanging mesh data between different 3D tools.
  • Importing models from asset libraries that distribute in OBJ format.
  • Quick inspection of geometry without complex scene hierarchies.

STL: Stereolithography

STL is the standard format for 3D printing. It represents raw triangulated geometry without materials, colors, or scene hierarchy. STL files come in two variants: ASCII (human-readable) and binary (compact).

Loading STL Files

// Simple load
Scene scene = Scene.fromFile("part.stl");

// With explicit options
StlLoadOptions opts = new StlLoadOptions();
Scene scene = Scene.fromFile("part.stl", opts);

Saving as STL

Scene scene = Scene.fromFile("model.obj");
scene.save("output.stl");

To control the output, use StlSaveOptions:

StlSaveOptions opts = new StlSaveOptions();
scene.save("output.stl", opts);

STL Considerations

  • STL files contain only triangulated geometry. Materials, textures, and scene hierarchy are lost during export.
  • Binary STL is significantly smaller than ASCII STL for large models.
  • STL is the format of choice when the target is a 3D printer or slicer software.

glTF: GL Transmission Format

glTF is a modern format designed for efficient transmission and loading of 3D content, particularly on the web and in real-time applications. It supports PBR materials, scene hierarchies, and animations.

Loading glTF Files

Scene scene = Scene.fromFile("scene.gltf");

// With options
GltfLoadOptions opts = new GltfLoadOptions();
Scene scene = Scene.fromFile("scene.gltf", opts);

Saving as glTF

The basic save uses the file extension to determine the format:

scene.save("output.gltf");

For detailed control, use GltfSaveOptions:

GltfSaveOptions opts = new GltfSaveOptions();
opts.setFlipCoordinateSystem(true);
opts.setPrettyPrint(true);

scene.save("output.gltf", opts);

GltfSaveOptions Details

MethodPurpose
setFlipCoordinateSystem(boolean)Flip the coordinate system axis during export. Useful when converting from Y-up to Z-up or vice versa.
setPrettyPrint(boolean)Format the output JSON with indentation for readability. Set to false for smaller file size in production.

glTF Use Cases

  • Web-based 3D viewers (three.js, Babylon.js).
  • Real-time applications and game engines.
  • Preserving PBR material definitions across tools.

FBX: Filmbox (Import Only)

FBX is a proprietary format by Autodesk that is widely used in game development and digital content creation. It supports rich scene hierarchies, materials, and animations. Aspose.3D FOSS for Java supports FBX for import only – export to FBX is not available.

Loading FBX Files

Scene scene = Scene.fromFile("character.fbx");

// With options
FbxLoadOptions opts = new FbxLoadOptions();
Scene scene = Scene.fromFile("character.fbx", opts);

Converting FBX to Other Formats

Since FBX export is not supported, convert imported FBX scenes to glTF, GLB, OBJ, or STL:

Scene scene = Scene.fromFile("character.fbx");

// Save as GLB
GltfSaveOptions opts = new GltfSaveOptions();
opts.setContentType(FileContentType.BINARY);
scene.save("character.glb", opts);

FBX Use Cases

  • Importing assets from Autodesk tools (Maya, 3ds Max) and converting to other formats.
  • Loading rigged characters and animated scenes for re-export to glTF/GLB.

Batch Conversion

A common workflow is converting an entire directory of files from one format to another. Here is a pattern for batch conversion:

import com.aspose.threed.*;
import java.io.File;

public class BatchConvert {
    public static void main(String[] args) throws Exception {
        File inputDir = new File("models/obj");
        File outputDir = new File("models/gltf");
        outputDir.mkdirs();

        GltfSaveOptions saveOpts = new GltfSaveOptions();
        saveOpts.setPrettyPrint(true);

        File[] objFiles = inputDir.listFiles(
            (dir, name) -> name.toLowerCase().endsWith(".obj")
        );

        if (objFiles == null) return;

        for (File objFile : objFiles) {
            String baseName = objFile.getName()
                .replaceFirst("\\.obj$", "");

            Scene scene = Scene.fromFile(objFile.getAbsolutePath());
            String outPath = new File(outputDir, baseName + ".gltf")
                .getAbsolutePath();

            scene.save(outPath, saveOpts);
            System.out.println("Converted: " + objFile.getName()
                + " -> " + baseName + ".gltf");
        }
    }
}

This loads every .obj file in a directory, converts each to glTF with pretty-printed output, and saves the results. You can adapt this pattern for any source and target format combination.

Cross-Format Conversion Reference

The following table shows what to expect when converting between formats.

FromToGeometryMaterialsHierarchyNotes
OBJSTLPreservedLostN/ASTL has no material support
OBJglTF/GLBPreservedConverted to PBRFlatMTL materials mapped where possible
STLOBJPreservedNoneN/ANo materials in source
STLglTF/GLBPreservedDefaultFlatDefault material applied
glTFOBJPreservedSimplifiedFlattenedPBR to basic material
glTFSTLPreservedLostFlattenedGeometry only
FBXOBJPreservedSimplifiedFlattenedMaterial simplification
FBXSTLPreservedLostFlattenedGeometry only
FBXglTF/GLBPreservedConverted to PBRPreservedGood fidelity

General Conversion Guidelines

  • Geometry is always preserved across all format pairs.
  • Materials survive best between glTF and FBX, which both support rich material models. Converting to STL always drops materials. Converting to OBJ simplifies materials to the basic MTL model.
  • Scene hierarchy is preserved between glTF and FBX. OBJ and STL produce flat structures.

Putting It All Together

Here is a complete example that loads an OBJ file, inspects its nodes, and exports to both glTF and GLB:

import com.aspose.threed.*;

public class FormatWorkflow {
    public static void main(String[] args) throws Exception {
        // Load
        Scene scene = Scene.fromFile("input.obj");

        // Inspect
        System.out.println("Nodes in scene:");
        for (Node child : scene.getRootNode().getChildNodes()) {
            System.out.println("  " + child.getName());
            Transform t = child.getTransform();
            System.out.println("    Translation: "
                + t.getTranslation());
        }

        // Export to glTF with options
        GltfSaveOptions gltfOpts = new GltfSaveOptions();
        gltfOpts.setPrettyPrint(true);
        scene.save("output.gltf", gltfOpts);

        // Export to GLB (binary glTF)
        GltfSaveOptions glbOpts = new GltfSaveOptions();
        glbOpts.setContentType(FileContentType.BINARY);
        scene.save("output.glb", glbOpts);

        System.out.println("Export complete.");
    }
}

Summary

Aspose.3D FOSS for Java gives you a consistent API across multiple formats. The key points:

  • OBJ – simple mesh interchange with basic materials.
  • STL – geometry-only format for 3D printing pipelines.
  • glTF / GLB – modern PBR-capable format for web and real-time use. Use GltfSaveOptions with setContentType(FileContentType.BINARY) for GLB output.
  • FBX – import only; rich format for loading assets from game engines and DCC tools.

Use format-specific load and save option classes (ObjLoadOptions, StlLoadOptions, StlSaveOptions, GltfLoadOptions, GltfSaveOptions, FbxLoadOptions) when you need fine-grained control over the import or export process.

For more details, visit the Aspose.3D documentation or browse the source on GitHub.