Working with glTF and GLB
Working with glTF and GLB
Aspose.3D for .NET supports reading and writing glTF 2.0 (.gltf with separate assets) and GLB (single-file binary glTF). Use GltfLoadOptions to configure loading behaviour and GltfSaveOptions to control export output.
Loading a glTF File
Load a .gltf or .glb file directly with Scene.Open. Supply GltfLoadOptions for finer control:
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 files reference external
.binbuffers and textures by relative path. Keep all referenced assets in the same directory as the.gltffile when loading.
Saving as glTF or GLB
Save any scene as glTF or the compact binary GLB format:
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);Controlling Embedded Image Format
When textures are embedded, control how image data is stored with GltfEmbeddedImageFormat:
var saveOpts = new GltfSaveOptions(FileFormat.GLTF2_Binary);
saveOpts.ImageFormat = GltfEmbeddedImageFormat.Jpeg;
scene.Save("output.glb", saveOpts);GltfEmbeddedImageFormat value | Description |
|---|---|
Jpeg | Re-encode embedded textures as JPEG (lossy, smaller) |
Png | Re-encode embedded textures as PNG (lossless) |
Webp | Re-encode embedded textures as WebP |
Original | Keep original encoding (default) |
API Quick Reference
| Member | Description |
|---|---|
new GltfLoadOptions() | Configure glTF import |
new GltfSaveOptions(format) | Configure glTF/GLB export |
saveOpts.EmbedAssets | Embed binary buffer inside the .gltf JSON |
saveOpts.ImageFormat | Embedded texture encoding (GltfEmbeddedImageFormat) |
FileFormat.GLTF2 | Target format: separate .gltf + .bin |
FileFormat.GLTF2_Binary | Target format: single .glb |
See Also
- Aspose.3D for .NET — Enterprise Documentation
- Format Support — full list of supported 3D formats