Example #1
0
        // Scene view handles to help with limb setup
        private static void AddLimbHelper(FBIKChain chain, float size, Transform root = null)
        {
            Vector3 cross = Vector3.Cross((chain.nodes[1].transform.position - chain.nodes[0].transform.position).normalized, (chain.nodes[2].transform.position - chain.nodes[0].transform.position).normalized);

            Vector3 bendDirection = -Vector3.Cross(cross.normalized, (chain.nodes[2].transform.position - chain.nodes[0].transform.position).normalized);

            if (bendDirection != Vector3.zero)
            {
                Color c        = Handles.color;
                bool  inverted = root != null && Vector3.Dot(root.forward, bendDirection.normalized) < 0f;

                // Inverted bend direction
                if (inverted)
                {
                    GUI.color     = new Color(1f, 0.75f, 0.75f);
                    Handles.color = Color.yellow;

                    if (Inspector.DotButton(chain.nodes[1].transform.position, Quaternion.identity, size * 0.5f, size))
                    {
                        Warning.logged = false;
                        Warning.Log("The bend direction of this limb appears to be inverted. Please rotate this bone so that the limb is bent in it's natural bending direction. If this limb is supposed to be bent in the direction pointed by the arrow, ignore this warning.", root, true);
                    }
                }

                Inspector.ArrowCap(0, chain.nodes[1].transform.position, Quaternion.LookRotation(bendDirection), size * 2f);

                GUI.color     = Color.white;
                Handles.color = c;
            }
            else
            {
                // The limb is completely stretched out
                Color c = Handles.color;
                Handles.color = Color.red;
                GUI.color     = new Color(1f, 0.75f, 0.75f);

                if (Inspector.DotButton(chain.nodes[1].transform.position, Quaternion.identity, size * 0.5f, size))
                {
                    Warning.logged = false;
                    Warning.Log("The limb is completely stretched out. Full Body Biped IK does not know which way the limb should be bent. Please rotate this bone slightly in it's bending direction.", root, true);
                }

                GUI.color     = Color.white;
                Handles.color = c;
            }
        }