[Bf-blender-cvs] [f2d8241b23b] blender2.8: GP: Add weights while drawing strokes

Antonioya noreply at git.blender.org
Thu Aug 30 11:13:24 CEST 2018


Commit: f2d8241b23bdf118336b94d54146bac41b791580
Author: Antonioya
Date:   Thu Aug 30 11:11:10 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBf2d8241b23bdf118336b94d54146bac41b791580

GP: Add weights while drawing strokes

Now it's possible to add the weight of the current selected vertex group to any new stroke created.

This is very handy when add drawings after the weight paint was done and it will be required with Armatures.

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

M	release/scripts/startup/bl_ui/space_topbar.py
M	source/blender/editors/gpencil/gpencil_fill.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index 3395889cf82..ea120a0e1fb 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -179,6 +179,7 @@ class TOPBAR_HT_lower_bar(Header):
             if context.tool_settings.gpencil_stroke_placement_view3d in ('ORIGIN', 'CURSOR'):
                 layout.prop(context.tool_settings.gpencil_sculpt, "lockaxis", text='')
             layout.prop(context.tool_settings, "use_gpencil_draw_onback", text="", icon='ORTHO')
+            layout.prop(context.tool_settings, "add_gpencil_weight_data", text="", icon='WPAINT_HLT')
             layout.prop(context.tool_settings, "use_gpencil_additive_drawing", text="", icon='FREEZE')
 
         elif mode == 'GPENCIL_SCULPT':
diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index 09a21cbca1e..2ff7e45d7a2 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -23,9 +23,9 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/** \file blender/editors/gpencil/gpencil_fill.c
- *  \ingroup edgpencil
- */
+ /** \file blender/editors/gpencil/gpencil_fill.c
+  *  \ingroup edgpencil
+  */
 
 #include <stdio.h>
 
@@ -47,6 +47,7 @@
 
 #include "BKE_main.h"
 #include "BKE_brush.h"
+#include "BKE_deform.h"
 #include "BKE_image.h"
 #include "BKE_gpencil.h"
 #include "BKE_material.h"
@@ -84,7 +85,7 @@
 #define LEAK_VERT 1
 
 
-/* Temporary fill operation data (op->customdata) */
+  /* Temporary fill operation data (op->customdata) */
 typedef struct tGPDfill {
 	struct Main *bmain;
 	struct Depsgraph *depsgraph;
@@ -124,10 +125,10 @@ typedef struct tGPDfill {
 } tGPDfill;
 
 
- /* draw a given stroke using same thickness and color for all points */
+/* draw a given stroke using same thickness and color for all points */
 static void gp_draw_basic_stroke(
-        tGPDfill *tgpf, bGPDstroke *gps, const float diff_mat[4][4],
-        bool cyclic, float ink[4], int flag, float thershold)
+	tGPDfill *tgpf, bGPDstroke *gps, const float diff_mat[4][4],
+	bool cyclic, float ink[4], int flag, float thershold)
 {
 	bGPDspoint *points = gps->points;
 
@@ -247,7 +248,7 @@ static void gp_draw_datablock(tGPDfill *tgpf, float ink[4])
 
 			/* normal strokes */
 			if ((tgpf->fill_draw_mode == GP_FILL_DMODE_STROKE) ||
-			    (tgpf->fill_draw_mode == GP_FILL_DMODE_BOTH))
+				(tgpf->fill_draw_mode == GP_FILL_DMODE_BOTH))
 			{
 				ED_gp_draw_fill(&tgpw);
 
@@ -255,7 +256,7 @@ static void gp_draw_datablock(tGPDfill *tgpf, float ink[4])
 
 			/* 3D Lines with basic shapes and invisible lines */
 			if ((tgpf->fill_draw_mode == GP_FILL_DMODE_CONTROL) ||
-			    (tgpf->fill_draw_mode == GP_FILL_DMODE_BOTH))
+				(tgpf->fill_draw_mode == GP_FILL_DMODE_BOTH))
 			{
 				gp_draw_basic_stroke(tgpf, gps, tgpw.diff_mat, gps->flag & GP_STROKE_CYCLIC, ink,
 					tgpf->flag, tgpf->fill_threshold);
@@ -266,7 +267,7 @@ static void gp_draw_datablock(tGPDfill *tgpf, float ink[4])
 	glDisable(GL_BLEND);
 }
 
