GLB
-Set materialGenerator argument, Material is replaced by URP version.
var data = new GlbFileParser(path).Parse();
-var loader = new UniGLTF.ImporterContext(data, materialGenerator: new GltfUrpMaterialDescriptorGenerator());
+This is 0.82.1 API.
+If use 0.82.0, please upgrade.
+GLB load is below steps.
+
+- Parse
GLB / GLTF, get a GltfData
+- Load
Unity Hierarchy from the GltfData, get a RuntimeGltfInstance, dispose loader.
+- Use the
RuntimeGltfInstance, destroy the RuntimeGltfInstance.
+
+1. Parse
+Parse glb from file path
+
+- same as
vrm
+
+GltfData Load(string path)
+{
+ return new GlbFileParser(path).Parse();
+}
+
+Parse glb byte array
+
+- same as
vrm
+
+GltfData Load(byte[] bytes)
+{
+ return new GlbBinaryParser(bytes, "LOAD_NAME").parse();
+}
+
+Parse gltf from file path
+GltfData Load(string path)
+{
+ return new GltfFileWithResourceFilesParser(path).Parse();
+}
+
+Parse gltf in zip archive from file path
+Zip archive that contain gltf and related files can parsed (experimental).
+GltfData Load(string path)
+{
+ return new ZipArchivedGltfFileParser(path).Parse();
+}
+
+Parse by file extension
+See SimpleViewer sample.
+GltfData Load(string path)
+{
+ var ext = Path.GetExtension(path).ToLower();
+ switch(ext)
+ {
+ case ".glb": return new GlbFileParser(path).Parse();
+ case ".gltf": return new GltfFileWithResourceFilesParser(path).Parse();
+ case ".zip": return new ZipArchivedGltfFileParser(path).Parse();
+ default: throw new Exception($"unknown: {ext}");
+ }
+}
+
+2. Load
+sync
+RuntimeGltfInstance Load(GltfData data)
+{
+ // Call ImporterContext.Dispose after load.
+ // Automatically load dispose by using.
+ using(var loader = new UniGLTF.ImporterContext(data)
+ {
+ var instance = loader.Load();
+ return instance;
+ }
+}
+
+async
+async RuntimeGltfInstance Load(GltfData data)
+{
+ // Call ImporterContext.Dispose after load.
+ // Automatically load dispose by using.
+ using(var loader = new UniGLTF.ImporterContext(data)
+ {
+ var instance = await loader.LoadAsync();
+ return instance;
+ }
+}
+
+Load URP material by materialGenerator argument
+You can load URP materials by setting the materialGenerator Argument (optional).
+async RuntimeGltfInstance Load(GltfData data)
+{
+ var materialGenerator = new GltfUrpMaterialDescriptorGenerator();
+ using(var loader = new UniGLTF.ImporterContext(data, materialGenerator: materialGenerator)
+ {
+ var instance = await loader.LoadAsync();
+ return instance;
+ }
+}
+
+3. Use instance
+// Setup for SkinnedMeshRenderer
+instance.EnableUpdateWhenOffscreen();
+// Show meshes when ready(invisible by default)
+instance.ShowMeshes();
+
+Destroy after use and discard related assets (textures, materials, meshes, etc.)
+GameObject.Destroy(instance);