[Bf-blender-cvs] [039d8fea23b] greasepencil-edit-curve: GPencil: Apply GSoC changes
Antonio Vazquez
noreply at git.blender.org
Wed Jul 1 13:25:00 CEST 2020
Commit: 039d8fea23b03d8d8e24d0cb1948582e37db2348
Author: Antonio Vazquez
Date: Wed Jul 1 13:22:28 2020 +0200
Branches: greasepencil-edit-curve
https://developer.blender.org/rB039d8fea23b03d8d8e24d0cb1948582e37db2348
GPencil: Apply GSoC changes
===================================================================
M release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
M release/scripts/presets/keyconfig/keymap_data/blender_default.py
M source/blender/blenkernel/BKE_gpencil_curve.h
M source/blender/blenkernel/intern/gpencil_curve.c
M source/blender/editors/gpencil/gpencil_edit_curve.c
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/editors/gpencil/gpencil_ops.c
M source/blender/editors/screen/area.c
M source/blender/editors/transform/transform_convert_gpencil.c
===================================================================
diff --git a/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py b/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
index 3b829de405a..c80b548b4f2 100644
--- a/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
+++ b/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
@@ -190,6 +190,7 @@ _km_hierarchy = [
]),
('Grease Pencil', 'EMPTY', 'WINDOW', [ # grease pencil stuff (per region)
+ ('Grease Pencil Stroke Curve Edit Mode', 'EMPTY', 'WINDOW', []),
('Grease Pencil Stroke Edit Mode', 'EMPTY', 'WINDOW', []),
('Grease Pencil Stroke Paint (Draw brush)', 'EMPTY', 'WINDOW', []),
('Grease Pencil Stroke Paint (Fill)', 'EMPTY', 'WINDOW', []),
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index a5dc075970c..190d208422c 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -3207,6 +3207,20 @@ def km_grease_pencil_stroke_edit_mode(params):
return keymap
+def km_grease_pencil_stroke_curve_edit_mode(params):
+ items = []
+ keymap = (
+ "Grease Pencil Stroke Curve Edit Mode",
+ {"space_type": 'EMPTY', "region_type": 'WINDOW'},
+ {"items": items},
+ )
+
+ items.extend([
+ # Set handle type
+ ("gpencil.stroke_editcurve_set_handle_type", {"type": 'V', "value": 'PRESS'}, None),
+ ])
+
+ return keymap
def km_grease_pencil_stroke_paint_mode(params):
items = []
@@ -6693,6 +6707,7 @@ def generate_keymaps(params=None):
# Modes.
km_grease_pencil(params),
+ km_grease_pencil_stroke_curve_edit_mode(params),
km_grease_pencil_stroke_edit_mode(params),
km_grease_pencil_stroke_paint_mode(params),
km_grease_pencil_stroke_paint_draw_brush(params),
diff --git a/source/blender/blenkernel/BKE_gpencil_curve.h b/source/blender/blenkernel/BKE_gpencil_curve.h
index eb9a02f7702..f16e8ae7acb 100644
--- a/source/blender/blenkernel/BKE_gpencil_curve.h
+++ b/source/blender/blenkernel/BKE_gpencil_curve.h
@@ -50,6 +50,7 @@ void BKE_gpencil_editcurve_stroke_sync_selection(struct bGPDstroke *gps, struct
void BKE_gpencil_stroke_editcurve_sync_selection(struct bGPDstroke *gps, struct bGPDcurve *gpc);
void BKE_gpencil_selected_strokes_editcurve_update(struct bGPdata *gpd);
void BKE_gpencil_stroke_update_geometry_from_editcurve(struct bGPDstroke *gps);
+void BKE_gpencil_editcurve_recalculate_handles(struct bGPDstroke *gps);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index 0ab6891abdd..01377b1b445 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -505,6 +505,10 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps, float error_th
cpt->strength = orig_pt->strength;
copy_v4_v4(cpt->vert_color, orig_pt->vert_color);
+ /* default handle type */
+ bezt->h1 |= HD_ALIGN;
+ bezt->h2 |= HD_ALIGN;
+
cpt->point_index = r_cubic_orig_index[i];
}
@@ -763,4 +767,34 @@ void BKE_gpencil_stroke_update_geometry_from_editcurve(bGPDstroke *gps)
MEM_freeN(points);
}
+void BKE_gpencil_editcurve_recalculate_handles(bGPDstroke *gps)
+{
+ if (gps == NULL || gps->editcurve == NULL) {
+ return;
+ }
+
+ bool changed = false;
+ bGPDcurve *gpc = gps->editcurve;
+ for (int i = 0; i < gpc->tot_curve_points; i++) {
+ bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+ if (gpc_pt->flag & GP_CURVE_POINT_SELECT) {
+ bGPDcurve_point *gpc_pt_prev = (i > 0) ? &gpc->curve_points[i - 1] : NULL;
+ bGPDcurve_point *gpc_pt_next = (i < gpc->tot_curve_points - 1) ?
+ &gpc->curve_points[i + 1] :
+ NULL;
+
+ BezTriple *bezt = &gpc_pt->bezt;
+ BezTriple *bezt_prev = gpc_pt_prev != NULL ? &gpc_pt_prev->bezt : NULL;
+ BezTriple *bezt_next = gpc_pt_next != NULL ? &gpc_pt_next->bezt : NULL;
+
+ BKE_nurb_handle_calc(bezt, bezt_prev, bezt_next, false, 0);
+ changed = true;
+ }
+ }
+
+ if (changed) {
+ gpc->flag |= GP_CURVE_RECALC_GEOMETRY;
+ }
+}
+
/** \} */
diff --git a/source/blender/editors/gpencil/gpencil_edit_curve.c b/source/blender/editors/gpencil/gpencil_edit_curve.c
index f3cab35890b..0a344a9cc1c 100644
--- a/source/blender/editors/gpencil/gpencil_edit_curve.c
+++ b/source/blender/editors/gpencil/gpencil_edit_curve.c
@@ -34,6 +34,7 @@
#include "DNA_view3d_types.h"
#include "BKE_context.h"
+#include "BKE_curve.h"
#include "BKE_gpencil.h"
#include "BKE_gpencil_curve.h"
#include "BKE_gpencil_geom.h"
@@ -53,6 +54,22 @@
#include "gpencil_intern.h"
+/* Poll callback for checking if there is an active layer and we are in curve edit mode. */
+static bool gpencil_curve_edit_mode_poll(bContext *C)
+{
+ Object *ob = CTX_data_active_object(C);
+ if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
+ return false;
+ }
+ bGPdata *gpd = (bGPdata *)ob->data;
+ if (!GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
+ return false;
+ }
+
+ bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd);
+ return (gpl != NULL);
+}
+
/* -------------------------------------------------------------------- */
/** \name Test Operator for curve editing
* \{ */
@@ -181,4 +198,75 @@ void GPENCIL_OT_stroke_enter_editcurve_mode(wmOperatorType *ot)
RNA_def_property_ui_range(prop, FLT_MIN, 10.0f, 0.1f, 5);
}
+static int gpencil_editcurve_set_handle_type_exec(bContext *C, wmOperator *op)
+{
+ Object *ob = CTX_data_active_object(C);
+ bGPdata *gpd = ob->data;
+ const int handle_type = RNA_enum_get(op->ptr, "type");
+
+ if (ELEM(NULL, gpd)) {
+ return OPERATOR_CANCELLED;
+ }
+
+ GP_EDITABLE_CURVES_BEGIN(gps_iter, C, gpl, gps, gpc)
+ {
+ for (int i = 0; i < gpc->tot_curve_points; i++) {
+ bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+
+ if (gpc_pt->flag & GP_CURVE_POINT_SELECT) {
+ bGPDcurve_point *gpc_pt_prev = (i > 0) ? &gpc->curve_points[i - 1] : NULL;
+ bGPDcurve_point *gpc_pt_next = (i < gpc->tot_curve_points - 1) ?
+ &gpc->curve_points[i + 1] :
+ NULL;
+ BezTriple *bezt_prev = gpc_pt_prev != NULL ? &gpc_pt_prev->bezt : NULL;
+ BezTriple *bezt = &gpc_pt->bezt;
+ BezTriple *bezt_next = gpc_pt_next != NULL ? &gpc_pt_next->bezt : NULL;
+
+ bezt->h1 = handle_type;
+ bezt->h2 = handle_type;
+
+ BKE_nurb_handle_calc(bezt, bezt_prev, bezt_next, false, 0);
+
+ /* TODO: recalculate curve when handles change */
+ gps->editcurve->flag |= GP_CURVE_RECALC_GEOMETRY;
+ BKE_gpencil_stroke_geometry_update(gps);
+ }
+ }
+ }
+ GP_EDITABLE_CURVES_END(gps_iter);
+
+ /* notifiers */
+ DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
+ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+
+ return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_stroke_editcurve_set_handle_type(wmOperatorType *ot)
+{
+ static const EnumPropertyItem editcurve_handle_type_items[] = {
+ {HD_FREE, "FREE", 0, "Free", ""},
+ {HD_AUTO, "AUTOMATIC", 0, "Automatic", ""},
+ {HD_VECT, "VECTOR", 0, "Vector", ""},
+ {HD_ALIGN, "ALIGNED", 0, "Aligned", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ /* identifiers */
+ ot->name = "Set handle type";
+ ot->idname = "GPENCIL_OT_stroke_editcurve_set_handle_type";
+ ot->description = "Set the type of a edit curve handle.";
+
+ /* api callbacks */
+ ot->invoke = WM_menu_invoke;
+ ot->exec = gpencil_editcurve_set_handle_type_exec;
+ ot->poll = gpencil_curve_edit_mode_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ ot->prop = RNA_def_enum(ot->srna, "type", editcurve_handle_type_items, 1, "Type", "Spline type");
+}
+
/** \} */
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 96c85dae542..d6c9df528a1 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -446,8 +446,11 @@ void GPENCIL_OT_snap_cursor_to_selected(struct wmOperatorType *ot);
void GPENCIL_OT_reproject(struct wmOperatorType *ot);
void GPENCIL_OT_recalc_geometry(struct wmOperatorType *ot);
+/* stroke editcurve */
+
void GPENCIL_OT_write_sample_stroke_curve_data(struct wmOperatorType *ot);
void GPENCIL_OT_stroke_enter_editcurve_mode(struct wmOperatorType *ot);
+void GPENCIL_OT_stroke_editcurve_set_handle_type(struct wmOperatorType *ot);
/* stroke sculpting -- */
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 7ab63bfc76a..05a47492bb6 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -69,6 +69,13 @@ static bool gpencil_stroke_editmode_poll(bContext *C)
return (gpd && (gpd->flag & GP_DATA_STROKE_EDITMODE));
}
+/* Poll callback for stroke curve editing mode */
+static bool gpencil_stroke_editmode_curve_poll(bContext *C)
+{
+ bGPdata *gpd = CTX_data_gpencil_data(C);
+ return (GPENCIL_EDIT_MODE(gpd) && GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd));
+}
+
/* Poll callback for stroke painting mode */
static bool gpencil_stroke_paintmode_poll(bContext *C)
{
@@ -316,6 +323,15 @@ static void ed_keymap_gpencil_editing(wmKeyConfig *keyconf)
keymap->poll = gpencil_stroke_editmode_poll;
}
+/* Stroke Curve Editing Keymap - Only when editmode is enabled and in curve edit mode */
+static void ed_keymap_gpencil_curve_editing(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Curve Edit Mode", 0, 0);
+
+ /* set poll callback - so that this keymap only gets enabled when curve editmode is enabled */
+ keymap->poll = gpencil_stroke_editmode_curve_poll;
+}
+
/* keys for draw with a drawing brush (no fill) */
static void ed_keymap_gpencil_painting_draw(wmKeyConfig *keyconf)
{
@@
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list