[Bf-blender-cvs] [9dddefcbae7] greasepencil-object: WIP: Basic rectangle primitive

Antonio Vazquez noreply at git.blender.org
Sun Oct 15 17:55:35 CEST 2017


Commit: 9dddefcbae7b2113cb11a8caf2d6fced50c1228b
Author: Antonio Vazquez
Date:   Sun Oct 15 13:31:38 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB9dddefcbae7b2113cb11a8caf2d6fced50c1228b

WIP: Basic rectangle primitive

Still pending to show the feedback ghost image while create the primitive.

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	source/blender/editors/gpencil/CMakeLists.txt
M	source/blender/editors/gpencil/drawgpencil.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c
A	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/include/ED_gpencil.h

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

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 034ee2d2c23..5d81ff816b2 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -86,7 +86,10 @@ class GreasePencilDrawingToolsPanel:
     def draw_header(self, context):
         layout = self.layout
         if context.space_data.type == 'VIEW_3D':
-            layout.label(text="Measurement")
+            if context.active_object and context.active_object.mode == 'GPENCIL_PAINT':
+                layout.label(text="Primitives")
+            else:
+                layout.label(text="Measurement")
         else:
             layout.label(text="Grease Pencil")
 
@@ -99,6 +102,11 @@ class GreasePencilDrawingToolsPanel:
 
         col = layout.column(align=True)
 
+        # XXX: Primitve tools maybe need a panel
+        if is_3d_view:
+            col.operator("gpencil.primitive", text="Rectangle", icon='UV_FACESEL').type = 'BOX'
+            col.operator("gpencil.primitive", text="Circle", icon='ANTIALIASED').type = 'CIRCLE'
+
         if not is_3d_view:
             col.label(text="Draw:")
             row = col.row(align=True)
