glTF_VRM_extensions.TryDeserilize

This commit is contained in:
ousttrue 2020-12-02 15:27:31 +09:00
parent 1bc63f503a
commit 34f3cbbd92
3 changed files with 26 additions and 20 deletions

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using UniGLTF;
using UniJSON;
namespace VRM
{
@ -11,13 +11,9 @@ VRM extension is for 3d humanoid avatars (and models) in VR applications.
")]
public class glTF_VRM_extensions
{
public static string ExtensionName
{
get
{
return "VRM";
}
}
public const string ExtensionName = "VRM";
public static readonly Utf8String ExtensionNameUtf8 = Utf8String.From(ExtensionName);
[JsonSchema(Description = @"Version of exporter that vrm created. " + VRMVersion.VRM_VERSION)]
public string exporterVersion = "UniVRM-" + VRMVersion.VERSION;
@ -31,5 +27,23 @@ VRM extension is for 3d humanoid avatars (and models) in VR applications.
public glTF_VRM_BlendShapeMaster blendShapeMaster = new glTF_VRM_BlendShapeMaster();
public glTF_VRM_SecondaryAnimation secondaryAnimation = new glTF_VRM_SecondaryAnimation();
public List<glTF_VRM_Material> materialProperties = new List<glTF_VRM_Material>();
public static bool TryDeserilize(glTFExtension extension, out glTF_VRM_extensions vrm)
{
if (extension is glTFExtensionImport import)
{
foreach (var kv in import.ObjectItems())
{
if (kv.Key.GetUtf8String() == ExtensionNameUtf8)
{
vrm = VrmDeserializer.Deserialize(kv.Value);
return true;
}
}
}
vrm = default;
return false;
}
}
}

View File

@ -1,7 +1,5 @@
fileFormatVersion: 2
guid: 20eca00211c61d047b586f852b818b8f
timeCreated: 1517308526
licenseType: Free
guid: d58b001b3cfa63e41b4d2d6afa403f5d
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -38,18 +38,12 @@ namespace VRM
base.ParseJson(json, storage);
// parse VRM part
if (GLTF.extensions is glTFExtensionImport imported)
if (glTF_VRM_extensions.TryDeserilize(GLTF.extensions, out glTF_VRM_extensions vrm))
{
foreach (var kv in imported.ObjectItems())
{
if (kv.Key.GetString() == "VRM")
{
VRM = VrmDeserializer.Deserialize(kv.Value);
break;
}
}
VRM = vrm;
}
// override material importer
SetMaterialImporter(new VRMMaterialImporter(this, VRM.materialProperties));
}