From 0d47703bd905f1786279f9f15b1bfbf9bce87145 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 19 Jul 2018 23:05:17 +0900 Subject: [PATCH] "class glTF_VRM: gltf" to "partial class glTF_extensions" --- Scripts/Editor/VRMTest.cs | 4 +- Scripts/FirstPerson/VRMFirstPerson.cs | 2 +- .../Format/Editor/vrmAssetPostprocessor.cs | 2 +- Scripts/Format/VRMExporter.cs | 8 +-- Scripts/Format/VRMFormat.cs | 56 +++++++++---------- Scripts/Format/VRMImporter.cs | 26 ++++----- Scripts/Format/VRMImporterContext.cs | 23 ++------ Scripts/Format/VRMVersion.cs | 3 - Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs | 2 +- Scripts/LookAt/VRMLookAtBoneApplyer.cs | 2 +- Scripts/LookAt/VRMLookAtHead.cs | 2 +- UniGLTF | 2 +- 12 files changed, 58 insertions(+), 74 deletions(-) diff --git a/Scripts/Editor/VRMTest.cs b/Scripts/Editor/VRMTest.cs index ffc3ef331..595d62b1b 100644 --- a/Scripts/Editor/VRMTest.cs +++ b/Scripts/Editor/VRMTest.cs @@ -59,9 +59,9 @@ public class VRMTest exporter.Export(); // import - context.ParseJson(gltf.ToJson(), new SimpleStorage()); + context.ParseJson(gltf.ToJson(), new SimpleStorage()); Debug.LogFormat("{0}", context.Json); - gltfImporter.Import(context); + gltfImporter.Import(context); AssertAreEqual(go.transform, context.Root.transform); } diff --git a/Scripts/FirstPerson/VRMFirstPerson.cs b/Scripts/FirstPerson/VRMFirstPerson.cs index 2deaa5724..41e7cfaf6 100644 --- a/Scripts/FirstPerson/VRMFirstPerson.cs +++ b/Scripts/FirstPerson/VRMFirstPerson.cs @@ -121,7 +121,7 @@ namespace VRM return FirstPersonFlag.Auto; } - foreach(var x in context.VRM.extensions.VRM.firstPerson.meshAnnotations) + foreach(var x in context.GLTF.extensions.VRM.firstPerson.meshAnnotations) { if (x.mesh == index) { diff --git a/Scripts/Format/Editor/vrmAssetPostprocessor.cs b/Scripts/Format/Editor/vrmAssetPostprocessor.cs index 771e608c3..f3bc97c8d 100644 --- a/Scripts/Format/Editor/vrmAssetPostprocessor.cs +++ b/Scripts/Format/Editor/vrmAssetPostprocessor.cs @@ -18,7 +18,7 @@ namespace VRM { var context = new VRMImporterContext(path); - context.ParseVrm(File.ReadAllBytes(context.Path)); + context.ParseGlb(File.ReadAllBytes(context.Path)); // // https://answers.unity.com/questions/647615/how-to-update-import-settings-for-newly-created-as.html diff --git a/Scripts/Format/VRMExporter.cs b/Scripts/Format/VRMExporter.cs index b393d1ac8..1f4197c13 100644 --- a/Scripts/Format/VRMExporter.cs +++ b/Scripts/Format/VRMExporter.cs @@ -9,12 +9,12 @@ namespace VRM { public class VRMExporter : gltfExporter { - public VRMExporter(glTF_VRM gltf) : base(gltf) + public VRMExporter(glTF gltf) : base(gltf) { } - public static glTF_VRM Export(GameObject go) + public static glTF Export(GameObject go) { - var gltf = new glTF_VRM(); + var gltf = new glTF(); using (var exporter = new VRMExporter(gltf) { #if VRM_EXPORTER_USE_SPARSE @@ -30,7 +30,7 @@ namespace VRM return gltf; } - public static void _Export(glTF_VRM gltf, VRMExporter exporter, GameObject go) + public static void _Export(glTF gltf, VRMExporter exporter, GameObject go) { exporter.Prepare(go); exporter.Export(); diff --git a/Scripts/Format/VRMFormat.cs b/Scripts/Format/VRMFormat.cs index 01df5792c..ee31f697c 100644 --- a/Scripts/Format/VRMFormat.cs +++ b/Scripts/Format/VRMFormat.cs @@ -3,6 +3,34 @@ using System.Collections.Generic; using UniGLTF; +namespace UniGLTF +{ + public partial class glTFUsedExtensions + { + [UsedExtension] + static string VRMGetUsedExtension + { + get + { + return "VRM"; + } + } + } + + [Serializable] + public partial class glTF_extensions : JsonSerializableBase + { + public VRM.glTF_VRM_extensions VRM = new VRM.glTF_VRM_extensions(); + + [JsonSerializeMembers] + void VRMSerializeMembers(GLTFJsonFormatter f) + { + f.KeyValue(() => VRM); + } + } +} + + namespace VRM { [Serializable] @@ -28,32 +56,4 @@ namespace VRM f.KeyValue(() => materialProperties); } } - - [Serializable] - public class glTF_extensions : JsonSerializableBase - { - public glTF_VRM_extensions VRM = new glTF_VRM_extensions(); - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => VRM); - } - } - - [Serializable] - public class glTF_VRM : glTF - { - public glTF_extensions extensions = new glTF_extensions(); - public List extensionsUsed = new List - { - "VRM", - }; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => extensionsUsed); - f.KeyValue(() => extensions); - base.SerializeMembers(f); - } - } } diff --git a/Scripts/Format/VRMImporter.cs b/Scripts/Format/VRMImporter.cs index f7dfcafe5..afb0286a7 100644 --- a/Scripts/Format/VRMImporter.cs +++ b/Scripts/Format/VRMImporter.cs @@ -21,7 +21,7 @@ namespace VRM public static GameObject LoadFromPath(string path) { var context = new VRMImporterContext(path); - context.ParseVrm(File.ReadAllBytes(path)); + context.ParseGlb(File.ReadAllBytes(path)); LoadFromBytes(context); return context.Root; } @@ -29,14 +29,14 @@ namespace VRM public static GameObject LoadFromBytes(Byte[] bytes) { var context = new VRMImporterContext(); - context.ParseVrm(bytes); + context.ParseGlb(bytes); LoadFromBytes(context); return context.Root; } public static void LoadFromPath(VRMImporterContext context) { - context.ParseVrm(File.ReadAllBytes(context.Path)); + context.ParseGlb(File.ReadAllBytes(context.Path)); LoadFromBytes(context); } @@ -44,16 +44,16 @@ namespace VRM { context.CreateMaterial = VRMImporter.GetMaterialFunc(glTF_VRM_Material.Parse(context.Json)); - gltfImporter.Import(context); + gltfImporter.Import(context); if (string.IsNullOrEmpty(context.Path)) { - if (string.IsNullOrEmpty(context.VRM.extensions.VRM.meta.title)) + if (string.IsNullOrEmpty(context.GLTF.extensions.VRM.meta.title)) { context.Root.name = "VRM_LOADED"; } else { - context.Root.name = context.VRM.extensions.VRM.meta.title; + context.Root.name = context.GLTF.extensions.VRM.meta.title; } } else @@ -82,7 +82,7 @@ namespace VRM var CreateZWrite = gltfImporter.CreateMaterialFuncFromShader(new ShaderStore("VRM/UnlitTransparentZWrite")); CreateMaterialFunc fallback = (ctx, i) => { - var vrm = ctx.GLTF as glTF_VRM; + var vrm = ctx.GLTF; if (vrm != null && vrm.materials[i].name.ToLower().Contains("zwrite")) { // 一応。不要かも @@ -184,7 +184,7 @@ namespace VRM LoadBlendShapeMaster(context); VRMSpringUtility.LoadSecondary(context.Root.transform, context.Nodes, - context.VRM.extensions.VRM.secondaryAnimation); + context.GLTF.extensions.VRM.secondaryAnimation); LoadFirstPerson(context); return Unit.Default; @@ -213,7 +213,7 @@ namespace VRM { var firstPerson = context.Root.AddComponent(); - var gltfFirstPerson = context.VRM.extensions.VRM.firstPerson; + var gltfFirstPerson = context.GLTF.extensions.VRM.firstPerson; if (gltfFirstPerson.firstPersonBone != -1) { firstPerson.FirstPersonBone = context.Nodes[gltfFirstPerson.firstPersonBone]; @@ -236,7 +236,7 @@ namespace VRM context.BlendShapeAvatar = ScriptableObject.CreateInstance(); context.BlendShapeAvatar.name = "BlendShape"; - var blendShapeList = context.VRM.extensions.VRM.blendShapeMaster.blendShapeGroups; + var blendShapeList = context.GLTF.extensions.VRM.blendShapeMaster.blendShapeGroups; if (blendShapeList != null && blendShapeList.Count > 0) { foreach (var x in blendShapeList) @@ -386,7 +386,7 @@ namespace VRM private static void LoadHumanoid(VRMImporterContext context) { - context.AvatarDescription = context.VRM.extensions.VRM.humanoid.ToDescription(context.Nodes); + context.AvatarDescription = context.GLTF.extensions.VRM.humanoid.ToDescription(context.Nodes); context.AvatarDescription.name = "AvatarDescription"; context.HumanoidAvatar = context.AvatarDescription.CreateAvatar(context.Root.transform); context.HumanoidAvatar.name = Path.GetFileNameWithoutExtension(context.Path); @@ -512,14 +512,14 @@ namespace VRM public static void LoadVrmAsync(string path, Action onLoaded, Action onError = null, bool show = true) { var context = new VRMImporterContext(path); - context.ParseVrm(File.ReadAllBytes(path)); + context.ParseGlb(File.ReadAllBytes(path)); LoadVrmAsync(context, onLoaded, onError, show); } public static void LoadVrmAsync(Byte[] bytes, Action onLoaded, Action onError = null, bool show = true) { var context = new VRMImporterContext(); - context.ParseVrm(bytes); + context.ParseGlb(bytes); LoadVrmAsync(context, onLoaded, onError, show); } diff --git a/Scripts/Format/VRMImporterContext.cs b/Scripts/Format/VRMImporterContext.cs index a341fb1ee..924cf8693 100644 --- a/Scripts/Format/VRMImporterContext.cs +++ b/Scripts/Format/VRMImporterContext.cs @@ -21,26 +21,13 @@ namespace VRM public BlendShapeAvatar BlendShapeAvatar; public VRMMetaObject Meta; - public glTF_VRM VRM - { - get - { - return (glTF_VRM)GLTF; - } - } - - public void ParseVrm(byte[] bytes) - { - ParseGlb(bytes); - } - public VRMMetaObject ReadMeta(bool createThumbnail=false) { var meta=ScriptableObject.CreateInstance(); meta.name = "Meta"; - meta.ExporterVersion = VRM.extensions.VRM.exporterVersion; + meta.ExporterVersion = GLTF.extensions.VRM.exporterVersion; - var gltfMeta = VRM.extensions.VRM.meta; + var gltfMeta = GLTF.extensions.VRM.meta; meta.Version = gltfMeta.version; // model version meta.Author = gltfMeta.author; meta.ContactInformation = gltfMeta.contactInformation; @@ -55,10 +42,10 @@ namespace VRM else if (createThumbnail) { // 作成する(先行ロード用) - if(gltfMeta.texture >= 0 && gltfMeta.texture < VRM.textures.Count) + if(gltfMeta.texture >= 0 && gltfMeta.texture < GLTF.textures.Count) { - var t = new TextureItem(VRM, gltfMeta.texture); - t.Process(VRM, Storage); + var t = new TextureItem(GLTF, gltfMeta.texture); + t.Process(GLTF, Storage); meta.Thumbnail=t.Texture; } } diff --git a/Scripts/Format/VRMVersion.cs b/Scripts/Format/VRMVersion.cs index dd6b57c99..dea8ea797 100644 --- a/Scripts/Format/VRMVersion.cs +++ b/Scripts/Format/VRMVersion.cs @@ -7,8 +7,5 @@ namespace VRM public const int MINOR = 41; public const string VERSION = "0.41"; - - public const string DecrementMenuName = "VRM/Version(0.41) Decrement"; - public const string IncrementMenuName = "VRM/Version(0.41) Increment"; } } diff --git a/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs b/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs index a53ba3061..6da7ab3d1 100644 --- a/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs +++ b/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs @@ -19,7 +19,7 @@ namespace VRM public void OnImported(VRMImporterContext context) { - var gltfFirstPerson = context.VRM.extensions.VRM.firstPerson; + var gltfFirstPerson = context.GLTF.extensions.VRM.firstPerson; Horizontal.Apply(gltfFirstPerson.lookAtHorizontalOuter); VerticalDown.Apply(gltfFirstPerson.lookAtVerticalDown); VerticalUp.Apply(gltfFirstPerson.lookAtVerticalUp); diff --git a/Scripts/LookAt/VRMLookAtBoneApplyer.cs b/Scripts/LookAt/VRMLookAtBoneApplyer.cs index d6588820e..9acd842a9 100644 --- a/Scripts/LookAt/VRMLookAtBoneApplyer.cs +++ b/Scripts/LookAt/VRMLookAtBoneApplyer.cs @@ -36,7 +36,7 @@ namespace VRM RightEye = OffsetOnTransform.Create(animator.GetBoneTransform(HumanBodyBones.RightEye)); } - var gltfFirstPerson = context.VRM.extensions.VRM.firstPerson; + var gltfFirstPerson = context.GLTF.extensions.VRM.firstPerson; HorizontalInner.Apply(gltfFirstPerson.lookAtHorizontalInner); HorizontalOuter.Apply(gltfFirstPerson.lookAtHorizontalOuter); VerticalDown.Apply(gltfFirstPerson.lookAtVerticalDown); diff --git a/Scripts/LookAt/VRMLookAtHead.cs b/Scripts/LookAt/VRMLookAtHead.cs index 82bfc983a..2888ba870 100644 --- a/Scripts/LookAt/VRMLookAtHead.cs +++ b/Scripts/LookAt/VRMLookAtHead.cs @@ -90,7 +90,7 @@ namespace VRM Head = OffsetOnTransform.Create(head); - var gltfFirstPerson = context.VRM.extensions.VRM.firstPerson; + var gltfFirstPerson = context.GLTF.extensions.VRM.firstPerson; switch (gltfFirstPerson.lookAtType) { case LookAtType.Bone: diff --git a/UniGLTF b/UniGLTF index 8aec1ffb9..45cac4d45 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit 8aec1ffb9fab67f681250481f2b150d51ee75411 +Subproject commit 45cac4d45646da00709e479f86eb6d0b9d41c5ca