mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-08 11:59:26 -05:00
Rename IUrlGetter to IStorage again.
This commit is contained in:
24
Assets/UniGLTF/Runtime/UniGLTF/Format/IStorage.cs
Normal file
24
Assets/UniGLTF/Runtime/UniGLTF/Format/IStorage.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents bytes access by URL in gltf
|
||||
/// </summary>
|
||||
public interface IStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// gltf の buffer の バイト列アクセス を実装する。
|
||||
/// 1. url による相対パス
|
||||
/// 2. url によるbase64 encoding
|
||||
/// 3. url がnullのときに bin chunk(buffers[0]) にアクセスする
|
||||
///
|
||||
/// TODO:
|
||||
/// 1. url による相対パス
|
||||
/// 以外をやめて、呼び出し側で分岐させる。
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
ArraySegment<Byte> Get(string url = default);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aed87db763d65564e96f23fc8bebd382
|
||||
guid: f87f7ed809642e0429061fd5f6c169f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,9 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public interface IUrlGetter
|
||||
{
|
||||
ArraySegment<Byte> Get(string url = default);
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -4,7 +4,10 @@ using System.IO;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public class SimpleStorage : IUrlGetter
|
||||
/// <summary>
|
||||
/// Implement bin chunk access
|
||||
/// </summary>
|
||||
public class SimpleStorage : IStorage
|
||||
{
|
||||
ArraySegment<Byte> m_bytes;
|
||||
|
||||
@@ -28,7 +31,10 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
|
||||
public class FileSystemStorage : IUrlGetter
|
||||
/// <summary>
|
||||
/// Implement url that represnet relative path
|
||||
/// </summary>
|
||||
public class FileSystemStorage : IStorage
|
||||
{
|
||||
string m_root;
|
||||
|
||||
@@ -60,7 +66,10 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
|
||||
public class GltfStorage : IUrlGetter
|
||||
/// <summary>
|
||||
/// for UnitTest
|
||||
/// </summary>
|
||||
public class GltfStorage : IStorage
|
||||
{
|
||||
glTF _gltf;
|
||||
|
||||
|
||||
@@ -47,40 +47,40 @@ namespace UniGLTF
|
||||
/// <summary>
|
||||
/// URI access
|
||||
/// </summary>
|
||||
IUrlGetter _urlGetter;
|
||||
public IStorage _storage;
|
||||
|
||||
/// <summary>
|
||||
/// Migration Flags used by ImporterContext
|
||||
/// </summary>
|
||||
public MigrationFlags MigrationFlags { get; }
|
||||
|
||||
public GltfData(string targetPath, string json, glTF gltf, IReadOnlyList<GlbChunk> chunks, IUrlGetter urlGetter, MigrationFlags migrationFlags)
|
||||
public GltfData(string targetPath, string json, glTF gltf, IReadOnlyList<GlbChunk> 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<byte> 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<GlbChunk>(),
|
||||
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<Byte> GetViewBytes(int bufferView)
|
||||
@@ -263,7 +263,7 @@ namespace UniGLTF
|
||||
}
|
||||
else
|
||||
{
|
||||
return _urlGetter.Get(image.uri);
|
||||
return _storage.Get(image.uri);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace UniGLTF
|
||||
return chunks;
|
||||
}
|
||||
|
||||
public static GltfData ParseGltf(string path, string json, IReadOnlyList<GlbChunk> chunks, IUrlGetter urlGetter, MigrationFlags migrationFlags)
|
||||
public static GltfData ParseGltf(string path, string json, IReadOnlyList<GlbChunk> 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)
|
||||
|
||||
@@ -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<byte>());
|
||||
_storage = storage ?? new SimpleStorage(new ArraySegment<byte>());
|
||||
}
|
||||
|
||||
public GltfData Parse()
|
||||
|
||||
@@ -292,7 +292,10 @@ namespace UniGLTF.Zip
|
||||
}
|
||||
}
|
||||
|
||||
class ZipArchiveStorage : IUrlGetter
|
||||
/// <summary>
|
||||
/// Implement url that reference zip archive
|
||||
/// </summary>
|
||||
class ZipArchiveStorage : IStorage
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user