[Bf-blender-cvs] [77b9002fa05] greasepencil-object: GP: Primitive: Chord shape

Charlie Jolly noreply at git.blender.org
Mon Dec 17 18:05:00 CET 2018


Commit: 77b9002fa05cd7f55db164ec6ba988cd02cb7a77
Author: Charlie Jolly
Date:   Mon Dec 17 16:51:19 2018 +0000
Branches: greasepencil-object
https://developer.blender.org/rB77b9002fa05cd7f55db164ec6ba988cd02cb7a77

GP: Primitive: Chord shape

Similar to Arc but based on a chord. Can create bulbous curves.

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

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

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 8c386af57be..044f1a587fa 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -5709,6 +5709,20 @@ def km_3d_view_tool_paint_gpencil_arc(params):
         ]},
     )
 
+def km_3d_view_tool_paint_gpencil_chord(params):
+    return (
+        "3D View Tool: Paint Gpencil, Chord",
+        {"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
+        {"items": [
+            ("gpencil.primitive", {"type": params.tool_tweak, "value": 'ANY'},
+             {"properties": [("type", 'CHORD'), ("wait_for_input", False)]}),
+            ("gpencil.primitive", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True},
+             {"properties": [("type", 'CHORD'), ("wait_for_input", False)]}),
+            ("gpencil.primitive", {"type": 'LEFTMOUSE', "value": 'PRESS', "alt": True},
+             {"properties": [("type", 'CHORD'), ("wait_for_input", False)]}),
+        ]},
+    )
+
 def km_3d_view_tool_paint_gpencil_curve(params):
     return (
         "3D View Tool: Paint Gpencil, Curve",
@@ -5717,7 +5731,7 @@ def km_3d_view_tool_paint_gpencil_curve(params):
             ("gpencil.primitive", {"type": params.tool_tweak, "value": 'ANY'},
              {"properties": [("type", 'CURVE'), ("wait_for_input", False)]}),
         ]},
-    )	
+    )
 
 def km_3d_view_tool_edit_gpencil_select(params):
     return (
@@ -6029,6 +6043,7 @@ def generate_keymaps(params=None):
         km_3d_view_tool_paint_gpencil_circle(params),
         km_3d_view_tool_paint_gpencil_arc(params),
         km_3d_view_tool_paint_gpencil_curve(params),
+        km_3d_view_tool_paint_gpencil_chord(params),
         km_3d_view_tool_edit_gpencil_select(params),
         km_3d_view_tool_edit_gpencil_select_box(params),
         km_3d_view_tool_edit_gpencil_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 8ba0ac6303c..560ec0c3929 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -647,6 +647,7 @@ class GPENCIL_MT_gpencil_draw_specials(Menu):
         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="Curve", icon='CURVE_BEZCURVE').type = 'CURVE'
+        layout.operator("gpencil.primitive", text="Chord", icon='SPHERECURVE').type = 'CHORD'
 
 
 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 1dba7b814d2..1cd56231bda 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1077,6 +1077,16 @@ class _defs_gpencil_paint:
             keymap=(),
         )
 
+    @ToolDef.from_fn
+    def chord():
+        return dict(
+            text="Chord",
+            icon="ops.gpencil.primitive_chord",
+            cursor='CROSSHAIR',
+            widget=None,
+            keymap=(),
+        )
+
     @ToolDef.from_fn
     def curve():
         return dict(
@@ -1594,6 +1604,7 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
             _defs_gpencil_paint.circle,
             _defs_gpencil_paint.arc,
             _defs_gpencil_paint.curve,
+            _defs_gpencil_paint.chord,
         ],
         'EDIT_GPENCIL': [
             *_tools_gpencil_select,
diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index ee5bdb38db7..f6eeb30e5c2 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", "Curve"}):
+            if (tool.name in {"Line", "Box", "Circle", "Arc", "Curve", "Chord"}):
                 is_paint = False
             elif (not tool.has_datablock):
                 return
@@ -376,7 +376,7 @@ class _draw_left_context_mode:
 
                 draw_color_selector()
 
-                if tool.name in {"Arc", "Curve", "Line", "Box", "Circle"}:
+                if tool.name in {"Arc", "Curve", "Line", "Box", "Circle", "Chord"}:
                     settings = context.tool_settings.gpencil_sculpt
                     row = layout.row(align=True)
                     row.prop(settings, "use_thickness_curve", text="", icon='CURVE_DATA')
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index e2cbeda2733..4e998e2ddcb 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -380,7 +380,8 @@ enum {
 	GP_STROKE_LINE = 1,
 	GP_STROKE_CIRCLE = 2,
 	GP_STROKE_ARC = 3,
-	GP_STROKE_CURVE = 4
+	GP_STROKE_CURVE = 4,
+	GP_STROKE_CHORD = 5
 };
 
 
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index e32639b1039..fecf34676f0 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -231,7 +231,7 @@ static void gp_primitive_update_cps(tGPDprimitive *tgpi)
 		copy_v2_v2(tgpi->cp1, tgpi->midpoint);
 		copy_v2_v2(tgpi->cp2, tgpi->cp1);
 	}
-	else if (tgpi->type == GP_STROKE_CURVE) {
+	else if (tgpi->type == GP_STROKE_CURVE || tgpi->type == GP_STROKE_CHORD) {
 		mid_v2_v2v2(tgpi->midpoint, tgpi->start, tgpi->end);
 		copy_v2_v2(tgpi->cp1, tgpi->midpoint);
 		copy_v2_v2(tgpi->cp2, tgpi->cp1);
@@ -246,6 +246,15 @@ static void gp_primitive_update_cps(tGPDprimitive *tgpi)
 	}
 }
 
