FileFormat — Aspose.3D FOSS for Java
Overview
FileFormat serves as both a format descriptor and a registry of all supported 3D file formats. Each format is represented as a FileFormat instance accessible as a class attribute or via static factory methods. You pass FileFormat instances to Scene.save() to force a specific format, or use FileFormat.detect() to identify an unknown file’s format.
Package: com.aspose.threed
import com.aspose.threed.FileFormat;Supported Format Constants
Format constants that are actively supported (importers and/or exporters registered) in the FOSS release are shown below.
Actively Supported (FOSS release)
| Attribute | Extension | Notes |
|---|---|---|
FileFormat.WAVEFRONT_OBJ() | .obj | Static method returning an ObjFormat instance |
FileFormat.GLTF2() | .gltf / .glb | glTF 2.0 and GLB; static method returning a GltfFormat instance. Use GltfSaveOptions with setContentType(FileContentType.BINARY) for GLB output. |
FileFormat.FBX7400ASCII() | .fbx | FBX 7.4 ASCII; import only (no export) |
FileFormat.STL_BINARY | .stl | STL binary (set at class load) |
FileFormat.STLASCII | .stl | STL ASCII |
Reserved (not yet implemented)
FBX versions 6100-7700 (binary), Maya ASCII/Binary, Discreet 3DS, Universal 3D, GLTF 1.0, GLTF binary, PDF, Blender, DXF, PLY, X (binary/text), Draco, RVM, ASE, IFC, Siemens JT, AMF, VRML, HTML5, ZIP, USD/USDA/USDZ, XYZ, PCD, PCD binary.
Static Methods
| Method | Return Type | Description |
|---|---|---|
FileFormat.detect(InputStream stream, String fileName) | FileFormat | Detects the format from a file stream; fileName is used as a hint |
FileFormat.getFormatByExtension(String ext) | FileFormat | Returns the format matching an extension string such as ".obj", ".glb", ".fbx", ".stl" |
Instance Properties
| Name | Type | Getter | Description |
|---|---|---|---|
extension | String | getExtension() | Primary file extension (without leading dot) |
extensions | List<String> | getExtensions() | All extensions supported by this format |
contentType | String | getContentType() | MIME type string |
canExport | boolean | getCanExport() | Whether exporting to this format is supported |
canImport | boolean | getCanImport() | Whether importing from this format is supported |
version | String | getVersion() | Format version string |
Instance Methods
| Method | Return Type | Description |
|---|---|---|
createLoadOptions() | LoadOptions | Creates the appropriate format-specific LoadOptions subclass |
createSaveOptions() | SaveOptions | Creates the appropriate format-specific SaveOptions subclass |
Example
import com.aspose.threed.Scene;
import com.aspose.threed.FileFormat;
import com.aspose.threed.*;
// Auto-detect and load
Scene scene = Scene.fromFile("model.obj");
// Save with explicit format (force GLB binary)
GltfSaveOptions opts = new GltfSaveOptions();
opts.setContentType(FileContentType.BINARY);
scene.save("output.glb", opts);
// Get format by extension
FileFormat fmt = FileFormat.getFormatByExtension(".fbx");
if (fmt != null) {
System.out.println(fmt.getCanImport()); // true
System.out.println(fmt.getCanExport()); // false (FBX export not available)
}
// Create options from a format instance
FileFormat fmtObj = FileFormat.getFormatByExtension(".obj");
LoadOptions loadOpts = fmtObj.createLoadOptions(); // ObjLoadOptions
SaveOptions saveOpts = fmtObj.createSaveOptions(); // ObjSaveOptions
// Detect format from file stream
try (FileInputStream fis = new FileInputStream("unknown_file.bin")) {
FileFormat detected = FileFormat.detect(fis, "unknown_file.bin");
if (detected != null) {
System.out.println(detected.getClass().getSimpleName());
}
}