mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-07 03:17:25 -05:00
GltfData.GetBytesFromUri
This commit is contained in:
@@ -185,6 +185,8 @@ namespace UniGLTF
|
||||
return f.ToString();
|
||||
}
|
||||
|
||||
public ArraySegment<byte> BinBytes => _gltf.buffers[0].GetBytes();
|
||||
|
||||
/// <summary>
|
||||
/// GLBバイト列
|
||||
/// </summary>
|
||||
@@ -197,7 +199,7 @@ namespace UniGLTF
|
||||
// remove unused extenions
|
||||
var json = f.ToString().ParseAsJson().ToString(" ");
|
||||
RemoveUnusedExtensions(_gltf, json);
|
||||
return Glb.Create(json, _gltf.buffers[0].GetBytes()).ToBytes();
|
||||
return Glb.Create(json, BinBytes).ToBytes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -42,7 +42,21 @@ namespace UniGLTF
|
||||
/// > This chunk MUST be the second chunk of the Binary glTF asset
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ArraySegment<byte> Bin => Chunks[1].Bytes;
|
||||
public ArraySegment<byte> Bin
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Chunks == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
if (Chunks.Count < 2)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
return Chunks[1].Bytes;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// URI access
|
||||
@@ -64,7 +78,12 @@ namespace UniGLTF
|
||||
MigrationFlags = migrationFlags;
|
||||
}
|
||||
|
||||
public static GltfData CreateFromGltfDataForTest(glTF gltf, ArraySegment<byte> bytes = default)
|
||||
public static GltfData CreateFromExport(ExportingGltfData data)
|
||||
{
|
||||
return CreateFromGltfDataForTest(data.GLTF, data.BinBytes);
|
||||
}
|
||||
|
||||
public static GltfData CreateFromGltfDataForTest(glTF gltf, ArraySegment<byte> bytes)
|
||||
{
|
||||
IStorage storage = null;
|
||||
if (bytes.Array != null)
|
||||
@@ -79,17 +98,41 @@ namespace UniGLTF
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
gltf,
|
||||
new List<GlbChunk>(),
|
||||
new List<GlbChunk>{
|
||||
new GlbChunk(), // json
|
||||
GlbChunk.CreateBin(bytes),
|
||||
},
|
||||
storage,
|
||||
new MigrationFlags()
|
||||
);
|
||||
}
|
||||
|
||||
public ArraySegment<Byte> GetBytesFromUri(string uri)
|
||||
{
|
||||
if (string.IsNullOrEmpty(uri))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
return _storage.Get(uri);
|
||||
}
|
||||
|
||||
public ArraySegment<Byte> GetBytes(int bufferIndex)
|
||||
{
|
||||
// TODO:
|
||||
var buffer = GLTF.buffers[bufferIndex];
|
||||
return _storage.Get(buffer.uri);
|
||||
if (bufferIndex == 0 && string.IsNullOrEmpty(buffer.uri))
|
||||
{
|
||||
// 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
|
||||
{
|
||||
return GetBytesFromUri(buffer.uri);
|
||||
}
|
||||
}
|
||||
|
||||
public ArraySegment<Byte> GetViewBytes(int bufferView)
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace UniGLTF
|
||||
UnityEngine.Object.DestroyImmediate(mat);
|
||||
UnityEngine.Object.DestroyImmediate(root);
|
||||
|
||||
var parsed = GltfData.CreateFromGltfDataForTest(gltf);
|
||||
var parsed = GltfData.CreateFromGltfDataForTest(gltf, data.BinBytes);
|
||||
|
||||
// Extract Image to Texture2D
|
||||
var exportedBytes = parsed.GetViewBytes(exportedImage.bufferView).ToArray();
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace UniGLTF
|
||||
: MeshExporter_SharedVertexBuffer.Export(data, unityMesh, Materials, axisInverter, meshExportSettings)
|
||||
;
|
||||
|
||||
var parsed = GltfData.CreateFromGltfDataForTest(data.GLTF);
|
||||
var parsed = GltfData.CreateFromGltfDataForTest(data.GLTF, data.BinBytes);
|
||||
|
||||
{
|
||||
var indices = parsed.GetIndices(gltfMesh.primitives[0].indices);
|
||||
@@ -186,7 +186,7 @@ namespace UniGLTF
|
||||
: MeshExporter_SharedVertexBuffer.Export(data, unityMesh, Materials, axisInverter, meshExportSettings)
|
||||
;
|
||||
|
||||
var parsed = GltfData.CreateFromGltfDataForTest(data.GLTF);
|
||||
var parsed = GltfData.CreateFromGltfDataForTest(data.GLTF, data.BinBytes);
|
||||
{
|
||||
var indices = parsed.GetIndices(gltfMesh.primitives[0].indices);
|
||||
Assert.AreEqual(0, indices[0]);
|
||||
|
||||
@@ -553,9 +553,7 @@ namespace UniGLTF
|
||||
|
||||
// import
|
||||
{
|
||||
var storage = new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024]));
|
||||
var parsed = new JsonWithStorageParser(json, storage).Parse();
|
||||
|
||||
var parsed = GltfData.CreateFromExport(data);
|
||||
using (var context = new ImporterContext(parsed))
|
||||
using (var loaded = context.Load())
|
||||
{
|
||||
@@ -573,10 +571,7 @@ namespace UniGLTF
|
||||
|
||||
// import new version
|
||||
{
|
||||
var storage = new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024]));
|
||||
var parsed = new JsonWithStorageParser(json, storage).Parse();
|
||||
|
||||
//Debug.LogFormat("{0}", context.Json);
|
||||
var parsed = GltfData.CreateFromExport(data);
|
||||
using (var context = new ImporterContext(parsed))
|
||||
using (var loaded = context.Load())
|
||||
{
|
||||
|
||||
@@ -58,7 +58,8 @@ namespace VRM
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
default
|
||||
);
|
||||
var vrm = new glTF_VRM_extensions
|
||||
{
|
||||
@@ -119,7 +120,8 @@ namespace VRM
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
default
|
||||
);
|
||||
var vrm = new glTF_VRM_extensions
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user