コード例 #1
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];
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Fills in BipedReferences using Animator.GetBoneTransform().
        /// </summary>
        public static void AssignHumanoidReferences(ref BipedReferences references, Animator animator, 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);

            AddBoneToHierarchy(ref references.spine, animator.GetBoneTransform(HumanBodyBones.Spine));
            AddBoneToHierarchy(ref references.spine, animator.GetBoneTransform(HumanBodyBones.Chest));

            // Make sure the neck bone is not above the arms
            if (references.leftUpperArm != null)
            {
                if (!IsNeckBone(animator.GetBoneTransform(HumanBodyBones.Neck), references.leftUpperArm))
                {
                    AddBoneToHierarchy(ref references.spine, animator.GetBoneTransform(HumanBodyBones.Neck));
                }
            }

            if (autoDetectParams.includeEyes)
            {
                AddBoneToHierarchy(ref references.eyes, animator.GetBoneTransform(HumanBodyBones.LeftEye));
                AddBoneToHierarchy(ref references.eyes, animator.GetBoneTransform(HumanBodyBones.RightEye));
            }
        }
コード例 #3
0
		// Determines whether a bone is valid for being added into the spine
		private static bool AddBoneToSpine(Transform bone, ref BipedReferences references, AutoDetectParams autoDetectParams) {
			if (bone == references.root) return false;
			
			bool isLegsParent = bone == references.leftThigh.parent;
			if (isLegsParent && !autoDetectParams.legsParentInSpine) return false;
			
			if (references.pelvis != null) {
				if (bone == references.pelvis) return false;
				if (Hierarchy.IsAncestor(references.pelvis, bone)) return false;
			}
			
			return true;
		}
コード例 #4
0
        /// <summary>
        /// Automatically detects biped bones. Returns true if a valid biped has been referenced.
        /// </summary>
        public static bool AutoDetectReferences(ref BipedReferences references, Transform root, AutoDetectParams autoDetectParams)
        {
            if (references == null)
            {
                references = new BipedReferences();
            }
            references.root = root;

            // If that failed try the Animator
            var animator = root.GetComponent <Animator>();

            if (animator != null && animator.isHuman)
            {
                AssignHumanoidReferences(ref references, animator, autoDetectParams);
                return(true);                // Assume humanoids are always valid
            }

            // Try with naming and hierarchy first
            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 (SetupError(references, ref message))
            {
                Warning.Log(message, references.root, true);
                return(false);
            }

            if (SetupWarning(references, ref message))
            {
                Warning.Log(message, references.root, true);
            }

            return(true);
        }
コード例 #5
0
		/// <summary>
		/// Fills in BipedReferences using Animator.GetBoneTransform().
		/// </summary>
		public static void AssignHumanoidReferences(ref BipedReferences references, Animator animator, 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);
			
			AddBoneToHierarchy(ref references.spine, animator.GetBoneTransform(HumanBodyBones.Spine));
			AddBoneToHierarchy(ref references.spine, animator.GetBoneTransform(HumanBodyBones.Chest));
			
			// Make sure the neck bone is not above the arms
			if (references.leftUpperArm != null) {
				if (!IsNeckBone(animator.GetBoneTransform(HumanBodyBones.Neck), references.leftUpperArm)) AddBoneToHierarchy(ref references.spine, animator.GetBoneTransform(HumanBodyBones.Neck));
			}
			
			if (autoDetectParams.includeEyes) {
				AddBoneToHierarchy(ref references.eyes, animator.GetBoneTransform(HumanBodyBones.LeftEye));
				AddBoneToHierarchy(ref references.eyes, animator.GetBoneTransform(HumanBodyBones.RightEye));
			}
		}
コード例 #6
0
		// Determines whether a bone is valid for being added into the eyes array
		private static bool AddBoneToEyes(Transform bone, ref BipedReferences references, AutoDetectParams autoDetectParams) {
			if (references.head != null) {
				if (!Hierarchy.IsAncestor(bone, references.head)) return false;
			}
			
			if (bone.GetComponent<SkinnedMeshRenderer>() != null) return false;
			
			return true;
		}
コード例 #7
0
		/// <summary>
		/// Automatically detects biped bones. Returns true if a valid biped has been referenced.
		/// </summary>
		public static bool AutoDetectReferences(ref BipedReferences references, Transform root, AutoDetectParams autoDetectParams) {
			if (references == null) references = new BipedReferences();
			references.root = root;
			
			// Try with naming and hierarchy first
			DetectReferencesByNaming(ref references, root, autoDetectParams);
			
			if (references.isValid && CheckSetupError(references, false) && CheckSetupWarning(references, false)) return true;
			
			// If that failed try the Animator
			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;
		}
