[Bf-blender-cvs] [ef57bc2d5fd] greasepencil-object: GP: New option to toggle Caps mode

Antonioya noreply at git.blender.org
Sat Jan 5 12:23:06 CET 2019


Commit: ef57bc2d5fd585556c8cd192934c4e6532473e63
Author: Antonioya
Date:   Sat Jan 5 12:21:49 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rBef57bc2d5fd585556c8cd192934c4e6532473e63

GP: New option to toggle Caps mode

Now it's possible to have flat or rounded (default) stroke caps.

The operator is accessible in edit mode.

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.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 cefe6ca1a34..0ec865683ac 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -191,6 +191,7 @@ class GreasePencilStrokeEditPanel:
         col.operator("gpencil.duplicate_move", text="Duplicate")
         if is_3d_view:
             col.operator("gpencil.stroke_cyclical_set", text="Toggle Cyclic").type = 'TOGGLE'
+            col.operator("gpencil.stroke_caps_set", text="Toggle Caps").type = 'TOGGLE'
 
         layout.separator()
 
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 47863156898..1c15983e58e 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -3955,6 +3955,7 @@ class VIEW3D_MT_edit_gpencil(Menu):
 
         layout.menu("VIEW3D_MT_edit_gpencil_delete")
         layout.operator("gpencil.stroke_cyclical_set", text="Toggle Cyclic").type = 'TOGGLE'
+        layout.operator("gpencil.stroke_caps_set", text="Toggle Caps").type = 'TOGGLE'
 
         layout.separator()
 
@@ -5563,6 +5564,7 @@ class VIEW3D_MT_gpencil_edit_specials(Menu):
         layout.operator("gpencil.stroke_join", text="Join").type = 'JOIN'
         layout.operator("gpencil.stroke_join", text="Join & Copy").type = 'JOINCOPY'
         layout.operator("gpencil.stroke_flip", text="Flip Direction")
+        layout.operator("gpencil.stroke_caps_set", text="Toggle Caps").type = 'TOGGLE'
 
         layout.separator()
         layout.operator("gpencil.frame_duplicate", text="Duplicate Active Frame")
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index fa16a00183e..f9e0fea223c 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -352,7 +352,7 @@ bool DRW_gpencil_onion_active(bGPdata *gpd)
 /* create shading group for strokes */
 DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
         GPENCIL_e_data *e_data, GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, Object *ob,
-        bGPdata *gpd, MaterialGPencilStyle *gp_style, int id, bool onion)
+        bGPdata *gpd, bGPDstroke *gps, MaterialGPencilStyle *gp_style, int id, bool onion)
 {
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
 	const float *viewport_size = DRW_viewport_size_get();
@@ -386,6 +386,9 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
 		}
 		DRW_shgroup_uniform_int(grp, "color_type", &stl->shgroups[id].color_type, 1);
 		DRW_shgroup_uniform_float(grp, "pixfactor", &gpd->pixfactor, 1);
