Introduction

Aspose.3D FOSS for .NET supports key 3D file formats: OBJ, STL, glTF, FBX, Collada, and 3MF. This post is a practical, format-by-format guide showing how to load and save each format, what options are available, and how to convert between them.

Getting Started

Install the NuGet package before using any of the examples:

dotnet add package Aspose.3D.FOSS

All code examples in this guide use the Aspose.ThreeD namespace:

using Aspose.ThreeD;
using Aspose.ThreeD.Formats;

OBJ (Wavefront)

OBJ is a widely supported text-based format for mesh geometry. Aspose.3D FOSS loads OBJ files along with their companion .mtl material files.

Loading OBJ

Open an OBJ file into a new scene and inspect its node hierarchy:

var scene = new Scene();
scene.Open("model.obj");

Console.WriteLine("Nodes: " + scene.RootNode.ChildNodes.Count);

Loading with Options

Pass an ObjLoadOptions instance to customize how the OBJ file is loaded:

var opts = new ObjLoadOptions();
// Configure loading behavior as needed
var scene = new Scene();
scene.Open("model.obj", opts);

Saving as OBJ

Create a scene with geometry and export it as an OBJ file:

var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);

scene.Save("output.obj");

OBJ with Save Options

Use ObjSaveOptions to configure the material file name and output options:

var opts = new ObjSaveOptions();
scene.Save("output.obj", opts);

STL (Stereolithography)

STL is the standard format for 3D printing. It stores raw triangulated geometry without materials or hierarchy.

Loading STL

Open an STL file into a new scene and inspect the loaded geometry:

var scene = new Scene();
scene.Open("part.stl");

Console.WriteLine("Nodes: " + scene.RootNode.ChildNodes.Count);

Saving as STL

Create a sphere entity and save the scene as an STL file:

var scene = new Scene();
var sphere = new Entities.Sphere(1);
scene.RootNode.CreateChildNode("SphereNode", sphere);

scene.Save("output.stl");

STL with Save Options

Use StlSaveOptions to control binary mode, scale, and coordinate flipping:

var opts = new StlSaveOptions();
// Control binary mode, scale, and coordinate flipping
scene.Save("output.stl", opts);

STL Round-Trip

Load an STL file and re-save it to verify that geometry is preserved:

// Load an STL file and re-save it -- geometry is preserved
var scene = new Scene();
scene.Open("original.stl");
scene.Save("copy.stl");

glTF 2.0 and GLB

glTF is the modern standard for web and real-time 3D. It supports PBR materials, full scene hierarchies, and efficient binary packing (GLB).

Loading glTF

Open a glTF file into a new scene for inspection or processing:

var scene = new Scene();
scene.Open("model.gltf");

Loading with Options

Pass a GltfLoadOptions instance to customize how the glTF file is imported:

var opts = new GltfLoadOptions();
var scene = new Scene();
scene.Open("model.gltf", opts);

Saving as glTF

Create a scene and export it as a glTF file:

var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);

scene.Save("output.gltf");

Saving as GLB (Binary glTF)

To produce a self-contained binary .glb file, save with a .glb extension. The library infers the binary glTF format from the extension:

scene.Save("output.glb");

FBX (Filmbox)

FBX is widely used in game development and digital content creation. Aspose.3D FOSS for .NET supports FBX import and export. The FbxSaveOptions class provides format-specific save settings.

Loading FBX

Open an FBX file into a new scene for inspection or processing:

var scene = new Scene();
scene.Open("model.fbx");

Loading with Options

Pass an FbxLoadOptions instance to customize how the FBX file is imported:

var opts = new FbxLoadOptions();
var scene = new Scene();
scene.Open("model.fbx", opts);

Saving as FBX

Create a scene and export it as an FBX file:

var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);

// FBX export always produces binary FBX output
scene.Save("output.fbx");

Saving with Options

Use FbxSaveOptions to pass format-specific settings to the FBX writer:

// Use FbxSaveOptions for format-specific defaults
var opts = new FbxSaveOptions(FileContentType.Binary);
scene.Save("output.fbx", opts);

3MF (3D Manufacturing Format)

3MF is a modern 3D printing format developed by the 3MF Consortium. It supports rich metadata, materials, and multi-object scenes in a single package.

Loading 3MF

Open a 3MF file into a new scene for inspection or processing:

var scene = new Scene();
scene.Open("model.3mf");

Saving as 3MF

Create a scene and export it as a 3MF file:

var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);

scene.Save("output.3mf");

Saving with Options

Use Microsoft3MFSaveOptions to pass format-specific settings to the 3MF writer:

var opts = new Microsoft3MFSaveOptions();
scene.Save("output.3mf", opts);

Stream-Based I/O

Formats support loading from and saving to streams, which is useful for web services and cloud processing:

using var stream = File.OpenRead("model.obj");
var scene = new Scene();
var opts = new ObjLoadOptions();
scene.Open(stream, opts);

// Save to a memory stream
using var output = new MemoryStream();
var saveOpts = new GltfSaveOptions(FileContentType.Binary);
scene.Save(output, saveOpts);

Format Detection

The library can auto-detect formats from file extensions or stream content:

// Auto-detect from extension
var scene = new Scene();
scene.Open("model.obj");  // Detects OBJ from .obj extension

// Auto-detect from stream content
using var stream = File.OpenRead("model.obj");
scene.Open(stream);  // Inspects stream content to determine format

Batch Conversion

For converting multiple files, iterate over a directory and convert each file:

using Aspose.ThreeD;
using Aspose.ThreeD.Formats;

var inputDir = "assets/";
var outputDir = "converted/";

foreach (var file in Directory.GetFiles(inputDir, "*.fbx"))
{
    var scene = new Scene();
    scene.Open(file);

    var outputPath = Path.Combine(outputDir,
        Path.GetFileNameWithoutExtension(file) + ".glb");

    scene.Save(outputPath);
    Console.WriteLine("Converted: " + file);
}

Format Comparison

FeatureOBJSTLglTFFBX3MF
MaterialsMTLNoPBRYesYes
Scene hierarchyNoNoYesYesYes
Animation stubsNoNoYesYesNo
Binary modeNoYesBinaryYesYes
3D printing readyLimitedYesNoNoYes
Web deliveryNoNoYesNoNo

Summary

Aspose.3D FOSS for .NET gives you a single, consistent API for working with all major 3D file formats. The pattern is always the same: create a Scene, call Open() to load, optionally configure format-specific options, and call Save() to export. Format detection, stream-based I/O, and batch conversion make it straightforward to integrate into any .NET pipeline.

For more information: