How to Convert 3D Models in Java

How to Convert 3D Models in Java

This guide shows how to convert 3D models between OBJ, STL, glTF, and FBX formats in Java using aspose-3d-foss. Format conversion with aspose-3d-foss is a two-step operation: load the source with scene.open(), then save to the target with scene.save().

Step-by-Step Guide

Step 1: Install the Package

Add the following Maven dependency to your pom.xml:

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

Step 2: Load and Convert

Create a Scene, open the source file, and save to the target format:

import com.aspose.threed.Scene;

Scene scene = new Scene();
scene.open("input.fbx");
scene.save("output.glb");

The output format is inferred from the file extension.


Step 3: Use Save Options

Pass format-specific SaveOptions to control the output, for example to export binary GLB:

import com.aspose.threed.GltfSaveOptions;
import com.aspose.threed.FileContentType;

GltfSaveOptions opts = new GltfSaveOptions();
opts.setContentType(FileContentType.BINARY);
scene.save("output.glb", opts);

Note: FBX is read-only in aspose-3d-foss. Saving to .fbx throws ExportException. Export your scene to OBJ, STL, or glTF/GLB instead.


Common Conversion Recipes

SourceTargetNotes
OBJ to GLBBinary glTF for webscene.open("in.obj"); scene.save("out.glb");
FBX to STLTriangulated for 3D printingscene.open("in.fbx"); scene.save("out.stl");
STL to OBJWavefront for modellingscene.open("in.stl"); scene.save("out.obj");

Frequently Asked Questions (FAQ)

Does conversion preserve materials?

Material mapping is best-effort. Not all formats carry the same material properties.

Can I batch-convert files?

Create a new Scene for each file. Each instance is independent.

See Also

 English