+
+		stl->shgroups[id].caps_mode = ((gps) && (gps->flag & GP_STROKE_FLATCAPS)) ? 1 : 0;
+		DRW_shgroup_uniform_int(grp, "caps_mode", &stl->shgroups[id].caps_mode, 1);
 	}
 	else {
 		stl->storage->obj_scale = 1.0f;
@@ -400,6 +403,8 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
 		else {
 			DRW_shgroup_uniform_float(grp, "pixfactor", &stl->storage->pixfactor, 1);
 		}
+		const int zero = 0;
+		DRW_shgroup_uniform_int(grp, "caps_mode", &zero, 1);
 	}
 
 	if ((gpd) && (id > -1)) {
@@ -1172,7 +1177,8 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data, void *vedata, T
 			if (gpd->runtime.sbuffer_size > 1) {
 				if ((gp_style) && (gp_style->mode == GP_STYLE_MODE_LINE)) {
 					stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_stroke_create(
-						e_data, vedata, psl->drawing_pass, e_data->gpencil_stroke_sh, NULL, gpd, gp_style, -1, false);
+						e_data, vedata, psl->drawing_pass, e_data->gpencil_stroke_sh, NULL,
+						gpd, NULL, gp_style, -1, false);
 				}
 				else {
 					stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_point_create(
@@ -1352,7 +1358,7 @@ static void DRW_gpencil_shgroups_create(
 
 				shgrp = DRW_gpencil_shgroup_stroke_create(
 				        e_data, vedata, psl->stroke_pass, e_data->gpencil_stroke_sh,
-				        ob, gpd, gp_style, stl->storage->shgroup_id, elm->onion);
+				        ob, gpd, gps, gp_style, stl->storage->shgroup_id, elm->onion);
 
 				DRW_shgroup_call_range_add(
 				        shgrp, cache->b_stroke.batch,
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 6f2b40136ca..0235ee06f9c 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -114,6 +114,7 @@ typedef struct GPENCIL_shgroup {
 	int texture_clamp;
 	int fill_style;
 	int keep_size;
+	int caps_mode;
 	float obj_scale;
 } GPENCIL_shgroup;
 
@@ -364,7 +365,8 @@ typedef struct GpencilBatchCache {
 /* general drawing functions */
 struct DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
         struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata, struct DRWPass *pass, struct GPUShader *shader,
-        struct Object *ob, struct bGPdata *gpd, struct MaterialGPencilStyle *gp_style, int id, bool onion);
+        struct Object *ob, struct bGPdata *gpd, struct bGPDstroke *gps,
+		struct MaterialGPencilStyle *gp_style, int id, bool onion);
 void DRW_gpencil_populate_datablock(
         struct GPENCIL_e_data *e_data, void *vedata,
         struct Object *ob, struct tGPencilObjectCache *cache_ob);
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl
index 748f69ab21a..471b6d96f1d 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl
@@ -2,6 +2,7 @@ uniform mat4 ModelViewProjectionMatrix;
 uniform vec2 Viewport;
 uniform int xraymode;
 uniform int color_type;
+uniform int caps_mode;
 
 layout(lines_adjacency) in;
 layout(triangle_strip, max_vertices = 13) out;
@@ -23,6 +24,8 @@ out float uvfac;
 #define GPENCIL_COLOR_TEXTURE 1
 #define GPENCIL_COLOR_PATTERN 2
 
+#define GPENCIL_FLATCAP 1
+
 /* project 3d point to 2d on screen space */
 vec2 toScreenSpace(vec4 vertex)
 {
@@ -159,7 +162,9 @@ void main(void)
 	}
 
 	/* generate the start endcap (alpha < 0 used as endcap flag)*/
-	if (is_equal(P0,P2) && (color_type == GPENCIL_COLOR_SOLID)){
+	if ((caps_mode != GPENCIL_FLATCAP) && is_equal(P0,P2) && 
+		(color_type == GPENCIL_COLOR_SOLID))
+	{
 		mTexCoord = vec2(2, 1);
 		mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0) ;
 		vec2 svn1 =  normalize(sp1 - sp2) * length_a * 4.0;
@@ -199,7 +204,9 @@ void main(void)
 	EmitVertex();
 
 	/* generate the end endcap (alpha < 0 used as endcap flag)*/
-	if (is_equal(P1,P3) && (color_type == GPENCIL_COLOR_SOLID) && (finaluvdata[2].x > 0)){
+	if ((caps_mode != GPENCIL_FLATCAP) && is_equal(P1,P3) && 
+		(color_type == GPENCIL_COLOR_SOLID) && (finaluvdata[2].x > 0))
+	{
 		mTexCoord = vec2(finaluvdata[2].x, 2);
 		mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0) ;
 		uvfac = finaluvdata[2].x;
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 7a54a485e9b..e7acfbbd7cc 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -2515,6 +2515,97 @@ void GPENCIL_OT_stroke_cyclical_set(wmOperatorType *ot)
 	ot->prop = RNA_def_enum(ot->srna, "type", cyclic_type, GP_STROKE_CYCLIC_TOGGLE, "Type", "");
 }
 
+/* ******************* Flat Stroke Caps ************************** */
+
+enum {
+	GP_STROKE_CAPS_ROUND = 0,
+	GP_STROKE_CAPS_FLAT = 1,
+	GP_STROKE_CAPS_TOGGLE = 2
+};
+
+static int gp_stroke_caps_set_exec(bContext *C, wmOperator *op)
+{
+	bGPdata *gpd = ED_gpencil_data_get_active(C);
+	Object *ob = CTX_data_active_object(C);
+
+	const int type = RNA_enum_get(op->ptr, "type");
+
+	/* sanity checks */
+	if (ELEM(NULL, gpd))
+		return OPERATOR_CANCELLED;
+
+	/* loop all selected strokes */
+	CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers)
+	{
+		if (gpl->actframe == NULL)
+			continue;
+
+		for (bGPDstroke *gps = gpl->actframe->strokes.last; gps; gps = gps->prev) {
+			MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
+
+			/* skip strokes that are not selected or invalid for current view */
+			if (((gps->flag & GP_STROKE_SELECT) == 0) || ED_gpencil_stroke_can_use(C, gps) == false)
+				continue;
+			/* skip hidden or locked colors */
+			if (!gp_style || (gp_style->flag & GP_STYLE_COLOR_HIDE) || (gp_style->flag & GP_STYLE_COLOR_LOCKED))
+				continue;
+
+			switch (type) {
+				case GP_STROKE_CAPS_ROUND:
+					/* Disable */
+					gps->flag &= ~GP_STROKE_FLATCAPS;
+					break;
+				case GP_STROKE_CAPS_FLAT:
+					/* Enable */
+					gps->flag |= GP_STROKE_FLATCAPS;
+					break;
+				case GP_STROKE_CAPS_TOGGLE:
+					/* Just toggle flag... */
+					gps->flag ^= GP_STROKE_FLATCAPS;
+					break;
+				default:
+					BLI_assert(0);
+					break;
+			}
+		}
+	}
+	CTX_DATA_END;
+
+	/* 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;
+}
+
+/**
+ * Change Stroke caps mode Rounded or Flat
+ */
+void GPENCIL_OT_stroke_caps_set(wmOperatorType *ot)
+{
+	static const EnumPropertyItem cyclic_type[] = {
+		{GP_STROKE_CAPS_ROUND, "ROUND", 0, "Rounded caps", ""},
+		{GP_STROKE_CAPS_FLAT, "FLAT", 0, "Flat caps", ""},
+		{GP_STROKE_CAPS_TOGGLE, "TOGGLE", 0, "Toggle", ""},
+		{0, NULL, 0, NULL, NULL}
+	};
+
+	/* identifiers */
+	ot->name = "Set Caps Mode";
+	ot->idname = "GPENCIL_OT_stroke_caps_set";
+	ot->description = "Change Stroke caps mode (rounded or flat)";
+
+	/* api callbacks */
+	ot->exec = gp_stroke_caps_set_exec;
+	ot->poll = gp_active_layer_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	/* properties */
+	ot->prop = RNA_def_enum(ot->srna, "type", cyclic_type, GP_STROKE_CAPS_TOGGLE, "Type", "");
+}
+
 /* ******************* Stroke join ************************** */
 
 /* Helper: flip stroke */
diff --git a/source/blender/editors/gpencil/gpencil_intern.h

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list