FileFormat — Aspose.3D FOSS for Python API Reference
Overview
FileFormat serves as both a format descriptor and a registry of all supported 3D file formats. Each format is represented as a FileFormat instance accessible as a class attribute or via static factory methods. You pass FileFormat instances to Scene.save() to force a specific format, or use FileFormat.detect() to identify an unknown file’s format.
Package: aspose.threed
from aspose.threed import FileFormatSupported Format Constants
Format constants that are actively supported (importers and/or exporters registered) in the FOSS release are shown below. Constants listed as None in the source are reserved names for formats not yet implemented.
Actively Supported (FOSS release)
| Attribute | Extension | Notes |
|---|---|---|
FileFormat.WAVEFRONT_OBJ() | .obj | Static method returning an ObjFormat instance |
FileFormat.GLTF2() | .gltf / .glb | glTF 2.0; static method returning a GltfFormat instance |
FileFormat.FBX7400ASCII() | .fbx | FBX 7.4 ASCII; static method |
FileFormat.MICROSOFT_3MF_FORMAT() | .3mf | 3MF; static method |
FileFormat.COLLADA | .dae | COLLADA (set at module load via plugin) |
FileFormat.STL_BINARY | .stl | STL binary (set at module load) |
FileFormat.STLASCII | .stl | STL ASCII |
Reserved (not yet implemented)
FBX versions 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.
Static Methods
| Method | Return Type | Description |
|---|---|---|
FileFormat.detect(stream, file_name) | FileFormat | None | Detects the format from a file stream; file_name is used as a hint |
FileFormat.get_format_by_extension(ext) | FileFormat | None | Returns the format matching an extension string such as ".obj", ".glb", ".fbx", ".dae", ".3mf", ".stl" |
Instance Properties
| Name | Type | Description |
|---|---|---|
extension | str | Primary file extension (without leading dot) |
extensions | list[str] | All extensions supported by this format |
content_type | str | MIME type string |
can_export | bool | Whether exporting to this format is supported |
can_import | bool | Whether importing from this format is supported |
version | str | Format version string |
Instance Methods
| Method | Return Type | Description |
|---|---|---|
create_load_options() | LoadOptions | Creates the appropriate format-specific LoadOptions subclass |
create_save_options() | SaveOptions | Creates the appropriate format-specific SaveOptions subclass |
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__)