FileFormat — Aspose.3D FOSS for Python API Reference
Example
FileFormat fungerar både som en formatbeskrivning och ett register över alla stödda 3D‑filformat. Varje format representeras som en FileFormat instans som är tillgänglig som ett klassattribut eller via statiska fabriksmetoder. Du skickar FileFormat instanser till Scene.save() för att tvinga ett specifikt format, eller använd FileFormat.detect() för att identifiera ett okänt fils format.
Example: aspose.threed
from aspose.threed import FileFormatStödda formatkonstanter
Formatkonstanter som aktivt stöds (importörer och/eller exportörer registrerade) i FOSS‑utgåvan visas nedan. Konstanter listade som None i källkoden är reserverade namn för format som ännu inte implementerats.
Aktivt stödda (FOSS-utgåva)
| Example | Example | Example |
|---|---|---|
FileFormat.WAVEFRONT_OBJ() | .obj | Statisk metod som returnerar en ObjFormat instans |
FileFormat.GLTF2() | .gltf / .glb | glTF 2.0; statisk metod som returnerar en GltfFormat instans |
FileFormat.FBX7400ASCII() | .fbx | FBX 7.4 ASCII; statisk metod |
FileFormat.MICROSOFT_3MF | .3mf | 3MF (set at module load) |
FileFormat.COLLADA | .dae | Example |
FileFormat.STL_BINARY | .stl | STL binär (sätts vid modulens laddning) |
FileFormat.STLASCII | .stl | STL ASCII |
Example
FBX-versioner 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.
Statiska metoder
| Example | Returtyp | Example |
|---|---|---|
FileFormat.detect(stream, file_name) | `FileFormat | None` |
FileFormat.get_format_by_extension(ext) | `FileFormat | None` |
Instansegenskaper
| Example | Example | Example |
|---|---|---|
extension | str | Primär filändelse (utan inledande punkt) |
extensions | list[str] | Alla filändelser som stöds av detta format |
content_type | str | MIME‑typsträng |
can_export | bool | Om export till detta format stöds |
can_import | bool | Om import från detta format stöds |
version | str | Formatversionssträng |
Instansmetoder
| Example | Returtyp | Example |
|---|---|---|
create_load_options() | LoadOptions | Skapar den lämpliga format‑specifika LoadOptions subklass |
create_save_options() | SaveOptions | Skapar den lämpliga format‑specifika SaveOptions subklass |
Example
from aspose.threed import Scene, FileFormat
# Auto-detect and load
scene = Scene.from_file("model.obj")
# Save with explicit format (force GLB binary)
from aspose.threed.formats import GltfSaveOptions
opts = GltfSaveOptions()
opts.binary_mode = True
scene.save("output.glb", opts)
# Get format by extension
fmt = FileFormat.get_format_by_extension(".fbx")
if fmt:
print(fmt.can_import) # True
print(fmt.can_export) # True
# Create options from a format instance
fmt_obj = FileFormat.get_format_by_extension(".obj")
load_opts = fmt_obj.create_load_options() # ObjLoadOptions
save_opts = fmt_obj.create_save_options() # ObjSaveOptions
# Detect format from file stream
with open("unknown_file.bin", "rb") as f:
detected = FileFormat.detect(f, "unknown_file.bin")
if detected:
print(type(detected).__name__)