Beispiel #1
0
        protected void DrawControlPoint(int i, bool selected)
        {
            ObiCurve.ControlPoint cp = spline.controlPoints[i];

            float size = HandleUtility.GetHandleSize(cp.position) * 0.04f;

            if (selected && !orientControlPointsMode)
            {
                Handles.color = handleColor;

                if (!(i == 0 && !spline.closed))
                {
                    if (Event.current.type == EventType.Repaint)
                    {
                        Handles.DrawDottedLine(cp.GetInTangent(), cp.position, 2);
                    }

                    EditorGUI.BeginChangeCheck();
                    Vector3 newTangent = Handles.FreeMoveHandle(cp.GetInTangent(), Quaternion.identity, size, Vector3.zero, Handles.DotHandleCap);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(spline, "Modify tangent");
                        spline.controlPoints[i] = cp.SetInTangent(newTangent);
                    }
                }

                if (!(i == spline.controlPoints.Count - 1 && !spline.closed))
                {
                    if (Event.current.type == EventType.Repaint)
                    {
                        Handles.DrawDottedLine(cp.GetOutTangent(), cp.position, 2);
                    }

                    EditorGUI.BeginChangeCheck();
                    Vector3 newTangent = Handles.FreeMoveHandle(cp.GetOutTangent(), Quaternion.identity, size, Vector3.zero, Handles.DotHandleCap);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(spline, "Modify tangent");
                        spline.controlPoints[i] = cp.SetOutTangent(newTangent);
                    }
                }
            }

            if (Event.current.type == EventType.Repaint)
            {
                Handles.color = selected ? handleColor : Color.white;

                if (orientControlPointsMode)
                {
                    Handles.ArrowHandleCap(0, cp.position, Quaternion.LookRotation(cp.normal), HandleUtility.GetHandleSize(cp.position), EventType.Repaint);
                }

                Handles.SphereHandleCap(0, cp.position, Quaternion.identity, size * 3, EventType.Repaint);
            }
        }
Beispiel #2
0
        protected void RotateTool(List <ObiCurve.ControlPoint> controlPoints, Vector3 handlePosition, Quaternion handleRotation)
        {
            EditorGUI.BeginChangeCheck();
            // TODO: investigate weird rotation gizmo:
            Quaternion newRotation = Handles.RotationHandle(prevRot, handlePosition);

            if (EditorGUI.EndChangeCheck())
            {
                Quaternion delta = newRotation * Quaternion.Inverse(prevRot);
                prevRot = newRotation;

                Undo.RecordObject(spline, "Rotate control point");

                if (Tools.pivotMode == PivotMode.Center)
                {
                    // Rotate all selected control points around their average:
                    for (int i = 0; i < controlPoints.Count; ++i)
                    {
                        if (selectedStatus[i])
                        {
                            Vector3 newPos = handlePosition + delta * (controlPoints[i].position - handlePosition);
                            controlPoints[i] = controlPoints[i].Transform(newPos - controlPoints[i].position, Quaternion.identity);
                        }
                    }
                }
                else
                {
                    // Rotate all handles of selected control points around their control point:
                    for (int i = 0; i < controlPoints.Count; ++i)
                    {
                        if (selectedStatus[i])
                        {
                            ObiCurve.ControlPoint cp = controlPoints[i];
                            cp.inTangent     = delta * cp.inTangent;
                            cp.outTangent    = delta * cp.outTangent;
                            controlPoints[i] = cp;
                        }
                    }
                }
            }
        }
