[Bf-blender-cvs] [dc2e2704adf] greasepencil-object: New Set Origin operator
Antonio Vazquez
noreply at git.blender.org
Sat Jul 8 16:24:29 CEST 2017
Commit: dc2e2704adf108187b80ada057aac12cbc3a2843
Author: Antonio Vazquez
Date: Sat Jul 8 16:24:07 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBdc2e2704adf108187b80ada057aac12cbc3a2843
New Set Origin operator
This operator allows to change the pivot point origin for strokes.
Only valid in Edit Mode
Keymap: Ctrl+Alt+Shift+C
===================================================================
M release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M source/blender/editors/gpencil/gpencil_edit.c
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/editors/gpencil/gpencil_ops.c
===================================================================
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 01ed2019fdb..00aadc3d9cf 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -221,6 +221,9 @@ class GreasePencilStrokeEditPanel:
if is_3d_view:
layout.separator()
layout.operator_menu_enum("gpencil.reproject", text="Reproject Strokes...", property="type")
+ layout.separator()
+ layout.label("Set Origin:")
+ layout.operator("gpencil.origin_to_cursor", text="Origin to 3D Cursor")
class GreasePencilAnimationPanel:
@@ -743,6 +746,15 @@ class GPENCIL_MT_snap(Menu):
layout.operator("view3d.snap_cursor_to_grid", text="Cursor to Grid")
+class GPENCIL_MT_origin(Menu):
+ bl_label = "Set GPencil Origin"
+
+ def draw(self, context):
+ layout = self.layout
+
+ layout.operator("gpencil.origin_to_cursor", text="Origin to 3D Cursor", icon="CURSOR")
+
+
class GPENCIL_MT_gpencil_edit_specials(Menu):
bl_label = "GPencil Specials"
@@ -1289,6 +1301,7 @@ classes = (
GPENCIL_PIE_tools_more,
GPENCIL_PIE_sculpt,
GPENCIL_MT_snap,
+ GPENCIL_MT_origin,
GPENCIL_MT_gpencil_edit_specials,
GPENCIL_UL_brush,
GPENCIL_UL_palettecolor,
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index eebe6094a99..79dc43834bd 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -2564,3 +2564,81 @@ void GPENCIL_OT_stroke_subdivide(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
+
+/* Poll callback for origin operators */
+/* We only allow these in the 3D view and edit mode
+*/
+static int gp_origin_to_cursor_poll(bContext *C)
+{
+ Object *obact = CTX_data_active_object(C);
+ bGPdata *gpd = CTX_data_gpencil_data(C);
+ ScrArea *sa = CTX_wm_area(C);
+
+ return (obact) && (obact->type == OB_GPENCIL) && (gpd != NULL) && ((sa != NULL) && (sa->spacetype == SPACE_VIEW3D));
+}
+
+/* --------------------------------- */
+
+static int gp_origin_to_cursor_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Scene *scene = CTX_data_scene(C);
+ View3D *v3d = CTX_wm_view3d(C);
+
+ bGPdata *gpd = ED_gpencil_data_get_active(C);
+ Object *obact = CTX_data_active_object(C);
+ bGPDspoint *pt;
+
+ float imat[3][3], bmat[3][3];
+ const float *cursor_loc = ED_view3d_cursor3d_get(scene, v3d);
+ float offset_global[3];
+ float offset_local[3];
+ int i;
+
+ if ((!obact) || (obact->type != OB_GPENCIL) || (!obact->gpd)) {
+ return OPERATOR_CANCELLED;
+ }
+
+ /* move pivot point to 3D cursor location */
+ WM_operator_name_call(C, "VIEW3D_OT_snap_selected_to_cursor", WM_OP_EXEC_REGION_WIN, NULL);
+
+ sub_v3_v3v3(offset_global, cursor_loc, obact->obmat[3]);
+ copy_m3_m4(bmat, obact->obmat);
+ invert_m3_m3(imat, bmat);
+ mul_m3_v3(imat, offset_global);
+ mul_v3_m3v3(offset_local, imat, offset_global);
+
+ /* recalculate all strokes (all layers are considered without evaluating lock attributtes) */
+ for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+ for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+ for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+ /* skip strokes that are invalid for current view */
+ if (ED_gpencil_stroke_can_use(C, gps) == false)
+ continue;
+
+ for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+ sub_v3_v3(&pt->x, offset_local);
+ }
+ }
+ }
+ }
+
+ BKE_gpencil_batch_cache_dirty(gpd);
+ WM_event_add_notifier(C, NC_SCENE | NC_GPENCIL, NULL);
+
+ return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_origin_to_cursor(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Origin to 3D cursor";
+ ot->idname = "GPENCIL_OT_origin_to_cursor";
+ ot->description = "Set origing to current 3D cursor location moving pivot point and recalcule strokes";
+
+ /* callbacks */
+ ot->exec = gp_origin_to_cursor_exec;
+ ot->poll = gp_origin_to_cursor_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 98adebf779a..8ac3aa1e54b 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -186,6 +186,8 @@ void GPENCIL_OT_snap_to_cursor(struct wmOperatorType *ot);
void GPENCIL_OT_snap_cursor_to_selected(struct wmOperatorType *ot);
void GPENCIL_OT_snap_cursor_to_center(struct wmOperatorType *ot);
+void GPENCIL_OT_origin_to_cursor(struct wmOperatorType *ot);
+
void GPENCIL_OT_reproject(struct wmOperatorType *ot);
/* stroke sculpting -- */
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index e29393bed4a..9e25ab57d03 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -294,7 +294,9 @@ static void ed_keymap_gpencil_editing(wmKeyConfig *keyconf)
/* snap */
WM_keymap_add_menu(keymap, "GPENCIL_MT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
-
+ /* set origin */
+ WM_keymap_add_menu(keymap, "GPENCIL_MT_origin", CKEY, KM_PRESS, KM_ALT | KM_SHIFT | KM_CTRL, 0);
+
/* convert to geometry */
WM_keymap_add_item(keymap, "GPENCIL_OT_convert", CKEY, KM_PRESS, KM_ALT, 0);
@@ -537,6 +539,8 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_snap_to_cursor);
WM_operatortype_append(GPENCIL_OT_snap_cursor_to_selected);
+ WM_operatortype_append(GPENCIL_OT_origin_to_cursor);
+
WM_operatortype_append(GPENCIL_OT_reproject);
WM_operatortype_append(GPENCIL_OT_brush_paint);
More information about the Bf-blender-cvs
mailing list