کار کردن با glTF و GLB
کار با glTF و GLB
Aspose.3D برای .NET از خواندن و نوشتن glTF 2.0 (.gltf با داراییهای جداگانه) و GLB (باینری تکفایلی glTF) پشتیبانی میکند. برای تنظیم رفتار بارگذاری از GltfLoadOptions استفاده کنید و برای کنترل خروجی صادرات از GltfSaveOptions بهره ببرید.
بارگذاری یک فایل glTF
فایل .gltf یا .glb را مستقیماً با Scene.Open بارگذاری کنید. برای کنترل دقیقتر، GltfLoadOptions را فراهم کنید:
using Aspose.ThreeD;
using Aspose.ThreeD.Formats;
// Basic load
var scene = Scene.FromFile("model.gltf");
// Load with options
var opts = new GltfLoadOptions();
var sceneWithOpts = new Scene();
sceneWithOpts.Open("model.gltf", opts);فایلهای glTF به بافرها و تکستچرهای خارجی
.binاز طریق مسیر نسبی ارجاع میدهند. تمام داراییهای ارجاعشده را هنگام بارگذاری در همان دایرکتوری که فایل.gltfقرار دارد نگه دارید.
ذخیره بهصورت glTF یا GLB
هر صحنهای را به عنوان glTF یا قالب باینری فشرده GLB ذخیره کنید:
using Aspose.ThreeD;
using Aspose.ThreeD.Formats;
var scene = new Scene();
scene.RootNode.CreateChildNode("box", new Aspose.ThreeD.Entities.Box());
// Save as glTF (separate JSON + .bin buffer)
scene.Save("output.gltf", FileFormat.GLTF2);
// Save as GLB (single binary file)
scene.Save("output.glb", FileFormat.GLTF2_Binary);
// Save with custom options — embed the binary buffer inside the JSON
var saveOpts = new GltfSaveOptions(FileFormat.GLTF2);
saveOpts.EmbedAssets = true;
scene.Save("output_embedded.gltf", saveOpts);کنترل قالب تصویر جاسازیشده
زمانی که بافتها جاسازی میشوند، نحوه ذخیرهسازی دادههای تصویر را با GltfEmbeddedImageFormat کنترل کنید:
var saveOpts = new GltfSaveOptions(FileFormat.GLTF2_Binary);
saveOpts.ImageFormat = GltfEmbeddedImageFormat.Jpeg;
scene.Save("output.glb", saveOpts);مقدار GltfEmbeddedImageFormat | توضیح |
|---|---|
Jpeg | دوباره رمزگذاری تکستچرهای جاسازیشده به JPEG (فشردهسازی با تلفات، کوچکتر) |
Png | دوباره رمزگذاری تکستچرهای جاسازیشده به PNG (بدون تلفات) |
NoChange | حفظ کدگذاری اصلی (پیشفرض) |
API Quick Reference
| Member | توضیح |
|---|---|
new GltfLoadOptions() | پیکربندی واردات glTF |
new GltfSaveOptions(format) | پیکربندی خروجی glTF/GLB |
saveOpts.EmbedAssets | بافر باینری را داخل .gltf JSON قرار دهید |
saveOpts.ImageFormat | رمزگذاری بافت جاسازیشده (GltfEmbeddedImageFormat) |
FileFormat.GLTF2 | قالب هدف: جداگانه .gltf + .bin |
FileFormat.GLTF2_Binary | قالب هدف: تک .glb |
همچنین ببینید:
- Aspose.3D for .NET — Enterprise Documentation
- پشتیبانی از قالب — فهرست کامل فرمتهای پشتیبانیشده 3D