Aspose.3D FOSS priekš .NET atbalsta septiņus 3D failu formātus: OBJ, STL, glTF, GLB, FBX, Collada, un 3MF. Šis raksts ir praktisks, formāts-pēc-formāta ceļvedis, kas parāda, kā ielādēt un saglabāt katru no tiem, kādas iespējas ir pieejamas un kā konvertēt starp tiem.
Visi piemēri izmanto Aspose.ThreeD nosaukumvietu:
using Aspose.ThreeD;
using Aspose.ThreeD.Formats;
NuGet pakotne:
dotnet add package Aspose.3D.Converter --version 1.0.0
OBJ (Wavefront)
OBJ ir plaši atbalstīts teksta balstīts formāts tīklu ģeometrijai. Aspose.3D FOSS ielādē OBJ failus kopā ar to sabiedroto .mtl materiālu failus.
OBJ ielāde
var scene = new Scene();
scene.Open("model.obj");
Console.WriteLine("Nodes: " + scene.RootNode.ChildNodes.Count);
Ielāde ar opcijām
var opts = new ObjLoadOptions();
// Configure loading behavior as needed
var scene = new Scene();
scene.Open("model.obj", opts);
Saglabāšana kā OBJ
var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);
scene.Save("output.obj");
OBJ ar saglabāšanas opcijām
var opts = new ObjSaveOptions();
scene.Save("output.obj", opts);
STL (Stereolitogrāfija)
STL ir standarta formāts 3D drukāšanai. Tas saglabā neapstrādātu trīsstūru ģeometriju bez materiāliem vai hierarhijas. Aspose.3D FOSS atbalsta gan bināro, gan ASCII STL.
STL ielāde
var scene = new Scene();
scene.Open("part.stl");
Console.WriteLine("Nodes: " + scene.RootNode.ChildNodes.Count);
Saglabāšana kā STL
var scene = new Scene();
var sphere = new Entities.Sphere(1);
scene.RootNode.CreateChildNode("SphereNode", sphere);
scene.Save("output.stl");
STL ar saglabāšanas opcijām
var opts = new StlSaveOptions();
// Control binary mode, scale, and coordinate flipping
scene.Save("output.stl", opts);
STL pilna cikla apstrāde
// 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 un GLB
glTF ir mūsdienu standarts tīmekļa un reāllaika 3D. Tas atbalsta PBR materiālus, pilnas ainas hierarhijas un efektīvu bināro pakotņu (GLB) saspiešanu.
Ielādē glTF
var scene = new Scene();
scene.Open("model.gltf");
Ielāde ar opcijām
var opts = new GltfLoadOptions();
var scene = new Scene();
scene.Open("model.gltf", opts);
Saglabā kā glTF
var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);
scene.Save("output.gltf");
Saglabā kā GLB (binārais glTF)
Lai izveidotu pašpietiekamu bināru .glb fails, saglabājiet ar .glb paplašinājumu. Bibliotēka secina bināro glTF formātu no paplašinājuma:
scene.Save("output.glb");
FBX (Filmbox)
FBX ir plaši izmantots spēļu izstrādē un digitālā satura veidošanā. Aspose.3D FOSS priekš .NET atbalsta FBX importēt un eksportēt gan ASCII, gan binārajā režīmā.
Ielādē FBX
var scene = new Scene();
scene.Open("model.fbx");
Ielāde ar opcijām
var opts = new FbxLoadOptions();
var scene = new Scene();
scene.Open("model.fbx", opts);
Saglabā kā 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);
Saglabā kā FBX bināro
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.
Ielādē 3MF
var scene = new Scene();
scene.Open("model.3mf");
Ielāde ar opcijām
var opts = new TmfLoadOptions();
var scene = new Scene();
scene.Open("model.3mf", opts);
Saglabāšana kā 3MF
var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);
scene.Save("output.3mf");
Saglabāšana ar opcijām
var opts = new TmfSaveOptions();
scene.Save("output.3mf", opts);
Plūsmas balstīta I/O
Visi formāti atbalsta ielādi no plūsmām un saglabāšanu uz plūsmām, kas ir noderīgi tīmekļa pakalpojumiem un mākoņa apstrādei:
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);
Formāta noteikšana
Bibliotēka var automātiski noteikt formātus no faila paplašinājumiem vai plūsmas satura:
// 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
Masveida konvertēšana
Lai konvertētu vairākus failus, iterējiet pāri direktorijai un konvertējiet katru no tiem:
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);
}
Formātu salīdzinājums
| Īpašība | OBJ | STL | glTF | FBX | 3MF |
|---|---|---|---|---|---|
| Materiāli | MTL | Nē | PBR | Jā | Jā |
| Ainas hierarhija | Nē | Nē | Jā | Jā | Jā |
| Animācijas stubi | Nē | Nē | Jā | Jā | Nē |
| Binārais režīms | Nē | Jā | GLB | Jā | ZIP |
| 3D printing ready | Ierobežots | Jā | Nē | Nē | Jā |
| Tīmekļa piegāde | Nē | Nē | Jā | Nē | Nē |
Kopsavilkums
Aspose.3D FOSS for .NET nodrošina vienotu, konsekventu API darbam ar visiem galvenajiem 3D failu formātiem. Paraugs vienmēr ir tas pats: izveidot Scene, izsaukt Open() lai ielādētu, pēc izvēles konfigurētu formāta specifiskās opcijas, un izsauktu Save() lai eksportētu. Formāta noteikšana, plūsmas bāzēta I/O un grupveida konvertēšana padara to vienkāršu integrēšanu jebkurā .NET caurulē.
Lai iegūtu vairāk informācijas:
- API atsauce – detalizēta klašu un metožu dokumentācija.
- Zināšanu bāze – praktiski pamācību raksti.
- GitHub – avota kods un problēmu izsekotājs.