- /* draw strokes in offscreen buffer */
+/* draw strokes in offscreen buffer */
 static void gp_render_offscreen(tGPDfill *tgpf)
 {
 	bool is_ortho = false;
@@ -298,8 +299,8 @@ static void gp_render_offscreen(tGPDfill *tgpf)
 	int bwiny = tgpf->ar->winy;
 	rcti brect = tgpf->ar->winrct;
 
-	tgpf->ar->winx = (short) tgpf->sizex;
-	tgpf->ar->winy = (short) tgpf->sizey;
+	tgpf->ar->winx = (short)tgpf->sizex;
+	tgpf->ar->winy = (short)tgpf->sizey;
 	tgpf->ar->winrct.xmin = 0;
 	tgpf->ar->winrct.ymin = 0;
 	tgpf->ar->winrct.xmax = tgpf->sizex;
@@ -314,8 +315,8 @@ static void gp_render_offscreen(tGPDfill *tgpf)
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
 	ED_view3d_update_viewmat(
-	        tgpf->depsgraph, tgpf->scene, tgpf->v3d, tgpf->ar,
-	        NULL, winmat, NULL);
+		tgpf->depsgraph, tgpf->scene, tgpf->v3d, tgpf->ar,
+		NULL, winmat, NULL);
 	/* set for opengl */
 	GPU_matrix_projection_set(tgpf->rv3d->winmat);
 	GPU_matrix_set(tgpf->rv3d->viewmat);
@@ -419,7 +420,7 @@ static bool is_leak_narrow(ImBuf *ibuf, const int maxpixel, int limit, int index
 			if (pt <= maxpixel) {
 				get_pixel(ibuf, pt, rgba);
 				if (rgba[0] == 1.0f) {
-					t_a =  true;
+					t_a = true;
 					break;
 				}
 			}
@@ -675,7 +676,7 @@ static  void gpencil_get_outline_points(tGPDfill *tgpf)
 		int cur_back_offset = -1;
 		for (int i = 0; i < NEIGHBOR_COUNT; i++) {
 			if (backtracked_offset[0][0] == offset[i][0] &&
-			    backtracked_offset[0][1] == offset[i][1])
+				backtracked_offset[0][1] == offset[i][1])
 			{
 				/* Finding the bracktracked pixel offset index */
 				cur_back_offset = i;
@@ -709,7 +710,7 @@ static  void gpencil_get_outline_points(tGPDfill *tgpf)
 		}
 		/* current pixel is equal to starting pixel */
 		if (boundary_co[0] == start_co[0] &&
-		    boundary_co[1] == start_co[1])
+			boundary_co[1] == start_co[1])
 		{
 			BLI_stack_pop(tgpf->stack, &v);
 			// boundary_found = true;
@@ -757,9 +758,9 @@ static void gpencil_get_depth_array(tGPDfill *tgpf)
 			copy_v2_v2_int(mval, &ptc->x);
 
 			if ((ED_view3d_autodist_depth(
-			             tgpf->ar, mval, depth_margin, tgpf->depth_arr + i) == 0) &&
-			    (i && (ED_view3d_autodist_depth_seg(
-			                   tgpf->ar, mval, mval_prev, depth_margin + 1, tgpf->depth_arr + i) == 0)))
+				tgpf->ar, mval, depth_margin, tgpf->depth_arr + i) == 0) &&
+				(i && (ED_view3d_autodist_depth_seg(
+					tgpf->ar, mval, mval_prev, depth_margin + 1, tgpf->depth_arr + i) == 0)))
 			{
 				interp_depth = true;
 			}
@@ -822,7 +823,7 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
 	}
 
 	bGPDspoint *pt;
-	MDeformVert *dvert;
+	MDeformVert *dvert = NULL;
 	tGPspoint *point2D;
 
 	if (tgpf->sbuffer_size == 0) {
@@ -867,25 +868,43 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
 
 	/* add points */
 	pt = gps->points;
-	dvert = gps->dvert;
 	point2D = (tGPspoint *)tgpf->sbuffer;
+
+	const int def_nr = tgpf->ob->actdef - 1;
+	const bool have_weight = (bool)BLI_findlink(&tgpf->ob->defbase, def_nr);
+
+	if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) {
+		BKE_gpencil_dvert_ensure(gps);
+		dvert = gps->dvert;
+	}
+
 	for (int i = 0; i < tgpf->sbuffer_size && point2D; i++, point2D++, pt++) {
 		/* convert screen-coordinates to 3D coordinates */
 		gp_stroke_convertcoords_tpoint(
-		        tgpf->scene, tgpf->ar, tgpf->v3d, tgpf->ob,
-		        tgpf->gpl, point2D,
-		        tgpf->depth_arr ? tgpf->depth_arr + i : NULL,
-		        &pt->x);
+			tgpf->scene, tgpf->ar, tgpf->v3d, tgpf->ob,
+			tgpf->gpl, point2D,
+			tgpf->depth_arr ? tgpf->depth_arr + i : NULL,
+			&pt->x);
 
 		pt->pressure = 1.0f;
 		pt->strength = 1.0f;
 		pt->time = 0.0f;
 
