Exemple #1
0
        public static void DrawMultiSelect(
            IBezier3DSplineData splineData,
            UnityEditor.Editor editorWindow,
            Transform transform = null)
        {
            Handles.color = Color.blue;
            for (var i = 0; i < CurveEditorState.SelectedKnots.Count; i++)
            {
                if (Handles.Button(
                        transform == null
                                                ? splineData.GetKnot(CurveEditorState.SelectedKnots[i]).position
                                                : transform.TransformPoint(splineData.GetKnot(CurveEditorState.SelectedKnots[i]).position),
                        Camera.current.transform.rotation,
                        SceneGUIConstants.HandleSize,
                        SceneGUIConstants.HandleSize,
                        Handles.CircleHandleCap))
                {
                    CurveEditorState.SelectKnot(CurveEditorState.SelectedKnots[i], true);
                    editorWindow.Repaint();
                }
            }

            var handlePos = Vector3.zero;

            if (Tools.pivotMode == PivotMode.Center)
            {
                for (var i = 0; i < CurveEditorState.SelectedKnots.Count; i++)
                {
                    handlePos += splineData.GetKnot(CurveEditorState.SelectedKnots[i]).position;
                }

                handlePos /= CurveEditorState.SelectedKnots.Count;
            }
            else
            {
                handlePos = splineData.GetKnot(CurveEditorState.SelectedKnotIndex).position;
            }

            if (transform != null)
            {
                handlePos = transform.TransformPoint(handlePos);
            }

            Handles.PositionHandle(handlePos, Tools.handleRotation);
        }
Exemple #2
0
        public static void DrawUnselectedKnots(
            IBezier3DSplineData splineData,
            UnityEditor.Editor editorWindow,
            Transform transform = null)
        {
            for (var i = 0; i < splineData.KnotCount; i++)
            {
                if (CurveEditorState.SelectedKnots.Contains(i))
                {
                    continue;
                }

                var knot         = splineData.GetKnot(i);
                var knotWorldPos = transform == null
                                        ? knot.position
                                        : transform.TransformPoint(knot.position);

                if (knot.rotation.HasValue)
                {
                    Handles.color = Handles.yAxisColor;
                    var rot = knot.rotation.Value;
                    Handles.ArrowHandleCap(
                        0,
                        knotWorldPos,
                        rot * Quaternion.AngleAxis(90, Vector3.left),
                        0.15f,
                        EventType.Repaint);
                }

                Handles.color = Color.white;
                if (Handles.Button(
                        knotWorldPos,
                        Camera.current.transform.rotation,
                        HandleUtility.GetHandleSize(knotWorldPos) * SceneGUIConstants.HandleSize,
                        HandleUtility.GetHandleSize(knotWorldPos) * SceneGUIConstants.HandleSize,
                        Handles.CircleHandleCap))
                {
                    CurveEditorState.SelectKnot(i, Event.current.control);
                    editorWindow.Repaint();
                }
            }
        }