コード例 #8
0
 public virtual bool Contains(Transform t, bool ignoreRoot = false /* Metadata: 0x00652D4A */) => default;                              // 0x00000001804B8640-0x00000001804B8AD0
 public static bool AutoDetectReferences(ref BipedReferences references, Transform root, AutoDetectParams autoDetectParams) => default; // 0x00000001804B82B0-0x00000001804B8640
コード例 #9
0
 private static bool AddBoneToEyes(Transform bone, ref BipedReferences references, AutoDetectParams autoDetectParams) => default;  // 0x00000001804B79C0-0x00000001804B7AC0
 private static bool AddBoneToSpine(Transform bone, ref BipedReferences references, AutoDetectParams autoDetectParams) => default; // 0x00000001804B7BB0-0x00000001804B7D40
コード例 #10
0
        /// <summary>
        /// Automatically detects biped bones. Returns true if a valid biped has been referenced.
        /// </summary>
        public static bool AutoDetectReferences(ref BipedReferences references, Transform root, AutoDetectParams autoDetectParams)
        {
            if (references == null)
            {
                references = new BipedReferences();
            }
            references.root = root;

            // Try with naming and hierarchy first
            DetectReferencesByNaming(ref references, root, autoDetectParams);

            if (references.isValid && CheckSetupError(references, false) && CheckSetupWarning(references, false))
            {
                return(true);
            }

            // If that failed try the Animator
            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);
        }
コード例 #11
0
 private static bool IsNeckBone(Transform bone, Transform leftUpperArm) => default;                                                // 0x00000001804BA1D0-0x00000001804BA2C0
 private static bool AddBoneToEyes(Transform bone, ref BipedReferences references, AutoDetectParams autoDetectParams) => default;  // 0x00000001804B79C0-0x00000001804B7AC0
コード例 #12
0
        }                                                                                                                                         // 0x00000001804B8C60-0x00000001804B97A0

        public static void AssignHumanoidReferences(ref BipedReferences references, Animator animator, AutoDetectParams autoDetectParams)
        {
        }                                                                                                                                 // 0x00000001804B7D40-0x00000001804B82B0
コード例 #13
0
        public static bool AutoDetectReferences(ref BipedReferences references, Transform root, AutoDetectParams autoDetectParams) => default; // 0x00000001804B82B0-0x00000001804B8640

        public static void DetectReferencesByNaming(ref BipedReferences references, Transform root, AutoDetectParams autoDetectParams)
        {
        }                                                                                                                                         // 0x00000001804B8C60-0x00000001804B97A0
コード例 #14
0
        // Determines whether a bone is valid for being added into the eyes array
        private static bool AddBoneToEyes(Transform bone, ref BipedReferences references, AutoDetectParams autoDetectParams)
        {
            if (references.head != null)
            {
                if (!Hierarchy.IsAncestor(bone, references.head))
                {
                    return(false);
                }
            }

            if (bone.GetComponent <SkinnedMeshRenderer>() != null)
            {
                return(false);
            }

            return(true);
        }
コード例 #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
        // Determines whether a bone is valid for being added into the spine
        private static bool AddBoneToSpine(Transform bone, ref BipedReferences references, AutoDetectParams autoDetectParams)
        {
            if (bone == references.root)
            {
                return(false);
            }

            bool isLegsParent = bone == references.leftThigh.parent;

            if (isLegsParent && !autoDetectParams.legsParentInSpine)
            {
                return(false);
            }

            if (references.pelvis != null)
            {
                if (bone == references.pelvis)
                {
                    return(false);
                }
                if (Hierarchy.IsAncestor(references.pelvis, bone))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #17
0
		/// <summary>
		/// Automatically detects biped bones. Returns true if a valid biped has been referenced.
		/// </summary>
		public static bool AutoDetectReferences(ref BipedReferences references, Transform root, AutoDetectParams autoDetectParams) {
			if (references == null) references = new BipedReferences();
			references.root = root;

			// If that failed try the Animator
			var animator = root.GetComponent<Animator>();
			if (animator != null && animator.isHuman) {
				AssignHumanoidReferences(ref references, animator, autoDetectParams);
				return true; // Assume humanoids are always valid
			}

			// Try with naming and hierarchy first
			DetectReferencesByNaming(ref references, root, autoDetectParams);

			Warning.logged = false;

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

			if (!CheckSetupError(references, true)) return false;

			CheckSetupWarning(references, true);
			
			return true;
		}