Exemple #1
0
    public void OnSceneGUI()
    {
        // Handles for the data points
        Handles.color = Color.red;
        bool changed = false;

        if (cardinalSpline.controlPoints.Count > 3)
        {
            for (int i = 0; i < cardinalSpline.controlPoints.Count; i++)
            {
                Vector3 oldPosition = cardinalSpline.controlPoints[i];
                Vector3 newPosition = Handles.FreeMoveHandle(oldPosition, Quaternion.identity, 1.0f, Vector3.zero, Handles.SphereCap);
                if (newPosition != oldPosition)
                {
                    cardinalSpline.controlPoints[i] = newPosition;
                    changed = true;
                }
            }
        }

        if (changed)
        {
            cardinalSpline.CalculateSplinePoints();
        }


//        Vector3 mousePosition = GetXZPlaneCollisionInEditor(Event.current);
////		Handles.SphereCap(0, mousePosition, Quaternion.identity, 5.3f);
////		mousePosition = Camera.current.ScreenToWorldPoint(Input.mousePosition);

////		Debug.Log(mousePosition);
//        Vector3 pointOnCurve = this.cardinalSpline.GetMinDistancePointOnCurve(mousePosition);
//        Handles.color = Color.yellow;
//        Handles.SphereCap(0, pointOnCurve, Quaternion.identity, 0.5f);


////		Vector2 pointOnScreen = (Vector2)Camera.current.WorldToScreenPoint(pointOnCurve);
//////		Vector3 mouseViewportPoint = Camera.current.ScreenToViewportPoint(Event.current.mousePosition);
////		Vector2 mouseViewportPoint = Event.current.mousePosition;
////
//////		Debug.Log(pointOnScreen +  "  " +  mouseViewportPoint);
////
////		float distance = Mathf.Abs(Vector2.Distance(mouseViewportPoint, pointOnScreen));
////		Debug.Log(pointOnScreen +  "  " +  mouseViewportPoint +  "  =  " + distance);
////
////		if(distance < 100f){
////			Handles.color = Color.yellow;
////			Handles.SphereCap(0, pointOnCurve, Quaternion.identity, 0.3f);
////		}

////
////		Handles.FreeMoveHandle(this.cubicBezier.GetMinDistancePointOnCurve(mousePosition), Quaternion.identity, 0.3f, Vector3.zero, Handles.SphereCap);

////		if (GUI.changed)
        EditorUtility.SetDirty(cardinalSpline);
    }
Exemple #2
0
    public static void DrawCurveGizmo(List <Vector3> points, float s, Color color)
    {
        List <Vector3> tmpSplinePoints = CardinalSpline.CalculateSplinePoints(points, s, points.Count * 10);

        //Debug.Log(tmpSplinePoints.Count);
        Gizmos.color = color;
        for (int i = 0; i < tmpSplinePoints.Count - 1; i++)
        {
            Gizmos.DrawLine(tmpSplinePoints[i], tmpSplinePoints[i + 1]);
        }
    }
Exemple #3
0
    public static void DrawCurve(Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4, float s, int numberOfPoints, Color color)
    {
        List <Vector3> tmpSplinePoints = CardinalSpline.CalculateSplinePoints(P1, P2, P3, P4, s, numberOfPoints);

        Debug.Log(tmpSplinePoints.Count);
        Gizmos.color = color;
        for (int i = 1; i < tmpSplinePoints.Count; i++)
        {
            Gizmos.DrawLine(tmpSplinePoints[i - 1], tmpSplinePoints[i]);
        }
    }