This commit is contained in:
ousttrue 2021-04-09 12:20:26 +09:00
parent 20af5606a0
commit 5a86d036bf
3 changed files with 22 additions and 5 deletions

View File

@ -226,6 +226,18 @@ namespace UniVRM10
await LoadConstraintAsync(awaitCaller, controller);
}
static ExpressionKey Key(UniGLTF.Extensions.VRMC_vrm.Expression e)
{
if (e.Preset == UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.custom)
{
return ExpressionKey.CreateCustom(e.Name);
}
else
{
return ExpressionKey.CreateFromPreset(e.Preset);
}
}
async Task LoadVrmAsync(IAwaitCaller awaitCaller, VRM10Controller controller, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm)
{
// meta
@ -281,7 +293,7 @@ namespace UniVRM10
var clip = ScriptableObject.CreateInstance<UniVRM10.VRM10Expression>();
clip.Preset = expression.Preset;
clip.ExpressionName = expression.Name;
clip.name = expression.ExtractName();
clip.name = Key(expression).ExtractKey;
clip.IsBinary = expression.IsBinary.GetValueOrDefault();
clip.OverrideBlink = expression.OverrideBlink;
clip.OverrideLookAt = expression.OverrideLookAt;

View File

@ -1,8 +1,7 @@
using System;
// using System.Collections.Generic;
using System.Linq;
using UniGLTF;
using UniGLTF.ShaderPropExporter;
// using UniGLTF.ShaderPropExporter;
using UnityEngine;
using VRMShaders;

View File

@ -14,12 +14,17 @@ namespace UniVRM10
{
var glb = UniGLTF.Glb.Parse(src);
var json = glb.Json.Bytes.ParseAsJson();
return Migrate(json, glb.Binary.Bytes);
}
public static byte[] Migrate(JsonNode json, ArraySegment<byte> bin)
{
var gltf = UniGLTF.GltfDeserializer.Deserialize(json);
// attach glb bin to buffer
foreach (var buffer in gltf.buffers)
{
buffer.OpenStorage(new UniGLTF.SimpleStorage(glb.Binary.Bytes));
buffer.OpenStorage(new UniGLTF.SimpleStorage(bin));
}
// https://github.com/vrm-c/vrm-specification/issues/205
@ -71,7 +76,8 @@ namespace UniVRM10
UniGLTF.GltfSerializer.Serialize(f, gltf);
vrm1Json = f.GetStoreBytes();
}
return UniGLTF.Glb.Create(vrm1Json, glb.Binary.Bytes).ToBytes();
// JSON 部分だけが改変されて、BIN はそのまま
return UniGLTF.Glb.Create(vrm1Json, bin).ToBytes();
}
public static void Check(JsonNode vrm0, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm1)