Working with glTF and GLB

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 .bin buffers and textures by relative path. Keep all referenced assets in the same directory as the .gltf file 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 valueDescription
JpegRe-encode embedded textures as JPEG (lossy, smaller)
PngRe-encode embedded textures as PNG (lossless)
WebpRe-encode embedded textures as WebP
OriginalKeep original encoding (default)

API Quick Reference

MemberDescription
new GltfLoadOptions()Configure glTF import
new GltfSaveOptions(format)Configure glTF/GLB export
saveOpts.EmbedAssetsEmbed binary buffer inside the .gltf JSON
saveOpts.ImageFormatEmbedded texture encoding (GltfEmbeddedImageFormat)
FileFormat.GLTF2Target format: separate .gltf + .bin
FileFormat.GLTF2_BinaryTarget format: single .glb

See Also