private void DebugMatchChoice(List <AvatarAutoMapper.BoneMatch> matches) { string str = this.GetNameOfBone(matches[0].item.bone) + " preferred order: "; for (int index = 0; index < matches.Count; ++index) { str = str + matches[index].bone.name + " (" + matches[index].score.ToString("0.0") + " / " + matches[index].totalSiblingScore.ToString("0.0") + "), "; } using (List <AvatarAutoMapper.BoneMatch> .Enumerator enumerator1 = matches.GetEnumerator()) { while (enumerator1.MoveNext()) { AvatarAutoMapper.BoneMatch current1 = enumerator1.Current; str = str + "\n Match " + current1.bone.name + " (" + current1.score.ToString("0.0") + " / " + current1.totalSiblingScore.ToString("0.0") + "):"; using (List <string> .Enumerator enumerator2 = current1.debugTracker.GetEnumerator()) { while (enumerator2.MoveNext()) { string current2 = enumerator2.Current; str = str + "\n - " + current2; } } } } Debug.Log((object)str); }
private void ScoreBoneMatch(AvatarAutoMapper.BoneMatch match) { int num1 = this.BoneHasBadKeyword(match.bone, match.item.keywords); match.score += (float)num1; if (AvatarAutoMapper.kDebug && num1 != 0) { match.debugTracker.Add(num1.ToString() + ": " + this.GetMatchString(match) + " matched bad keywords"); } if (num1 < 0) { return; } int num2 = this.BoneHasKeyword(match.bone, match.item.keywords); match.score += (float)num2; if (AvatarAutoMapper.kDebug && num2 != 0) { match.debugTracker.Add(num2.ToString() + ": " + this.GetMatchString(match) + " matched keywords"); } if (match.item.keywords.Length != 0 || !match.item.alwaysInclude) { return; } ++match.score; if (!AvatarAutoMapper.kDebug) { return; } match.debugTracker.Add(1.ToString() + ": " + this.GetMatchString(match) + " always-include point"); }
private void ApplyMapping(AvatarAutoMapper.BoneMatch match, Dictionary <int, Transform> mapping) { if (match.doMap) { mapping[match.item.bone] = match.bone; } foreach (AvatarAutoMapper.BoneMatch current in match.children) { this.ApplyMapping(current, mapping); } }
private void MapBonesFromRootDown(AvatarAutoMapper.BoneMatch rootMatch, Dictionary <int, Transform> mapping) { List <AvatarAutoMapper.BoneMatch> list = this.RecursiveFindPotentialBoneMatches(rootMatch, this.m_MappingData[0], true); if (list != null && list.Count > 0) { if (AvatarAutoMapper.kDebug) { this.EvaluateBoneMatch(list[0], true); } this.ApplyMapping(list[0], mapping); } }
private void ApplyMapping(AvatarAutoMapper.BoneMatch match, Dictionary <int, Transform> mapping) { if (match.doMap) { mapping[match.item.bone] = match.bone; } using (List <AvatarAutoMapper.BoneMatch> .Enumerator enumerator = match.children.GetEnumerator()) { while (enumerator.MoveNext()) { this.ApplyMapping(enumerator.Current, mapping); } } }
private int GetMatchKey(AvatarAutoMapper.BoneMatch parentMatch, Transform t, AvatarAutoMapper.BoneMappingItem goalItem) { int num = goalItem.bone + t.GetInstanceID() * 1000; if (parentMatch != null) { num += parentMatch.bone.GetInstanceID() * 1000000; if (parentMatch.parent != null) { num += parentMatch.parent.bone.GetInstanceID() * 1000000000; } } return(num); }
private void MapBonesFromRootDown(AvatarAutoMapper.BoneMatch rootMatch, Dictionary <int, Transform> mapping) { List <AvatarAutoMapper.BoneMatch> potentialBoneMatches = this.RecursiveFindPotentialBoneMatches(rootMatch, this.m_MappingData[0], true); if (potentialBoneMatches == null || potentialBoneMatches.Count <= 0) { return; } if (AvatarAutoMapper.kDebug) { this.EvaluateBoneMatch(potentialBoneMatches[0], true); } this.ApplyMapping(potentialBoneMatches[0], mapping); }
private int GetBoneSideMatchPoints(AvatarAutoMapper.BoneMatch match) { string name = match.bone.name; if (match.item.side == AvatarAutoMapper.Side.None && (this.MatchesSideKeywords(name, false) || this.MatchesSideKeywords(name, true))) { return(-1000); } bool left = match.item.side == AvatarAutoMapper.Side.Left; if (this.MatchesSideKeywords(name, left)) { return(15); } return(this.MatchesSideKeywords(name, !left) ? -1000 : 0); }
private void ScoreBoneMatch(AvatarAutoMapper.BoneMatch match) { int num = this.BoneHasBadKeyword(match.bone, match.item.keywords); match.score += (float)num; if (AvatarAutoMapper.kDebug && num != 0) { match.debugTracker.Add(string.Concat(new object[] { num, ": ", this.GetMatchString(match), " matched bad keywords" })); } if (num < 0) { return; } int num2 = this.BoneHasKeyword(match.bone, match.item.keywords); match.score += (float)num2; if (AvatarAutoMapper.kDebug && num2 != 0) { match.debugTracker.Add(string.Concat(new object[] { num2, ": ", this.GetMatchString(match), " matched keywords" })); } if (match.item.keywords.Length == 0 && match.item.alwaysInclude) { match.score += 1f; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add(string.Concat(new object[] { 1, ": ", this.GetMatchString(match), " always-include point" })); } } }
private List <AvatarAutoMapper.BoneMatch> GetBestChildMatches(AvatarAutoMapper.BoneMatch parentMatch, List <List <AvatarAutoMapper.BoneMatch> > childMatchesLists) { List <AvatarAutoMapper.BoneMatch> boneMatchList = new List <AvatarAutoMapper.BoneMatch>(); if (childMatchesLists.Count == 1) { boneMatchList.Add(childMatchesLists[0][0]); return(boneMatchList); } int[] choices = new int[childMatchesLists.Count]; float score; int[] childMatchChoices = this.GetBestChildMatchChoices(parentMatch, childMatchesLists, choices, out score); for (int index = 0; index < childMatchChoices.Length; ++index) { if (childMatchChoices[index] >= 0) { boneMatchList.Add(childMatchesLists[index][childMatchChoices[index]]); } } return(boneMatchList); }
private List <AvatarAutoMapper.BoneMatch> GetBestChildMatches(AvatarAutoMapper.BoneMatch parentMatch, List <List <AvatarAutoMapper.BoneMatch> > childMatchesLists) { List <AvatarAutoMapper.BoneMatch> list = new List <AvatarAutoMapper.BoneMatch>(); if (childMatchesLists.Count == 1) { list.Add(childMatchesLists[0][0]); return(list); } int[] array = new int[childMatchesLists.Count]; float num; array = this.GetBestChildMatchChoices(parentMatch, childMatchesLists, array, out num); for (int i = 0; i < array.Length; i++) { if (array[i] >= 0) { list.Add(childMatchesLists[i][array[i]]); } } return(list); }
private void EvaluateBoneMatch(AvatarAutoMapper.BoneMatch match, bool confirmedChoice) { match.score = 0.0f; match.siblingScore = 0.0f; List <List <AvatarAutoMapper.BoneMatch> > childMatchesLists = new List <List <AvatarAutoMapper.BoneMatch> >(); int num1 = 0; foreach (int child in match.item.GetChildren(this.m_MappingData)) { AvatarAutoMapper.BoneMappingItem goalItem = this.m_MappingData[child]; if (goalItem.parent == match.item.bone) { ++num1; List <AvatarAutoMapper.BoneMatch> potentialBoneMatches = this.RecursiveFindPotentialBoneMatches(match, goalItem, confirmedChoice); if (potentialBoneMatches != null && potentialBoneMatches.Count != 0) { childMatchesLists.Add(potentialBoneMatches); } } } bool flag = (UnityEngine.Object)match.bone == (UnityEngine.Object)match.humanBoneParent.bone; int num2 = 0; if (childMatchesLists.Count > 0) { match.children = this.GetBestChildMatches(match, childMatchesLists); using (List <AvatarAutoMapper.BoneMatch> .Enumerator enumerator = match.children.GetEnumerator()) { while (enumerator.MoveNext()) { AvatarAutoMapper.BoneMatch current = enumerator.Current; if (AvatarAutoMapper.kDebug && confirmedChoice) { this.EvaluateBoneMatch(current, confirmedChoice); } ++num2; match.score += current.score; if (AvatarAutoMapper.kDebug) { match.debugTracker.AddRange((IEnumerable <string>)current.debugTracker); } if ((UnityEngine.Object)current.bone == (UnityEngine.Object)match.bone && current.item.bone >= 0) { flag = true; } } } } if (!match.item.optional || !flag) { this.ScoreBoneMatch(match); } if (match.item.dir != Vector3.zero) { Vector3 dir = match.item.dir; if (this.m_MappingIndexOffset >= 24 && this.m_MappingIndexOffset < 39) { dir.x *= -1f; } float num3 = Vector3.Dot(Quaternion.Inverse(this.m_Orientation) * (match.bone.position - match.humanBoneParent.bone.position).normalized, dir) * (!match.item.optional ? 10f : 5f); match.siblingScore += num3; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add("* " + (object)num3 + ": " + this.GetMatchString(match) + " matched dir (" + (object)(match.bone.position - match.humanBoneParent.bone.position).normalized + " , " + (object)dir + ")"); } if ((double)num3 > 0.0) { match.score += 10f; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add(10.ToString() + ": " + this.GetMatchString(match) + " matched dir (" + (object)(match.bone.position - match.humanBoneParent.bone.position).normalized + " , " + (object)dir + ")"); } } } if (this.m_MappingIndexOffset == 0) { int boneSideMatchPoints = this.GetBoneSideMatchPoints(match); if (match.parent.item.side == AvatarAutoMapper.Side.None || boneSideMatchPoints < 0) { match.siblingScore += (float)boneSideMatchPoints; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add("* " + (object)boneSideMatchPoints + ": " + this.GetMatchString(match) + " matched side"); } } } if ((double)match.score > 0.0) { if (match.item.optional && !flag) { match.score += 5f; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add(5.ToString() + ": " + this.GetMatchString(match) + " optional bone is included"); } } if (num1 == 0 && match.bone.childCount > 0) { ++match.score; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add(1.ToString() + ": " + this.GetMatchString(match) + " has dummy child bone"); } } if ((double)match.item.lengthRatio != 0.0) { float num3 = Vector3.Distance(match.bone.position, match.humanBoneParent.bone.position); if ((double)num3 == 0.0 && (UnityEngine.Object)match.bone != (UnityEngine.Object)match.humanBoneParent.bone) { match.score -= 1000f; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add(-1000.ToString() + ": " + this.GetMatchString(match.humanBoneParent) + " has zero length"); } } float num4 = Vector3.Distance(match.humanBoneParent.bone.position, match.humanBoneParent.humanBoneParent.bone.position); if ((double)num4 > 0.0) { float num5 = Mathf.Log(num3 / num4, 2f); float num6 = Mathf.Log(match.item.lengthRatio, 2f); float num7 = 10f * Mathf.Clamp((float)(1.0 - 0.600000023841858 * (double)Mathf.Abs(num5 - num6)), 0.0f, 1f); match.score += num7; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add(((double)num7).ToString() + ": parent " + this.GetMatchString(match.humanBoneParent) + " matched lengthRatio - " + (object)num3 + " / " + (object)num4 + " = " + (object)(float)((double)num3 / (double)num4) + " (" + (object)num5 + ") goal: " + (object)match.item.lengthRatio + " (" + (object)num6 + ")"); } } } } if (match.item.bone < 0 || match.item.optional && flag) { return; } match.doMap = true; }
private int[] GetBestChildMatchChoices(AvatarAutoMapper.BoneMatch parentMatch, List <List <AvatarAutoMapper.BoneMatch> > childMatchesLists, int[] choices, out float score) { List <int> intList = new List <int>(); for (int index1 = 0; index1 < choices.Length; ++index1) { if (choices[index1] >= 0) { intList.Clear(); intList.Add(index1); for (int index2 = index1 + 1; index2 < choices.Length; ++index2) { if (choices[index2] >= 0 && this.ShareTransformPath(parentMatch.bone, childMatchesLists[index1][choices[index1]].bone, childMatchesLists[index2][choices[index2]].bone)) { intList.Add(index2); } } if (intList.Count > 1) { break; } } } if (intList.Count <= 1) { score = 0.0f; for (int index = 0; index < choices.Length; ++index) { if (choices[index] >= 0) { score = score + childMatchesLists[index][choices[index]].totalSiblingScore; } } return(choices); } float num = 0.0f; int[] numArray = choices; for (int index1 = 0; index1 < intList.Count; ++index1) { int[] choices1 = new int[choices.Length]; Array.Copy((Array)choices, (Array)choices1, choices.Length); for (int index2 = 0; index2 < intList.Count; ++index2) { if (index1 != index2) { if (intList[index2] >= choices1.Length) { Debug.LogError((object)("sharedIndices[j] (" + (object)intList[index2] + ") >= altChoices.Length (" + (object)choices1.Length + ")")); } if (intList[index2] >= childMatchesLists.Count) { Debug.LogError((object)("sharedIndices[j] (" + (object)intList[index2] + ") >= childMatchesLists.Count (" + (object)childMatchesLists.Count + ")")); } if (choices1[intList[index2]] < childMatchesLists[intList[index2]].Count - 1) { ++choices1[intList[index2]]; } else { choices1[intList[index2]] = -1; } } } float score1; int[] childMatchChoices = this.GetBestChildMatchChoices(parentMatch, childMatchesLists, choices1, out score1); if ((double)score1 > (double)num) { num = score1; numArray = childMatchChoices; } } score = num; return(numArray); }
private string GetMatchString(AvatarAutoMapper.BoneMatch match) { return(this.GetNameOfBone(match.item.bone) + ":" + ((!(match.bone == null)) ? match.bone.name : "null")); }
private string GetMatchString(AvatarAutoMapper.BoneMatch match) { return(this.GetNameOfBone(match.item.bone) + ":" + (!((UnityEngine.Object)match.bone == (UnityEngine.Object)null) ? match.bone.name : "null")); }
private List <AvatarAutoMapper.BoneMatch> RecursiveFindPotentialBoneMatches(AvatarAutoMapper.BoneMatch parentMatch, AvatarAutoMapper.BoneMappingItem goalItem, bool confirmedChoice) { List <AvatarAutoMapper.BoneMatch> matches = new List <AvatarAutoMapper.BoneMatch>(); Queue <AvatarAutoMapper.QueuedBone> queuedBoneQueue = new Queue <AvatarAutoMapper.QueuedBone>(); queuedBoneQueue.Enqueue(new AvatarAutoMapper.QueuedBone(parentMatch.bone, 0)); while (queuedBoneQueue.Count > 0) { AvatarAutoMapper.QueuedBone queuedBone = queuedBoneQueue.Dequeue(); Transform bone = queuedBone.bone; if (queuedBone.level >= goalItem.minStep && (this.m_TreatDummyBonesAsReal || this.m_ValidBones == null || this.m_ValidBones.ContainsKey(bone) && this.m_ValidBones[bone])) { int matchKey = this.GetMatchKey(parentMatch, bone, goalItem); AvatarAutoMapper.BoneMatch match; if (this.m_BoneMatchDict.ContainsKey(matchKey)) { match = this.m_BoneMatchDict[matchKey]; } else { match = new AvatarAutoMapper.BoneMatch(parentMatch, bone, goalItem); this.EvaluateBoneMatch(match, false); this.m_BoneMatchDict[matchKey] = match; } if ((double)match.score > 0.0 || AvatarAutoMapper.kDebug) { matches.Add(match); } } if (queuedBone.level < goalItem.maxStep) { foreach (Transform index in bone) { if (this.m_ValidBones == null || this.m_ValidBones.ContainsKey(index)) { if (!this.m_TreatDummyBonesAsReal && this.m_ValidBones != null && !this.m_ValidBones[index]) { queuedBoneQueue.Enqueue(new AvatarAutoMapper.QueuedBone(index, queuedBone.level)); } else { queuedBoneQueue.Enqueue(new AvatarAutoMapper.QueuedBone(index, queuedBone.level + 1)); } } } } } if (matches.Count == 0) { return((List <AvatarAutoMapper.BoneMatch>)null); } matches.Sort(); if ((double)matches[0].score <= 0.0) { return((List <AvatarAutoMapper.BoneMatch>)null); } if (AvatarAutoMapper.kDebug && confirmedChoice) { this.DebugMatchChoice(matches); } while (matches.Count > 3) { matches.RemoveAt(matches.Count - 1); } matches.TrimExcess(); return(matches); }
public Dictionary <int, Transform> MapBones(Transform root) { AvatarAutoMapper.InitGlobalMappingData(); Dictionary <int, Transform> dictionary = new Dictionary <int, Transform>(); this.m_Orientation = Quaternion.identity; this.m_MappingData = AvatarAutoMapper.s_MappingDataBody; this.m_MappingIndexOffset = 0; this.m_BoneMatchDict.Clear(); AvatarAutoMapper.BoneMatch boneMatch = new AvatarAutoMapper.BoneMatch(null, root, this.m_MappingData[0]); this.m_TreatDummyBonesAsReal = false; this.MapBonesFromRootDown(boneMatch, dictionary); if (dictionary.Count < 15) { this.m_TreatDummyBonesAsReal = true; this.MapBonesFromRootDown(boneMatch, dictionary); } if (dictionary.ContainsKey(1) && dictionary.ContainsKey(2) && dictionary.ContainsKey(13) && dictionary.ContainsKey(14)) { this.m_Orientation = AvatarSetupTool.AvatarComputeOrientation(dictionary[1].position, dictionary[2].position, dictionary[13].position, dictionary[14].position); if (Vector3.Angle(this.m_Orientation * Vector3.up, Vector3.up) > 20f || Vector3.Angle(this.m_Orientation * Vector3.forward, Vector3.forward) > 20f) { if (AvatarAutoMapper.kDebug) { Debug.Log("*** Mapping with new computed orientation"); } dictionary.Clear(); this.m_BoneMatchDict.Clear(); this.MapBonesFromRootDown(boneMatch, dictionary); } } bool flag = !this.m_ValidBones.ContainsKey(root) || !this.m_ValidBones[root]; if (flag && dictionary.Count > 0 && dictionary.ContainsKey(0)) { while (true) { Transform parent = dictionary[0].parent; if (!(parent != null) || !(parent != boneMatch.bone) || !this.m_ValidBones.ContainsKey(parent) || !this.m_ValidBones[parent]) { break; } dictionary[0] = parent; } } int num = 3; Quaternion orientation = this.m_Orientation; if (dictionary.ContainsKey(17)) { Transform transform = dictionary[15]; Transform transform2 = dictionary[17]; this.m_Orientation = Quaternion.FromToRotation(orientation * -Vector3.right, transform2.position - transform.position) * orientation; this.m_MappingData = AvatarAutoMapper.s_LeftMappingDataHand; this.m_MappingIndexOffset = 24; this.m_BoneMatchDict.Clear(); AvatarAutoMapper.BoneMatch rootMatch = new AvatarAutoMapper.BoneMatch(null, transform, this.m_MappingData[0]); this.m_TreatDummyBonesAsReal = true; int count = dictionary.Count; this.MapBonesFromRootDown(rootMatch, dictionary); if (dictionary.Count < count + num) { for (int i = 24; i <= 38; i++) { dictionary.Remove(i); } } } if (dictionary.ContainsKey(18)) { Transform transform3 = dictionary[16]; Transform transform4 = dictionary[18]; this.m_Orientation = Quaternion.FromToRotation(orientation * Vector3.right, transform4.position - transform3.position) * orientation; this.m_MappingData = AvatarAutoMapper.s_RightMappingDataHand; this.m_MappingIndexOffset = 39; this.m_BoneMatchDict.Clear(); AvatarAutoMapper.BoneMatch rootMatch2 = new AvatarAutoMapper.BoneMatch(null, transform3, this.m_MappingData[0]); this.m_TreatDummyBonesAsReal = true; int count2 = dictionary.Count; this.MapBonesFromRootDown(rootMatch2, dictionary); if (dictionary.Count < count2 + num) { for (int j = 39; j <= 53; j++) { dictionary.Remove(j); } } } return(dictionary); }
public Dictionary <int, Transform> MapBones(Transform root) { AvatarAutoMapper.InitGlobalMappingData(); Dictionary <int, Transform> mapping = new Dictionary <int, Transform>(); this.m_Orientation = Quaternion.identity; this.m_MappingData = AvatarAutoMapper.s_MappingDataBody; this.m_MappingIndexOffset = 0; this.m_BoneMatchDict.Clear(); AvatarAutoMapper.BoneMatch rootMatch1 = new AvatarAutoMapper.BoneMatch((AvatarAutoMapper.BoneMatch)null, root, this.m_MappingData[0]); this.m_TreatDummyBonesAsReal = false; this.MapBonesFromRootDown(rootMatch1, mapping); if (mapping.Count < 15) { this.m_TreatDummyBonesAsReal = true; this.MapBonesFromRootDown(rootMatch1, mapping); } if (mapping.ContainsKey(1) && mapping.ContainsKey(2) && (mapping.ContainsKey(13) && mapping.ContainsKey(14))) { this.m_Orientation = AvatarSetupTool.AvatarComputeOrientation(mapping[1].position, mapping[2].position, mapping[13].position, mapping[14].position); if ((double)Vector3.Angle(this.m_Orientation * Vector3.up, Vector3.up) > 20.0 || (double)Vector3.Angle(this.m_Orientation * Vector3.forward, Vector3.forward) > 20.0) { if (AvatarAutoMapper.kDebug) { Debug.Log((object)"*** Mapping with new computed orientation"); } mapping.Clear(); this.m_BoneMatchDict.Clear(); this.MapBonesFromRootDown(rootMatch1, mapping); } } if ((!this.m_ValidBones.ContainsKey(root) ? 0 : (this.m_ValidBones[root] ? 1 : 0)) == 0 && mapping.Count > 0 && mapping.ContainsKey(0)) { while (true) { Transform parent = mapping[0].parent; if ((UnityEngine.Object)parent != (UnityEngine.Object)null && (UnityEngine.Object)parent != (UnityEngine.Object)rootMatch1.bone && (this.m_ValidBones.ContainsKey(parent) && this.m_ValidBones[parent])) { mapping[0] = parent; } else { break; } } } int num = 3; Quaternion orientation = this.m_Orientation; if (mapping.ContainsKey(17)) { Transform bone = mapping[15]; Transform transform = mapping[17]; this.m_Orientation = Quaternion.FromToRotation(orientation * -Vector3.right, transform.position - bone.position) * orientation; this.m_MappingData = AvatarAutoMapper.s_LeftMappingDataHand; this.m_MappingIndexOffset = 24; this.m_BoneMatchDict.Clear(); AvatarAutoMapper.BoneMatch rootMatch2 = new AvatarAutoMapper.BoneMatch((AvatarAutoMapper.BoneMatch)null, bone, this.m_MappingData[0]); this.m_TreatDummyBonesAsReal = true; int count = mapping.Count; this.MapBonesFromRootDown(rootMatch2, mapping); if (mapping.Count < count + num) { for (int key = 24; key <= 38; ++key) { mapping.Remove(key); } } } if (mapping.ContainsKey(18)) { Transform bone = mapping[16]; Transform transform = mapping[18]; this.m_Orientation = Quaternion.FromToRotation(orientation * Vector3.right, transform.position - bone.position) * orientation; this.m_MappingData = AvatarAutoMapper.s_RightMappingDataHand; this.m_MappingIndexOffset = 39; this.m_BoneMatchDict.Clear(); AvatarAutoMapper.BoneMatch rootMatch2 = new AvatarAutoMapper.BoneMatch((AvatarAutoMapper.BoneMatch)null, bone, this.m_MappingData[0]); this.m_TreatDummyBonesAsReal = true; int count = mapping.Count; this.MapBonesFromRootDown(rootMatch2, mapping); if (mapping.Count < count + num) { for (int key = 39; key <= 53; ++key) { mapping.Remove(key); } } } return(mapping); }
private void EvaluateBoneMatch(AvatarAutoMapper.BoneMatch match, bool confirmedChoice) { match.score = 0f; match.siblingScore = 0f; List <List <AvatarAutoMapper.BoneMatch> > list = new List <List <AvatarAutoMapper.BoneMatch> >(); int num = 0; int[] children = match.item.GetChildren(this.m_MappingData); for (int i = 0; i < children.Length; i++) { int num2 = children[i]; AvatarAutoMapper.BoneMappingItem goalItem = this.m_MappingData[num2]; if (goalItem.parent == match.item.bone) { num++; List <AvatarAutoMapper.BoneMatch> list2 = this.RecursiveFindPotentialBoneMatches(match, goalItem, confirmedChoice); if (list2 != null && list2.Count != 0) { list.Add(list2); } } } bool flag = match.bone == match.humanBoneParent.bone; int num3 = 0; if (list.Count > 0) { match.children = this.GetBestChildMatches(match, list); foreach (AvatarAutoMapper.BoneMatch current in match.children) { if (AvatarAutoMapper.kDebug && confirmedChoice) { this.EvaluateBoneMatch(current, confirmedChoice); } num3++; match.score += current.score; if (AvatarAutoMapper.kDebug) { match.debugTracker.AddRange(current.debugTracker); } if (current.bone == match.bone && current.item.bone >= 0) { flag = true; } } } if (!match.item.optional || !flag) { this.ScoreBoneMatch(match); } if (match.item.dir != Vector3.zero) { Vector3 dir = match.item.dir; if (this.m_MappingIndexOffset >= 24 && this.m_MappingIndexOffset < 39) { dir.x *= -1f; } Vector3 vector = (match.bone.position - match.humanBoneParent.bone.position).normalized; vector = Quaternion.Inverse(this.m_Orientation) * vector; float num4 = Vector3.Dot(vector, dir) * (float)((!match.item.optional) ? 10 : 5); match.siblingScore += num4; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add(string.Concat(new object[] { "* ", num4, ": ", this.GetMatchString(match), " matched dir (", (match.bone.position - match.humanBoneParent.bone.position).normalized, " , ", dir, ")" })); } if (num4 > 0f) { match.score += 10f; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add(string.Concat(new object[] { 10, ": ", this.GetMatchString(match), " matched dir (", (match.bone.position - match.humanBoneParent.bone.position).normalized, " , ", dir, ")" })); } } } if (this.m_MappingIndexOffset == 0) { int boneSideMatchPoints = this.GetBoneSideMatchPoints(match); if (match.parent.item.side == AvatarAutoMapper.Side.None || boneSideMatchPoints < 0) { match.siblingScore += (float)boneSideMatchPoints; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add(string.Concat(new object[] { "* ", boneSideMatchPoints, ": ", this.GetMatchString(match), " matched side" })); } } } if (match.score > 0f) { if (match.item.optional && !flag) { match.score += 5f; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add(string.Concat(new object[] { 5, ": ", this.GetMatchString(match), " optional bone is included" })); } } if (num == 0 && match.bone.childCount > 0) { match.score += 1f; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add(string.Concat(new object[] { 1, ": ", this.GetMatchString(match), " has dummy child bone" })); } } if (match.item.lengthRatio != 0f) { float num5 = Vector3.Distance(match.bone.position, match.humanBoneParent.bone.position); if (num5 == 0f && match.bone != match.humanBoneParent.bone) { match.score -= 1000f; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add(string.Concat(new object[] { -1000, ": ", this.GetMatchString(match.humanBoneParent), " has zero length" })); } } float num6 = Vector3.Distance(match.humanBoneParent.bone.position, match.humanBoneParent.humanBoneParent.bone.position); if (num6 > 0f) { float num7 = Mathf.Log(num5 / num6, 2f); float num8 = Mathf.Log(match.item.lengthRatio, 2f); float num9 = 10f * Mathf.Clamp(1f - 0.6f * Mathf.Abs(num7 - num8), 0f, 1f); match.score += num9; if (AvatarAutoMapper.kDebug) { match.debugTracker.Add(string.Concat(new object[] { num9, ": parent ", this.GetMatchString(match.humanBoneParent), " matched lengthRatio - ", num5, " / ", num6, " = ", num5 / num6, " (", num7, ") goal: ", match.item.lengthRatio, " (", num8, ")" })); } } } } if (match.item.bone >= 0 && (!match.item.optional || !flag)) { match.doMap = true; } }
private int[] GetBestChildMatchChoices(AvatarAutoMapper.BoneMatch parentMatch, List <List <AvatarAutoMapper.BoneMatch> > childMatchesLists, int[] choices, out float score) { List <int> list = new List <int>(); for (int i = 0; i < choices.Length; i++) { if (choices[i] >= 0) { list.Clear(); list.Add(i); for (int j = i + 1; j < choices.Length; j++) { if (choices[j] >= 0) { if (this.ShareTransformPath(parentMatch.bone, childMatchesLists[i][choices[i]].bone, childMatchesLists[j][choices[j]].bone)) { list.Add(j); } } } if (list.Count > 1) { break; } } } if (list.Count <= 1) { score = 0f; for (int k = 0; k < choices.Length; k++) { if (choices[k] >= 0) { score += childMatchesLists[k][choices[k]].totalSiblingScore; } } return(choices); } float num = 0f; int[] result = choices; for (int l = 0; l < list.Count; l++) { int[] array = new int[choices.Length]; Array.Copy(choices, array, choices.Length); for (int m = 0; m < list.Count; m++) { if (l != m) { if (list[m] >= array.Length) { Debug.LogError(string.Concat(new object[] { "sharedIndices[j] (", list[m], ") >= altChoices.Length (", array.Length, ")" })); } if (list[m] >= childMatchesLists.Count) { Debug.LogError(string.Concat(new object[] { "sharedIndices[j] (", list[m], ") >= childMatchesLists.Count (", childMatchesLists.Count, ")" })); } if (array[list[m]] < childMatchesLists[list[m]].Count - 1) { array[list[m]]++; } else { array[list[m]] = -1; } } } float num2; array = this.GetBestChildMatchChoices(parentMatch, childMatchesLists, array, out num2); if (num2 > num) { num = num2; result = array; } } score = num; return(result); }