void ShowDirections()
        {
            Handles.color = Color.green;
            Vector3 point = spline.GetPoint(0f);

            Handles.DrawLine(point, point + spline.GetDirection(0f) * directionScale);
            int steps = stepsPerCurve * spline.CurveCount;

            for (int i = 1; i <= steps; i++)
            {
                point = spline.GetPoint(i / (float)steps);
                Handles.DrawLine(point, point + spline.GetDirection(i / (float)steps) * directionScale);
            }
        }
Esempio n. 2
0
        protected virtual void OnSceneGUI()
        {
            spline          = target as SplinePath;
            handleTransform = spline.transform;

            if (currentTool != Tools.current ||
                currentPivotRotation != Tools.pivotRotation)
            {
                currentTool          = Tools.current;
                currentPivotRotation = Tools.pivotRotation;

                ResetHandleSettings();
            }

            Vector3 p0 = ShowPoint(0);

            for (int i = 1; i < spline.ControlPointCount; i += 3)
            {
                Vector3 p1 = ShowPoint(i);
                Vector3 p2 = ShowPoint(i + 1);
                Vector3 p3 = ShowPoint(i + 2);

                Handles.color = Color.gray;
                Handles.DrawLine(p0, p1);
                Handles.DrawLine(p2, p3);

                Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f);
                p0 = p3;
            }

            Handles.color = Color.green.SetA(0.3f);
            Handles.SphereHandleCap(0, spline.GetPoint(0f), Quaternion.identity, 0.1f, EventType.Repaint);

            Handles.color = Color.red.SetA(0.3f);
            Handles.SphereHandleCap(0, spline.GetPoint(1f), Quaternion.identity, 0.1f, EventType.Repaint);

            if (spline.NormalType == NormalType.Perpendicular)
            {
                for (int i = 0; i < spline.Normals.Length; i++)
                {
                    if (i % 3 == 0)
                    {
                        Vector3 pos    = spline.GetControlPoint(i);
                        Vector3 normal = spline.GetControlNormal(i);

                        Handles.color = Color.red;
                        Handles.DrawLine(pos, pos + normal * 0.8f);
                    }
                }
            }

            int numIterations = 10 * spline.ControlPointCount;

            for (int i = 1; i < numIterations; i++)
            {
                float alpha = i / (float)numIterations;

                Vector3 pos    = spline.GetPoint(alpha);
                Vector3 normal = spline.GetNormal(alpha);

                Handles.color = Color.green;
                Handles.DrawLine(pos, pos + normal * 0.4f);
            }
        }