diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFBuffer.cs b/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFBuffer.cs index 540ea36ae..ed5dbb166 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFBuffer.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFBuffer.cs @@ -6,11 +6,12 @@ namespace UniGLTF [Serializable] public class glTFBuffer { - IBytesBuffer Storage; + IBytesBuffer m_buffer; + public IBytesBuffer Buffer => m_buffer; public void OpenStorage(IStorage storage) { - Storage = new ArraySegmentByteBuffer(storage.Get(uri)); + m_buffer = new ArraySegmentByteBuffer(storage.Get(uri)); } public glTFBuffer() @@ -20,7 +21,7 @@ namespace UniGLTF public glTFBuffer(IBytesBuffer storage) { - Storage = storage; + m_buffer = storage; } public string uri; @@ -39,14 +40,14 @@ namespace UniGLTF } public glTFBufferView Append(ArraySegment segment, glBufferTarget target) where T : struct { - var view = Storage.Extend(segment, target); - byteLength = Storage.Bytes.Count; + var view = m_buffer.Extend(segment, target); + byteLength = m_buffer.Bytes.Count; return view; } public ArraySegment GetBytes() { - return Storage.Bytes; + return m_buffer.Bytes; } } diff --git a/Assets/VRM10/Runtime/IO/ModelLoader.cs b/Assets/VRM10/Runtime/IO/ModelLoader.cs index 15b283615..6ee364c2d 100644 --- a/Assets/VRM10/Runtime/IO/ModelLoader.cs +++ b/Assets/VRM10/Runtime/IO/ModelLoader.cs @@ -19,7 +19,6 @@ namespace UniVRM10 AssetGenerator = storage.AssetGenerator, AssetCopyright = storage.AssetCopyright, AssetMinVersion = storage.AssetMinVersion, - OriginalJson = storage.OriginalJson, }; // node diff --git a/Assets/VRM10/Runtime/IO/Vrm10Storage.cs b/Assets/VRM10/Runtime/IO/Vrm10Storage.cs index 1f839839b..a28127e64 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Storage.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Storage.cs @@ -11,14 +11,10 @@ namespace UniVRM10 { public class Vrm10Storage { - public ArraySegment OriginalJson { get; private set; } - public UniGLTF.glTF Gltf - { - get; - private set; - } + UniGLTF.GltfParser m_parser; + public UniGLTF.glTF Gltf => m_parser.GLTF; - public readonly List Buffers; + public List Buffers; public UniGLTF.Extensions.VRMC_vrm.VRMC_vrm gltfVrm; @@ -29,9 +25,12 @@ namespace UniVRM10 /// public Vrm10Storage() { - Gltf = new UniGLTF.glTF() + m_parser = new UniGLTF.GltfParser { - extensionsUsed = new List(), + GLTF = new UniGLTF.glTF() + { + extensionsUsed = new List(), + } }; Buffers = new List() { @@ -44,10 +43,9 @@ namespace UniVRM10 /// /// /// - public Vrm10Storage(ArraySegment json, ArraySegment bin) + public Vrm10Storage(UniGLTF.GltfParser parser) { - OriginalJson = json; - Gltf = UniGLTF.GltfDeserializer.Deserialize(json.ParseAsJson()); + m_parser = parser; if (UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(Gltf.extensions, out UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm)) @@ -63,7 +61,7 @@ namespace UniVRM10 Buffers = new List() { - new UniGLTF.ArraySegmentByteBuffer(bin) + Gltf.buffers[0].Buffer, }; } diff --git a/Assets/VRM10/Runtime/UnityBuilder/VrmLoader.cs b/Assets/VRM10/Runtime/UnityBuilder/VrmLoader.cs index 1c0159475..e0657d34d 100644 --- a/Assets/VRM10/Runtime/UnityBuilder/VrmLoader.cs +++ b/Assets/VRM10/Runtime/UnityBuilder/VrmLoader.cs @@ -2,6 +2,7 @@ using System.IO; using VrmLib; using UniJSON; +using UniGLTF; namespace UniVRM10 { @@ -24,40 +25,12 @@ namespace UniVRM10 public static Model CreateVrmModel(byte[] bytes, FileInfo path) { - if (!UniGLTF.Glb.TryParse(bytes, out UniGLTF.Glb glb, out Exception ex)) - { - throw ex; - } - - var json = glb.Json.Bytes.ParseAsJson(); - - var extensions = json["extensions"]; - - foreach (var kv in extensions.ObjectItems()) - { - switch (kv.Key.GetString()) - { - // case "VRM": - // { - // var storage = new Vrm10Storage(glb.Json.Bytes, glb.Binary.Bytes); - // var model = ModelLoader.Load(storage, path.Name); - // model.ConvertCoordinate(Coordinates.Unity); - // return model; - // } - - case "VRMC_vrm": - { - var storage = new Vrm10Storage(glb.Json.Bytes, glb.Binary.Bytes); - var model = ModelLoader.Load(storage, path.Name); - model.ConvertCoordinate(Coordinates.Unity); - return model; - } - } - } - - // this is error - // throw new NotImplementedException(); - return null; + var parser = new GltfParser(); + parser.Parse(path.FullName, bytes); + var storage = new Vrm10Storage(parser); + var model = ModelLoader.Load(storage, path.Name); + model.ConvertCoordinate(Coordinates.Unity); + return model; } } } diff --git a/Assets/VRM10/vrmlib/Runtime/Model.cs b/Assets/VRM10/vrmlib/Runtime/Model.cs index deb5546fb..e858dd55a 100644 --- a/Assets/VRM10/vrmlib/Runtime/Model.cs +++ b/Assets/VRM10/vrmlib/Runtime/Model.cs @@ -18,8 +18,6 @@ namespace VrmLib Coordinates = coordinates; } - public ArraySegment OriginalJson; - public Coordinates Coordinates; public string AssetVersion = "2.0";