FileFormat — Aspose.3D FOSS for .NET
Overview
The FileFormat class is a registry of all supported 3D file formats. There are no public named constants for individual formats — format instances are obtained at runtime through the static discovery methods or the Formats collection.
Format Registry
Supported formats are registered internally. Use the following API to access them:
| Member | Type | Description |
|---|---|---|
FileFormat.Formats | IList<FileFormat> | All registered format instances |
FileFormat.Detect(string filePath) | FileFormat | Detects format from a file path (by extension and content) |
FileFormat.GetFormatByExtension(string ext) | FileFormat | Returns the format for a given file extension (e.g. ".obj") |
Registered formats include: OBJ, STL, glTF/GLB, FBX, COLLADA, PLY, and 3MF.
Methods
| Method | Return Type | Description |
|---|---|---|
Detect(string filePath) | FileFormat | Detects the format from a file path |
GetFormatByExtension(string ext) | FileFormat | Returns the format matching the extension |
CreateLoadOptions() | LoadOptions | Returns load options appropriate for this format instance |
CreateSaveOptions() | SaveOptions | Returns save options appropriate for this format instance |
Note on
CreateLoadOptions()/CreateSaveOptions(): These methods work correctly when called on format instances returned byDetect()orGetFormatByExtension()— each registered format overrides these methods with its own implementation. Calling them on a raw base-classFileFormatinstance (not obtained through the registry) throwsNotImplementedException.
Example
using Aspose.ThreeD;
using Aspose.ThreeD.Formats;
// Detect format from a file path
var format = FileFormat.Detect("model.obj");
Console.WriteLine(format.Extension); // ".obj"
// Get load options from the detected format instance
var loadOpts = format.CreateLoadOptions(); // returns ObjLoadOptions via polymorphism
// Load and save — format inferred from extension
var scene = new Scene();
scene.Open("model.obj");
scene.Save("output.glb"); // binary GLB inferred from .glb extension
// Enumerate all registered formats
foreach (var fmt in FileFormat.Formats)
Console.WriteLine($"{fmt.Extension}: import={fmt.CanImport}, export={fmt.CanExport}");