Exemple #3
0
        public static void DrawSelectedSplitters(
            Bezier3DSplineData splineData,
            Action <IReadOnly3DSplineData> onUpdateSpline,
            Transform transform = null)
        {
            Handles.color = Color.white;

            //Start add
            if (!splineData.IsClosed && CurveEditorState.SelectedKnotIndex == 0)
            {
                var curve = splineData.GetCurve(0);
                var a     = transform == null
                                                ? curve.StartPoint
                                                : transform.TransformPoint(curve.StartPoint);
                var b = transform == null
                                                ? curve.FirstHandle.normalized * 2f
                                                : transform.TransformDirection(curve.FirstHandle).normalized * 2f;

                var handleScale = HandleUtility.GetHandleSize(a);
                b *= handleScale;
                Handles.DrawDottedLine(a, a - b, 3f);
                if (Handles.Button(
                        a - b,
                        Camera.current.transform.rotation,
                        handleScale * SceneGUIConstants.HandleSize * 0.4f,
                        handleScale * SceneGUIConstants.HandleSize * 0.4f,
                        Handles.DotHandleCap))
                {
                    Undo.RecordObject(splineData, "Add Bezier Point");
                    var knot = splineData.GetKnot(CurveEditorState.SelectedKnotIndex);
                    splineData.InsertKnot(
                        0,
                        new Knot(
                            curve.StartPoint - curve.FirstHandle.normalized * handleScale * 2,
                            Vector3.zero,
                            curve.FirstHandle.normalized * 0.5f,
                            knot.auto,
                            knot.rotation));
                    onUpdateSpline?.Invoke(splineData);
                }
            }

            //End add
            if (!splineData.IsClosed && CurveEditorState.SelectedKnotIndex == splineData.CurveCount)
            {
                var curve = splineData.GetCurve(splineData.CurveCount - 1);
                var c     = transform == null
                                                ? curve.SecondHandle.normalized * 2f
                                                : transform.TransformDirection(curve.SecondHandle).normalized * 2f;
                var d = transform == null
                                                ? curve.EndPoint
                                                : transform.TransformPoint(curve.EndPoint);
                var handleScale = HandleUtility.GetHandleSize(d);
                c *= handleScale;
                Handles.DrawDottedLine(d, d - c, 3f);

                if (Handles.Button(
                        d - c,
                        Camera.current.transform.rotation,
                        handleScale * SceneGUIConstants.HandleSize * 0.4f,
                        handleScale * SceneGUIConstants.HandleSize * 0.4f,
                        Handles.DotHandleCap))
                {
                    Undo.RecordObject(splineData, "Add Bezier Point");

                    var knot = splineData.GetKnot(CurveEditorState.SelectedKnotIndex);
                    splineData.AddKnot(
                        new Knot(
                            curve.EndPoint - curve.SecondHandle.normalized * handleScale * 2,
                            curve.SecondHandle.normalized * 0.5f,
                            Vector3.zero,
                            knot.auto,
                            knot.rotation));

                    CurveEditorState.SelectKnot(splineData.CurveCount, false);

                    onUpdateSpline?.Invoke(splineData);
                }
            }

            // Prev split
            if (splineData.IsClosed || CurveEditorState.SelectedKnotIndex != 0)
            {
                var curve       = splineData.GetCurve(CurveEditorState.SelectedKnotIndex == 0 ? splineData.CurveCount - 1 : CurveEditorState.SelectedKnotIndex - 1);
                var centerLocal = curve.GetPoint(curve.ConvertDistanceToTime(curve.Length * 0.5f));
                var center      = transform == null ? centerLocal : transform.TransformPoint(centerLocal);

                var a           = curve.StartPoint + curve.FirstHandle;
                var b           = curve.SecondHandle + curve.EndPoint;
                var ab          = (b - a) * 0.3f;
                var handleScale = HandleUtility.GetHandleSize(center);

                if (Handles.Button(
                        center,
                        Camera.current.transform.rotation,
                        handleScale * SceneGUIConstants.HandleSize * 0.4f,
                        handleScale * SceneGUIConstants.HandleSize * 0.4f,
                        Handles.DotHandleCap))
                {
                    Undo.RecordObject(splineData, "Add Bezier Point");
                    var knot = splineData.GetKnot(CurveEditorState.SelectedKnotIndex);
                    splineData.InsertKnot(
                        CurveEditorState.SelectedKnotIndex == 0 ? splineData.CurveCount : CurveEditorState.SelectedKnotIndex,
                        new Knot(
                            centerLocal,
                            -ab,
                            ab,
                            knot.auto,
                            knot.rotation));

                    if (CurveEditorState.SelectedKnotIndex == 0)
                    {
                        CurveEditorState.SelectKnot(splineData.CurveCount - 1, false);
                    }

                    onUpdateSpline?.Invoke(splineData);
                }
            }

            // Next split
            if (CurveEditorState.SelectedKnotIndex != splineData.CurveCount)
            {
                var curve       = splineData.GetCurve(CurveEditorState.SelectedKnotIndex);
                var centerLocal = curve.GetPoint(curve.ConvertDistanceToTime(curve.Length * 0.5f));
                var center      = transform == null ? centerLocal : transform.TransformPoint(centerLocal);

                var a           = curve.StartPoint + curve.FirstHandle;
                var b           = curve.SecondHandle + curve.EndPoint;
                var ab          = (b - a) * 0.3f;
                var handleScale = HandleUtility.GetHandleSize(center);
                if (Handles.Button(
                        center,
                        Camera.current.transform.rotation,
                        handleScale * SceneGUIConstants.HandleSize * 0.4f,
                        handleScale * SceneGUIConstants.HandleSize * 0.4f,
                        Handles.DotHandleCap))
                {
                    Undo.RecordObject(splineData, "Add Bezier Point");
                    splineData.InsertKnot(CurveEditorState.SelectedKnotIndex + 1, new Knot(centerLocal, -ab, ab));
                    CurveEditorState.SelectKnot(CurveEditorState.SelectedKnotIndex + 1, false);
                    onUpdateSpline?.Invoke(splineData);
                }
            }
        }