[Bf-blender-cvs] [6551b09f410] greasepencil-object: WIP: Weight paint mode

Antonio Vazquez noreply at git.blender.org
Tue Aug 1 16:51:36 CEST 2017


Commit: 6551b09f41058346a8a443797467ab4a6bebed8f
Author: Antonio Vazquez
Date:   Mon Jul 31 20:55:45 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB6551b09f41058346a8a443797467ab4a6bebed8f

WIP: Weight paint mode

Initial work to implement new weight paint mode.

Now only the new weight paint brush in sculpt mode is available, but not the mode itself.

New brush paint icon design by Matias Mendiola.

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

A	release/datafiles/brushicons/gp_brush_weight.PNG
M	source/blender/blenloader/intern/versioning_defaults.c
M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/draw/engines/gpencil/gpencil_geom.c
M	source/blender/editors/datafiles/CMakeLists.txt
M	source/blender/editors/gpencil/gpencil_brush.c
M	source/blender/editors/include/ED_datafiles.h
M	source/blender/editors/include/UI_icons.h
M	source/blender/editors/interface/interface_icons.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_sculpt_paint.c

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

diff --git a/release/datafiles/brushicons/gp_brush_weight.PNG b/release/datafiles/brushicons/gp_brush_weight.PNG
new file mode 100644
index 00000000000..81c99bf90ca
Binary files /dev/null and b/release/datafiles/brushicons/gp_brush_weight.PNG differ
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index cea3adaf614..121cb5f09d1 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -143,46 +143,83 @@ void BLO_update_defaults_startup_blend(Main *bmain)
 			if (ts->gp_sculpt.brush[0].size == 0) {
 				GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
 				GP_EditBrush_Data *brush;
+				float curcolor[3], curcolor_add[3], curcolor_sub[3];
+				ARRAY_SET_ITEMS(curcolor, 1.0f, 1.0f, 1.0f);
+				ARRAY_SET_ITEMS(curcolor_add, 1.0f, 0.6f, 0.6f);
+				ARRAY_SET_ITEMS(curcolor_sub, 0.6f, 0.6f, 1.0f);
+
 				
 				brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH];
 				brush->size = 25;
 				brush->strength = 0.3f;
 				brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE;
-				
+				brush->flag |= GP_EDITBRUSH_FLAG_ENABLE_CURSOR;
+				copy_v3_v3(brush->curcolor_add, curcolor_add);
+				copy_v3_v3(brush->curcolor_sub, curcolor_sub);
+
 				brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS];
 				brush->size = 25;
 				brush->strength = 0.5f;
 				brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
-				
+				brush->flag |= GP_EDITBRUSH_FLAG_ENABLE_CURSOR;
+				copy_v3_v3(brush->curcolor_add, curcolor_add);
+				copy_v3_v3(brush->curcolor_sub, curcolor_sub);
+
 				brush = &gset->brush[GP_EDITBRUSH_TYPE_STRENGTH];
 				brush->size = 25;
 				brush->strength = 0.5f;
 				brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
+				brush->flag |= GP_EDITBRUSH_FLAG_ENABLE_CURSOR;
+				copy_v3_v3(brush->curcolor_add, curcolor_add);
+				copy_v3_v3(brush->curcolor_sub, curcolor_sub);
 
 				brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
 				brush->size = 50;
 				brush->strength = 0.3f;
 				brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
-				
+				brush->flag |= GP_EDITBRUSH_FLAG_ENABLE_CURSOR;
+				copy_v3_v3(brush->curcolor_add, curcolor_add);
+				copy_v3_v3(brush->curcolor_sub, curcolor_sub);
+
 				brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH];
 				brush->size = 25;
 				brush->strength = 0.3f;
 				brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
-				
+				brush->flag |= GP_EDITBRUSH_FLAG_ENABLE_CURSOR;
+				copy_v3_v3(brush->curcolor_add, curcolor_add);
+				copy_v3_v3(brush->curcolor_sub, curcolor_sub);
+
 				brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST];
 				brush->size = 50;
 				brush->strength = 0.3f; // XXX?
 				brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
-				
+				brush->flag |= GP_EDITBRUSH_FLAG_ENABLE_CURSOR;
+				copy_v3_v3(brush->curcolor_add, curcolor_add);
+				copy_v3_v3(brush->curcolor_sub, curcolor_sub);
+
 				brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH];
 				brush->size = 50;
 				brush->strength = 0.5f; // XXX?
 				brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
