コード例 #1
0
        private static void DrawPose(AimPoser.Pose pose, Vector3 position, Quaternion rotation, Color color)
        {
            if (pose.pitch <= 0f || pose.yaw <= 0f)
            {
                return;
            }
            if (pose.direction == Vector3.zero)
            {
                return;
            }

            Handles.color = color;
            GUI.color     = color;

            Vector3 up = rotation * Vector3.up;
            Vector3 normalizedPoseDirection = pose.direction.normalized;
            Vector3 direction = rotation * normalizedPoseDirection;

            // Direction and label
            Handles.DrawLine(position, position + direction);
            Inspector.ConeCap(0, position + direction, Quaternion.LookRotation(direction), 0.05f);
            Handles.Label(position + direction.normalized * 1.1f, pose.name);

            if (pose.yaw >= 180f && pose.pitch >= 180f)
            {
                Handles.color = Color.white;
                GUI.color     = Color.white;
                return;
            }

            Quaternion halfYaw = Quaternion.AngleAxis(pose.yaw, up);

            float   directionPitch = Vector3.Angle(up, direction);
            Vector3 crossRight     = halfYaw * Vector3.Cross(up, direction);
            Vector3 crossLeft      = Quaternion.Inverse(halfYaw) * Vector3.Cross(up, direction);

            bool isVertical = normalizedPoseDirection == Vector3.up || normalizedPoseDirection == Vector3.down;

            if (isVertical)
            {
                crossRight = halfYaw * Vector3.right;
                crossLeft  = Quaternion.Inverse(halfYaw) * Vector3.right;
            }

            float minPitch = Mathf.Clamp(directionPitch - pose.pitch, 0f, 180f);
            float maxPitch = Mathf.Clamp(directionPitch + pose.pitch, 0f, 180f);

            Quaternion upToCornerUpperRight = Quaternion.AngleAxis(minPitch, crossRight);
            Quaternion upToCornerLowerRight = Quaternion.AngleAxis(maxPitch, crossRight);
            Quaternion upToCornerUpperLeft  = Quaternion.AngleAxis(minPitch, crossLeft);
            Quaternion upToCornerLowerLeft  = Quaternion.AngleAxis(maxPitch, crossLeft);

            Vector3 toCornerUpperRight = upToCornerUpperRight * up;
            Vector3 toCornerLowerRight = upToCornerLowerRight * up;
            Vector3 toCornerUpperLeft  = upToCornerUpperLeft * up;
            Vector3 toCornerLowerLeft  = upToCornerLowerLeft * up;

            if (pose.yaw < 180f)
            {
                Handles.DrawLine(position, position + toCornerUpperRight);
                Handles.DrawLine(position, position + toCornerUpperLeft);

                Handles.DrawLine(position, position + toCornerLowerRight);
                Handles.DrawLine(position, position + toCornerLowerLeft);
            }

            Vector3 d = direction;

            if (isVertical)
            {
                d = Vector3.forward;
            }

            if (pose.pitch < 180f)
            {
                DrawPolyLineOnSphere(position, toCornerUpperLeft, toCornerUpperRight, d, Vector3.up, color);
                DrawPolyLineOnSphere(position, toCornerLowerLeft, toCornerLowerRight, d, Vector3.up, color);
            }

            if (pose.yaw < 180f)
            {
                DrawPolyLineOnSphere(position, toCornerUpperLeft, toCornerLowerLeft, Quaternion.Inverse(halfYaw) * d, crossLeft, color);
                DrawPolyLineOnSphere(position, toCornerUpperRight, toCornerLowerRight, halfYaw * d, crossRight, color);
            }

            Handles.color = Color.white;
            GUI.color     = Color.white;
        }
