From 1dfa3cd9bcc7b6b33fbff2fa130bbad47fd11b3b Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 8 Nov 2021 15:44:53 +0900 Subject: [PATCH] =?UTF-8?q?glTF=20=E5=BD=A2=E5=BC=8F=E3=81=AE=20uri=20?= =?UTF-8?q?=E3=82=A2=E3=82=AF=E3=82=BB=E3=82=B9=E3=82=92=E3=82=AD=E3=83=A3?= =?UTF-8?q?=E3=83=83=E3=82=B7=E3=83=A5(=E3=81=9F=E3=81=B6=E3=82=93?= =?UTF-8?q?=E3=80=810.87=E4=BB=A5=E5=89=8D=E3=81=AE=E5=8B=95=E4=BD=9C)?= =?UTF-8?q?=E3=80=82=20=E4=B8=80=E9=83=A8=E3=81=AE=E3=83=A2=E3=83=87?= =?UTF-8?q?=E3=83=AB=E3=81=A7=20File.ReadAllBytes(=E3=82=82=E3=81=97?= =?UTF-8?q?=E3=81=8F=E3=81=AFzip=20decode)=20=E3=81=AE=E5=A4=9A=E7=99=BA?= =?UTF-8?q?=E3=81=A7=E4=BD=8E=E9=80=9F=E5=8C=96=E3=81=99=E3=82=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * glb(vrm)には影響しない * buffer.uri が "data:" でないときもキャッシュする * buffers[0] を glb bin chunk と見做す判定を修正 --- Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs index fb6107190..aedfe0391 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs @@ -68,7 +68,12 @@ namespace UniGLTF /// IStorage _storage; - Dictionary> _dataUriCache = new Dictionary>(); + /// + /// uri = data: base64デコード + /// uri = 相対パス。File.ReadAllBytes + /// + /// + Dictionary> _UriCache = new Dictionary>(); public GltfData(string targetPath, string json, glTF gltf, IReadOnlyList chunks, IStorage storage, MigrationFlags migrationFlags) { @@ -101,39 +106,37 @@ namespace UniGLTF ); } - public ArraySegment GetBytesFromUri(string uri) + ArraySegment GetBytesFromUri(string uri) { if (string.IsNullOrEmpty(uri)) { throw new ArgumentNullException(); } + + if (_UriCache.TryGetValue(uri, out ArraySegment data)) + { + // return cache + return data; + } + if (uri.StartsWith("data:", StringComparison.Ordinal)) { - if (_dataUriCache.TryGetValue(uri, out ArraySegment data)) - { - return data; - } data = new ArraySegment(UriByteBuffer.ReadEmbedded(uri)); - _dataUriCache.Add(uri, data); - return data; } else { - return _storage.Get(uri); + data = _storage.Get(uri); } + _UriCache.Add(uri, data); + return data; } public ArraySegment GetBytesFromBuffer(int bufferIndex) { var buffer = GLTF.buffers[bufferIndex]; - if (bufferIndex == 0 && string.IsNullOrEmpty(buffer.uri)) + if (bufferIndex == 0 && Bin.Array != null) { // https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#glb-stored-buffer - // this buffer is reference bin chunk - if (Bin.Array == null) - { - throw new NullReferenceException(); - } return Bin; } else