Example #1
0
        public static void InitGlobalMappingData()
        {
            if (AvatarAutoMapper.s_DidPerformInit)
            {
                return;
            }
            List <AvatarAutoMapper.BoneMappingItem> boneMappingItemList = new List <AvatarAutoMapper.BoneMappingItem>((IEnumerable <AvatarAutoMapper.BoneMappingItem>)AvatarAutoMapper.s_MappingDataBody);
            int count = boneMappingItemList.Count;

            for (int index = 0; index < count; ++index)
            {
                AvatarAutoMapper.BoneMappingItem boneMappingItem = boneMappingItemList[index];
                if (boneMappingItem.side == AvatarAutoMapper.Side.Right)
                {
                    int boneIndexFromRight1 = AvatarAutoMapper.GetLeftBoneIndexFromRight(boneMappingItem.bone);
                    int boneIndexFromRight2 = AvatarAutoMapper.GetLeftBoneIndexFromRight(boneMappingItem.parent);
                    boneMappingItemList.Add(new AvatarAutoMapper.BoneMappingItem(boneIndexFromRight2, boneIndexFromRight1, boneMappingItem.minStep, boneMappingItem.maxStep, boneMappingItem.lengthRatio, new Vector3(-boneMappingItem.dir.x, boneMappingItem.dir.y, boneMappingItem.dir.z), AvatarAutoMapper.Side.Left, boneMappingItem.optional, boneMappingItem.alwaysInclude, boneMappingItem.keywords));
                }
            }
            AvatarAutoMapper.s_MappingDataBody = boneMappingItemList.ToArray();
            for (int index = 0; index < AvatarAutoMapper.s_MappingDataBody.Length; ++index)
            {
                AvatarAutoMapper.s_MappingDataBody[index].GetChildren(AvatarAutoMapper.s_MappingDataBody);
            }
            for (int index = 0; index < AvatarAutoMapper.s_LeftMappingDataHand.Length; ++index)
            {
                AvatarAutoMapper.s_LeftMappingDataHand[index].GetChildren(AvatarAutoMapper.s_LeftMappingDataHand);
            }
            for (int index = 0; index < AvatarAutoMapper.s_RightMappingDataHand.Length; ++index)
            {
                AvatarAutoMapper.s_RightMappingDataHand[index].GetChildren(AvatarAutoMapper.s_RightMappingDataHand);
            }
            AvatarAutoMapper.s_DidPerformInit = true;
        }
Example #2
0
        public static void InitGlobalMappingData()
        {
            if (AvatarAutoMapper.s_DidPerformInit)
            {
                return;
            }
            List <AvatarAutoMapper.BoneMappingItem> list = new List <AvatarAutoMapper.BoneMappingItem>(AvatarAutoMapper.s_MappingDataBody);
            int count = list.Count;

            for (int i = 0; i < count; i++)
            {
                AvatarAutoMapper.BoneMappingItem boneMappingItem = list[i];
                if (boneMappingItem.side == AvatarAutoMapper.Side.Right)
                {
                    int leftBoneIndexFromRight  = AvatarAutoMapper.GetLeftBoneIndexFromRight(boneMappingItem.bone);
                    int leftBoneIndexFromRight2 = AvatarAutoMapper.GetLeftBoneIndexFromRight(boneMappingItem.parent);
                    list.Add(new AvatarAutoMapper.BoneMappingItem(leftBoneIndexFromRight2, leftBoneIndexFromRight, boneMappingItem.minStep, boneMappingItem.maxStep, boneMappingItem.lengthRatio, new Vector3(-boneMappingItem.dir.x, boneMappingItem.dir.y, boneMappingItem.dir.z), AvatarAutoMapper.Side.Left, boneMappingItem.optional, boneMappingItem.alwaysInclude, boneMappingItem.keywords));
                }
            }
            AvatarAutoMapper.s_MappingDataBody = list.ToArray();
            for (int j = 0; j < AvatarAutoMapper.s_MappingDataBody.Length; j++)
            {
                AvatarAutoMapper.s_MappingDataBody[j].GetChildren(AvatarAutoMapper.s_MappingDataBody);
            }
            for (int k = 0; k < AvatarAutoMapper.s_LeftMappingDataHand.Length; k++)
            {
                AvatarAutoMapper.s_LeftMappingDataHand[k].GetChildren(AvatarAutoMapper.s_LeftMappingDataHand);
            }
            for (int l = 0; l < AvatarAutoMapper.s_RightMappingDataHand.Length; l++)
            {
                AvatarAutoMapper.s_RightMappingDataHand[l].GetChildren(AvatarAutoMapper.s_RightMappingDataHand);
            }
            AvatarAutoMapper.s_DidPerformInit = true;
        }
Example #3
0
 private AvatarAutoMapper.BoneMappingItem GetBoneMappingItem(int bone)
 {
     AvatarAutoMapper.BoneMappingItem[] mappingData = this.m_MappingData;
     for (int i = 0; i < mappingData.Length; i++)
     {
         AvatarAutoMapper.BoneMappingItem result = mappingData[i];
         if (result.bone == bone)
         {
             return(result);
         }
     }
     return(default(AvatarAutoMapper.BoneMappingItem));
 }
Example #4
0
        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);
        }
Example #5
0
 public BoneMatch(AvatarAutoMapper.BoneMatch parent, Transform bone, AvatarAutoMapper.BoneMappingItem item)
 {
     this.parent = parent;
     this.bone   = bone;
     this.item   = item;
 }
Example #6
0
 public BoneMappingItem(int parent, int bone, int minStep, int maxStep, float lengthRatio, AvatarAutoMapper.Side side, params string[] keywords)
 {
     this = new AvatarAutoMapper.BoneMappingItem(parent, bone, minStep, maxStep, lengthRatio, Vector3.zero, side, false, false, keywords);
 }
Example #7
0
        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;
        }
Example #8
0
        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);
        }
Example #9
0
        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;
            }
        }