-				
+				brush->flag |= GP_EDITBRUSH_FLAG_ENABLE_CURSOR;
+				copy_v3_v3(brush->curcolor_add, curcolor_add);
+				copy_v3_v3(brush->curcolor_sub, curcolor_sub);
+
 				brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE];
 				brush->size = 25;
 				brush->strength = 0.5f;
 				brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
+				brush->flag |= GP_EDITBRUSH_FLAG_ENABLE_CURSOR;
+				copy_v3_v3(brush->curcolor_add, curcolor_add);
+				copy_v3_v3(brush->curcolor_sub, curcolor_sub);
+
+				brush = &gset->brush[GP_EDITBRUSH_TYPE_WEIGHT];
+				brush->size = 25;
+				brush->strength = 0.5f;
+				brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
+				brush->flag |= GP_EDITBRUSH_FLAG_ENABLE_CURSOR;
+				copy_v3_v3(brush->curcolor_add, curcolor_add);
+				copy_v3_v3(brush->curcolor_sub, curcolor_sub);
 			}
 			
 			ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
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 2cea9df7ec6..279700f4980 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -556,9 +556,13 @@ static void gpencil_add_editpoints_shgroup(GPENCIL_StorageList *stl, GpencilBatc
 	if ((gpl->flag & GP_LAYER_LOCKED) == 0 && (gpd->flag & (GP_DATA_STROKE_EDITMODE | GP_DATA_STROKE_SCULPTMODE)))
 	{
 		const DRWContextState *draw_ctx = DRW_context_state_get();
+		Scene *scene = draw_ctx->scene;
 		Object *obact = draw_ctx->obact;
+		GP_BrushEdit_Settings *gset = &scene->toolsettings->gp_sculpt;
+		int brush_index = gset->brushtype;
+		bool is_weight_paint = (gpd) && (brush_index >= GP_EDITBRUSH_TYPE_WEIGHT) && (gpd->flag & GP_DATA_STROKE_SCULPTMODE);
 
-		if (gps->flag & GP_STROKE_SELECT) {
+		if ((gps->flag & GP_STROKE_SELECT) || (is_weight_paint)) {
 			if ((gpl->flag & GP_LAYER_UNLOCK_COLOR) || ((gps->palcolor->flag & PC_COLOR_LOCKED) == 0)) {
 				if (cache->is_dirty) {
 					gpencil_batch_cache_check_free_slots(ob, gpd);
diff --git a/source/blender/draw/engines/gpencil/gpencil_geom.c b/source/blender/draw/engines/gpencil/gpencil_geom.c
index 6e2ce9c9121..b01b4d4080c 100644
--- a/source/blender/draw/engines/gpencil/gpencil_geom.c
+++ b/source/blender/draw/engines/gpencil/gpencil_geom.c
@@ -29,6 +29,7 @@
 
 
 #include "BLI_polyfill2d.h"
+#include "BLI_math_color.h"
 
 #include "DNA_gpencil_types.h"
 #include "DNA_screen_types.h"
@@ -610,6 +611,20 @@ Gwn_Batch *DRW_gpencil_get_fill_geom(bGPDstroke *gps, const float color[4])
 /* Draw selected verts for strokes being edited */
 Gwn_Batch *DRW_gpencil_get_edit_geom(bGPDstroke *gps, float alpha, short dflag)
 {
+	const DRWContextState *draw_ctx = DRW_context_state_get();
+	Scene *scene = draw_ctx->scene;
+	Object *ob = draw_ctx->obact;
+	bGPdata *gpd = ob->gpd;
+	ToolSettings *ts = scene->toolsettings;
+	GP_BrushEdit_Settings *gset = &scene->toolsettings->gp_sculpt;
+	int brush_index = gset->brushtype;
+	bool is_weight_paint = (gpd) && (brush_index >= GP_EDITBRUSH_TYPE_WEIGHT) && (gpd->flag & GP_DATA_STROKE_SCULPTMODE);
+
+	int vgindex = ob->actdef - 1;
+	if (!BLI_findlink(&ob->defbase, vgindex)) {
+		vgindex = -1;
+	}
+
 	/* Get size of verts:
 	* - The selected state needs to be larger than the unselected state so that
 	*   they stand out more.
@@ -652,25 +667,36 @@ Gwn_Batch *DRW_gpencil_get_edit_geom(bGPDstroke *gps, float alpha, short dflag)
 	int idx = 0;
 	float fcolor[4];
 	float fsize = 0;
-
 	for (int i = 0; i < gps->totpoints; i++, pt++) {
-		if (show_direction_hint && i == 0) {
-			/* start point in green bigger */
-			ARRAY_SET_ITEMS(fcolor, 0.0f, 1.0f, 0.0f, 1.0f);
-			fsize = vsize + 4;
-		}
-		else if (show_direction_hint && (i == gps->totpoints - 1)) {
-			/* end point in red smaller */
-			ARRAY_SET_ITEMS(fcolor, 1.0f, 0.0f, 0.0f, 1.0f);
-			fsize = vsize + 1;
-		}
-		else if (pt->flag & GP_SPOINT_SELECT) {
+		/* weight paint */
+		if (is_weight_paint) {
+			float weight = BKE_gpencil_vgroup_use_index(pt, vgindex);
+			CLAMP(weight, 0.0f, 1.0f);
+			float hue = 2.0f * (1.0f - weight) / 3.0f;
+			hsv_to_rgb(hue, 1.0f, 1.0f, &selectColor[0], &selectColor[1], &selectColor[2]);
+			selectColor[3] = 1.0f;
 			copy_v4_v4(fcolor, selectColor);
-			fsize = vsize;
+			fsize = vsize + 3;
 		}
 		else {
-			copy_v4_v4(fcolor, palcolor->rgb);
-			fsize = bsize;
+			if (show_direction_hint && i == 0) {
+				/* start point in green bigger */
+				ARRAY_SET_ITEMS(fcolor, 0.0f, 1.0f, 0.0f, 1.0f);
+				fsize = vsize + 4;
+			}
+			else if (show_direction_hint && (i == gps->totpoints - 1)) {
+				/* end point in red smaller */
+				ARRAY_SET_ITEMS(fcolor, 1.0f, 0.0f, 0.0f, 1.0f);
+				fsize = vsize + 1;
+			}
+			else if (pt->flag & GP_SPOINT_SELECT) {
+				copy_v4_v4(fcolor, selectColor);
+				fsize = vsize;
+			}
+			else {
+				copy_v4_v4(fcolor, palcolor->rgb);
+				fsize = bsize;
+			}
 		}
 
 		GWN_vertbuf_attr_set(vbo, color_id, idx, fcolor);
diff --git a/source/blender/editors/datafiles/CMakeLists.txt b/source/blender/editors/datafiles/CMakeLists.txt
index f7417ca88a1..418a623eb0e 100644
--- a/source/blender/editors/datafiles/CMakeLists.txt
+++ b/source/blender/editors/datafiles/CMakeLists.txt
@@ -135,6 +135,7 @@ if(WITH_BLENDER)
 		data_to_c_simple(../../../../release/datafiles/brushicons/gp_brush_pinch.png SRC)
 		data_to_c_simple(../../../../release/datafiles/brushicons/gp_brush_randomize.png SRC)
 		data_to_c_simple(../../../../release/datafiles/brushicons/gp_brush_clone.png SRC)
+		data_to_c_simple(../../../../release/datafiles/brushicons/gp_brush_weight.png SRC)
 
 	endif()
 
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index 705c47da5bd..464b6637ea8 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -59,6 +59,7 @@
 #include "BKE_library.h"
 #include "BKE_report.h"
 #include "BKE_screen.h"
+#include "BKE_object_deform.h"
 
 #include "UI_interface.h"
 
@@ -89,7 +90,8 @@ typedef struct tGP_BrushEditData {
 	/* Current editor/region/etc. */
 	/* NOTE: This stuff is mainly needed to handle 3D view projection stuff... */
 	Scene *scene;
-	
+	Object *object;
+
 	ScrArea *sa;
 	ARegion *ar;
 	
@@ -140,6 +142,7 @@ typedef struct tGP_BrushEditData {
 	/* Timer for in-place accumulation of brush effect */
 	wmTimer *timer;
 	bool timerTick; /* is this event from a timer */
+	int vrgroup;    /* active vertex group */
 } tGP_BrushEditData;
 
 
@@ -800,6 +803,60 @@ static bool gp_brush_randomize_apply(tGP_BrushEditData *gso, bGPDstroke *gps, in
 	return true;
 }
 
+/* Weight Paint Brush */
+
+/* Change weight paint for vertex groups */
+static bool gp_brush_weight_apply(tGP_BrushEditData *gso, bGPDstroke *gps, int i,
+	const int radius, const int co[2])
+{
+	bGPDspoint *pt = gps->points + i;
+	float inf;
+
+	/* Compute strength of effect
+	* - We divide the strength by 10, so that users can set "sane" values.
+	*   Otherwise, good default values are in the range of 0.093
+	*/
+	inf = gp_brush_influence_calc(gso, radius, co) / 10.0f;
+
+	/* need a vertex group */
+	if (gso->vrgroup ==

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list