diff --git a/Assets/VRM/Runtime/Format/VRMFormat.cs b/Assets/VRM/Runtime/Format/glTF_VRM_extensions.cs similarity index 61% rename from Assets/VRM/Runtime/Format/VRMFormat.cs rename to Assets/VRM/Runtime/Format/glTF_VRM_extensions.cs index 548ab400c..26340156d 100644 --- a/Assets/VRM/Runtime/Format/VRMFormat.cs +++ b/Assets/VRM/Runtime/Format/glTF_VRM_extensions.cs @@ -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 materialProperties = new List(); + + 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; + } } } diff --git a/Assets/VRM/Runtime/Format/VRMFormat.cs.meta b/Assets/VRM/Runtime/Format/glTF_VRM_extensions.cs.meta similarity index 71% rename from Assets/VRM/Runtime/Format/VRMFormat.cs.meta rename to Assets/VRM/Runtime/Format/glTF_VRM_extensions.cs.meta index ae2eaf1f5..5cf92e8ef 100644 --- a/Assets/VRM/Runtime/Format/VRMFormat.cs.meta +++ b/Assets/VRM/Runtime/Format/glTF_VRM_extensions.cs.meta @@ -1,7 +1,5 @@ fileFormatVersion: 2 -guid: 20eca00211c61d047b586f852b818b8f -timeCreated: 1517308526 -licenseType: Free +guid: d58b001b3cfa63e41b4d2d6afa403f5d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/VRM/Runtime/IO/VRMImporterContext.cs b/Assets/VRM/Runtime/IO/VRMImporterContext.cs index 96a8ee827..9921b6ba2 100644 --- a/Assets/VRM/Runtime/IO/VRMImporterContext.cs +++ b/Assets/VRM/Runtime/IO/VRMImporterContext.cs @@ -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)); }