Lavorare con glTF e GLB
Lavorare con glTF e GLB
Aspose.3D per .NET supporta la lettura e la scrittura di glTF 2.0 (.gltf con asset separati) e GLB (single-file binary glTF). Usa GltfLoadOptions per configurare il comportamento di caricamento e GltfSaveOptions per controllare l’output di esportazione.
Caricamento di un file glTF
Carica un file .gltf o .glb direttamente con Scene.Open. Fornisci GltfLoadOptions per un controllo più fine:
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);I file glTF fanno riferimento a buffer e texture esterni
.bintramite percorso relativo. Mantieni tutte le risorse di riferimento nella stessa directory del file.gltfdurante il caricamento.
Salvataggio come glTF o GLB
Salva qualsiasi scena come glTF o nel compatto formato binario 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);Controllare il formato immagine incorporato
Quando le texture sono incorporate, controlla come i dati dell’immagine vengono memorizzati con GltfEmbeddedImageFormat:
var saveOpts = new GltfSaveOptions(FileFormat.GLTF2_Binary);
saveOpts.ImageFormat = GltfEmbeddedImageFormat.Jpeg;
scene.Save("output.glb", saveOpts);GltfEmbeddedImageFormat valore | Descrizione |
|---|---|
Jpeg | Ricodifica le texture incorporate come JPEG (lossy, più piccole) |
Png | Ricodifica le texture incorporate come PNG (lossless) |
NoChange | Mantieni la codifica originale (default) |
API Quick Reference
| Member | Descrizione |
|---|---|
new GltfLoadOptions() | Configura glTF import |
new GltfSaveOptions(format) | Configura glTF/GLB export |
saveOpts.EmbedAssets | Incorpora buffer binario all’interno del .gltf JSON |
saveOpts.ImageFormat | Codifica della texture incorporata (GltfEmbeddedImageFormat) |
FileFormat.GLTF2 | Formato di destinazione: .gltf separati + .bin |
FileFormat.GLTF2_Binary | Formato di destinazione: unico .glb |
Vedi anche
- Aspose.3D for .NET — Enterprise Documentation
- Supporto dei formati — elenco completo dei formati 3D supportati