Beispiel #3
0
        protected void ScaleTool(List <ObiCurve.ControlPoint> controlPoints, Vector3 handlePosition, Quaternion handleRotation)
        {
            EditorGUI.BeginChangeCheck();
            Vector3 scale = Handles.ScaleHandle(prevScale, handlePosition, handleRotation, HandleUtility.GetHandleSize(handlePosition));

            if (EditorGUI.EndChangeCheck())
            {
                Vector3 deltaScale = new Vector3(scale.x / prevScale.x, scale.y / prevScale.y, scale.z / prevScale.z);
                prevScale = scale;

                Undo.RecordObject(spline, "Scale control point");

                if (Tools.pivotMode == PivotMode.Center)
                {
                    for (int i = 0; i < controlPoints.Count; ++i)
                    {
                        if (selectedStatus[i])
                        {
                            Vector3 newPos = handlePosition + Vector3.Scale(controlPoints[i].position - handlePosition, deltaScale);
                            controlPoints[i] = controlPoints[i].Transform(newPos - controlPoints[i].position, Quaternion.identity);
                        }
                    }
                }
                else
                {
                    // Scale all handles of selected control points relative to their control point:
                    for (int i = 0; i < controlPoints.Count; ++i)
                    {
                        if (selectedStatus[i])
                        {
                            ObiCurve.ControlPoint cp = controlPoints[i];
                            cp.inTangent     = Vector3.Scale(controlPoints[i].inTangent, deltaScale);
                            cp.outTangent    = Vector3.Scale(controlPoints[i].outTangent, deltaScale);
                            controlPoints[i] = cp;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        protected void OrientTool(List <ObiCurve.ControlPoint> controlPoints, Vector3 averagePos, Quaternion pivotRotation)
        {
            EditorGUI.BeginChangeCheck();
            Quaternion newRotation = Handles.RotationHandle(prevRot, averagePos);

            if (EditorGUI.EndChangeCheck())
            {
                Quaternion delta = newRotation * Quaternion.Inverse(prevRot);
                prevRot = newRotation;

                Undo.RecordObject(spline, "Orient control point");

                // Rotate all selected control points around their average:
                for (int i = 0; i < controlPoints.Count; ++i)
                {
                    if (selectedStatus[i])
                    {
                        ObiCurve.ControlPoint cp = controlPoints[i];
                        cp.normal        = delta * cp.normal;
                        controlPoints[i] = cp;
                    }
                }
            }
        }
Beispiel #5
0
        protected void DrawUIWindow(int windowID)
        {
            GUILayout.BeginHorizontal();
            addControlPointsMode = GUILayout.Toggle(addControlPointsMode, new GUIContent(Resources.Load <Texture2D>("AddControlPoint"), "Add CPs"), "Button", GUILayout.MaxHeight(24), GUILayout.Width(42));

            if (GUILayout.Button(new GUIContent(Resources.Load <Texture2D>("RemoveControlPoint"), "Remove selected CPs"), GUILayout.MaxHeight(24), GUILayout.Width(42)))
            {
                Undo.RecordObject(spline, "Remove control point");

                for (int i = spline.controlPoints.Count - 1; i >= 0; --i)
                {
                    if (selectedStatus[i])
                    {
                        spline.controlPoints.RemoveAt(i);
                    }
                }

                for (int i = 0; i < selectedStatus.Length; ++i)
                {
                    selectedStatus[i] = false;
                }

                ResizeCPArrays();
            }

            orientControlPointsMode = GUILayout.Toggle(orientControlPointsMode, new GUIContent(Resources.Load <Texture2D>("OrientControlPoint"), "Orient CPs"), "Button", GUILayout.MaxHeight(24), GUILayout.Width(42));
            GUILayout.EndHorizontal();

            EditorGUI.showMixedValue = false;
            ObiCurve.ControlPoint.BezierCPMode mode = ObiCurve.ControlPoint.BezierCPMode.Free;
            bool firstSelected = true;

            for (int i = 0; i < spline.controlPoints.Count; ++i)
            {
                if (selectedStatus[i])
                {
                    if (firstSelected)
                    {
                        mode          = spline.controlPoints[i].tangentMode;
                        firstSelected = false;
                    }
                    else if (mode != spline.controlPoints[i].tangentMode)
                    {
                        EditorGUI.showMixedValue = true;
                        break;
                    }
                }
            }

            EditorGUI.BeginChangeCheck();
            ObiCurve.ControlPoint.BezierCPMode newMode = (ObiCurve.ControlPoint.BezierCPMode)EditorGUILayout.EnumPopup(mode, GUI.skin.FindStyle("DropDown"));
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(spline, "Change control points mode");

                for (int i = 0; i < spline.controlPoints.Count; ++i)
                {
                    if (selectedStatus[i])
                    {
                        ObiCurve.ControlPoint cp = spline.controlPoints[i];
                        cp.tangentMode          = newMode;
                        spline.controlPoints[i] = cp;
                    }
                }
            }
        }