[Bf-blender-cvs] [454563ffac6] greasepencil-object: GP: Add bezier tool [wip]

Charlie Jolly noreply at git.blender.org
Thu Dec 6 18:12:30 CET 2018


Commit: 454563ffac60856714247d39ceb294f5330463fd
Author: Charlie Jolly
Date:   Thu Dec 6 17:10:54 2018 +0000
Branches: greasepencil-object
https://developer.blender.org/rB454563ffac60856714247d39ceb294f5330463fd

GP: Add bezier tool [wip]

Shift drag to move curve.
Ctrl-shift to move both cps.

===================================================================

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	release/scripts/startup/bl_ui/space_topbar.py
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/windowmanager/intern/wm_cursors.c
M	source/blender/windowmanager/wm_cursors.h

===================================================================

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index fe4fe5b52c7..b1168ec83da 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -5707,6 +5707,15 @@ def km_3d_view_tool_gpencil_paint_arc(params):
         ]},
     )
 
+def km_3d_view_tool_gpencil_paint_bezier(params):
+    return (
+        "3D View Tool: Gpencil Paint, Bezier",
+        {"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
+        {"items": [
+            ("gpencil.primitive", {"type": params.tool_tweak, "value": 'ANY'},
+             {"properties": [("type", 'BEZIER'), ("wait_for_input", False)]}),
+        ]},
+    )	
 
 def km_3d_view_tool_gpencil_edit_select(params):
     return (
@@ -5981,6 +5990,7 @@ def generate_keymaps(params=None):
         km_3d_view_tool_gpencil_paint_box(params),
         km_3d_view_tool_gpencil_paint_circle(params),
         km_3d_view_tool_gpencil_paint_arc(params),
+        km_3d_view_tool_gpencil_paint_bezier(params),
         km_3d_view_tool_gpencil_edit_select(params),
         km_3d_view_tool_gpencil_edit_select_box(params),
         km_3d_view_tool_gpencil_edit_select_circle(params),
diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 5a0c2bd1e43..125063f05a4 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -645,6 +645,7 @@ class GPENCIL_MT_gpencil_draw_specials(Menu):
         layout.operator("gpencil.primitive", text="Rectangle", icon='UV_FACESEL').type = 'BOX'
         layout.operator("gpencil.primitive", text="Circle", icon='ANTIALIASED').type = 'CIRCLE'
         layout.operator("gpencil.primitive", text="Arc", icon='SPHERECURVE').type = 'ARC'
+        layout.operator("gpencil.primitive", text="Bezier", icon='CURVE_BEZCURVE').type = 'BEZIER'
 
 
 class GPENCIL_MT_gpencil_draw_delete(Menu):
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 5c930b68dd9..0a42fef3546 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1076,6 +1076,17 @@ class _defs_gpencil_paint:
             widget=None,
             keymap=(),
         )
+		
+
+    @ToolDef.from_fn
+    def bezier():
+        return dict(
+            text="Bezier",
+            icon="ops.gpencil.primitive_bezier",
+            cursor='CROSSHAIR',
+            widget=None,
+            keymap=(),
+        )		
 
 class _defs_gpencil_edit:
     @ToolDef.from_fn
@@ -1583,6 +1594,7 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
             _defs_gpencil_paint.box,
             _defs_gpencil_paint.circle,
             _defs_gpencil_paint.arc,
+            _defs_gpencil_paint.bezier,
         ],
         'GPENCIL_EDIT': [
             *_tools_gpencil_select,
diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index a74683d2849..69e96d9d196 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -301,7 +301,7 @@ class _draw_left_context_mode:
                 return
 
             is_paint = True
-            if (tool.name in {"Line", "Box", "Circle", "Arc"}):
+            if (tool.name in {"Line", "Box", "Circle", "Arc", "Bezier"}):
                 is_paint = False
             elif (not tool.has_datablock):
                 return
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 6b269b865cd..98b37542c91 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -155,13 +155,18 @@ typedef struct tGPDprimitive {
 	struct bGPDlayer *gpl;            /* layer */
 	struct bGPDframe *gpf;            /* frame */
 	int type;                         /* type of primitive */
-	short cyclic;                       /* cyclic option */
-	short flip;                         /* flip option */
+	bool curve;                         /* type of primitive is a curve */
+	short cyclic;                     /* cyclic option */
+	short flip;                       /* flip option */
 	int tot_edges;                    /* number of polygon edges */
 	int top[2];                       /* first box corner */
 	int bottom[2];                    /* last box corner */
 	int origin[2];                    /* initial box corner */
+	int bezcp1[2];                     /* first bezier control point */
+	int bezcp2[2];                     /* second bezier control point */
 	int flag;                         /* flag to determine operations in progress */
+	int sel_cp;                         /* flag to determine control point is selected */
+	int mvalo[2];                     /* previous recorded mouse-position */
 
 	int lock_axis;                    /* lock to viewport axis */
 
@@ -380,7 +385,8 @@ enum {
 	GP_STROKE_BOX = -1,
 	GP_STROKE_LINE = 1,
 	GP_STROKE_CIRCLE = 2,
-	GP_STROKE_ARC = 3
+	GP_STROKE_ARC = 3,
+	GP_STROKE_BEZIER = 4
 };
 
 
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 6d0f22a6645..97657501213 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -88,6 +88,15 @@
 
 #define IDLE 0
 #define IN_PROGRESS 1
+#define IN_CURVE_EDIT_A 2
+#define IN_CURVE_EDIT_B 3
+#define IN_CURVE_EDIT_BEZIER 4
+
+#define CURVE_CP_NONE 0
+#define CURVE_CP_T 1
+#define CURVE_CP_1 2
+#define CURVE_CP_2 3
+#define CURVE_CP_B 4
 
   /* ************************************************ */
   /* Core/Shared Utilities */
@@ -291,6 +300,9 @@ static void gpencil_primitive_status_indicators(bContext *C, tGPDprimitive *tgpi
 	else if (tgpi->type == GP_STROKE_ARC) {
 		BLI_strncpy(msg_str, IFACE_("Arc: ESC/RMB to cancel, Enter/LMB to confirm, WHEEL/+- to adjust edge number, Shift to square, Alt to center, F to flip, C to Close"), UI_MAX_DRAW_STR);
 	}
+	else if (tgpi->type == GP_STROKE_BEZIER) {
+		BLI_strncpy(msg_str, IFACE_("Bezier: ESC/RMB to cancel, Enter/LMB to confirm, WHEEL/+- to adjust edge number, Shift to square, Alt to center, F to flip, C to Close"), UI_MAX_DRAW_STR);
+	}
 	else {
 		BLI_strncpy(msg_str, IFACE_("Circle: ESC/RMB to cancel, Enter/LMB to confirm, WHEEL/+- to adjust edge number, Shift to square, Alt to center"), UI_MAX_DRAW_STR);
 	}
@@ -393,6 +405,29 @@ static void gp_primitive_arc(tGPDprimitive *tgpi, tPGPspoint *points2D)
 	}
 }
 
+/* create a bezier */
+static void gp_primitive_bezier(tGPDprimitive *tgpi, tPGPspoint *points2D)
+{
+	const int totpoints = tgpi->tot_edges;
+	const float step = 1.0f / (float)(totpoints - 1);
+	float cp1[2];
+	float cp2[2];
+	float cp3[2];
+	float cp4[2];
+	float a = 0.0f;
+
+	copy_v2fl_v2i(cp1, tgpi->top);
+	copy_v2fl_v2i(cp2, tgpi->bezcp1);
+	copy_v2fl_v2i(cp3, tgpi->bezcp2);
+	copy_v2fl_v2i(cp4, tgpi->bottom);
+
+	for (int i = 0; i < totpoints; i++) {
+		tPGPspoint *p2d = &points2D[i];
+		interp_v2_v2v2v2v2_cubic(&p2d->x, cp1, cp2, cp3, cp4, a);
+		a += step;
+	}
+}
+
 /* create a circle */
 static void gp_primitive_circle(tGPDprimitive *tgpi, tPGPspoint *points2D)
 {
@@ -448,15 +483,20 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
 			break;
 		case GP_STROKE_ARC:
 			gp_primitive_arc(tgpi, points2D);
-			if (tgpi->cyclic)
-				gps->flag |= GP_STROKE_CYCLIC;
-			else
-				gps->flag &= ~GP_STROKE_CYCLIC;
 			break;
+		case GP_STROKE_BEZIER:
+			gp_primitive_bezier(tgpi, points2D);
 		default:
 			break;
 	}
 
+	if (ELEM(tgpi->type, GP_STROKE_ARC, GP_STROKE_BEZIER)) {
+		if (tgpi->cyclic)
+			gps->flag |= GP_STROKE_CYCLIC;
+		else
+			gps->flag &= ~GP_STROKE_CYCLIC;
+	}	
+
 	/* convert screen-coordinates to 3D coordinates */
 	gp_session_validatebuffer(tgpi);
 	gp_init_colors(tgpi);
@@ -538,14 +578,11 @@ static void gpencil_primitive_update(bContext *C, wmOperator *op, tGPDprimitive
 
 static void gpencil_primitive_interaction_begin(tGPDprimitive *tgpi, const wmEvent *event)
 {
-	tgpi->origin[0] = event->mval[0];
-	tgpi->origin[1] = event->mval[1];
-
-	tgpi->top[0] = event->mval[0];
-	tgpi->top[1] = event->mval[1];
-
-	tgpi->bottom[0] = event->mval[0];
-	tgpi->bottom[1] = event->mval[1];
+	copy_v2_v2_int(tgpi->origin, event->mval);
+	copy_v2_v2_int(tgpi->top, event->mval);
+	copy_v2_v2_int(tgpi->bottom, event->mval);
+	copy_v2_v2_int(tgpi->bezcp1, event->mval);
+	copy_v2_v2_int(tgpi->bezcp2, event->mval);
 }
 
 /* Exit and free memory */
@@ -624,11 +661,16 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op)
 	/* set parameters */
 	tgpi->type = RNA_enum_get(op->ptr, "type");
 
+	if(ELEM(tgpi->type, GP_STROKE_ARC, GP_STROKE_BEZIER))
+		tgpi->curve = true;
+	else
+		tgpi->curve = false;
+
 	/* set default edge count */
 	if (tgpi->type == GP_STROKE_CIRCLE) {
 		RNA_int_set(op->ptr, "edges", 64);
 	}
-	else if (tgpi->type == GP_STROKE_ARC) {
+	else if (tgpi->curve) {
 		RNA_int_set(op->ptr, "edges", 32);
 	}
 	else if (tgpi->type == GP_STROKE_BOX) {
@@ -735,7 +777,18 @@ static void gpencil_primitive_interaction_end(bContext *C, wmOperator *op, wmWin
 	DEG_id_tag_update(&tgpi->gpd->id, OB_RECALC_OB | OB_RECALC_DATA);
 
 	/* clean up temp data */
-	gpencil_primitive_exit(C, op);
+	
+}
+
+/* Helper to set bezier cp */
+static void gpencil_primitive_set_midpoint(tGPDprimitive *tgpi)
+{
+	float midpoint[2], start[2], end[2];
+	copy_v2fl_v2i(start, tgpi->top);
+	copy_v2fl_v2i(end, tgpi->bottom);
+	mid_v2_v2v2(midpoint, start, end);
+	round_v2i_v2fl(tgpi->bezcp1, midpoint);
+	copy_v2_v2_int(tgpi->bezcp2, tgpi->bezcp1);
 }
 
 /* Helper to square a primitive */
@@ -757,6 +810,101 @@ static void gpencil_primitive_to_square(tGPDprimitive *tgpi, const int x, const
 	}
 }
 
+#define MOVE_NONE 0
+#define MOVE_ENDS 1
+#define MOVE_CP 2
+
+/* bezier event handling */
+static void gpencil_primitive_bezier_e

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list