From 3dcec1376f501d0e9607bffb38705aca7d95a5a5 Mon Sep 17 00:00:00 2001 From: hiroj Date: Fri, 29 May 2020 15:23:32 +0900 Subject: [PATCH 1/3] add CacheEnum --- .../VRM/UniGLTF/Editor/Tests/CacheEnumTest.cs | 21 ++++ .../Editor/Tests/CacheEnumTest.cs.meta | 11 ++ Assets/VRM/UniGLTF/Scripts/Util.meta | 8 ++ Assets/VRM/UniGLTF/Scripts/Util/CacheEnum.cs | 100 ++++++++++++++++++ .../UniGLTF/Scripts/Util/CacheEnum.cs.meta | 11 ++ 5 files changed, 151 insertions(+) create mode 100644 Assets/VRM/UniGLTF/Editor/Tests/CacheEnumTest.cs create mode 100644 Assets/VRM/UniGLTF/Editor/Tests/CacheEnumTest.cs.meta create mode 100644 Assets/VRM/UniGLTF/Scripts/Util.meta create mode 100644 Assets/VRM/UniGLTF/Scripts/Util/CacheEnum.cs create mode 100644 Assets/VRM/UniGLTF/Scripts/Util/CacheEnum.cs.meta diff --git a/Assets/VRM/UniGLTF/Editor/Tests/CacheEnumTest.cs b/Assets/VRM/UniGLTF/Editor/Tests/CacheEnumTest.cs new file mode 100644 index 000000000..a1e3a2ac0 --- /dev/null +++ b/Assets/VRM/UniGLTF/Editor/Tests/CacheEnumTest.cs @@ -0,0 +1,21 @@ +using NUnit.Framework; +using UnityEngine; + + +namespace UniGLTF +{ + public class CacheEnumTest + { + [Test] + public void CacheEnumTestSimplePasses() + { + Assert.AreEqual(default(HumanBodyBones), CacheEnum.TryParseOrDefault("xxx")); + +#if UNITY_5_6_OR_NEWER + Assert.AreEqual(HumanBodyBones.UpperChest, CacheEnum.TryParseOrDefault("upperchest", true)); +#else + Assert.AreEqual(default(HumanBodyBones), CacheEnum.TryParseOrDefault("upperchest")); +#endif + } + } +} diff --git a/Assets/VRM/UniGLTF/Editor/Tests/CacheEnumTest.cs.meta b/Assets/VRM/UniGLTF/Editor/Tests/CacheEnumTest.cs.meta new file mode 100644 index 000000000..5b29bb588 --- /dev/null +++ b/Assets/VRM/UniGLTF/Editor/Tests/CacheEnumTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9051db9a028cfa64bacbae8644969dd0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniGLTF/Scripts/Util.meta b/Assets/VRM/UniGLTF/Scripts/Util.meta new file mode 100644 index 000000000..d519486c3 --- /dev/null +++ b/Assets/VRM/UniGLTF/Scripts/Util.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 980062d19c06cb347b7a8874479d90b7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniGLTF/Scripts/Util/CacheEnum.cs b/Assets/VRM/UniGLTF/Scripts/Util/CacheEnum.cs new file mode 100644 index 000000000..5c90f6282 --- /dev/null +++ b/Assets/VRM/UniGLTF/Scripts/Util/CacheEnum.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace UniGLTF +{ + public sealed class CacheEnum + { + public static T Parse(string name, bool ignoreCase = false) where T : struct, Enum + { + if(ignoreCase) + { + return CacheParse.ParseIgnoreCase(name); + } + else + { + return CacheParse.Parse(name); + } + } + + public static T TryParseOrDefault(string name, bool ignoreCase = false, T defaultValue=default(T)) where T : struct, Enum + { + try + { + if(ignoreCase) + { + return CacheParse.ParseIgnoreCase(name); + } + else + { + return CacheParse.Parse(name); + } + } + catch + { + return defaultValue; + } + } + + public static T[] GetValues() where T : struct, Enum + { + return CacheValues.Values; + } + + private static class CacheParse where T : struct, Enum + { + private static Dictionary _values = new Dictionary(); + private static Dictionary _ignoreCaseValues = new Dictionary(StringComparer.OrdinalIgnoreCase); + + static CacheParse() + { + } + + public static T ParseIgnoreCase(string name) + { + if(_ignoreCaseValues.TryGetValue(name, out var value)) + { + return value; + } + else + { + T result; + value = Enum.TryParse(name, true, out result) + ? result + : throw new ArgumentException(nameof(result)); + _ignoreCaseValues.Add(name, value); + return value; + } + } + + public static T Parse(string name) + { + if(_values.TryGetValue(name, out var value)) + { + return value; + } + else + { + T result; + value = Enum.TryParse(name, false, out result) + ? result + : throw new ArgumentException(nameof(result)); + _values.Add(name, value); + return value; + } + } + } + + private static class CacheValues where T : struct, Enum + { + public static readonly T[] Values; + + static CacheValues() + { + Values = Enum.GetValues(typeof(T)) as T[]; + } + } + } +} + diff --git a/Assets/VRM/UniGLTF/Scripts/Util/CacheEnum.cs.meta b/Assets/VRM/UniGLTF/Scripts/Util/CacheEnum.cs.meta new file mode 100644 index 000000000..523c73135 --- /dev/null +++ b/Assets/VRM/UniGLTF/Scripts/Util/CacheEnum.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 517a813d69d7a774f8277f39bfde8a76 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 4a3f4c354838edd18f610faca8276cd8b72cd95b Mon Sep 17 00:00:00 2001 From: hiroj Date: Fri, 29 May 2020 15:33:25 +0900 Subject: [PATCH 2/3] EnumUtil to CacheEnum --- .../Scripts/BlendShape/BlendShapeAvatar.cs | 18 +++++++++++++++--- .../Scripts/FirstPerson/VRMFirstPerson.cs | 2 +- .../Scripts/Format/VRMImporterContext.cs | 4 ++-- .../Scripts/Format/glTF_VRM_FirstPerson.cs | 2 +- .../UniVRM/Scripts/Format/glTF_VRM_Humanoid.cs | 6 +++--- .../VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs | 6 +++--- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Assets/VRM/UniVRM/Scripts/BlendShape/BlendShapeAvatar.cs b/Assets/VRM/UniVRM/Scripts/BlendShape/BlendShapeAvatar.cs index 60df90e52..62b164b5c 100644 --- a/Assets/VRM/UniVRM/Scripts/BlendShape/BlendShapeAvatar.cs +++ b/Assets/VRM/UniVRM/Scripts/BlendShape/BlendShapeAvatar.cs @@ -79,17 +79,29 @@ namespace VRM /// public void CreateDefaultPreset() { - foreach (var preset in ((BlendShapePreset[])Enum.GetValues(typeof(BlendShapePreset))) - .Where(x => x != BlendShapePreset.Unknown)) + var presets = CacheEnum.GetValues(); + + foreach (var preset in presets) { + if (preset == BlendShapePreset.Unknown) continue; CreateDefaultPreset(preset); } } void CreateDefaultPreset(BlendShapePreset preset) { - var clip = GetClip(preset); + BlendShapeClip clip = null; + + foreach (var c in Clips) + { + if (c.Preset == preset) + { + clip = c; + break; + } + } if (clip != null) return; + clip = ScriptableObject.CreateInstance(); clip.name = preset.ToString(); clip.BlendShapeName = preset.ToString(); diff --git a/Assets/VRM/UniVRM/Scripts/FirstPerson/VRMFirstPerson.cs b/Assets/VRM/UniVRM/Scripts/FirstPerson/VRMFirstPerson.cs index 5e9b1d076..c5bf7ac2e 100644 --- a/Assets/VRM/UniVRM/Scripts/FirstPerson/VRMFirstPerson.cs +++ b/Assets/VRM/UniVRM/Scripts/FirstPerson/VRMFirstPerson.cs @@ -128,7 +128,7 @@ namespace VRM { if (x.mesh == index) { - return EnumUtil.TryParseOrDefault(x.firstPersonFlag); + return CacheEnum.TryParseOrDefault(x.firstPersonFlag, true); } } diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMImporterContext.cs b/Assets/VRM/UniVRM/Scripts/Format/VRMImporterContext.cs index a4d092286..a13629540 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMImporterContext.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/VRMImporterContext.cs @@ -158,12 +158,12 @@ namespace VRM if (group != null) { asset.BlendShapeName = groupName; - asset.Preset = EnumUtil.TryParseOrDefault(group.presetName); + asset.Preset = CacheEnum.TryParseOrDefault(group.presetName, true); asset.IsBinary = group.isBinary; if (asset.Preset == BlendShapePreset.Unknown) { // fallback - asset.Preset = EnumUtil.TryParseOrDefault(group.name); + asset.Preset = CacheEnum.TryParseOrDefault(group.name, true); } asset.Values = group.binds.Select(x => { diff --git a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_FirstPerson.cs b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_FirstPerson.cs index 57bcf85a0..d376478fa 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_FirstPerson.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_FirstPerson.cs @@ -87,7 +87,7 @@ namespace VRM { get { - return EnumUtil.TryParseOrDefault(lookAtTypeName); + return CacheEnum.TryParseOrDefault(lookAtTypeName, true); } set { lookAtTypeName = value.ToString(); } } diff --git a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Humanoid.cs b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Humanoid.cs index 5061ff7e2..6065a38da 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Humanoid.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Humanoid.cs @@ -73,7 +73,7 @@ namespace VRM { public static VRMBone FromHumanBodyBone(this HumanBodyBones human) { - return EnumUtil.TryParseOrDefault(human.ToString(), VRMBone.unknown); + return human.ToVrmBone(); } public static HumanBodyBones ToHumanBodyBone(this VRMBone bone) @@ -85,7 +85,7 @@ namespace VRM return HumanBodyBones.LastBone; } #endif - return EnumUtil.TryParseOrDefault(bone.ToString(), HumanBodyBones.LastBone); + return bone.ToUnityBone(); } } @@ -161,7 +161,7 @@ namespace VRM } get { - return EnumUtil.TryParseOrDefault(bone); + return CacheEnum.Parse(bone, true); } } diff --git a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs index c88c22dc0..7610142ff 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs @@ -36,7 +36,7 @@ namespace VRM { static UssageLicense FromString(string src) { - return EnumUtil.TryParseOrDefault(src); + return CacheEnum.TryParseOrDefault(src, true); } [JsonSchema(Description = "Title of VRM model")] @@ -69,7 +69,7 @@ namespace VRM { get { - return EnumUtil.TryParseOrDefault(allowedUserName); + return CacheEnum.TryParseOrDefault(allowedUserName, true); } set { @@ -135,7 +135,7 @@ namespace VRM { get { - return EnumUtil.TryParseOrDefault(licenseName); + return CacheEnum.TryParseOrDefault(licenseName, true); } set { From 9441a74758720d900a7a71f949ee289cae515908 Mon Sep 17 00:00:00 2001 From: hiroj Date: Fri, 29 May 2020 15:36:46 +0900 Subject: [PATCH 3/3] add EnumExtensions --- .../VRM/UniHumanoid/Scripts/Extensions.meta | 8 + .../Scripts/Extensions/EnumExtensions.cs | 71 +++++++++ .../Scripts/Extensions/EnumExtensions.cs.meta | 11 ++ Assets/VRM/UniVRM/Scripts/Extensions.meta | 8 + .../Scripts/Extensions/EnumExtensions.cs | 137 ++++++++++++++++++ .../Scripts/Extensions/EnumExtensions.cs.meta | 11 ++ 6 files changed, 246 insertions(+) create mode 100644 Assets/VRM/UniHumanoid/Scripts/Extensions.meta create mode 100644 Assets/VRM/UniHumanoid/Scripts/Extensions/EnumExtensions.cs create mode 100644 Assets/VRM/UniHumanoid/Scripts/Extensions/EnumExtensions.cs.meta create mode 100644 Assets/VRM/UniVRM/Scripts/Extensions.meta create mode 100644 Assets/VRM/UniVRM/Scripts/Extensions/EnumExtensions.cs create mode 100644 Assets/VRM/UniVRM/Scripts/Extensions/EnumExtensions.cs.meta diff --git a/Assets/VRM/UniHumanoid/Scripts/Extensions.meta b/Assets/VRM/UniHumanoid/Scripts/Extensions.meta new file mode 100644 index 000000000..e559e8cb3 --- /dev/null +++ b/Assets/VRM/UniHumanoid/Scripts/Extensions.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a08328e411d14d8419fc89356b6ddbc4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniHumanoid/Scripts/Extensions/EnumExtensions.cs b/Assets/VRM/UniHumanoid/Scripts/Extensions/EnumExtensions.cs new file mode 100644 index 000000000..8ae5d2df4 --- /dev/null +++ b/Assets/VRM/UniHumanoid/Scripts/Extensions/EnumExtensions.cs @@ -0,0 +1,71 @@ +using UnityEngine; + +namespace UniHumanoid +{ + public static class EnumExtensions + { + public static string ToStringFromEnum(this HumanBodyBones val, bool compareBoneTrait = false) + { + switch (val) + { + case HumanBodyBones.Hips: return "Hips"; + case HumanBodyBones.LeftUpperLeg: return "LeftUpperLeg"; + case HumanBodyBones.RightUpperLeg: return "RightUpperLeg"; + case HumanBodyBones.LeftLowerLeg: return "LeftLowerLeg"; + case HumanBodyBones.RightLowerLeg: return "RightLowerLeg"; + case HumanBodyBones.LeftFoot: return "LeftFoot"; + case HumanBodyBones.RightFoot: return "RightFoot"; + case HumanBodyBones.Spine: return "Spine"; + case HumanBodyBones.Chest: return "Chest"; + case HumanBodyBones.Neck: return "Neck"; + case HumanBodyBones.Head: return "Head"; + case HumanBodyBones.LeftShoulder: return "LeftShoulder"; + case HumanBodyBones.RightShoulder: return "RightShoulder"; + case HumanBodyBones.LeftUpperArm: return "LeftUpperArm"; + case HumanBodyBones.RightUpperArm: return "RightUpperArm"; + case HumanBodyBones.LeftLowerArm: return "LeftLowerArm"; + case HumanBodyBones.RightLowerArm: return "RightLowerArm"; + case HumanBodyBones.LeftHand: return "LeftHand"; + case HumanBodyBones.RightHand: return "RightHand"; + case HumanBodyBones.LeftToes: return "LeftToes"; + case HumanBodyBones.RightToes: return "RightToes"; + case HumanBodyBones.LeftEye: return "LeftEye"; + case HumanBodyBones.RightEye: return "RightEye"; + case HumanBodyBones.Jaw: return "Jaw"; + case HumanBodyBones.LeftThumbProximal: return compareBoneTrait ? "Left Thumb Proximal" : "LeftThumbProximal"; + case HumanBodyBones.LeftThumbIntermediate: return compareBoneTrait ? "Left Thumb Intermediate" : "LeftThumbIntermediate"; + case HumanBodyBones.LeftThumbDistal: return compareBoneTrait ? "Left Thumb Distal" : "LeftThumbDistal"; + case HumanBodyBones.LeftIndexProximal: return compareBoneTrait ? "Left Index Proximal" : "LeftIndexProximal"; + case HumanBodyBones.LeftIndexIntermediate: return compareBoneTrait ? "Left Index Intermediate" : "LeftIndexIntermediate"; + case HumanBodyBones.LeftIndexDistal: return compareBoneTrait ? "Left Index Distal" : "LeftIndexDistal"; + case HumanBodyBones.LeftMiddleProximal: return compareBoneTrait ? "Left Middle Proximal" : "LeftMiddleProximal"; + case HumanBodyBones.LeftMiddleIntermediate: return compareBoneTrait ? "Left Middle Intermediate" : "LeftMiddleIntermediate"; + case HumanBodyBones.LeftMiddleDistal: return compareBoneTrait ? "Left Middle Distal" : "LeftMiddleDistal"; + case HumanBodyBones.LeftRingProximal: return compareBoneTrait ? "Left Ring Proximal" : "LeftRingProximal"; + case HumanBodyBones.LeftRingIntermediate: return compareBoneTrait ? "Left Ring Intermediate" : "LeftRingIntermediate"; + case HumanBodyBones.LeftRingDistal: return compareBoneTrait ? "Left Ring Distal" : "LeftRingDistal"; + case HumanBodyBones.LeftLittleProximal: return compareBoneTrait ? "Left Little Proximal" : "LeftLittleProximal"; + case HumanBodyBones.LeftLittleIntermediate: return compareBoneTrait ? "Left Little Intermediate" : "LeftLittleIntermediate"; + case HumanBodyBones.LeftLittleDistal: return compareBoneTrait ? "Left Little Distal" : "LeftLittleDistal"; + case HumanBodyBones.RightThumbProximal: return compareBoneTrait ? "Right Thumb Proximal" : "RightThumbProximal"; + case HumanBodyBones.RightThumbIntermediate: return compareBoneTrait ? "Right Thumb Intermediate" : "RightThumbIntermediate"; + case HumanBodyBones.RightThumbDistal: return compareBoneTrait ? "Right Thumb Distal" : "RightThumbDistal"; + case HumanBodyBones.RightIndexProximal: return compareBoneTrait ? "Right Index Proximal" : "RightIndexProximal"; + case HumanBodyBones.RightIndexIntermediate: return compareBoneTrait ? "Right Index Intermediate" : "RightIndexIntermediate"; + case HumanBodyBones.RightIndexDistal: return compareBoneTrait ? "Right Index Distal" : "RightIndexDistal"; + case HumanBodyBones.RightMiddleProximal: return compareBoneTrait ? "Right Middle Proximal" : "RightMiddleProximal"; + case HumanBodyBones.RightMiddleIntermediate: return compareBoneTrait ? "Right Middle Intermediate" : "RightMiddleIntermediate"; + case HumanBodyBones.RightMiddleDistal: return compareBoneTrait ? "Right Middle Distal" : "RightMiddleDistal"; + case HumanBodyBones.RightRingProximal: return compareBoneTrait ? "Right Ring Proximal" : "RightRingProximal"; + case HumanBodyBones.RightRingIntermediate: return compareBoneTrait ? "Right Ring Intermediate" : "RightRingIntermediate"; + case HumanBodyBones.RightRingDistal: return compareBoneTrait ? "Right Ring Distal" : "RightRingDistal"; + case HumanBodyBones.RightLittleProximal: return compareBoneTrait ? "Right Little Proximal" : "RightLittleProximal"; + case HumanBodyBones.RightLittleIntermediate: return compareBoneTrait ? "Right Little Intermediate" : "RightLittleIntermediate"; + case HumanBodyBones.RightLittleDistal: return compareBoneTrait ? "Right Little Distal" : "RightLittleDistal"; + case HumanBodyBones.UpperChest: return "UpperChest"; + case HumanBodyBones.LastBone: return "LastBone"; + default: throw new System.InvalidOperationException(); + } + } + } +} \ No newline at end of file diff --git a/Assets/VRM/UniHumanoid/Scripts/Extensions/EnumExtensions.cs.meta b/Assets/VRM/UniHumanoid/Scripts/Extensions/EnumExtensions.cs.meta new file mode 100644 index 000000000..e9fc631d4 --- /dev/null +++ b/Assets/VRM/UniHumanoid/Scripts/Extensions/EnumExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 04d0b56405dbe18439be5a95598deb36 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniVRM/Scripts/Extensions.meta b/Assets/VRM/UniVRM/Scripts/Extensions.meta new file mode 100644 index 000000000..dd6ebd73c --- /dev/null +++ b/Assets/VRM/UniVRM/Scripts/Extensions.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 62d471cb6d6ebcb43b1ec282ae6cd8d0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniVRM/Scripts/Extensions/EnumExtensions.cs b/Assets/VRM/UniVRM/Scripts/Extensions/EnumExtensions.cs new file mode 100644 index 000000000..98a98e600 --- /dev/null +++ b/Assets/VRM/UniVRM/Scripts/Extensions/EnumExtensions.cs @@ -0,0 +1,137 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace VRM +{ + public static class EnumExtensions + { + public static HumanBodyBones ToUnityBone(this VRMBone val) + { + switch (val) + { + case VRMBone.hips: return HumanBodyBones.Hips;//"hips" + case VRMBone.leftUpperLeg: return HumanBodyBones.LeftUpperLeg;//"leftUpperLeg"; + case VRMBone.rightUpperLeg: return HumanBodyBones.RightUpperLeg;//"rightUpperLeg"; + case VRMBone.leftLowerLeg: return HumanBodyBones.LeftLowerLeg;//"leftLowerLeg"; + case VRMBone.rightLowerLeg: return HumanBodyBones.RightLowerLeg;//"rightLowerLeg"; + case VRMBone.leftFoot: return HumanBodyBones.LeftFoot;//"leftFoot"; + case VRMBone.rightFoot: return HumanBodyBones.RightFoot;//"rightFoot"; + case VRMBone.spine: return HumanBodyBones.Spine;//"spine"; + case VRMBone.chest: return HumanBodyBones.Chest;//"chest"; + case VRMBone.neck: return HumanBodyBones.Neck;//"neck"; + case VRMBone.head: return HumanBodyBones.Head;//"head"; + case VRMBone.leftShoulder: return HumanBodyBones.LeftShoulder;//"leftShoulder"; + case VRMBone.rightShoulder: return HumanBodyBones.RightShoulder;//"rightShoulder"; + case VRMBone.leftUpperArm: return HumanBodyBones.LeftUpperArm;//"leftUpperArm"; + case VRMBone.rightUpperArm: return HumanBodyBones.RightUpperArm;//"rightUpperArm"; + case VRMBone.leftLowerArm: return HumanBodyBones.LeftLowerArm;//"leftLowerArm"; + case VRMBone.rightLowerArm: return HumanBodyBones.RightLowerArm;//"rightLowerArm"; + case VRMBone.leftHand: return HumanBodyBones.LeftHand;//"leftHand"; + case VRMBone.rightHand: return HumanBodyBones.RightHand;//"rightHand"; + case VRMBone.leftToes: return HumanBodyBones.LeftToes;//"leftToes"; + case VRMBone.rightToes: return HumanBodyBones.RightToes;//"rightToes"; + case VRMBone.leftEye: return HumanBodyBones.LeftEye;//"leftEye"; + case VRMBone.rightEye: return HumanBodyBones.RightEye;//"rightEye"; + case VRMBone.jaw: return HumanBodyBones.Jaw;//"jaw"; + case VRMBone.leftThumbProximal: return HumanBodyBones.LeftThumbProximal; + case VRMBone.leftThumbIntermediate: return HumanBodyBones.LeftThumbIntermediate; + case VRMBone.leftThumbDistal: return HumanBodyBones.LeftThumbDistal; + case VRMBone.leftIndexProximal: return HumanBodyBones.LeftIndexProximal; + case VRMBone.leftIndexIntermediate: return HumanBodyBones.LeftIndexIntermediate; + case VRMBone.leftIndexDistal: return HumanBodyBones.LeftIndexDistal; + case VRMBone.leftMiddleProximal: return HumanBodyBones.LeftMiddleProximal; + case VRMBone.leftMiddleIntermediate: return HumanBodyBones.LeftMiddleIntermediate; + case VRMBone.leftMiddleDistal: return HumanBodyBones.LeftMiddleDistal; + case VRMBone.leftRingProximal: return HumanBodyBones.LeftRingProximal; + case VRMBone.leftRingIntermediate: return HumanBodyBones.LeftRingIntermediate; + case VRMBone.leftRingDistal: return HumanBodyBones.LeftRingDistal; + case VRMBone.leftLittleProximal: return HumanBodyBones.LeftLittleProximal; + case VRMBone.leftLittleIntermediate: return HumanBodyBones.LeftLittleIntermediate; + case VRMBone.leftLittleDistal: return HumanBodyBones.LeftLittleDistal; + case VRMBone.rightThumbProximal: return HumanBodyBones.RightThumbProximal; + case VRMBone.rightThumbIntermediate: return HumanBodyBones.RightThumbIntermediate; + case VRMBone.rightThumbDistal: return HumanBodyBones.RightThumbDistal; + case VRMBone.rightIndexProximal: return HumanBodyBones.RightIndexProximal; + case VRMBone.rightIndexIntermediate: return HumanBodyBones.RightIndexIntermediate; + case VRMBone.rightIndexDistal: return HumanBodyBones.RightIndexDistal; + case VRMBone.rightMiddleProximal: return HumanBodyBones.RightMiddleProximal; + case VRMBone.rightMiddleIntermediate: return HumanBodyBones.RightMiddleIntermediate; + case VRMBone.rightMiddleDistal: return HumanBodyBones.RightMiddleDistal; + case VRMBone.rightRingProximal: return HumanBodyBones.RightRingProximal; + case VRMBone.rightRingIntermediate: return HumanBodyBones.RightRingIntermediate; + case VRMBone.rightRingDistal: return HumanBodyBones.RightRingDistal; + case VRMBone.rightLittleProximal: return HumanBodyBones.RightLittleProximal; + case VRMBone.rightLittleIntermediate: return HumanBodyBones.RightLittleIntermediate; + case VRMBone.rightLittleDistal: return HumanBodyBones.RightLittleDistal; + case VRMBone.upperChest: return HumanBodyBones.UpperChest; + default: throw new System.InvalidOperationException(); + } + } + + + public static VRMBone ToVrmBone(this HumanBodyBones val) + { + switch (val) + { + case HumanBodyBones.Hips: return VRMBone.hips; + case HumanBodyBones.LeftUpperLeg: return VRMBone.leftUpperLeg; + case HumanBodyBones.RightUpperLeg: return VRMBone.rightUpperLeg; + case HumanBodyBones.LeftLowerLeg: return VRMBone.leftLowerLeg; + case HumanBodyBones.RightLowerLeg: return VRMBone.rightLowerLeg; + case HumanBodyBones.LeftFoot: return VRMBone.leftFoot; + case HumanBodyBones.RightFoot: return VRMBone.rightFoot; + case HumanBodyBones.Spine: return VRMBone.spine; + case HumanBodyBones.Chest: return VRMBone.chest; + case HumanBodyBones.Neck: return VRMBone.neck; + case HumanBodyBones.Head: return VRMBone.head; + case HumanBodyBones.LeftShoulder: return VRMBone.leftShoulder; + case HumanBodyBones.RightShoulder: return VRMBone.rightShoulder; + case HumanBodyBones.LeftUpperArm: return VRMBone.leftUpperArm; + case HumanBodyBones.RightUpperArm: return VRMBone.rightUpperArm; + case HumanBodyBones.LeftLowerArm: return VRMBone.leftLowerArm; + case HumanBodyBones.RightLowerArm: return VRMBone.rightLowerArm; + case HumanBodyBones.LeftHand: return VRMBone.leftHand; + case HumanBodyBones.RightHand: return VRMBone.rightHand; + case HumanBodyBones.LeftToes: return VRMBone.leftToes; + case HumanBodyBones.RightToes: return VRMBone.rightToes; + case HumanBodyBones.LeftEye: return VRMBone.leftEye; + case HumanBodyBones.RightEye: return VRMBone.rightEye; + case HumanBodyBones.Jaw: return VRMBone.jaw; + case HumanBodyBones.LeftThumbProximal: return VRMBone.leftThumbProximal; + case HumanBodyBones.LeftThumbIntermediate: return VRMBone.leftThumbIntermediate; + case HumanBodyBones.LeftThumbDistal: return VRMBone.leftThumbDistal; + case HumanBodyBones.LeftIndexProximal: return VRMBone.leftIndexProximal; + case HumanBodyBones.LeftIndexIntermediate: return VRMBone.leftIndexIntermediate; + case HumanBodyBones.LeftIndexDistal: return VRMBone.leftIndexDistal; + case HumanBodyBones.LeftMiddleProximal: return VRMBone.leftMiddleProximal; + case HumanBodyBones.LeftMiddleIntermediate: return VRMBone.leftMiddleIntermediate; + case HumanBodyBones.LeftMiddleDistal: return VRMBone.leftMiddleDistal; + case HumanBodyBones.LeftRingProximal: return VRMBone.leftRingProximal; + case HumanBodyBones.LeftRingIntermediate: return VRMBone.leftRingIntermediate; + case HumanBodyBones.LeftRingDistal: return VRMBone.leftRingDistal; + case HumanBodyBones.LeftLittleProximal: return VRMBone.leftLittleProximal; + case HumanBodyBones.LeftLittleIntermediate: return VRMBone.leftLittleIntermediate; + case HumanBodyBones.LeftLittleDistal: return VRMBone.leftLittleDistal; + case HumanBodyBones.RightThumbProximal: return VRMBone.rightThumbProximal; + case HumanBodyBones.RightThumbIntermediate: return VRMBone.rightThumbIntermediate; + case HumanBodyBones.RightThumbDistal: return VRMBone.rightThumbDistal; + case HumanBodyBones.RightIndexProximal: return VRMBone.rightIndexProximal; + case HumanBodyBones.RightIndexIntermediate: return VRMBone.rightIndexIntermediate; + case HumanBodyBones.RightIndexDistal: return VRMBone.rightIndexDistal; + case HumanBodyBones.RightMiddleProximal: return VRMBone.rightMiddleProximal; + case HumanBodyBones.RightMiddleIntermediate: return VRMBone.rightMiddleIntermediate; + case HumanBodyBones.RightMiddleDistal: return VRMBone.rightMiddleDistal; + case HumanBodyBones.RightRingProximal: return VRMBone.rightRingProximal; + case HumanBodyBones.RightRingIntermediate: return VRMBone.rightRingIntermediate; + case HumanBodyBones.RightRingDistal: return VRMBone.rightRingDistal; + case HumanBodyBones.RightLittleProximal: return VRMBone.rightLittleProximal; + case HumanBodyBones.RightLittleIntermediate: return VRMBone.rightLittleIntermediate; + case HumanBodyBones.RightLittleDistal: return VRMBone.rightLittleDistal; + case HumanBodyBones.UpperChest: return VRMBone.upperChest; + //case HumanBodyBones.LastBone: + default: throw new System.InvalidOperationException(); + } + } + } +} \ No newline at end of file diff --git a/Assets/VRM/UniVRM/Scripts/Extensions/EnumExtensions.cs.meta b/Assets/VRM/UniVRM/Scripts/Extensions/EnumExtensions.cs.meta new file mode 100644 index 000000000..0ceb45410 --- /dev/null +++ b/Assets/VRM/UniVRM/Scripts/Extensions/EnumExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d5e9521d3f142254ab773f38bacd0905 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: