العمل مع 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 المدعومة