コード例 #1
0
 public static BipedNaming.BoneType GetBoneType(string boneName)
 {
     if (BipedNaming.isSpine(boneName))
     {
         return(BipedNaming.BoneType.Spine);
     }
     if (BipedNaming.isHead(boneName))
     {
         return(BipedNaming.BoneType.Head);
     }
     if (BipedNaming.isArm(boneName))
     {
         return(BipedNaming.BoneType.Arm);
     }
     if (BipedNaming.isLeg(boneName))
     {
         return(BipedNaming.BoneType.Leg);
     }
     if (BipedNaming.isTail(boneName))
     {
         return(BipedNaming.BoneType.Tail);
     }
     if (BipedNaming.isEye(boneName))
     {
         return(BipedNaming.BoneType.Eye);
     }
     return(BipedNaming.BoneType.Unassigned);
 }
コード例 #2
0
        // Tries to guess the limb bones based on naming
        private static void DetectLimb(BipedNaming.BoneType boneType, BipedNaming.BoneSide boneSide, ref Transform firstBone, ref Transform secondBone, ref Transform lastBone, Transform[] transforms)
        {
            Transform[] limb = BipedNaming.GetBonesOfTypeAndSide(boneType, boneSide, transforms);

            if (limb.Length < 3)
            {
                //Warning.Log("Unable to detect biped bones by bone names. Please manually assign bone references.", firstBone, true);
                return;
            }

            // Standard biped characters
            if (limb.Length == 3)
            {
                firstBone  = limb[0];
                secondBone = limb[1];
                lastBone   = limb[2];
            }

            // For Bootcamp soldier type of characters with more than 3 limb bones
            if (limb.Length > 3)
            {
                firstBone  = limb[0];
                secondBone = limb[2];
                lastBone   = limb[limb.Length - 1];
            }
        }
コード例 #3
0
 public static Transform GetFirstBoneOfTypeAndSide(BipedNaming.BoneType boneType, BipedNaming.BoneSide boneSide, Transform[] bones)
 {
     Transform[] bonesOfTypeAndSide = BipedNaming.GetBonesOfTypeAndSide(boneType, boneSide, bones);
     if (bonesOfTypeAndSide.Length == 0)
     {
         return(null);
     }
     return(bonesOfTypeAndSide[0]);
 }
