FileFormat — Aspose.3D FOSS for Java
Example
FileFormat slúži ako opis formátu aj ako register všetkých podporovaných 3D formátov súborov. Každý formát je reprezentovaný ako a FileFormat inštancia prístupná ako atribút triedy alebo prostredníctvom statických továrenských metód. Predáte FileFormat inštancie do Scene.save() na vynútenie konkrétneho formátu, alebo použite FileFormat.detect() na identifikáciu formátu neznámeho súboru.
Example: com.aspose.threed
import com.aspose.threed.FileFormat;Podporované konštanty formátov
Konštanty formátov, ktoré sú aktívne podporované (importéry a/alebo exportéry zaregistrované) vo vydaní FOSS, sú uvedené nižšie.
Aktívne podporované (vydanie FOSS)
| Example | Example | Example |
|---|---|---|
FileFormat.WAVEFRONT_OBJ() | .obj | Statická metóda vracajúca ObjFormat inštanciu |
FileFormat.GLTF2() | .gltf / .glb | glTF 2.0 a GLB; statická metóda vracajúca a GltfFormat inštancia. Použiť GltfSaveOptions s setContentType(FileContentType.BINARY) pre výstup GLB. |
FileFormat.FBX7400ASCII() | .fbx | FBX 7.4 ASCII; iba import (žiadny export) |
FileFormat.STL_BINARY | .stl | STL binárny (nastavené pri načítaní triedy) |
FileFormat.STLASCII | .stl | STL ASCII |
Example
FBX verzie 6100-7700 (binárne), Maya ASCII/Binárny, Discreet 3DS, Universal 3D, GLTF 1.0, GLTF binárny, PDF, Blender, DXF, PLY, X (binárny/text), Draco, RVM, ASE, IFC, Siemens JT, AMF, VRML, HTML5, ZIP, USD/USDA/USDZ, XYZ, PCD, PCD binárny.
Statické metódy
| Example | Návratový typ | Example |
|---|---|---|
FileFormat.detect(InputStream stream, String fileName) | FileFormat | Zistí formát zo súborového prúdu; fileName sa používa ako nápoveda |
FileFormat.getFormatByExtension(String ext) | FileFormat | Vráti formát zodpovedajúci reťazcu prípony, napríklad ".obj", ".glb", ".fbx", ".stl" |
Vlastnosti inštancie
| Example | Example | Example | Example |
|---|---|---|---|
extension | String | getExtension() | Primárna prípona súboru (bez úvodnej bodky) |
extensions | List<String> | getExtensions() | Všetky prípony podporované týmto formátom |
contentType | String | getContentType() | Reťazec typu MIME |
canExport | boolean | getCanExport() | Či je export do tohto formátu podporovaný |
canImport | boolean | getCanImport() | Či je import z tohto formátu podporovaný |
version | String | getVersion() | Reťazec verzie formátu |
Metódy inštancie
| Example | Návratový typ | Example |
|---|---|---|
createLoadOptions() | LoadOptions | Vytvára príslušný formátovo-špecifický LoadOptions podtrieda |
createSaveOptions() | SaveOptions | Vytvára príslušný formátovo-špecifický SaveOptions podtrieda |
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());
}
}