+/* Helper to reflect point */
+static void gp_reflect_point_v2_v2v2v2(float va[2], const float p[2], const float a[2], const float b[2])
+{
+	float point[2];
+	closest_to_line_v2(point, p, a, b);
+	va[0] = point[0] - (p[0] - point[0]);
+	va[1] = point[1] - (p[1] - point[1]);
+}
+
   /* Poll callback for primitive operators */
 static bool gpencil_primitive_add_poll(bContext *C)
 {
@@ -405,11 +414,14 @@ static void gpencil_primitive_status_indicators(bContext *C, tGPDprimitive *tgpi
 	else if (tgpi->type == GP_STROKE_ARC) {
 		BLI_strncpy(msg_str, IFACE_("Arc: ESC to cancel, Enter/RMB to confirm, WHEEL/+- to adjust edge number, Shift to square, Alt to center, M: Flip"), UI_MAX_DRAW_STR);
 	}
+	else if (tgpi->type == GP_STROKE_CHORD) {
+		BLI_strncpy(msg_str, IFACE_("Chord: ESC to cancel, Enter/RMB to confirm, WHEEL/+- to adjust edge number, Shift to square, Alt to center, M: Flip"), UI_MAX_DRAW_STR);
+	}
 	else if (tgpi->type == GP_STROKE_CURVE) {
 		BLI_strncpy(msg_str, IFACE_("Curve: ESC to cancel, Enter/RMB to confirm, WHEEL/+- to adjust edge number, Shift to square, Alt to center, E: extrude"), UI_MAX_DRAW_STR);
 	}
 
-	if (ELEM(tgpi->type, GP_STROKE_CIRCLE, GP_STROKE_ARC, GP_STROKE_LINE, GP_STROKE_BOX)) {
+	if (ELEM(tgpi->type, GP_STROKE_CIRCLE, GP_STROKE_ARC, GP_STROKE_CHORD, GP_STROKE_LINE, GP_STROKE_BOX)) {
 		if (hasNumInput(&tgpi->num)) {
 			char str_offs[NUM_STR_REP_LEN];
 
@@ -521,6 +533,63 @@ static void gp_primitive_line(tGPDprimitive *tgpi, tGPspoint *points2D)
 		gp_primitive_set_cp(tgpi, tgpi->start, color, BIG_SIZE_CTL);
 }
 
+/* create a chord */
+static void gp_primitive_chord(tGPDprimitive *tgpi, tGPspoint *points2D)
+{
+	const int totpoints = (tgpi->tot_edges + tgpi->tot_stored_edges);
+	float cp[2];
+	float point[2];
+	float center[2];
+
+	copy_v2_v2(cp, tgpi->cp1);
+	mid_v2_v2v2(tgpi->midpoint, tgpi->start, tgpi->end);
+	closest_to_line_v2(point, cp, tgpi->start, tgpi->end);
+
+	center[0] = tgpi->midpoint[0] + cp[0] - point[0];
+	center[1] = tgpi->midpoint[1] + cp[1] - point[1];
+
+	float cross = cross_tri_v2(tgpi->start, center, tgpi->end);
+	float stepangle;
+	float step;
+
+	if (!tgpi->flip) {
+		float fcenter[2];
+		gp_reflect_point_v2_v2v2v2(fcenter, center, tgpi->start, tgpi->end);
+		stepangle = angle_v2v2v2(tgpi->start, fcenter, tgpi->end);
+		if (cross < 0.0f) {
+			stepangle = (M_PI * 2.0f) - stepangle;
+		}
+		step = stepangle / (float)(tgpi->tot_edges - 1);
+		step = -step;
+	}
+	else {
+		stepangle = angle_v2v2v2(tgpi->start, center, tgpi->end); ;
+		if (cross > 0.0f) {
+			stepangle = (M_PI * 2.0f) - stepangle;
+		}
+		step = stepangle / (float)(tgpi->tot_edges - 1);
+	}
+
+	float a = tgpi->tot_stored_edges ? step : 0.0f;
+
+	for (int i = tgpi->tot_stored_edges; i < totpoints; i++) {
+		tGPspoint *p2d = &points2D[i];
+		gp_rotate_v2_v2v2fl(&p2d->x, tgpi->start, center, a);
+		a += step;
+	}
+	float color[4];
+	UI_GetThemeColor4fv(TH_ACTIVE_VERT, color);
+	gp_primitive_set_cp(tgpi, tgpi->end, color, BIG_SIZE_CTL);
+	if (tgpi->tot_stored_edges) {
+		UI_GetThemeColor4fv(TH_REDALERT, color);
+		gp_primitive_set_cp(tgpi, tgpi->start, color, SMALL_SIZE_CTL);
+	}
+	else
+		gp_primitive_set_cp(tgpi, tgpi->start, color, BIG_SIZE_CTL);
+	UI_GetThemeColor4fv(TH_GP_VERTEX_SELECT, color);
+	gp_primitive_set_cp(tgpi, center, color, BIG_SIZE_CTL * 0.9f);
+}
+
 /* create an arc */
 static void gp_primitive_arc(tGPDprimitive *tgpi, tGPspoint *points2D)
 {
@@ -662,6 +731,9 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
 		case GP_STROKE_ARC:
 			gp_primitive_arc(tgpi, points2D);
 			break;
+		case GP_STROKE_CHORD:
+			gp_primitive_chord(tgpi, points2D);
+			break;
 		case GP_STROKE_CURVE:
 			gp_primitive_bezier(tgpi, points2D);
 		default:
@@ -1044,7 +1116,7 @@ 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_CURVE)) {
+	if (ELEM(tgpi->type, GP_STROKE_ARC, GP_STROKE_CURVE, GP_STROKE_CHORD)) {
 		tgpi->curve = true;
 	}
 	else {
@@ -1263,7 +1335,7 @@ static void gpencil_primitiv

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list