// Warning: Some assembly references could not be resolved automatically. This might lead to incorrect decompilation of some parts, // for ex. property getter/setter access. To get optimal decompilation results, please manually add the missing references to the list of loaded assemblies. // EdenAutoMorpherScript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Eden.AutoMorpher.MeshClassifier using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using Eden.AutoMorpher; using UnityEngine; public class MeshClassifier { private HumanBodyBones[] bodyBones; private HumanBodyBones[] headBones; public SkinnedMeshRenderer GetBodyMesh(Transform root, Animator animator) { List list = HumanBodyBonesTrsnforms(bodyBones, animator); if (list.Count != bodyBones.Length) { if (AutoMorpherDev.isDeveloperMode) { Debug.LogWarning((object)"[Body Mesh] Animator Bone is not enough"); } return null; } return GetBoneMatchedMesh(root, list); } public SkinnedMeshRenderer GetHeadMesh(Transform root, Animator animator) { List list = HumanBodyBonesTrsnforms(headBones, animator); if (list.Count != headBones.Length) { return null; } return GetBoneMatchedMesh(root, list); } private List HumanBodyBonesTrsnforms(HumanBodyBones[] humanBonesList, Animator animator) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) List list = new List(); List list2 = new List(); foreach (HumanBodyBones val in humanBonesList) { Transform boneTransform = animator.GetBoneTransform(val); if ((Object)(object)boneTransform == (Object)null) { list2.Add(val); } else { list.Add(boneTransform); } } if (list2.Count > 0) { string text = string.Join(", ", list2); throw new AutoMorpherException("[Body Mesh Finding] Required Humanoid Bones are Missing", "[BodyMeshUtil] HumanBodyBonesTrsnforms\n - Missing Humanoid Bones: [" + text + "]\n - Animator Humanoid mapping may be broken\n - Please check whether the missing humanoid bones are correctly assigned in [Animator → Avatar → Configure]."); } return list; } private SkinnedMeshRenderer GetBoneMatchedMesh(Transform root, List humanBoneTransforms) { SkinnedMeshRenderer[] componentsInChildren = ((Component)root).GetComponentsInChildren(false); foreach (SkinnedMeshRenderer val in componentsInChildren) { bool flag = true; HashSet activeBones = GetActiveBones(val); if (AutoMorpherDev.isDeveloperMode) { Debug.Log((object)$"[Body Mesh] {((Object)((Component)val).gameObject).name} have bone Set {activeBones.Count}"); } foreach (Transform humanBoneTransform in humanBoneTransforms) { if (!activeBones.Contains(humanBoneTransform) && !BoneExistsByPosition(humanBoneTransform, activeBones)) { flag = false; if (AutoMorpherDev.isDeveloperMode) { Debug.Log((object)("[Body Mesh] " + ((Object)((Component)val).gameObject).name + " Doesn't hav bone " + ((Object)humanBoneTransform).name)); } break; } } if (flag) { return val; } } return null; } private bool BoneExistsByPosition(Transform boneToCheck, HashSet smrBoneSet, float posTolerance = 0.0001f) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) foreach (Transform item in smrBoneSet) { Vector3 val = item.position - boneToCheck.position; if (((Vector3)(ref val)).sqrMagnitude <= posTolerance * posTolerance) { return true; } } return false; } public HashSet GetActiveBones(SkinnedMeshRenderer smr, float weightThreshold = 0.0001f) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) Mesh sharedMesh = smr.sharedMesh; if ((Object)(object)sharedMesh == (Object)null) { Debug.LogWarning((object)"SkinnedMeshRenderer에 연결된 Mesh가 없습니다."); return new HashSet(); } Transform[] bones = smr.bones; BoneWeight[] boneWeights = sharedMesh.boneWeights; HashSet hashSet = new HashSet(); BoneWeight[] array = boneWeights; for (int i = 0; i < array.Length; i++) { BoneWeight val = array[i]; if (((BoneWeight)(ref val)).weight0 > weightThreshold) { hashSet.Add(((BoneWeight)(ref val)).boneIndex0); } if (((BoneWeight)(ref val)).weight1 > weightThreshold) { hashSet.Add(((BoneWeight)(ref val)).boneIndex1); } if (((BoneWeight)(ref val)).weight2 > weightThreshold) { hashSet.Add(((BoneWeight)(ref val)).boneIndex2); } if (((BoneWeight)(ref val)).weight3 > weightThreshold) { hashSet.Add(((BoneWeight)(ref val)).boneIndex3); } } HashSet hashSet2 = new HashSet(); foreach (int item in hashSet) { if (item >= 0 && item < bones.Length) { hashSet2.Add(bones[item]); } } return hashSet2; } public Dictionary> MeshHumanoidBoneMatcher(Animator animator, IReadOnlyList bodyMeshes, float posTolerance = 0.0001f, float weightThreshold = 0.0001f) { //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) Dictionary> dictionary = new Dictionary>(); if ((Object)(object)animator == (Object)null) { throw new AutoMorpherException("Animator is Missing", "[MeshHumanoidBoneMatcher] MeshHumanoidBoneMatcher\n - animator is null"); } HashSet hashSet = new HashSet(); if (bodyMeshes != null) { foreach (SkinnedMeshRenderer bodyMesh in bodyMeshes) { if ((Object)(object)bodyMesh == (Object)null) { continue; } foreach (Transform activeBone in GetActiveBones(bodyMesh, weightThreshold)) { if ((Object)(object)activeBone != (Object)null) { hashSet.Add(activeBone); } } } } for (int i = 0; i < 55; i++) { HumanBodyBones val = (HumanBodyBones)i; Transform boneTransform = animator.GetBoneTransform(val); if ((Object)(object)boneTransform == (Object)null) { continue; } HashSet hashSet2 = new HashSet(); hashSet2.Add(boneTransform); foreach (Transform item in FindBonesByPosition(boneTransform, hashSet, posTolerance)) { hashSet2.Add(item); } dictionary[val] = hashSet2; } return dictionary; } private List FindBonesByPosition(Transform boneToCheck, HashSet smrBoneSet, float posTolerance = 0.0001f) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) List list = new List(); if ((Object)(object)boneToCheck == (Object)null) { return list; } float num = posTolerance * posTolerance; Vector3 position = boneToCheck.position; foreach (Transform item in smrBoneSet) { if (!((Object)(object)item == (Object)null) && !((Object)(object)item == (Object)(object)boneToCheck) && NameMatches(((Object)((Component)item).gameObject).name, ((Object)((Component)boneToCheck).gameObject).name)) { Vector3 val = item.position - position; if (((Vector3)(ref val)).sqrMagnitude <= num) { list.Add(item); } } } return list; } private string[] TokenizeBoneName(string name) { if (string.IsNullOrWhiteSpace(name)) { return Array.Empty(); } char[] separator = new char[5] { '-', '_', ':', '.', '|' }; name = name.Trim(); return name.Split(separator, StringSplitOptions.RemoveEmptyEntries); } private bool NameMatches(string boneToCheckName, string candidateName) { string[] array = TokenizeBoneName(boneToCheckName); string[] array2 = TokenizeBoneName(candidateName); if (array.Length == 0 || array2.Length == 0) { return false; } if (!array[0].Equals(array2[0], StringComparison.OrdinalIgnoreCase)) { return false; } if (array.Length > 1 && array2.Length > 1 && !array[1].Equals(array2[1], StringComparison.OrdinalIgnoreCase)) { return false; } return true; } public MeshClassifier() { HumanBodyBones[] array = new HumanBodyBones[28]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); bodyBones = (HumanBodyBones[])(object)array; HumanBodyBones[] array2 = new HumanBodyBones[3]; RuntimeHelpers.InitializeArray(array2, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); headBones = (HumanBodyBones[])(object)array2; base._002Ector(); } }