mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-22 02:24:57 -05:00
Migrate(UniGLTF.GltfData data)
This commit is contained in:
@@ -4,7 +4,7 @@ namespace UniGLTF
|
||||
{
|
||||
public interface IStorage
|
||||
{
|
||||
ArraySegment<Byte> Get(string url);
|
||||
ArraySegment<Byte> Get(string url = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get original filepath if exists
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
@@ -31,6 +28,12 @@ namespace UniGLTF
|
||||
/// </summary>
|
||||
public IReadOnlyList<GlbChunk> Chunks { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Bin chunk bytes
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ArraySegment<byte> Bin => Chunks.First(x => x.ChunkType == GlbChunkType.BIN).Bytes;
|
||||
|
||||
/// <summary>
|
||||
/// URI access
|
||||
/// </summary>
|
||||
|
||||
@@ -6,8 +6,8 @@ namespace UniGLTF
|
||||
{
|
||||
private readonly byte[] _data;
|
||||
private readonly string _name;
|
||||
|
||||
public GlbBinaryParser(byte[] data, string uniqueName)
|
||||
|
||||
public GlbBinaryParser(byte[] data, string uniqueName = "tmp")
|
||||
{
|
||||
_data = data;
|
||||
|
||||
|
||||
@@ -68,8 +68,6 @@ namespace UniVRM10
|
||||
try
|
||||
{
|
||||
var json = data.Json.ParseAsJson();
|
||||
var bin = data.Chunks.First(x => x.ChunkType == GlbChunkType.BIN);
|
||||
|
||||
try
|
||||
{
|
||||
if (!json.TryGet("extensions", out JsonNode extensions))
|
||||
@@ -95,7 +93,7 @@ namespace UniVRM10
|
||||
return false;
|
||||
}
|
||||
|
||||
migrated = MigrationVrm.Migrate(json, bin.Bytes);
|
||||
migrated = MigrationVrm.Migrate(data);
|
||||
if (migrated == null)
|
||||
{
|
||||
result = new Vrm10Data(default, default, Vrm10FileType.Vrm0, "vrm0: cannot migrate");
|
||||
|
||||
@@ -12,20 +12,14 @@ namespace UniVRM10
|
||||
{
|
||||
public static byte[] Migrate(byte[] src)
|
||||
{
|
||||
var glb = UniGLTF.Glb.Parse(src);
|
||||
var json = glb.Json.Bytes.ParseAsJson();
|
||||
return Migrate(json, glb.Binary.Bytes);
|
||||
var data = new UniGLTF.GlbBinaryParser(src).Parse();
|
||||
return Migrate(data);
|
||||
}
|
||||
|
||||
public static byte[] Migrate(JsonNode json, ArraySegment<byte> bin)
|
||||
public static byte[] Migrate(UniGLTF.GltfData data)
|
||||
{
|
||||
var gltf = UniGLTF.GltfDeserializer.Deserialize(json);
|
||||
|
||||
// attach glb bin to buffer
|
||||
foreach (var buffer in gltf.buffers)
|
||||
{
|
||||
buffer.OpenStorage(new UniGLTF.SimpleStorage(bin));
|
||||
}
|
||||
var gltf = data.GLTF;
|
||||
var json = data.Json.ParseAsJson();
|
||||
|
||||
// https://github.com/vrm-c/vrm-specification/issues/205
|
||||
RotateY180.Rotate(gltf);
|
||||
@@ -107,7 +101,7 @@ namespace UniVRM10
|
||||
vrm1Json = f.GetStoreBytes();
|
||||
}
|
||||
// JSON 部分だけが改変されて、BIN はそのまま
|
||||
return UniGLTF.Glb.Create(vrm1Json, bin).ToBytes();
|
||||
return UniGLTF.Glb.Create(vrm1Json, data.Bin).ToBytes();
|
||||
}
|
||||
|
||||
public static void Check(JsonNode vrm0, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm1)
|
||||
@@ -121,4 +115,5 @@ namespace UniVRM10
|
||||
// Migration.CheckSpringBone(vrm0["secondaryAnimation"], vrm1.sp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user