Esempio n. 1
0
        // Check if eyes are properly set up
        private static bool CheckEyesError(BipedReferences references, bool log)
        {
            if (references.eyes.Length == 0)
            {
                return(true);
            }

            for (int i = 0; i < references.eyes.Length; i++)
            {
                if (references.eyes[i] == null)
                {
                    if (log)
                    {
                        Warning.Log("BipedReferences eye bone at index " + i + " is null.", references.root, true);
                    }
                    return(false);
                }
            }

            Transform duplicate = (Transform)Hierarchy.ContainsDuplicate(references.eyes);

            if (duplicate != null)
            {
                if (log)
                {
                    Warning.Log(duplicate.name + " is represented multiple times in BipedReferences eyes.", references.eyes[0], true);
                }
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        // Check if eyes are properly set up
        private static bool EyesError(BipedReferences references, ref string errorMessage)
        {
            // No eyes might be a valid setup
            if (references.eyes.Length == 0)
            {
                return(false);
            }

            for (int i = 0; i < references.eyes.Length; i++)
            {
                if (references.eyes[i] == null)
                {
                    errorMessage = "BipedReferences eye bone at index " + i + " is null.";
                    return(true);
                }
            }

            Transform duplicate = (Transform)Hierarchy.ContainsDuplicate(references.eyes);

            if (duplicate != null)
            {
                errorMessage = duplicate.name + " is represented multiple times in BipedReferences eyes.";
                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        private static bool LimbError(Transform bone1, Transform bone2, Transform bone3, ref string errorMessage)
        {
            if (bone1 == null)
            {
                errorMessage = "Bone 1 of a BipedReferences limb is null.";
                return(true);
            }
            if (bone2 == null)
            {
                errorMessage = "Bone 2 of a BipedReferences limb is null.";
                return(true);
            }
            if (bone3 == null)
            {
                errorMessage = "Bone 3 of a BipedReferences limb is null.";
                return(true);
            }
            UnityEngine.Object[] objects = new Transform[]
            {
                bone1,
                bone2,
                bone3
            };
            Transform transform = (Transform)Hierarchy.ContainsDuplicate(objects);

            if (transform != null)
            {
                errorMessage = transform.name + " is represented multiple times in the same BipedReferences limb.";
                return(true);
            }
            if (bone2.position == bone1.position)
            {
                errorMessage = "Second bone's position equals first bone's position in the biped's limb.";
                return(true);
            }
            if (bone3.position == bone2.position)
            {
                errorMessage = "Third bone's position equals second bone's position in the biped's limb.";
                return(true);
            }
            if (!Hierarchy.HierarchyIsValid(new Transform[]
            {
                bone1,
                bone2,
                bone3
            }))
            {
                errorMessage = string.Concat(new string[]
                {
                    "BipedReferences limb hierarchy is invalid. Bone transforms in a limb do not belong to the same ancestry. Please make sure the bones are parented to each other. Bones: ",
                    bone1.name,
                    ", ",
                    bone2.name,
                    ", ",
                    bone3.name
                });
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
        private static bool CheckSpineError(BipedReferences references, bool log)
        {
            if (references.spine.Length == 0)
            {
                return(true);
            }
            for (int i = 0; i < references.spine.Length; i++)
            {
                if (references.spine[i] == null)
                {
                    if (log)
                    {
                        Warning.Log("BipedReferences spine bone at index " + i + " is null.", references.root, true);
                    }
                    return(false);
                }
            }
            Transform transform = (Transform)Hierarchy.ContainsDuplicate(references.spine);

            if (transform != null)
            {
                if (log)
                {
                    Warning.Log(transform.name + " is represented multiple times in BipedReferences spine.", references.spine[0], true);
                }
                return(false);
            }
            if (!Hierarchy.HierarchyIsValid(references.spine))
            {
                if (log)
                {
                    Warning.Log("BipedReferences spine hierarchy is invalid. Bone transforms in the spine do not belong to the same ancestry. Please make sure the bones are parented to each other.", references.spine[0], true);
                }
                return(false);
            }
            for (int j = 0; j < references.spine.Length; j++)
            {
                bool flag = false;
                if (j == 0 && references.spine[j].position == references.pelvis.position)
                {
                    flag = true;
                }
                if (j != 0 && references.spine.Length > 1 && references.spine[j].position == references.spine[j - 1].position)
                {
                    flag = true;
                }
                if (flag)
                {
                    if (log)
                    {
                        Warning.Log("Biped's spine bone nr " + j + " position is the same as it's parent spine/pelvis bone's position. Please remove this bone from the spine.", references.spine[j], true);
                    }
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 5
0
        // Check if the limb is properly set up
        private static bool LimbError(Transform bone1, Transform bone2, Transform bone3, ref string errorMessage)
        {
            if (bone1 == null)
            {
                errorMessage = "Bone 1 of a BipedReferences limb is null.";
                return(true);
            }

            if (bone2 == null)
            {
                errorMessage = "Bone 2 of a BipedReferences limb is null.";
                return(true);
            }

            if (bone3 == null)
            {
                errorMessage = "Bone 3 of a BipedReferences limb is null.";
                return(true);
            }

            Transform duplicate = (Transform)Hierarchy.ContainsDuplicate(new Transform[3] {
                bone1, bone2, bone3
            });

            if (duplicate != null)
            {
                errorMessage = duplicate.name + " is represented multiple times in the same BipedReferences limb.";
                return(true);
            }

            if (bone2.position == bone1.position)
            {
                errorMessage = "Second bone's position equals first bone's position in the biped's limb.";
                return(true);
            }

            if (bone3.position == bone2.position)
            {
                errorMessage = "Third bone's position equals second bone's position in the biped's limb.";
                return(true);
            }

            if (!Hierarchy.HierarchyIsValid(new Transform[3] {
                bone1, bone2, bone3
            }))
            {
                errorMessage = "BipedReferences limb hierarchy is invalid. Bone transforms in a limb do not belong to the same ancestry. Please make sure the bones are parented to each other. " +
                               "Bones: " + bone1.name + ", " + bone2.name + ", " + bone3.name;

                return(true);
            }

            return(false);
        }
Esempio n. 6
0
        // Check if spine is properly set up
        private static bool SpineError(BipedReferences references, ref string errorMessage)
        {
            // No spine might be a valid setup in some cases
            if (references.spine.Length == 0)
            {
                return(false);
            }

            for (int i = 0; i < references.spine.Length; i++)
            {
                if (references.spine[i] == null)
                {
                    errorMessage = "BipedReferences spine bone at index " + i + " is null.";
                    return(true);
                }
            }

            Transform duplicate = (Transform)Hierarchy.ContainsDuplicate(references.spine);

            if (duplicate != null)
            {
                errorMessage = duplicate.name + " is represented multiple times in BipedReferences spine.";
                return(true);
            }

            if (!Hierarchy.HierarchyIsValid(references.spine))
            {
                errorMessage = "BipedReferences spine hierarchy is invalid. Bone transforms in the spine do not belong to the same ancestry. Please make sure the bones are parented to each other.";
                return(true);
            }

            for (int i = 0; i < references.spine.Length; i++)
            {
                bool matchesParentPosition = false;
                if (i == 0 && references.spine[i].position == references.pelvis.position)
                {
                    matchesParentPosition = true;
                }
                if (i != 0 && references.spine.Length > 1 && references.spine[i].position == references.spine[i - 1].position)
                {
                    matchesParentPosition = true;
                }

                if (matchesParentPosition)
                {
                    errorMessage = "Biped's spine bone nr " + i + " position is the same as it's parent spine/pelvis bone's position. Please remove this bone from the spine.";
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 7
0
        // Check if the limb is properly set up
        private static bool CheckLimbError(Transform bone1, Transform bone2, Transform bone3, bool log)
        {
            if (bone2.position == bone1.position)
            {
                if (log)
                {
                    Warning.Log("Second bone's position equals first bone's position in the biped's limb.", bone2, true);
                }
                return(false);
            }

            if (bone3.position == bone2.position)
            {
                if (log)
                {
                    Warning.Log("Third bone's position equals second bone's position in the biped's limb.", bone3, true);
                }
                return(false);
            }

            Transform duplicate = (Transform)Hierarchy.ContainsDuplicate(new Transform[3] {
                bone1, bone2, bone3
            });

            if (duplicate != null)
            {
                if (log)
                {
                    Warning.Log(duplicate.name + " is represented multiple times in the same BipedReferences limb.", bone1, true);
                }
                return(false);
            }

            if (!Hierarchy.HierarchyIsValid(new Transform[3] {
                bone1, bone2, bone3
            }))
            {
                if (log)
                {
                    Warning.Log(
                        "BipedReferences limb hierarchy is invalid. Bone transforms in a limb do not belong to the same ancestry. Please make sure the bones are parented to each other. " +
                        "Bones: " + bone1.name + ", " + bone2.name + ", " + bone3.name,
                        bone1,
                        true);
                }
                return(false);
            }

            return(true);
        }
Esempio n. 8
0
        // Check if spine is properly set up
        private static bool CheckSpineError(BipedReferences references, bool log)
        {
            if (references.spine.Length == 0)
            {
                return(true);
            }

            Transform duplicate = (Transform)Hierarchy.ContainsDuplicate(references.spine);

            if (duplicate != null)
            {
                if (log)
                {
                    Warning.Log(duplicate.name + " is represented multiple times in BipedReferences spine.", references.spine[0], true);
                }
                return(false);
            }

            if (!Hierarchy.HierarchyIsValid(references.spine))
            {
                if (log)
                {
                    Warning.Log("BipedReferences spine hierarchy is invalid. Bone transforms in the spine do not belong to the same ancestry. Please make sure the bones are parented to each other.", references.spine[0], true);
                }
                return(false);
            }

            for (int i = 0; i < references.spine.Length; i++)
            {
                bool matchesParentPositon = i == 0? references.spine[i].position == references.pelvis.position: references.spine[i].position == references.spine[i - 1].position;

                if (matchesParentPositon)
                {
                    if (log)
                    {
                        Warning.Log("Biped's spine bone nr " + i + " position is the same as it's parent spine/pelvis bone's position. Please remove this bone from the spine.", references.spine[i], true);
                    }
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 9
0
        // Check if eyes are properly set up
        private static bool CheckEyesError(BipedReferences references, bool log)
        {
            if (references.eyes.Length == 0)
            {
                return(true);
            }

            Transform duplicate = (Transform)Hierarchy.ContainsDuplicate(references.eyes);

            if (duplicate != null)
            {
                if (log)
                {
                    Warning.Log(duplicate.name + " is represented multiple times in BipedReferences eyes.", references.eyes[0], true);
                }
                return(false);
            }

            return(true);
        }
Esempio n. 10
0
        private static bool EyesError(BipedReferences references, ref string errorMessage)
        {
            if (references.eyes.Length == 0)
            {
                return(false);
            }
            for (int i = 0; i < references.eyes.Length; i++)
            {
                if (references.eyes[i] == null)
                {
                    errorMessage = "BipedReferences eye bone at index " + i + " is null.";
                    return(true);
                }
            }
            UnityEngine.Object[] objects   = references.eyes;
            Transform            transform = (Transform)Hierarchy.ContainsDuplicate(objects);

            if (transform != null)
            {
                errorMessage = transform.name + " is represented multiple times in BipedReferences eyes.";
                return(true);
            }
            return(false);
        }
Esempio n. 11
0
        /*
         * Check if the limb is properly set up
         * */
        private static bool CheckLimb(Transform bone1, Transform bone2, Transform bone3, bool log)
        {
            if (bone2.position == bone1.position)
            {
                if (log)
                {
                    Warning.Log("Second bone's position equals first bone's position in the biped's limb.", bone2, true);
                }
                return(false);
            }

            if (bone3.position == bone2.position)
            {
                if (log)
                {
                    Warning.Log("Third bone's position equals second bone's position in the biped's limb.", bone3, true);
                }
                return(false);
            }

            Transform duplicate = (Transform)Hierarchy.ContainsDuplicate(new Transform[3] {
                bone1, bone2, bone3
            });

            if (duplicate != null)
            {
                if (log)
                {
                    Warning.Log(duplicate.name + " is represented multiple times in the same BipedReferences limb.", bone1, true);
                }
                return(false);
            }

            if (!Hierarchy.HierarchyIsValid(new Transform[3] {
                bone1, bone2, bone3
            }))
            {
                if (log)
                {
                    Warning.Log(
                        "BipedReferences limb hierarchy is invalid. Bone transforms in a limb do not belong to the same ancestry. Please make sure the bones are parented to each other. " +
                        "Bones: " + bone1.name + ", " + bone2.name + ", " + bone3.name,
                        bone1,
                        true);
                }
                return(false);
            }

            Vector3 cross = Vector3.Cross(bone2.position - bone1.position, bone3.position - bone1.position);

            if (cross == Vector3.zero)
            {
                if (log)
                {
                    Warning.Log(
                        "BipedReferences limb is completely stretched out in the initial pose. IK solver can not calculate the default bend plane for the limb. " +
                        "Please make sure you character's limbs are at least slightly bent in the initial pose. " +
                        "First bone: " + bone1.name + ", second bone: " + bone2.name + ".",
                        bone1,
                        true);
                }
                return(false);
            }

            return(true);
        }