[Bf-blender-cvs] [7098683f26e] greasepencil-experimental: GP: Draw: Speedline guides

Charlie Jolly noreply at git.blender.org
Sat Jan 5 08:22:14 CET 2019


Commit: 7098683f26ee01ec4dd5c9ff6868105e1ef178ff
Author: Charlie Jolly
Date:   Sat Jan 5 06:52:43 2019 +0000
Branches: greasepencil-experimental
https://developer.blender.org/rB7098683f26ee01ec4dd5c9ff6868105e1ef178ff

GP: Draw: Speedline guides

+ Show reference point in paint mode, gizmo primary color in UI
+ Option to use 3d cursor as reference point, red color in UI
+ Split CIRCULAR into two modes, new mode called RADIAL
+ OKEY sets reference point (was Alt CKey before)
+ Removed flip option as it was confusing
+ Added GRID mode for crossing lines
+ Added angle snapping to RADIAL
+ Spacing snapping to CIRCULAR and GRID
+ Simplified shortcuts

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_sculpt_paint.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 2b46e39beb0..40dedee9e04 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -3047,6 +3047,7 @@ def km_grease_pencil_stroke_paint_draw_brush(params):
          {"properties": [("mode", 'ERASER'), ("wait_for_input", False)]}),
         # Constrain Guides Speedlines
 		# Freehand
+        ("gpencil.draw", {"type": 'O', "value": 'PRESS'}, None),
         ("gpencil.draw", {"type": 'J', "value": 'PRESS'}, None),
         ("gpencil.draw", {"type": 'J', "value": 'PRESS', "alt": True}, None),
         ("gpencil.draw", {"type": 'J', "value": 'PRESS', "shift": True}, None),
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index a4e0cd4a20e..5a003b5b5cb 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -252,7 +252,7 @@ class VIEW3D_HT_header(Header):
                 row = layout.row(align=True)
                 row.prop(settings, "use_speed_guide", text="", icon='GRID')
                 sub = row.row(align=True)
-                sub.enabled = settings.use_speed_guide
+                sub.active = settings.use_speed_guide
                 sub.popover(
                     panel="VIEW3D_PT_gpencil_guide",
                     text="Guides"
@@ -5345,15 +5345,27 @@ class VIEW3D_PT_gpencil_guide(Panel):
         layout = self.layout
         layout.label(text="Guides")
         
-        row = layout.row()
-        col = row.column()
+        col = layout.column()
+        col.prop(settings, "use_speed_guide")
+
+        col = col.column()
+        col.active = settings.use_speed_guide
         col.prop(settings, "guide_type", expand=True)
-                
+        col.prop(settings, "use_snapping")
+
         row = col.row(align=True)
-        row.active = bool(settings.guide_type == "PARALLEL");
+        row.active = settings.guide_type in {'PARALLEL', 'RADIAL'}
         row.prop(settings, "guide_angle")
+
+        row = col.row(align=True)
+        row.active = settings.use_snapping
+        row.prop(settings, "guide_spacing")
         
-        col.prop(settings, "guide_flip")
+        col.prop(settings, "use_cursor")       
+        if not settings.use_cursor:
+            row = col.row(align=True)
+            col = row.column()
+            col.prop(settings, "guide_origin")        
 
         
 class VIEW3D_PT_overlay_gpencil_options(Panel):
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index d5927ebca9a..85bb68f0e21 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -390,6 +390,14 @@ GPUBatch *DRW_gpencil_get_buffer_ctrlpoint_geom(bGPdata *gpd)
 	bGPDcontrolpoint *cps = gpd->runtime.cp_points;
 	int totpoints = gpd->runtime.tot_cp_points;
 
+	const DRWContextState *draw_ctx = DRW_context_state_get();
+	Scene *scene = draw_ctx->scene;
+	ToolSettings *ts = scene->toolsettings;
+
+	if (ts->gp_sculpt.use_speed_guide) {
+		totpoints++;
+	}
+	
 	static GPUVertFormat format = { 0 };
 	static uint pos_id, color_id, size_id;
 	if (format.attr_len == 0) {
@@ -415,6 +423,23 @@ GPUBatch *DRW_gpencil_get_buffer_ctrlpoint_geom(bGPdata *gpd)
 		idx++;
 	}
 
+	if (ts->gp_sculpt.use_speed_guide) {
+		float size = 10 * 0.8f;
+		float color[4];
+		float position[3];
+		if (ts->gp_sculpt.use_cursor) {
+			UI_GetThemeColor4fv(TH_REDALERT, color);
+			copy_v3_v3(position, scene->cursor.location);
+		}
+		else {
+			UI_GetThemeColor4fv(TH_GIZMO_PRIMARY, color);
+			copy_v3_v3(position, ts->gp_sculpt.guide_origin);
+		}
+		GPU_vertbuf_attr_set(vbo, pos_id, idx, position);
+		GPU_vertbuf_attr_set(vbo, size_id, idx, &size);
+		GPU_vertbuf_attr_set(vbo, color_id, idx, color);
+	}
+
 	return GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, NULL, GPU_BATCH_OWNS_VBO);
 }
 
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index fa16a00183e..ff75f68365a 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -1236,7 +1236,8 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data, void *vedata, T
 	}
 
 	/* control points */
