Пример #1
0
        public bool ReferencesWarning(ref string warningMessage)
        {
            if (BipedReferences.SetupWarning(this.references, ref warningMessage))
            {
                return(true);
            }
            Vector3 vector  = this.references.rightUpperArm.position - this.references.leftUpperArm.position;
            Vector3 vector2 = this.solver.rootNode.position - this.references.leftUpperArm.position;
            float   num     = Vector3.Dot(vector.normalized, vector2.normalized);

            if (num > 0.95f)
            {
                warningMessage = "The root node, the left upper arm and the right upper arm bones should ideally form a triangle that is as close to equilateral as possible. Currently the root node bone seems to be very close to the line between the left upper arm and the right upper arm bones. This might cause unwanted behaviour like the spine turning upside down when pulled by a hand effector.Please set the root node bone to be one of the lower bones in the spine.";
                return(true);
            }
            Vector3 vector3 = this.references.rightThigh.position - this.references.leftThigh.position;
            Vector3 vector4 = this.solver.rootNode.position - this.references.leftThigh.position;

            num = Vector3.Dot(vector3.normalized, vector4.normalized);
            if (num > 0.95f)
            {
                warningMessage = "The root node, the left thigh and the right thigh bones should ideally form a triangle that is as close to equilateral as possible. Currently the root node bone seems to be very close to the line between the left thigh and the right thigh bones. This might cause unwanted behaviour like the hip turning upside down when pulled by an effector.Please set the root node bone to be one of the higher bones in the spine.";
                return(true);
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        /// Check for possible warnings with the biped references setup. Returns true if warning found. The solver can still run, but probably not how you expected.
        /// </summary>
        public bool ReferencesWarning(ref string warningMessage)
        {
            // Check for all the warnings common to all bipeds
            if (BipedReferences.SetupWarning(references, ref warningMessage))
            {
                return(true);
            }

            // Check for warnings specific to FBBIK
            Vector3 toRightShoulder    = references.rightUpperArm.position - references.leftUpperArm.position;
            Vector3 shoulderToRootNode = solver.rootNode.position - references.leftUpperArm.position;
            float   dot = Vector3.Dot(toRightShoulder.normalized, shoulderToRootNode.normalized);

            if (dot > 0.95f)
            {
                warningMessage = "The root node, the left upper arm and the right upper arm bones should ideally form a triangle that is as close to equilateral as possible. " +
                                 "Currently the root node bone seems to be very close to the line between the left upper arm and the right upper arm bones. This might cause unwanted behaviour like the spine turning upside down when pulled by a hand effector." +
                                 "Please set the root node bone to be one of the lower bones in the spine.";
                return(true);
            }

            Vector3 toRightThigh    = references.rightThigh.position - references.leftThigh.position;
            Vector3 thighToRootNode = solver.rootNode.position - references.leftThigh.position;

            dot = Vector3.Dot(toRightThigh.normalized, thighToRootNode.normalized);

            if (dot > 0.95f)
            {
                warningMessage = "The root node, the left thigh and the right thigh bones should ideally form a triangle that is as close to equilateral as possible. " +
                                 "Currently the root node bone seems to be very close to the line between the left thigh and the right thigh bones. This might cause unwanted behaviour like the hip turning upside down when pulled by an effector." +
                                 "Please set the root node bone to be one of the higher bones in the spine.";
                return(true);
            }

            return(false);
        }
Пример #3
0
        public void OnEnable()
        {
            if (serializedObject == null)
            {
                return;
            }

            // Store the MonoScript for changing script execution order
            if (!Application.isPlaying)
            {
                MonoScript monoScript = MonoScript.FromMonoBehaviour(script);

                // Changing the script execution order to make sure BipedIK always executes after any other script except FullBodyBipedIK
                int executionOrder = MonoImporter.GetExecutionOrder(monoScript);
                if (executionOrder != 9998)
                {
                    MonoImporter.SetExecutionOrder(monoScript, 9998);
                }
            }

            references    = serializedObject.FindProperty("references");
            solvers       = serializedObject.FindProperty("solvers");
            solversProps  = BipedIKSolversInspector.FindProperties(solvers);
            fixTransforms = new SerializedContent(serializedObject.FindProperty("fixTransforms"), new GUIContent("Fix Transforms", "If true, will fix all the Transforms used by the solver to their initial state in each Update. This prevents potential problems with unanimated bones and animator culling with a small cost of performance."));

            // Automatically detecting references
            if (!Application.isPlaying)
            {
                if (script.references.isEmpty)
                {
                    BipedReferences.AutoDetectReferences(ref script.references, script.transform, new BipedReferences.AutoDetectParams(false, true));

                    references.isExpanded = true;
                    solvers.isExpanded    = false;
                    for (int i = 0; i < solversProps.Length; i++)
                    {
                        solversProps[i].isExpanded = false;
                    }

                    // Setting default values and initiating
                    script.InitiateBipedIK();
                    script.SetToDefaults();
                    EditorUtility.SetDirty(script);
                }
                else
                {
                    script.InitiateBipedIK();
                }

                Warning.logged = false;

                string message = string.Empty;
                if (Application.isPlaying)
                {
                    if (BipedReferences.SetupError(script.references, ref message) || BipedReferences.SetupWarning(script.references, ref message))
                    {
                        Warning.Log(message, script.references.root, false);
                    }
                }
            }
        }