update thumbnail migration

This commit is contained in:
ousttrue 2021-09-07 15:06:51 +09:00
parent f0aedd454e
commit c365dd41fc
2 changed files with 22 additions and 3 deletions

View File

@ -38,7 +38,7 @@ namespace UniVRM10
var vrm1 = new UniGLTF.Extensions.VRMC_vrm.VRMC_vrm();
// meta (required)
vrm1.Meta = MigrationVrmMeta.Migrate(vrm0["meta"]);
vrm1.Meta = MigrationVrmMeta.Migrate(gltf, vrm0["meta"]);
// humanoid (required)
vrm1.Humanoid = MigrationVrmHumanoid.Migrate(vrm0["humanoid"]);

View File

@ -27,7 +27,7 @@ namespace UniVRM10
// },
public static class MigrationVrmMeta
{
public static UniGLTF.Extensions.VRMC_vrm.Meta Migrate(JsonNode vrm0)
public static UniGLTF.Extensions.VRMC_vrm.Meta Migrate(UniGLTF.glTF gltf, JsonNode vrm0)
{
var meta = new UniGLTF.Extensions.VRMC_vrm.Meta
{
@ -54,7 +54,26 @@ namespace UniVRM10
case "author": meta.Authors = new List<string>() { kv.Value.GetString() }; break;
case "contactInformation": meta.ContactInformation = kv.Value.GetString(); break;
case "reference": meta.References = new List<string>() { kv.Value.GetString() }; break;
case "texture": meta.ThumbnailImage = kv.Value.GetInt32(); break;
case "texture":
{
// vrm0x use texture. vrm10 use image
var textureIndex = kv.Value.GetInt32();
var gltfTexture = gltf.textures[textureIndex];
meta.ThumbnailImage = gltfTexture.source;
var gltfImage = gltf.images[gltfTexture.source];
if (string.IsNullOrEmpty(gltfImage.name))
{
// use texture name
gltfImage.name = gltfTexture.name;
if (string.IsNullOrEmpty(gltfImage.name))
{
// fall back default name
gltfImage.name = "__VRM10_thumbnail__";
}
}
break;
}
case "allowedUserName":
{