Aspose.3D FOSS für .NET unterstützt sieben 3D-Dateiformate: OBJ, STL, glTF, GLB, FBX, Collada, und 3MF. Dieser Beitrag ist ein praktischer, format‑für‑format Leitfaden, der zeigt, wie man jedes einzelne lädt und speichert, welche Optionen verfügbar sind und wie man zwischen ihnen konvertiert.
Alle Beispiele verwenden das Aspose.ThreeD Namensraum:
using Aspose.ThreeD;
using Aspose.ThreeD.Formats;
NuGet-Paket:
dotnet add package Aspose.3D --version 26.1.0
OBJ (Wavefront)
OBJ ist ein weit verbreitetes textbasiertes Format für Mesh‑Geometrie. Aspose.3D FOSS lädt OBJ‑Dateien zusammen mit ihren zugehörigen .mtl Materialdateien.
Laden von OBJ
var scene = new Scene();
scene.Open("model.obj");
Console.WriteLine("Nodes: " + scene.RootNode.ChildNodes.Count);
Laden mit Optionen
var opts = new ObjLoadOptions();
// Configure loading behavior as needed
var scene = new Scene();
scene.Open("model.obj", opts);
Speichern als OBJ
var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);
scene.Save("output.obj");
OBJ mit Speicheroptionen
var opts = new ObjSaveOptions();
scene.Save("output.obj", opts);
STL (Stereolithografie)
STL ist das Standardformat für den 3D-Druck. Es speichert rohe triangulierte Geometrie ohne Materialien oder Hierarchie. Aspose.3D FOSS unterstützt sowohl binäres als auch ASCII-STL.
Laden von STL
var scene = new Scene();
scene.Open("part.stl");
Console.WriteLine("Nodes: " + scene.RootNode.ChildNodes.Count);
Speichern als STL
var scene = new Scene();
var sphere = new Entities.Sphere(1);
scene.RootNode.CreateChildNode("SphereNode", sphere);
scene.Save("output.stl");
STL mit Speicheroptionen
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 -- geometry is preserved
var scene = new Scene();
scene.Open("original.stl");
scene.Save("copy.stl");
glTF 2.0 und GLB
glTF ist der moderne Standard für Web- und Echtzeit‑3D. Es unterstützt PBR‑Materialien, vollständige Szenenhierarchien und effizientes binäres Packen (GLB).
Laden von glTF
var scene = new Scene();
scene.Open("model.gltf");
Laden mit Optionen
var opts = new GltfLoadOptions();
var scene = new Scene();
scene.Open("model.gltf", opts);
Speichern als glTF
var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);
scene.Save("output.gltf");
Speichern als GLB (binäres glTF)
Um eine eigenständige Binär .glb datei zu erzeugen, speichern Sie mit einem .glb Erweiterung. Die Bibliothek leitet das binäre glTF-Format aus der Erweiterung ab:
scene.Save("output.glb");
FBX (Filmbox)
FBX wird häufig in der Spieleentwicklung und der digitalen Inhaltserstellung verwendet. Aspose.3D FOSS für .NET unterstützt FBX Import und Export sowohl im ASCII- als auch im Binärmodus.
Laden von FBX
var scene = new Scene();
scene.Open("model.fbx");
Laden mit Optionen
var opts = new FbxLoadOptions();
var scene = new Scene();
scene.Open("model.fbx", opts);
Speichern als FBX ASCII
var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);
var opts = new FbxSaveOptions() { IsAscii = true };
scene.Save("output.fbx", opts);
Speichern als FBX Binär
var opts = new FbxSaveOptions() { IsAscii = false };
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 ZIP-based package.
Laden von 3MF
var scene = new Scene();
scene.Open("model.3mf");
Laden mit Optionen
var opts = new TmfLoadOptions();
var scene = new Scene();
scene.Open("model.3mf", opts);
Speichern als 3MF
var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);
scene.Save("output.3mf");
Speichern mit Optionen
var opts = new TmfSaveOptions();
scene.Save("output.3mf", opts);
Stream-basierte Ein-/Ausgabe
Alle Formate unterstützen das Laden aus und das Speichern in Streams, was für Webdienste und Cloud-Verarbeitung nützlich ist:
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();
scene.Save(output, saveOpts);
Format-Erkennung
Die Bibliothek kann Formate automatisch anhand von Dateierweiterungen oder Stream-Inhalt erkennen:
// 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
Stapelkonvertierung
Um mehrere Dateien zu konvertieren, iterieren Sie über ein Verzeichnis und konvertieren jede Datei:
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);
}
Formatvergleich
| Funktion | OBJ | STL | glTF | FBX | 3MF |
|---|---|---|---|---|---|
| Materialien | MTL | Nein | PBR | Ja | Ja |
| Szenenhierarchie | Nein | Nein | Ja | Ja | Ja |
| Animations-Stubs | Nein | Nein | Ja | Ja | Nein |
| Binärmodus | Nein | Ja | GLB | Ja | ZIP |
| 3D printing ready | Begrenzt | Ja | Nein | Nein | Ja |
| Weblieferung | Nein | Nein | Ja | Nein | Nein |
Zusammenfassung
Aspose.3D FOSS für .NET gibt Ihnen eine einheitliche, konsistente API für die Arbeit mit allen wichtigen 3D-Dateiformaten. Das Muster ist immer dasselbe: erstellen Sie ein(e) Scene, rufen Sie Open() zum Laden, optional formatbezogene Optionen konfigurieren und rufen Sie Save() zum Exportieren. Format-Erkennung, streambasierte I/O und Batch-Konvertierung machen es einfach, in jede .NET-Pipeline zu integrieren.
Weitere Informationen:
- API-Referenz – detaillierte Klassen- und Methodendokumentation.
- Wissensdatenbank – praktische How-to-Artikel.
- GitHub – Quellcode und Issue Tracker.