コード例 #4
0
 private static bool matchesLastLetter(string boneName, string[] namingConvention)
 {
     foreach (string letter in namingConvention)
     {
         if (BipedNaming.LastLetterIs(boneName, letter))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #5
0
 public static BipedNaming.BoneSide GetBoneSide(string boneName)
 {
     if (BipedNaming.isLeft(boneName))
     {
         return(BipedNaming.BoneSide.Left);
     }
     if (BipedNaming.isRight(boneName))
     {
         return(BipedNaming.BoneSide.Right);
     }
     return(BipedNaming.BoneSide.Center);
 }
コード例 #6
0
 private static bool matchesLastLetter(string boneName, string[] namingConvention)
 {
     for (int i = 0; i < namingConvention.Length; i++)
     {
         string letter = namingConvention[i];
         if (BipedNaming.LastLetterIs(boneName, letter))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #7
0
 public static Transform[] GetBonesOfType(BipedNaming.BoneType boneType, Transform[] bones)
 {
     Transform[] array = new Transform[0];
     foreach (Transform transform in bones)
     {
         if (transform != null && BipedNaming.GetBoneType(transform.name) == boneType)
         {
             Array.Resize <Transform>(ref array, array.Length + 1);
             array[array.Length - 1] = transform;
         }
     }
     return(array);
 }
コード例 #8
0
 public static Transform[] GetBonesOfSide(BipedNaming.BoneSide boneSide, Transform[] bones)
 {
     Transform[] array = new Transform[0];
     for (int i = 0; i < bones.Length; i++)
     {
         Transform transform = bones[i];
         if (transform != null && BipedNaming.GetBoneSide(transform.name) == boneSide)
         {
             Array.Resize <Transform>(ref array, array.Length + 1);
             array[array.Length - 1] = transform;
         }
     }
     return(array);
 }
コード例 #9
0
 private static bool matchesNaming(string boneName, string[] namingConvention)
 {
     if (BipedNaming.excludesNaming(boneName, BipedNaming.typeExclude))
     {
         return(false);
     }
     foreach (string value in namingConvention)
     {
         if (boneName.Contains(value))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #10
0
 private static bool matchesNaming(string boneName, string[] namingConvention)
 {
     if (BipedNaming.excludesNaming(boneName, BipedNaming.typeExclude))
     {
         return(false);
     }
     for (int i = 0; i < namingConvention.Length; i++)
     {
         string value = namingConvention[i];
         if (boneName.Contains(value))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #11
0
 public static Transform GetNamingMatch(Transform[] transforms, params string[][] namings)
 {
     foreach (Transform transform in transforms)
     {
         bool flag = true;
         foreach (string namingConvention in namings)
         {
             if (!BipedNaming.matchesNaming(transform.name, namingConvention))
             {
                 flag = false;
                 break;
             }
         }
         if (flag)
         {
             return(transform);
         }
     }
     return(null);
 }
コード例 #12
0
 private static void DetectLimb(BipedNaming.BoneType boneType, BipedNaming.BoneSide boneSide, ref Transform firstBone, ref Transform secondBone, ref Transform lastBone, Transform[] transforms)
 {
     Transform[] bonesOfTypeAndSide = BipedNaming.GetBonesOfTypeAndSide(boneType, boneSide, transforms);
     if (bonesOfTypeAndSide.Length < 3)
     {
         return;
     }
     if (bonesOfTypeAndSide.Length == 3)
     {
         firstBone  = bonesOfTypeAndSide[0];
         secondBone = bonesOfTypeAndSide[1];
         lastBone   = bonesOfTypeAndSide[2];
     }
     if (bonesOfTypeAndSide.Length > 3)
     {
         firstBone  = bonesOfTypeAndSide[0];
         secondBone = bonesOfTypeAndSide[2];
         lastBone   = bonesOfTypeAndSide[bonesOfTypeAndSide.Length - 1];
     }
 }
コード例 #13
0
 public static Transform GetNamingMatch(Transform[] transforms, params string[][] namings)
 {
     for (int i = 0; i < transforms.Length; i++)
     {
         Transform transform = transforms[i];
         bool      flag      = true;
         for (int j = 0; j < namings.Length; j++)
         {
             string[] namingConvention = namings[j];
             if (!BipedNaming.matchesNaming(transform.name, namingConvention))
             {
                 flag = false;
                 break;
             }
         }
         if (flag)
         {
             return(transform);
         }
     }
     return(null);
 }
コード例 #14
0
 private static bool isEye(string boneName)
 {
     return(BipedNaming.matchesNaming(boneName, BipedNaming.typeEye) && !BipedNaming.excludesNaming(boneName, BipedNaming.typeExcludeEye));
 }
コード例 #15
0
        /// <summary>
        /// Detects the references based on naming and hierarchy.
        /// </summary>
        public static void DetectReferencesByNaming(ref BipedReferences references, Transform root, AutoDetectParams autoDetectParams)
        {
            if (references == null)
            {
                references = new BipedReferences();
            }

            Transform[] children = root.GetComponentsInChildren <Transform>();

            // Find limbs
            DetectLimb(BipedNaming.BoneType.Arm, BipedNaming.BoneSide.Left, ref references.leftUpperArm, ref references.leftForearm, ref references.leftHand, children);
            DetectLimb(BipedNaming.BoneType.Arm, BipedNaming.BoneSide.Right, ref references.rightUpperArm, ref references.rightForearm, ref references.rightHand, children);
            DetectLimb(BipedNaming.BoneType.Leg, BipedNaming.BoneSide.Left, ref references.leftThigh, ref references.leftCalf, ref references.leftFoot, children);
            DetectLimb(BipedNaming.BoneType.Leg, BipedNaming.BoneSide.Right, ref references.rightThigh, ref references.rightCalf, ref references.rightFoot, children);

            // Find head bone
            references.head = BipedNaming.GetBone(children, BipedNaming.BoneType.Head);

            // Find Pelvis
            references.pelvis = BipedNaming.GetNamingMatch(children, BipedNaming.pelvis);

            // If pelvis is not an ancestor of a leg, it is not a valid pelvis
            if (references.pelvis == null || !Hierarchy.IsAncestor(references.leftThigh, references.pelvis))
            {
                if (references.leftThigh != null)
                {
                    references.pelvis = references.leftThigh.parent;
                }
            }

            // Find spine and head bones
            if (references.leftUpperArm != null && references.rightUpperArm != null && references.pelvis != null && references.leftThigh != null)
            {
                Transform neck = Hierarchy.GetFirstCommonAncestor(references.leftUpperArm, references.rightUpperArm);

                if (neck != null)
                {
                    Transform[] inverseSpine = new Transform[1] {
                        neck
                    };
                    Hierarchy.AddAncestors(inverseSpine[0], references.pelvis, ref inverseSpine);

                    references.spine = new Transform[0];
                    for (int i = inverseSpine.Length - 1; i > -1; i--)
                    {
                        if (AddBoneToSpine(inverseSpine[i], ref references, autoDetectParams))
                        {
                            Array.Resize(ref references.spine, references.spine.Length + 1);
                            references.spine[references.spine.Length - 1] = inverseSpine[i];
                        }
                    }

                    // Head
                    if (references.head == null)
                    {
                        for (int i = 0; i < neck.childCount; i++)
                        {
                            Transform child = neck.GetChild(i);

                            if (!Hierarchy.ContainsChild(child, references.leftUpperArm) && !Hierarchy.ContainsChild(child, references.rightUpperArm))
                            {
                                references.head = child;
                                break;
                            }
                        }
                    }
                }
            }

            // Find eye bones
            Transform[] eyes = BipedNaming.GetBonesOfType(BipedNaming.BoneType.Eye, children);
            references.eyes = new Transform[0];

            if (autoDetectParams.includeEyes)
            {
                for (int i = 0; i < eyes.Length; i++)
                {
                    if (AddBoneToEyes(eyes[i], ref references, autoDetectParams))
                    {
                        Array.Resize(ref references.eyes, references.eyes.Length + 1);
                        references.eyes[references.eyes.Length - 1] = eyes[i];
                    }
                }
            }
        }
コード例 #16
0
		// Tries to guess the limb bones based on naming
		private static void DetectLimb(BipedNaming.BoneType boneType, BipedNaming.BoneSide boneSide, ref Transform firstBone, ref Transform secondBone, ref Transform lastBone, Transform[] transforms) {
			Transform[] limb = BipedNaming.GetBonesOfTypeAndSide(boneType, boneSide, transforms);
			
			if (limb.Length < 3) {
				//Warning.Log("Unable to detect biped bones by bone names. Please manually assign bone references.", firstBone, true);
				return;
			}
			
			// Standard biped characters
			if (limb.Length == 3) {
				firstBone = limb[0];
				secondBone = limb[1];
				lastBone = limb[2];
			}
			
			// For Bootcamp soldier type of characters with more than 3 limb bones
			if (limb.Length > 3) {
				firstBone = limb[0];
				secondBone = limb[2];
				lastBone = limb[limb.Length - 1];
			}
		}
コード例 #17
0
 public static void DetectReferencesByNaming(ref BipedReferences references, Transform root, BipedReferences.AutoDetectParams autoDetectParams)
 {
     if (references == null)
     {
         references = new BipedReferences();
     }
     Transform[] componentsInChildren = root.GetComponentsInChildren <Transform>();
     BipedReferences.DetectLimb(BipedNaming.BoneType.Arm, BipedNaming.BoneSide.Left, ref references.leftUpperArm, ref references.leftForearm, ref references.leftHand, componentsInChildren);
     BipedReferences.DetectLimb(BipedNaming.BoneType.Arm, BipedNaming.BoneSide.Right, ref references.rightUpperArm, ref references.rightForearm, ref references.rightHand, componentsInChildren);
     BipedReferences.DetectLimb(BipedNaming.BoneType.Leg, BipedNaming.BoneSide.Left, ref references.leftThigh, ref references.leftCalf, ref references.leftFoot, componentsInChildren);
     BipedReferences.DetectLimb(BipedNaming.BoneType.Leg, BipedNaming.BoneSide.Right, ref references.rightThigh, ref references.rightCalf, ref references.rightFoot, componentsInChildren);
     references.head   = BipedNaming.GetBone(componentsInChildren, BipedNaming.BoneType.Head, BipedNaming.BoneSide.Center, Array.Empty <string[]>());
     references.pelvis = BipedNaming.GetNamingMatch(componentsInChildren, new string[][]
     {
         BipedNaming.pelvis
     });
     if ((references.pelvis == null || !Hierarchy.IsAncestor(references.leftThigh, references.pelvis)) && references.leftThigh != null)
     {
         references.pelvis = references.leftThigh.parent;
     }
     if (references.leftUpperArm != null && references.rightUpperArm != null && references.pelvis != null && references.leftThigh != null)
     {
         Transform firstCommonAncestor = Hierarchy.GetFirstCommonAncestor(references.leftUpperArm, references.rightUpperArm);
         if (firstCommonAncestor != null)
         {
             Transform[] array = new Transform[]
             {
                 firstCommonAncestor
             };
             Hierarchy.AddAncestors(array[0], references.pelvis, ref array);
             references.spine = new Transform[0];
             for (int i = array.Length - 1; i > -1; i--)
             {
                 if (BipedReferences.AddBoneToSpine(array[i], ref references, autoDetectParams))
                 {
                     Array.Resize <Transform>(ref references.spine, references.spine.Length + 1);
                     references.spine[references.spine.Length - 1] = array[i];
                 }
             }
             if (references.head == null)
             {
                 for (int j = 0; j < firstCommonAncestor.childCount; j++)
                 {
                     Transform child = firstCommonAncestor.GetChild(j);
                     if (!Hierarchy.ContainsChild(child, references.leftUpperArm) && !Hierarchy.ContainsChild(child, references.rightUpperArm))
                     {
                         references.head = child;
                         break;
                     }
                 }
             }
         }
     }
     Transform[] bonesOfType = BipedNaming.GetBonesOfType(BipedNaming.BoneType.Eye, componentsInChildren);
     references.eyes = new Transform[0];
     if (autoDetectParams.includeEyes)
     {
         for (int k = 0; k < bonesOfType.Length; k++)
         {
             if (BipedReferences.AddBoneToEyes(bonesOfType[k], ref references, autoDetectParams))
             {
                 Array.Resize <Transform>(ref references.eyes, references.eyes.Length + 1);
                 references.eyes[references.eyes.Length - 1] = bonesOfType[k];
             }
         }
     }
 }
コード例 #18
0
 public static Transform[] GetBonesOfTypeAndSide(BipedNaming.BoneType boneType, BipedNaming.BoneSide boneSide, Transform[] bones)
 {
     Transform[] bonesOfType = BipedNaming.GetBonesOfType(boneType, bones);
     return(BipedNaming.GetBonesOfSide(boneSide, bonesOfType));
 }
コード例 #19
0
 public static Transform GetBone(Transform[] transforms, BipedNaming.BoneType boneType, BipedNaming.BoneSide boneSide = BipedNaming.BoneSide.Center, params string[][] namings)
 {
     return(BipedNaming.GetNamingMatch(BipedNaming.GetBonesOfTypeAndSide(boneType, boneSide, transforms), namings));
 }
コード例 #20
0
 private static bool isTypeExclude(string boneName)
 {
     return(BipedNaming.matchesNaming(boneName, BipedNaming.typeExclude));
 }
コード例 #21
0
 private static bool isTail(string boneName)
 {
     return(BipedNaming.matchesNaming(boneName, BipedNaming.typeTail) && !BipedNaming.excludesNaming(boneName, BipedNaming.typeExcludeTail));
 }
コード例 #22
0
 private static bool isHead(string boneName)
 {
     return(BipedNaming.matchesNaming(boneName, BipedNaming.typeHead) && !BipedNaming.excludesNaming(boneName, BipedNaming.typeExcludeHead));
 }
コード例 #23
0
 private static bool isRight(string boneName)
 {
     return(BipedNaming.matchesNaming(boneName, BipedNaming.typeRight) || BipedNaming.lastLetter(boneName) == "R" || BipedNaming.firstLetter(boneName) == "R");
 }
コード例 #24
0
 private static bool isLeft(string boneName)
 {
     return(BipedNaming.matchesNaming(boneName, BipedNaming.typeLeft) || BipedNaming.lastLetter(boneName) == "L" || BipedNaming.firstLetter(boneName) == "L");
 }