-		if (gps->dvert != NULL) {
-			dvert->totweight = 0;
-			dvert->dw = NULL;
+		if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) {
+			MDeformWeight *dw = defvert_verify_index(dvert, def_nr);
+			if (dw) {
+				dw->weight = ts->vgroup_weight;
+			}
+
 			dvert++;
 		}
+		else {
+			if (dvert != NULL) {
+				dvert->totweight = 0;
+				dvert->dw = NULL;
+				dvert++;
+			}
+		}
 	}
 
 	/* smooth stroke */
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index ef70608d99c..9822f4a1029 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -23,9 +23,9 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/** \file blender/editors/gpencil/gpencil_paint.c
- *  \ingroup edgpencil
- */
+ /** \file blender/editors/gpencil/gpencil_paint.c
+  *  \ingroup edgpencil
+  */
 
 
 #include <stdio.h>
@@ -59,6 +59,7 @@
 #include "BKE_brush.h"
 #include "BKE_paint.h"
 #include "BKE_context.h"
+#include "BKE_deform.h"
 #include "BKE_global.h"
 #include "BKE_gpencil.h"
 #include "BKE_report.h"
@@ -92,10 +93,10 @@
 
 #include "gpencil_intern.h"
 
-/* ******************************************* */
-/* 'Globals' and Defines */
+  /* ******************************************* */
+  /* 'Globals' and Defines */
 
-/* values for tGPsdata->status */
+  /* values for tGPsdata->status */
 typedef enum eGPencil_PaintStatus {
 	GP_STATUS_IDLING = 0,   /* stroke isn't in progress yet */
 	GP_STATUS_PAINTING,     /* a stroke is in progress */
@@ -170,7 +171,7 @@ typedef struct tGPsdata {
 	double ocurtime;    /* Used when converting to path */
 
 	float imat[4][4];   /* inverted transformation matrix applying when converting coords from screen-space
-	                     * to region space */
+						 * to region space */
 	float mat[4][4];
 
 	float custom_color[4]; /* custom color - hack for enforcing a particular color for track/mask editing */
@@ -552,7 +553,7 @@ static void gp_smooth_buffer(tGPsdata *p, float inf, int idx)
 
 /* add current stroke-point to buffer (returns whether point was successfully added) */
 static short gp_stroke_addpoint(
-        tGPsdata *p, const int mval[2], float pressure, double curtime)
+	tGPsdata *p, const int mval[2], float pressure, double curtime)
 {
 	bGPdata *gpd = p->gpd;
 	Brush *brush = p->brush;
@@ -560,9 +561,11 @@ static short gp_stroke_addpoint(
 	ToolSettings *ts = p->scene->toolsettings;
 	Object *obact = (Object *)p->ownerPtr.data;
 	Depsgraph *depsgraph = p->depsgraph;                                      \
-	RegionView3D *rv3d = p->ar->regiondata;
+		RegionView3D *rv3d = p->ar->regiondata;
 	View3D *v3d = p->sa->spacedata.first;
 	MaterialGPencilStyle *gp_style = p->material->gp_style;
+	const int def_nr = obact->actdef - 1;
+	const bool have_weight = (bool)BLI_findlink(&obact->defbase, def_nr);
 
 	/* check painting mode */
 	if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) {
@@ -631,7 +634,7 @@ static short gp_stroke_addpoint(
 		}
 		/* apply randomness to pressure */
 		if ((brush->gpencil_settings->flag & GP_BRUSH_GROUP_RANDOM) &&
-		    (brush->gpencil_settings->draw_random_press > 0.0f))
+			(brush->gpencil_settings->draw_random_press > 0.0f))
 		{
 			float curvef = curvemapping_evaluateF(brush->gpencil_settings->curve_sensitivity, 0, pressure);
 			float tmp_pressure = curvef * brush->gpe

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list