コード例 #2
0
        //Draws the scene view helpers for AimIKJ
        public static void AddScene(AimIKJ ik, Color color, bool modifiable)
        {
            // Protect from null reference errors
            if (ik.aimTransform == null)
            {
                return;
            }
            if (Application.isPlaying && !ik.initiated)
            {
                return;
            }

            foreach (Transform bone in ik.bones)
            {
                if (bone == null)
                {
                    return;
                }
            }

            Handles.color = color;
            GUI.color     = color;

            // Display the bones
            for (int i = 0; i < ik.bones.Length; i++)
            {
                if (i < ik.bones.Length - 1)
                {
                    Handles.DrawLine(ik.bones[i].position, ik.bones[i + 1].position);
                }
                Inspector.SphereCap(0, ik.bones[i].transform.position, Quaternion.identity, IKSolverInspector.GetHandleSize(ik.bones[i].position));
            }

            if (ik.axis != Vector3.zero)
            {
                Inspector.ConeCap(0, ik.aimTransform.position, Quaternion.LookRotation(ik.aimTransform.rotation * ik.axis), IKSolverInspector.GetHandleSize(ik.aimTransform.position) * 2f);
            }

            // Selecting joint and manipulating IKPosition
            if (Application.isPlaying && ik.weight > 0)
            {
                if (ik.target != null)
                {
                    // Inspector.SphereCap(0, ik.target.position, Quaternion.identity, IKSolverInspector.GetHandleSize(ik.target.position));
                    Handles.DrawLine(ik.aimTransform.position, ik.target.position);

                    if (Inspector.SphereButton(ik.target.position, Quaternion.identity, IKSolverInspector.GetHandleSize(ik.target.position), IKSolverInspector.GetHandleSize(ik.target.position)))
                    {
                        Selection.activeGameObject = ik.target.gameObject;
                    }
                }

                // Draw a transparent line from transform to IKPosition
                Handles.color = new Color(color.r, color.g, color.b, color.a * ik.weight);
                Handles.DrawLine(ik.bones[ik.bones.Length - 1].position, ik.aimTransform.position);
            }

            Handles.color = color;

            // Pole
            if (Application.isPlaying && ik.poleWeight > 0f)
            {
                if (ik.poleTarget != null)
                {
                    Inspector.SphereCap(0, ik.poleTarget.position, Quaternion.identity, IKSolverInspector.GetHandleSize(ik.poleTarget.position) * 0.5f);
                    Handles.DrawLine(ik.aimTransform.position, ik.poleTarget.position);
                }

                // Draw a transparent line from transform to polePosition
                Handles.color = new Color(color.r, color.g, color.b, color.a * ik.poleWeight);
            }

            Handles.color = Color.white;
            GUI.color     = Color.white;
        }
コード例 #3
0
        /// <summary>
        /// Draws the scene view helpers for IKSolverAim
        /// </summary>
        public static void AddScene(IKSolverAim solver, Color color, bool modifiable)
        {
            // Protect from null reference errors
            if (solver.transform == null)
            {
                return;
            }
            if (Application.isPlaying && !solver.initiated)
            {
                return;
            }

            if (!Application.isPlaying)
            {
                string message = string.Empty;
                if (!solver.IsValid(ref message))
                {
                    return;
                }
            }

            Handles.color = color;
            GUI.color     = color;

            // Display the bones
            for (int i = 0; i < solver.bones.Length; i++)
            {
                IKSolver.Bone bone = solver.bones[i];

                if (i < solver.bones.Length - 1)
                {
                    Handles.DrawLine(bone.transform.position, solver.bones[i + 1].transform.position);
                }
                Inspector.SphereCap(0, solver.bones[i].transform.position, Quaternion.identity, GetHandleSize(solver.bones[i].transform.position));
            }

            if (solver.axis != Vector3.zero)
            {
                Inspector.ConeCap(0, solver.transform.position, Quaternion.LookRotation(solver.transform.rotation * solver.axis), GetHandleSize(solver.transform.position) * 2f);
            }

            // Selecting joint and manipulating IKPosition
            if (Application.isPlaying && solver.IKPositionWeight > 0)
            {
                if (modifiable)
                {
                    Inspector.SphereCap(0, solver.IKPosition, Quaternion.identity, GetHandleSize(solver.IKPosition));

                    // Manipulating position
                    solver.IKPosition = Handles.PositionHandle(solver.IKPosition, Quaternion.identity);
                }

                // Draw a transparent line from transform to IKPosition
                Handles.color = new Color(color.r, color.g, color.b, color.a * solver.IKPositionWeight);
                Handles.DrawLine(solver.bones[solver.bones.Length - 1].transform.position, solver.transform.position);
                Handles.DrawLine(solver.transform.position, solver.IKPosition);
            }

            Handles.color = color;

            // Pole
            if (Application.isPlaying && solver.poleWeight > 0f)
            {
                if (modifiable)
                {
                    Inspector.SphereCap(0, solver.polePosition, Quaternion.identity, GetHandleSize(solver.IKPosition) * 0.5f);

                    // Manipulating position
                    solver.polePosition = Handles.PositionHandle(solver.polePosition, Quaternion.identity);
                }

                // Draw a transparent line from transform to polePosition
                Handles.color = new Color(color.r, color.g, color.b, color.a * solver.poleWeight);
                Handles.DrawLine(solver.transform.position, solver.polePosition);
            }

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