How to Convert 3D Models in .NET
This guide shows how to convert 3D models between OBJ, STL, glTF, FBX, and COLLADA formats in C# using Aspose.3D FOSS for .NET. Format conversion is a two-step operation: load the source file with Scene.Open(), then save to the target format with Scene.Save(). The output format is inferred from the file extension.
Step-by-Step Guide
Step 1: Install the Package
Run the following command to add the NuGet package to your project:
dotnet add package Aspose.3D --version 26.1.0Step 2: Import Namespaces
Add the required namespaces at the top of your C# file:
using Aspose.ThreeD;
using Aspose.ThreeD.Formats;Step 3: Load the Source File
Create a Scene instance and call Open() with the source file path:
var scene = new Scene();
scene.Open("input.fbx");Step 4: Save in the Target Format
Call Save() with the output file path; the library infers the format from the file extension:
scene.Save("output.glb");Supported export formats include OBJ, STL, glTF 2.0 / GLB, and COLLADA.
Step 5: Use Format-Specific Save Options
Pass a format-specific SaveOptions subclass to control export parameters such as coordinate system or XML formatting:
// OBJ with flipped coordinate system
scene.Save("output.obj", new ObjSaveOptions { FlipCoordinateSystem = true });
// COLLADA with indented XML
scene.Save("output.dae", new ColladaSaveOptions { Indented = true });Common Conversion Recipes
| Source | Target | Code |
|---|---|---|
| OBJ to GLB | scene.Open("input.obj"); scene.Save("output.glb"); | Binary glTF for web viewers |
| FBX to STL | scene.Open("input.fbx"); scene.Save("output.stl"); | Triangulated mesh for 3D printing |
| glTF to COLLADA | scene.Open("input.gltf"); scene.Save("output.dae"); | DAE exchange format |
| STL to OBJ | scene.Open("input.stl"); scene.Save("output.obj"); | Wavefront for modelling tools |
Common Issues and Fixes
Output file is empty or very small
Ensure the source file loaded successfully. Check scene.RootNode.ChildNodes.Count after Open().
Materials lost during conversion
Material properties vary across formats. OBJ materials use Lambert/Phong; glTF uses PBR. Material mapping is best-effort across format boundaries.
Scale difference between source and output
Different tools use different unit systems. Apply ObjLoadOptions.Scale on import or adjust node.Transform.Scale before saving.
Frequently Asked Questions (FAQ)
Can I convert PLY to another format?
PLY is import-only. Load a PLY file and save to any export format (OBJ, STL, GLB, FBX, COLLADA).
Does conversion preserve animations?
Animation data (AnimationClip) is preserved when both formats support it (e.g., FBX to glTF). STL and OBJ do not carry animation data.
Can I batch-convert multiple files?
Create a new Scene for each file in a loop. Each Scene is independent and can be processed in parallel.