Params for automatic biped recognition. (Using a struct here because I might need to add more parameters in the future).
Beispiel #1
0
 public static void AssignHumanoidReferences(ref BipedReferences references, Animator animator, BipedReferences.AutoDetectParams autoDetectParams)
 {
     if (references == null)
     {
         references = new BipedReferences();
     }
     if (animator == null || !animator.isHuman)
     {
         return;
     }
     references.spine         = new Transform[0];
     references.eyes          = new Transform[0];
     references.head          = animator.GetBoneTransform(HumanBodyBones.Head);
     references.leftThigh     = animator.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
     references.leftCalf      = animator.GetBoneTransform(HumanBodyBones.LeftLowerLeg);
     references.leftFoot      = animator.GetBoneTransform(HumanBodyBones.LeftFoot);
     references.rightThigh    = animator.GetBoneTransform(HumanBodyBones.RightUpperLeg);
     references.rightCalf     = animator.GetBoneTransform(HumanBodyBones.RightLowerLeg);
     references.rightFoot     = animator.GetBoneTransform(HumanBodyBones.RightFoot);
     references.leftUpperArm  = animator.GetBoneTransform(HumanBodyBones.LeftUpperArm);
     references.leftForearm   = animator.GetBoneTransform(HumanBodyBones.LeftLowerArm);
     references.leftHand      = animator.GetBoneTransform(HumanBodyBones.LeftHand);
     references.rightUpperArm = animator.GetBoneTransform(HumanBodyBones.RightUpperArm);
     references.rightForearm  = animator.GetBoneTransform(HumanBodyBones.RightLowerArm);
     references.rightHand     = animator.GetBoneTransform(HumanBodyBones.RightHand);
     references.pelvis        = animator.GetBoneTransform(HumanBodyBones.Hips);
     BipedReferences.AddBoneToHierarchy(ref references.spine, animator.GetBoneTransform(HumanBodyBones.Spine));
     BipedReferences.AddBoneToHierarchy(ref references.spine, animator.GetBoneTransform(HumanBodyBones.Chest));
     if (references.leftUpperArm != null && !BipedReferences.IsNeckBone(animator.GetBoneTransform(HumanBodyBones.Neck), references.leftUpperArm))
     {
         BipedReferences.AddBoneToHierarchy(ref references.spine, animator.GetBoneTransform(HumanBodyBones.Neck));
     }
     if (autoDetectParams.includeEyes)
     {
         BipedReferences.AddBoneToHierarchy(ref references.eyes, animator.GetBoneTransform(HumanBodyBones.LeftEye));
         BipedReferences.AddBoneToHierarchy(ref references.eyes, animator.GetBoneTransform(HumanBodyBones.RightEye));
     }
 }
Beispiel #2
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];
             }
         }
     }
 }
Beispiel #3
0
        public static bool AutoDetectReferences(ref BipedReferences references, Transform root, BipedReferences.AutoDetectParams autoDetectParams)
        {
            if (references == null)
            {
                references = new BipedReferences();
            }
            references.root = root;
            Animator component = root.GetComponent <Animator>();

            if (component != null && component.isHuman)
            {
                BipedReferences.AssignHumanoidReferences(ref references, component, autoDetectParams);
                return(true);
            }
            BipedReferences.DetectReferencesByNaming(ref references, root, autoDetectParams);
            Warning.logged = false;
            if (!references.isFilled)
            {
                Warning.Log("BipedReferences contains one or more missing Transforms.", root, true);
                return(false);
            }
            string message = "";

            if (BipedReferences.SetupError(references, ref message))
            {
                Warning.Log(message, references.root, true);
                return(false);
            }
            if (BipedReferences.SetupWarning(references, ref message))
            {
                Warning.Log(message, references.root, true);
            }
            return(true);
        }
Beispiel #4
0
        private static bool AddBoneToSpine(Transform bone, ref BipedReferences references, BipedReferences.AutoDetectParams autoDetectParams)
        {
            if (bone == references.root)
            {
                return(false);
            }
            bool flag = bone == references.leftThigh.parent;

            if (flag && !autoDetectParams.legsParentInSpine)
            {
                return(false);
            }
            if (references.pelvis != null)
            {
                if (bone == references.pelvis)
                {
                    return(false);
                }
                if (Hierarchy.IsAncestor(references.pelvis, bone))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #5
0
 private static bool AddBoneToEyes(Transform bone, ref BipedReferences references, BipedReferences.AutoDetectParams autoDetectParams)
 {
     return((!(references.head != null) || Hierarchy.IsAncestor(bone, references.head)) && !(bone.GetComponent <SkinnedMeshRenderer>() != null));
 }
        public static bool AutoDetectReferences(ref BipedReferences references, Transform root, BipedReferences.AutoDetectParams autoDetectParams)
        {
            if (references == null)
            {
                references = new BipedReferences();
            }
            references.root = root;
            BipedReferences.DetectReferencesByNaming(ref references, root, autoDetectParams);
            if (references.isValid && BipedReferences.CheckSetupError(references, false) && BipedReferences.CheckSetupWarning(references, false))
            {
                return(true);
            }
            BipedReferences.AssignHumanoidReferences(ref references, root.GetComponent <Animator>(), autoDetectParams);
            bool isValid = references.isValid;

            if (!isValid)
            {
                Warning.Log("BipedReferences contains one or more missing Transforms.", root, true);
            }
            return(isValid);
        }