示例#1
0
        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);
        }
示例#2
0
        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);
        }