FileFormat — Aspose.3D FOSS for Java
Example
FileFormat slouží jako popis formátu i registr všech podporovaných 3D souborových formátů. Každý formát je reprezentován jako FileFormat instance přístupná jako atribut třídy nebo prostřednictvím statických továrních metod. Předáte FileFormat instance do Scene.save() k vynucení konkrétního formátu, nebo použijte FileFormat.detect() k identifikaci formátu neznámého souboru.
Example: com.aspose.threed
import com.aspose.threed.FileFormat;Podporované konstanty formátů
Níže jsou uvedeny konstanty formátů, které jsou v FOSS vydání aktivně podporovány (registrované importéry a/nebo exportéry).
Aktivně podporováno (FOSS vydání)
| Example | Example | Example |
|---|---|---|
FileFormat.WAVEFRONT_OBJ() | .obj | Statická metoda vracející ObjFormat instanci |
FileFormat.GLTF2() | .gltf / .glb | glTF 2.0 a GLB; statická metoda vracející GltfFormat instance. Použijte GltfSaveOptions s setContentType(FileContentType.BINARY) pro výstup GLB. |
FileFormat.FBX7400ASCII() | .fbx | FBX 7.4 ASCII; pouze import (žádný export) |
FileFormat.STL_BINARY | .stl | STL binární (nastaveno při načtení třídy) |
FileFormat.STLASCII | .stl | STL ASCII |
Example
verze FBX 6100-7700 (binární), Maya ASCII/Binární, Discreet 3DS, Universal 3D, GLTF 1.0, GLTF binární, PDF, Blender, DXF, PLY, X (binární/text), Draco, RVM, ASE, IFC, Siemens JT, AMF, VRML, HTML5, ZIP, USD/USDA/USDZ, XYZ, PCD, PCD binární.
Statické metody
| Example | Návratový typ | Example |
|---|---|---|
FileFormat.detect(InputStream stream, String fileName) | FileFormat | Detekuje formát ze souborového proudu; fileName se používá jako nápověda |
FileFormat.getFormatByExtension(String ext) | FileFormat | Vrací formát odpovídající řetězci přípony, například ".obj", ".glb", ".fbx", ".stl" |
Vlastnosti instance
| Example | Example | Example | Example |
|---|---|---|---|
extension | String | getExtension() | Primární přípona souboru (bez úvodní tečky) |
extensions | List<String> | getExtensions() | Všechny přípony podporované tímto formátem |
contentType | String | getContentType() | Řetězec typu MIME |
canExport | boolean | getCanExport() | Zda je export do tohoto formátu podporován |
canImport | boolean | getCanImport() | Zda je import z tohoto formátu podporován |
version | String | getVersion() | Řetězec verze formátu |
Metody instance
| Example | Návratový typ | Example |
|---|---|---|
createLoadOptions() | LoadOptions | Vytvoří odpovídající formátově specifický LoadOptions podtřídu |
createSaveOptions() | SaveOptions | Vytvoří odpovídající formátově specifický SaveOptions podtřídu |
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());
}
}