diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Format/IStorage.cs b/Assets/UniGLTF/Runtime/UniGLTF/Format/IStorage.cs
new file mode 100644
index 000000000..4d4d65774
--- /dev/null
+++ b/Assets/UniGLTF/Runtime/UniGLTF/Format/IStorage.cs
@@ -0,0 +1,24 @@
+using System;
+
+namespace UniGLTF
+{
+ ///
+ /// Represents bytes access by URL in gltf
+ ///
+ public interface IStorage
+ {
+ ///
+ /// gltf の buffer の バイト列アクセス を実装する。
+ /// 1. url による相対パス
+ /// 2. url によるbase64 encoding
+ /// 3. url がnullのときに bin chunk(buffers[0]) にアクセスする
+ ///
+ /// TODO:
+ /// 1. url による相対パス
+ /// 以外をやめて、呼び出し側で分岐させる。
+ ///
+ ///
+ ///
+ ArraySegment Get(string url = default);
+ }
+}
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Format/IUrlGetter.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/Format/IStorage.cs.meta
similarity index 83%
rename from Assets/UniGLTF/Runtime/UniGLTF/Format/IUrlGetter.cs.meta
rename to Assets/UniGLTF/Runtime/UniGLTF/Format/IStorage.cs.meta
index f416db4ca..f70761485 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/Format/IUrlGetter.cs.meta
+++ b/Assets/UniGLTF/Runtime/UniGLTF/Format/IStorage.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: aed87db763d65564e96f23fc8bebd382
+guid: f87f7ed809642e0429061fd5f6c169f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Format/IUrlGetter.cs b/Assets/UniGLTF/Runtime/UniGLTF/Format/IUrlGetter.cs
deleted file mode 100644
index e1052d157..000000000
--- a/Assets/UniGLTF/Runtime/UniGLTF/Format/IUrlGetter.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using System;
-
-namespace UniGLTF
-{
- public interface IUrlGetter
- {
- ArraySegment Get(string url = default);
- }
-}
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFBuffer.cs b/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFBuffer.cs
index 8f5ffe939..ed5dbb166 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFBuffer.cs
+++ b/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFBuffer.cs
@@ -9,9 +9,9 @@ namespace UniGLTF
IBytesBuffer m_buffer;
public IBytesBuffer Buffer => m_buffer;
- public void OpenStorage(IUrlGetter urlGetter)
+ public void OpenStorage(IStorage storage)
{
- m_buffer = new ArraySegmentByteBuffer(urlGetter.Get(uri));
+ m_buffer = new ArraySegmentByteBuffer(storage.Get(uri));
}
public glTFBuffer()
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/FileSystemStorage.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/FileSystemStorage.cs
index 5712f4c95..2ffb85872 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/FileSystemStorage.cs
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/FileSystemStorage.cs
@@ -4,7 +4,10 @@ using System.IO;
namespace UniGLTF
{
- public class SimpleStorage : IUrlGetter
+ ///
+ /// Implement bin chunk access
+ ///
+ public class SimpleStorage : IStorage
{
ArraySegment m_bytes;
@@ -28,7 +31,10 @@ namespace UniGLTF
}
}
- public class FileSystemStorage : IUrlGetter
+ ///
+ /// Implement url that represnet relative path
+ ///
+ public class FileSystemStorage : IStorage
{
string m_root;
@@ -60,7 +66,10 @@ namespace UniGLTF
}
}
- public class GltfStorage : IUrlGetter
+ ///
+ /// for UnitTest
+ ///
+ public class GltfStorage : IStorage
{
glTF _gltf;
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs
index 8c1092edc..068530dc3 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs
@@ -47,40 +47,40 @@ namespace UniGLTF
///
/// URI access
///
- IUrlGetter _urlGetter;
+ public IStorage _storage;
///
/// Migration Flags used by ImporterContext
///
public MigrationFlags MigrationFlags { get; }
- public GltfData(string targetPath, string json, glTF gltf, IReadOnlyList chunks, IUrlGetter urlGetter, MigrationFlags migrationFlags)
+ public GltfData(string targetPath, string json, glTF gltf, IReadOnlyList chunks, IStorage storage, MigrationFlags migrationFlags)
{
TargetPath = targetPath;
Json = json;
GLTF = gltf;
Chunks = chunks;
- _urlGetter = urlGetter;
+ _storage = storage;
MigrationFlags = migrationFlags;
}
public static GltfData CreateFromGltfDataForTest(glTF gltf, ArraySegment bytes = default)
{
- IUrlGetter urlGetter = null;
+ IStorage storage = null;
if (bytes.Array != null)
{
- urlGetter = new SimpleStorage(bytes);
+ storage = new SimpleStorage(bytes);
}
else
{
- urlGetter = new GltfStorage(gltf);
+ storage = new GltfStorage(gltf);
}
return new GltfData(
string.Empty,
string.Empty,
gltf,
new List(),
- urlGetter,
+ storage,
new MigrationFlags()
);
}
@@ -90,7 +90,7 @@ namespace UniGLTF
{
// TODO:
var buffer = GLTF.buffers[bufferIndex];
- return _urlGetter.Get(buffer.uri);
+ return _storage.Get(buffer.uri);
}
public ArraySegment GetViewBytes(int bufferView)
@@ -263,7 +263,7 @@ namespace UniGLTF
}
else
{
- return _urlGetter.Get(image.uri);
+ return _storage.Get(image.uri);
}
}
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbLowLevelParser.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbLowLevelParser.cs
index 8c206e782..a0ecdfd51 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbLowLevelParser.cs
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbLowLevelParser.cs
@@ -71,7 +71,7 @@ namespace UniGLTF
return chunks;
}
- public static GltfData ParseGltf(string path, string json, IReadOnlyList chunks, IUrlGetter urlGetter, MigrationFlags migrationFlags)
+ public static GltfData ParseGltf(string path, string json, IReadOnlyList chunks, IStorage storage, MigrationFlags migrationFlags)
{
var GLTF = GltfDeserializer.Deserialize(json.ParseAsJson());
if (GLTF.asset.version != "2.0")
@@ -96,10 +96,10 @@ namespace UniGLTF
//GLTF.baseDir = System.IO.Path.GetDirectoryName(Path);
foreach (var buffer in GLTF.buffers)
{
- buffer.OpenStorage(urlGetter);
+ buffer.OpenStorage(storage);
}
- return new GltfData(path, json, GLTF, chunks, urlGetter, migrationFlags);
+ return new GltfData(path, json, GLTF, chunks, storage, migrationFlags);
}
private static void FixMeshNameUnique(glTF GLTF)
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/JsonWithStorageParser.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/JsonWithStorageParser.cs
index c04d8f2f4..5037dd55b 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/JsonWithStorageParser.cs
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/JsonWithStorageParser.cs
@@ -10,12 +10,12 @@ namespace UniGLTF
public sealed class JsonWithStorageParser
{
private readonly string _json;
- private readonly IUrlGetter _storage;
+ private readonly IStorage _storage;
- public JsonWithStorageParser(string json, IUrlGetter urlGetter = null)
+ public JsonWithStorageParser(string json, IStorage storage = null)
{
_json = json;
- _storage = urlGetter ?? new SimpleStorage(new ArraySegment());
+ _storage = storage ?? new SimpleStorage(new ArraySegment());
}
public GltfData Parse()
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ZipArchiveStorage.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ZipArchiveStorage.cs
index fe284e16e..eaee1d74c 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ZipArchiveStorage.cs
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ZipArchiveStorage.cs
@@ -292,7 +292,10 @@ namespace UniGLTF.Zip
}
}
- class ZipArchiveStorage : IUrlGetter
+ ///
+ /// Implement url that reference zip archive
+ ///
+ class ZipArchiveStorage : IStorage
{
public override string ToString()
{