FileFormat — Aspose.3D FOSS for Java
Example
FileFormat funge sia da descrittore di formato sia da registro di tutti i formati di file 3D supportati. Ogni formato è rappresentato come un FileFormat istanza accessibile come attributo di classe o tramite metodi factory statici. Si passa FileFormat istanze a Scene.save() per forzare un formato specifico, oppure utilizzare FileFormat.detect() per identificare il formato di un file sconosciuto.
Example: com.aspose.threed
import com.aspose.threed.FileFormat;Costanti di Formato Supportate
Le costanti di formato attivamente supportate (importatori e/o esportatori registrati) nella versione FOSS sono elencate di seguito.
Supportati Attivamente (versione FOSS)
| Example | Example | Example |
|---|---|---|
FileFormat.WAVEFRONT_OBJ() | .obj | Metodo statico che restituisce un ObjFormat istanza |
FileFormat.GLTF2() | .gltf / .glb | glTF 2.0 e GLB; metodo statico che restituisce un GltfFormat istanza. Usa GltfSaveOptions con setContentType(FileContentType.BINARY) per l’output GLB. |
FileFormat.FBX7400ASCII() | .fbx | FBX 7.4 ASCII; solo importazione (nessuna esportazione) |
FileFormat.STL_BINARY | .stl | STL binario (impostato al caricamento della classe) |
FileFormat.STLASCII | .stl | STL ASCII |
Example
Versioni FBX 6100-7700 (binario), Maya ASCII/Binario, Discreet 3DS, Universal 3D, GLTF 1.0, GLTF binario, PDF, Blender, DXF, PLY, X (binario/testo), Draco, RVM, ASE, IFC, Siemens JT, AMF, VRML, HTML5, ZIP, USD/USDA/USDZ, XYZ, PCD, PCD binario.
Metodi statici
| Example | Tipo di ritorno | Example |
|---|---|---|
FileFormat.detect(InputStream stream, String fileName) | FileFormat | Rileva il formato da un flusso di file; fileName è usato come suggerimento |
FileFormat.getFormatByExtension(String ext) | FileFormat | Restituisce il formato corrispondente a una stringa di estensione come ".obj", ".glb", ".fbx", ".stl" |
Proprietà dell’istanza
| Example | Example | Example | Example |
|---|---|---|---|
extension | String | getExtension() | Estensione file principale (senza punto iniziale) |
extensions | List<String> | getExtensions() | Tutte le estensioni supportate da questo formato |
contentType | String | getContentType() | Stringa del tipo MIME |
canExport | boolean | getCanExport() | Se l’esportazione in questo formato è supportata |
canImport | boolean | getCanImport() | Se l’importazione da questo formato è supportata |
version | String | getVersion() | Stringa della versione del formato |
Metodi dell’istanza
| Example | Tipo di ritorno | Example |
|---|---|---|
createLoadOptions() | LoadOptions | Crea il formato specifico appropriato LoadOptions sottoclasse |
createSaveOptions() | SaveOptions | Crea il formato specifico appropriato SaveOptions sottoclasse |
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());
}
}