-	if ((overlay) && (gpd->runtime.tot_cp_points > 0) &&
+	if ((overlay) && ((gpd->runtime.tot_cp_points > 0) ||
+		(ts->gp_sculpt.use_speed_guide && (draw_ctx->object_mode == OB_MODE_PAINT_GPENCIL))) &&
 	    ((gpd->runtime.sbuffer_sflag & GP_STROKE_ERASER) == 0) &&
 	    ((v3d->gizmo_flag & V3D_GIZMO_HIDE) == 0) &&
 	    ((v3d->gizmo_flag & V3D_GIZMO_HIDE_TOOL) == 0))
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 2267f7f1492..4294ce72ac1 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -234,6 +234,8 @@ void gp_apply_parent(struct Depsgraph *depsgraph, struct Object *obact, bGPdata
  */
 void gp_apply_parent_point(struct Depsgraph *depsgraph, struct Object *obact, bGPdata *gpd, bGPDlayer *gpl, bGPDspoint *pt);
 
+void gp_point_3d_to_xy(GP_SpaceConversion *gsc, const short flag, const float pt[3], float xy[2]);
+
 bool gp_point_xy_to_3d(GP_SpaceConversion *gsc, struct Scene *scene, const float screen_co[2], float r_out[3]);
 
 /* helper to convert 2d to 3d */
@@ -296,7 +298,8 @@ typedef enum eGPencil_PaintModes {
 	GP_PAINTMODE_DRAW = 0,
 	GP_PAINTMODE_ERASER,
 	GP_PAINTMODE_DRAW_STRAIGHT,
-	GP_PAINTMODE_DRAW_POLY
+	GP_PAINTMODE_DRAW_POLY,
+	GP_PAINTMODE_SET_CP
 } eGPencil_PaintModes;
 
 /* maximum sizes of gp-session buffer */
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 20e93494fc9..5c4c2625639 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -119,6 +119,7 @@ typedef enum eGPencil_PaintFlags {
 	GP_PAINTFLAG_SELECTMASK     = (1 << 3),
 	GP_PAINTFLAG_HARD_ERASER    = (1 << 4),
 	GP_PAINTFLAG_STROKE_ERASER  = (1 << 5),
+	GP_PAINTFLAG_REQ_VECTOR     = (1 << 6),
 } eGPencil_PaintFlags;
 
 
@@ -183,7 +184,7 @@ typedef struct tGPsdata {
 
 	Brush *brush;    /* current drawing brush */
 	Brush *eraser;   /* default eraser brush */
-	short straight[2];   /* 1: line horizontal, 2: line vertical, 3: speed lines, other: not defined, second element position */
+	short straight;   /* 1: line horizontal, 2: line vertical, other: not defined */
 	int lock_axis;       /* lock drawing to one axis */
 	bool disable_fill;   /* the stroke is no fill mode */
 
@@ -191,6 +192,7 @@ typedef struct tGPsdata {
 
 	short keymodifier;   /* key used for invoking the operator */
 	short shift;         /* shift modifier flag */
+	char use_cursor;     /* reference point for guides */
 
 	float totpixlen;     /* size in pixels for uv calculation */
 
@@ -199,6 +201,9 @@ typedef struct tGPsdata {
 
 /* ------ */
 
+#define STROKE_HORIZONTAL 1
+#define STROKE_VERTICAL 2
+
 /* Macros for accessing sensitivity thresholds... */
 /* minimum number of pixels mouse should move before new point created */
 #define MIN_MANHATTEN_PX    (U.gp_manhattendist)
@@ -294,11 +299,11 @@ static void gp_get_3d_reference(tGPsdata *p, float vec[3])
 
 /* Stroke Editing ---------------------------- */
 /* check if the current mouse position is suitable for adding a new point */
-static bool gp_stroke_filtermval(tGPsdata *p, const float mval[2], float pmval[2])
+static bool gp_stroke_filtermval(tGPsdata *p, const float mval[2], float mvalo[2])
 {
 	Brush *brush = p->brush;
-	int dx = (int)fabsf(mval[0] - pmval[0]);
-	int dy = (int)fabsf(mval[1] - pmval[1]);
+	int dx = (int)fabsf(mval[0] - mvalo[0]);
+	int dy = (int)fabsf(mval[1] - mvalo[1]);
 	brush->gpencil_settings->flag &= ~GP_BRUSH_STABILIZE_MOUSE_TEMP;
 
 	/* if buffer is empty, just let this go through (i.e. so that dots will work) */
@@ -1977,7 +1982,7 @@ static void gp_session_cleanup(tGPsdata *p)
 	/* free stroke buffer */
 	if (gpd->runtime.sbuffer) {
 		/* printf("\t\tGP - free sbuffer\n"); */
-		MEM_freeN(gpd->runtime.sbuffer);
+		MEM_SAFE_FREE(gpd->runtime.sbuffer);
 		gpd->runtime.sbuffer = NULL;
 	}
 
@@ -1992,10 +1997,10 @@ static void gp_session_free(tGPsdata *p)
 	if (p->rng != NULL) {
 		BLI_rng_free(p->rng);
 	}
+
 	MEM_freeN(p);
 }
 
-
 /* init new stroke */
 static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Depsgraph *depsgraph)
 {
@@ -2429,6 +2434,10 @@ static void gpencil_draw_status_indicators(bContext *C, tGPsdata *p)
 					ED_workspace_status_text(C, IFACE_("Grease Pencil Line Session: Hold and drag LMB to draw | "
 						"ESC/Enter to end  (or click outside this area)"));
 					break;
+				case GP_PAINTMODE_SET_CP:
+					ED_workspace_status_text(C, IFACE_("Grease Pencil Guides: LMB click and release to place reference point | "
+						"Esc/RMB to cancel"));
+					break;
 				case GP_PAINTMODE_DRAW:
 					ED_workspace_status_text(C, IFACE_("Grease Pencil Freehand Session: Hold and drag LMB to draw"));
 					break;
@@ -2467,8 +2476,7 @@ static void gpencil_draw_apply(bContext *C, wmOperator *op, tGPsdata *p, Depsgra
 		gp_stroke_doeraser(p);
 
 		/* store used values */
-		p->mvalo[0] = p->mval[0];
-		p->mvalo[1] = p->mval[1];
+		copy_v2_v2(p->mvalo, p->mval);
 		p->opressure = p->pressure;
 	}
 	/* only add current point to buffer if mouse moved (even though we got an event, it might be just noise) */
@@ -2517,8 +2525,7 @@ static void gpencil_draw_apply(bContext *C, wmOperator *op, tGPsdata *p, Depsgra
 		}
 
 		/* store used values */
-		p->mvalo[0] = p->mval[0];
-		p->mvalo[1] = p->mval[1];
+		copy_v2_v2(p->mvalo, p->mval);
 		p->opressure = p->pressure;
 		p->ocurtime = p->curtime;
 
@@ -2547,6 +2554,60 @@ static void gp_rotate_v2_v2v2fl(float v[2], const float p[2], const float origin
 	add_v2_v2v2(v, r, origin);
 }
 
+/* Helper t

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list