עבודה עם 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

ראה גם

 עברית