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)

AttributeExtensionNotes
FileFormat.WAVEFRONT_OBJ().objStatic method returning an ObjFormat instance
FileFormat.GLTF2().gltf / .glbglTF 2.0 and GLB; static method returning a GltfFormat instance. Use GltfSaveOptions with setContentType(FileContentType.BINARY) for GLB output.
FileFormat.FBX7400ASCII().fbxFBX 7.4 ASCII; import only (no export)
FileFormat.STL_BINARY.stlSTL binary (set at class load)
FileFormat.STLASCII.stlSTL 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

MethodReturn TypeDescription
FileFormat.detect(InputStream stream, String fileName)FileFormatDetects the format from a file stream; fileName is used as a hint
FileFormat.getFormatByExtension(String ext)FileFormatReturns the format matching an extension string such as ".obj", ".glb", ".fbx", ".stl"

Instance Properties

NameTypeGetterDescription
extensionStringgetExtension()Primary file extension (without leading dot)
extensionsList<String>getExtensions()All extensions supported by this format
contentTypeStringgetContentType()MIME type string
canExportbooleangetCanExport()Whether exporting to this format is supported
canImportbooleangetCanImport()Whether importing from this format is supported
versionStringgetVersion()Format version string

Instance Methods

MethodReturn TypeDescription
createLoadOptions()LoadOptionsCreates the appropriate format-specific LoadOptions subclass
createSaveOptions()SaveOptionsCreates 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());
    }
}

See Also