diff --git a/source/blender/editors/gpencil/CMakeLists.txt b/source/blender/editors/gpencil/CMakeLists.txt
index 57b6aa67e7f..4add2a33754 100644
--- a/source/blender/editors/gpencil/CMakeLists.txt
+++ b/source/blender/editors/gpencil/CMakeLists.txt
@@ -47,6 +47,7 @@ set(SRC
 	gpencil_data.c
 	gpencil_edit.c
 	gpencil_interpolate.c
+	gpencil_primitive.c
 	gpencil_ops.c
 	gpencil_paint.c
 	gpencil_select.c
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 5ef2111b5a1..22781fc2a13 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -1446,6 +1446,37 @@ void ED_gp_draw_interpolation(const bContext *C, tGPDinterpolate *tgpi, const in
 	glDisable(GL_BLEND);
 }
 
+/* draw interpolate strokes (used only while operator is running) */
+void ED_gp_draw_primitives(const bContext *C, tGPDprimitive *tgpi, const int type)
+{
+	Object *obact = CTX_data_active_object(C);
+	float diff_mat[4][4];
+	float color[4];
+
+	int offsx = 0;
+	int offsy = 0;
+	int winx = tgpi->ar->winx;
+	int winy = tgpi->ar->winy;
+
+	UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, color);
+	color[3] = 0.6f;
+	int dflag = 0;
+	/* if 3d stuff, enable flags */
+	if (type == REGION_DRAW_POST_VIEW) {
+		dflag |= (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_NOSTATUS);
+	}
+
+	/* turn on alpha-blending */
+	glEnable(GL_BLEND);
+	/* calculate parent position */
+	ED_gpencil_parent_location(obact, tgpi->gpd, tgpi->gpl, diff_mat);
+	if (tgpi->gpf) {
+		gp_draw_strokes(tgpi->gpd, tgpi->gpf, offsx, offsy, winx, winy, dflag, false,
+			tgpi->gpl->thickness, 1.0f, color, true, true, diff_mat);
+	}
+	glDisable(GL_BLEND);
+}
+
 /* loop over gpencil data layers, drawing them */
 static void gp_draw_data_layers(
         const bGPDbrush *brush, float alpha, Object *ob, bGPdata *gpd,
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 87daefd1bd4..09d3dacf61b 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -235,6 +235,11 @@ enum {
 	GP_MOVE_PALETTE_CURRENT = 4
 };
 
+enum {
+	GP_STROKE_BOX = -1,
+	GP_STROKE_CIRCLE = 1
+};
+
 
 void GPENCIL_OT_stroke_arrange(struct wmOperatorType *ot);
 void GPENCIL_OT_stroke_change_palette(struct wmOperatorType *ot);
@@ -274,6 +279,10 @@ void GPENCIL_OT_interpolate(struct wmOperatorType *ot);
 void GPENCIL_OT_interpolate_sequence(struct wmOperatorType *ot);
 void GPENCIL_OT_interpolate_reverse(struct wmOperatorType *ot);
 
+/* primitves ---------- */
+
+void GPENCIL_OT_primitive(struct wmOperatorType *ot);
+
 /* vertex groups ------------ */
 void GPENCIL_OT_vertex_group_assign(struct wmOperatorType *ot);
 void GPENCIL_OT_vertex_group_remove_from(struct wmOperatorType *ot);
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index bb6ebc78098..1970c318849 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -706,6 +706,9 @@ void ED_operatortypes_gpencil(void)
 	WM_operatortype_append(GPENCIL_OT_interpolate);
 	WM_operatortype_append(GPENCIL_OT_interpolate_sequence);
 	WM_operatortype_append(GPENCIL_OT_interpolate_reverse);
+
+	/* Primitives */
+	WM_operatortype_append(GPENCIL_OT_primitive);
 }
 
 void ED_operatormacros_gpencil(void)
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
new file mode 100644
index 00000000000..f98222d9214
--- /dev/null
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -0,0 +1,658 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017, Blender Foundation
+ * This is a new part of Blender
+ *
+ * Contributor(s): Antonio Vazquez
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ * Operators for creating new Grease Pencil primitives (boxes, circles, ...)
+ */
+
+/** \file blender/editors/gpencil/gpencil_primitive.c
+ *  \ingroup edgpencil
+ */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <math.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_utildefines.h"
+#include "BLI_math.h"
+
+#include "BLT_translation.h"
+
+#include "DNA_gpencil_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BKE_main.h"
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "BKE_gpencil.h"
+#include "BKE_library.h"
+#include "BKE_paint.h"
+#include "BKE_report.h"
+
+#include "UI_interface.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "ED_gpencil.h"
+#include "ED_object.h"
+#include "ED_screen.h"
+#include "ED_view3d.h"
+#include "ED_space_api.h"
+
+#include "gpencil_intern.h"
+
+#define MIN_EDGES 3
+#define MAX_EDGES 100
+
+#define IDLE 0
+#define IN_PROGRESS 1
+
+/* ************************************************ */
+/* Core/Shared Utilities */
+
+/* Poll callback for primitive operators */
+static int gpencil_view3d_poll(bContext *C)
+{
+	bGPdata *gpd = CTX_data_gpencil_data(C);
+	bGPDlayer *gpl = CTX_data_active_gpencil_layer(C);
+	
+	/* only 3D view */
+	ScrArea *sa = CTX_wm_area(C);
+	if (sa && sa->spacetype != SPACE_VIEW3D) {
+		return 0;
+	}
+	
+	/* need data to create primitive */
+	if (ELEM(NULL, gpd, gpl)) {
+		return 0;
+	}
+
+	/* only in paint mode */
+	if ((gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0) {
+		return 0;
+	}
+
+	return 1;
+}
+
+
+/* ****************** Primitive Interactive *********************** */
+
+/* Helper: Create internal strokes primitives data */
+static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
+{
+	Scene *scene = CTX_data_scene(C);
+	bGPdata *gpd = tgpi->gpd;
+	bGPDlayer *gpl = CTX_data_active_gpencil_layer(C);
+	int totpoints = 3;
+
+	tgpi->cframe = CFRA;
+	tgpi->gpl = gpl;
+
+	/* create a new temporary frame */
+	tgpi->gpf = MEM_callocN(sizeof(bGPDframe), "Temp bGPDframe");
+	tgpi->gpf->framenum = tgpi->cframe;
+
+	/* create new temp stroke */
+	bGPDstroke *gps = MEM_callocN(sizeof(bGPDstroke), "Temp bGPDstroke");
+	if (tgpi->type == GP_STROKE_BOX) {
+		totpoints = 4;
+	}
+	else {
+		totpoints = tgpi->tot_edges;
+	}
+	gps->thickness = 5;
+	gps->inittime = 0.0f;
+
+	/* enable recalculation flag by default */
+	gps->flag |= GP_STROKE_RECALC_CACHES;
+	/* the polygon must be closed, so enabled cyclic */
+	gps->flag |= GP_STROKE_CYCLIC;
+
+	gps->palette = tgpi->palette;
+	gps->palcolor = tgpi->palcolor;
+
+	/* allocate enough memory for a continuous array for storage points */
+	gps->totpoints = totpoints;
+	gps->points = MEM_callocN(sizeof(bGPDspoint) * totpoints, "gp_stroke_points");
+	/* initialize triangle memory to dummy data */
+	gps->tot_triangles = 0;
+	gps->triangles = NULL;
+	gps->flag |= GP_STROKE_RECALC_CACHES;
+
+	/* add to strokes */
+	BLI_addtail(&tgpi->gpf->strokes, gps);
+}
+
+/* ----------------------- */
+/* Drawing Callbacks */
+
+/* Drawing callback for modal operator in screen mode */
+static void gpencil_primitive_draw_screen(const struct bContext *C, ARegion *UNUSED(ar), void *arg)
+{
+	tGPDprimitive *tgpi = (tGPDprimitive *)arg;
+	ED_gp_draw_primitives(C, tgpi, REGION_DRAW_POST_PIXEL);
+}
+
+/* Drawing callback for modal operator in 3d mode */
+static void gpencil_primitive_draw_3d(const bContext *C, ARegion *UNUSED(ar), void *arg)
+{
+	tGPDprimitive *tgpi = (tGPDprimitive *)arg;
+	ED_gp_draw_primitives(C, tgpi, REGION_DRAW_POST_VIEW);
+}
+
+/* ----------------------- */
+
+/* Helper: Draw status message while the user is running the operator */
+static void gpencil_primitive_status_indicators(tGPDprimitive *tgpi)
+{
+	Scene *scene = tgpi->scene;
+	char status_str[UI_MAX_DRAW_STR];
+	char msg_str[UI_MAX_DRAW_STR];
+	
+	if (tgpi->type == GP_STROKE_BOX) {
+		BLI_strncpy(msg_str, IFACE_("GP Primitive: ESC/RMB to cancel, LMB set origin, Enter/LMB to confirm, Shift to square"), UI_MAX_DRAW_STR);
+	}
+	else {
+		BLI_strncpy(msg_str, IFACE_("Circle: ESC/R

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list