FileFormat — Aspose.3D FOSS for Java
Example
FileFormat služi i kao opisnik formata i kao registar svih podržanih 3D formata datoteka. Svaki format je predstavljen kao FileFormat instanca dostupna kao atribut klase ili putem statičkih tvorničkih metoda. Proslijedite FileFormat instance u Scene.save() da biste prisilili određeni format, ili koristite FileFormat.detect() za identificiranje formata nepoznate datoteke.
Example: com.aspose.threed
import com.aspose.threed.FileFormat;Podržane konstante formata
Konstantе formata koje su aktivno podržane (registrirani uvoznici i/ili izvoznici) u FOSS izdanju prikazane su u nastavku.
Aktivno podržano (FOSS izdanje)
| Example | Example | Example |
|---|---|---|
FileFormat.WAVEFRONT_OBJ() | .obj | Statička metoda koja vraća ObjFormat instancu |
FileFormat.GLTF2() | .gltf / .glb | glTF 2.0 i GLB; statička metoda koja vraća GltfFormat instanca. Koristite GltfSaveOptions s setContentType(FileContentType.BINARY) za GLB izlaz. |
FileFormat.FBX7400ASCII() | .fbx | FBX 7.4 ASCII; samo uvoz (bez izvoza) |
FileFormat.STL_BINARY | .stl | STL binarni (postavljeno pri učitavanju klase) |
FileFormat.STLASCII | .stl | STL ASCII |
Example
FBX verzije 6100-7700 (binarno), Maya ASCII/Binarno, Discreet 3DS, Universal 3D, GLTF 1.0, GLTF binarno, PDF, Blender, DXF, PLY, X (binarno/tekst), Draco, RVM, ASE, IFC, Siemens JT, AMF, VRML, HTML5, ZIP, USD/USDA/USDZ, XYZ, PCD, PCD binarno.
Statičke metode
| Example | Tip povratne vrijednosti | Example |
|---|---|---|
FileFormat.detect(InputStream stream, String fileName) | FileFormat | Otkriva format iz datotečnog toka; fileName se koristi kao nagovještaj |
FileFormat.getFormatByExtension(String ext) | FileFormat | Vraća format koji odgovara nizu ekstenzija, poput ".obj", ".glb", ".fbx", ".stl" |
Svojstva instance
| Example | Example | Example | Example |
|---|---|---|---|
extension | String | getExtension() | Primarna ekstenzija datoteke (bez početne točke) |
extensions | List<String> | getExtensions() | Sve ekstenzije koje podržava ovaj format |
contentType | String | getContentType() | MIME tip string |
canExport | boolean | getCanExport() | Podržava li izvoz u ovaj format |
canImport | boolean | getCanImport() | Podržava li uvoz iz ovog formata |
version | String | getVersion() | String verzije formata |
Metode instance
| Example | Tip povratne vrijednosti | Example |
|---|---|---|
createLoadOptions() | LoadOptions | Stvara odgovarajući, specifičan za format LoadOptions podklasu |
createSaveOptions() | SaveOptions | Stvara odgovarajući, specifičan za format SaveOptions podklasu |
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());
}
}