diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Format/IStorage.cs b/Assets/UniGLTF/Runtime/UniGLTF/Format/IStorage.cs index d12009ce2..b7495b2be 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/Format/IStorage.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/Format/IStorage.cs @@ -4,7 +4,7 @@ namespace UniGLTF { public interface IStorage { - ArraySegment Get(string url); + ArraySegment Get(string url = default); /// /// Get original filepath if exists diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs index 67534b39b..8196458d5 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Text; -using UnityEngine; namespace UniGLTF { @@ -31,6 +28,12 @@ namespace UniGLTF /// public IReadOnlyList Chunks { get; } + /// + /// Bin chunk bytes + /// + /// + public ArraySegment Bin => Chunks.First(x => x.ChunkType == GlbChunkType.BIN).Bytes; + /// /// URI access /// diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbBinaryParser.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbBinaryParser.cs index e14fe83d8..6785a6f22 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbBinaryParser.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbBinaryParser.cs @@ -6,8 +6,8 @@ namespace UniGLTF { private readonly byte[] _data; private readonly string _name; - - public GlbBinaryParser(byte[] data, string uniqueName) + + public GlbBinaryParser(byte[] data, string uniqueName = "tmp") { _data = data; diff --git a/Assets/VRM10/Runtime/IO/Vrm10Data.cs b/Assets/VRM10/Runtime/IO/Vrm10Data.cs index 9ad29fcea..4e0deb9ee 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Data.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Data.cs @@ -68,8 +68,6 @@ namespace UniVRM10 try { var json = data.Json.ParseAsJson(); - var bin = data.Chunks.First(x => x.ChunkType == GlbChunkType.BIN); - try { if (!json.TryGet("extensions", out JsonNode extensions)) @@ -95,7 +93,7 @@ namespace UniVRM10 return false; } - migrated = MigrationVrm.Migrate(json, bin.Bytes); + migrated = MigrationVrm.Migrate(data); if (migrated == null) { result = new Vrm10Data(default, default, Vrm10FileType.Vrm0, "vrm0: cannot migrate"); diff --git a/Assets/VRM10/Runtime/Migration/MigrationVrm.cs b/Assets/VRM10/Runtime/Migration/MigrationVrm.cs index 5d027fa91..9f23fb099 100644 --- a/Assets/VRM10/Runtime/Migration/MigrationVrm.cs +++ b/Assets/VRM10/Runtime/Migration/MigrationVrm.cs @@ -12,20 +12,14 @@ namespace UniVRM10 { public static byte[] Migrate(byte[] src) { - var glb = UniGLTF.Glb.Parse(src); - var json = glb.Json.Bytes.ParseAsJson(); - return Migrate(json, glb.Binary.Bytes); + var data = new UniGLTF.GlbBinaryParser(src).Parse(); + return Migrate(data); } - public static byte[] Migrate(JsonNode json, ArraySegment bin) + public static byte[] Migrate(UniGLTF.GltfData data) { - var gltf = UniGLTF.GltfDeserializer.Deserialize(json); - - // attach glb bin to buffer - foreach (var buffer in gltf.buffers) - { - buffer.OpenStorage(new UniGLTF.SimpleStorage(bin)); - } + var gltf = data.GLTF; + var json = data.Json.ParseAsJson(); // https://github.com/vrm-c/vrm-specification/issues/205 RotateY180.Rotate(gltf); @@ -107,7 +101,7 @@ namespace UniVRM10 vrm1Json = f.GetStoreBytes(); } // JSON 部分だけが改変されて、BIN はそのまま - return UniGLTF.Glb.Create(vrm1Json, bin).ToBytes(); + return UniGLTF.Glb.Create(vrm1Json, data.Bin).ToBytes(); } public static void Check(JsonNode vrm0, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm1) @@ -121,4 +115,5 @@ namespace UniVRM10 // Migration.CheckSpringBone(vrm0["secondaryAnimation"], vrm1.sp) } } -} + +} \ No newline at end of file