Commit: b425c0a302dbc949c63cd35532f1fbb8bb4e08ee
Author: Antonioya
Date:   Mon Aug 20 16:59:01 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rBb425c0a302dbc949c63cd35532f1fbb8bb4e08ee

Add weight data when drawing

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

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 881d3db8a4c..5c8c195c39a 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -172,6 +172,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 c6df07ae83e..9a15284abae 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -865,6 +865,10 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
        pt = gps->points;
        dvert = gps->dvert;
        point2D = (tGPspoint *)tgpf->sbuffer;
+
+       const int def_nr = tgpf->ob->actdef - 1;
+       const bool is_weight = (bool)BLI_findlink(&tgpf->ob->defbase, def_nr);
+
        for (int i = 0; i < tgpf->sbuffer_size && point2D; i++, point2D++, 
pt++, dvert++) {
                /* convert screen-coordinates to 3D coordinates */
                gp_stroke_convertcoords_tpoint(
@@ -877,8 +881,13 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
                pt->strength = 1.0f;;
                pt->time = 0.0f;
 
-               dvert->totweight = 0;
-               dvert->dw = NULL;
+               if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && 
(is_weight)) {
+                       BKE_gpencil_vgroup_add_point_weight(dvert, def_nr, 
ts->vgroup_weight);
+               }
+               else {
+                       dvert->totweight = 0;
+                       dvert->dw = NULL;
+               }
        }
 
        /* smooth stroke */
diff --git a/source/blender/editors/gpencil/gpencil_paint.c 
b/source/blender/editors/gpencil/gpencil_paint.c
index d4371926eb4..5481ae85f7c 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -554,6 +554,8 @@ static short gp_stroke_addpoint(
        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 is_weight = (bool)BLI_findlink(&obact->defbase, def_nr);
 
        /* check painting mode */
        if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) {
@@ -786,8 +788,13 @@ static short gp_stroke_addpoint(
                        pts->uv_fac = pt->uv_fac;
                        pts->uv_rot = pt->uv_rot;
 
-                       dvert->totweight = 0;
-                       dvert->dw = NULL;
+                       if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) 
&& (is_weight)) {
+                               BKE_gpencil_vgroup_add_point_weight(dvert, 
def_nr, ts->vgroup_weight);
+                       }
+                       else {
+                               dvert->totweight = 0;
+                               dvert->dw = NULL;
+                       }
 
                        /* force fill recalc */
                        gps->flag |= GP_STROKE_RECALC_CACHES;
@@ -897,6 +904,8 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
        ToolSettings *ts = p->scene->toolsettings;
        Depsgraph *depsgraph = p->depsgraph;
        Object *obact = (Object *)p->ownerPtr.data;
+       const int def_nr = obact->actdef - 1;
+       const bool is_weight = (bool)BLI_findlink(&obact->defbase, def_nr);
 
        int i, totelem;
        /* since strokes are so fine, when using their depth we need a margin 
otherwise they might get missed */
@@ -973,8 +982,13 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
                        CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
                        pt->time = ptc->time;
 
-                       dvert->totweight = 0;
-                       dvert->dw = NULL;
+                       if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) 
&& (is_weight)) {
+                               BKE_gpencil_vgroup_add_point_weight(dvert, 
def_nr, ts->vgroup_weight);
+                       }
+                       else {
+                               dvert->totweight = 0;
+                               dvert->dw = NULL;
+                       }
 
                        pt++;
                        dvert++;
@@ -992,8 +1006,13 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
                        CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
                        pt->time = ptc->time;
 
-                       dvert->totweight = 0;
-                       dvert->dw = NULL;
+                       if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) 
&& (is_weight)) {
+                               BKE_gpencil_vgroup_add_point_weight(dvert, 
def_nr, ts->vgroup_weight);
+                       }
+                       else {
+                               dvert->totweight = 0;
+                               dvert->dw = NULL;
+                       }
                }
 
                /* reproject to plane (only in 3d space) */
@@ -1020,8 +1039,13 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
                CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
                pt->time = ptc->time;
 
-               dvert->totweight = 0;
-               dvert->dw = NULL;
+               if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && 
(is_weight)) {
+                       BKE_gpencil_vgroup_add_point_weight(dvert, def_nr, 
ts->vgroup_weight);
+               }
+               else {
+                       dvert->totweight = 0;
+                       dvert->dw = NULL;
+               }
 
        }
        else {
@@ -1087,9 +1111,10 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
                }
 
                pt = gps->points;
+               dvert = gps->dvert;
 
                /* convert all points (normal behavior) */
-               for (i = 0, ptc = gpd->runtime.sbuffer; i < 
gpd->runtime.sbuffer_size && ptc; i++, ptc++, pt++) {
+               for (i = 0, ptc = gpd->runtime.sbuffer; i < 
gpd->runtime.sbuffer_size && ptc; i++, ptc++, pt++, dvert++) {
                        /* convert screen-coordinates to appropriate 
coordinates (and store them) */
                        gp_stroke_convertcoords(p, &ptc->x, &pt->x, depth_arr ? 
depth_arr + i : NULL);
 
@@ -1100,6 +1125,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
                        pt->time = ptc->time;
                        pt->uv_fac = ptc->uv_fac;
                        pt->uv_rot = ptc->uv_rot;
+
+                       dvert->totweight = 0;
+                       dvert->dw = NULL;
                }
 
                /* subdivide and smooth the stroke */
@@ -1165,6 +1193,14 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
        else {
                BLI_addtail(&p->gpf->strokes, gps);
        }
+       /* add weights */
+       if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (is_weight)) {
+               for (i = 0; i < gps->totpoints; i++) {
+                       MDeformVert *ve = &gps->dvert[i];
+                       BKE_gpencil_vgroup_add_point_weight(ve, def_nr, 
ts->vgroup_weight);
+               }
+       }
+
        gp_stroke_added_enable(p);
 }
 
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c 
b/source/blender/editors/gpencil/gpencil_primitive.c
index 2dfdeeba0b6..938691b5991 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -528,6 +528,11 @@ static void gpencil_primitive_done(bContext *C, wmOperator 
*op, wmWindow *win, t
        bGPDframe *gpf;
        bGPDstroke *gps;
 
+       ToolSettings *ts = tgpi->scene->toolsettings;
+
+       const int def_nr = tgpi->ob->actdef - 1;
+       const bool is_weight = (bool)BLI_findlink(&tgpi->ob->defbase, def_nr);
+
        /* return to normal cursor and header status */
        ED_workspace_status_text(C, NULL);
        WM_cursor_modal_restore(win);
@@ -546,6 +551,14 @@ static void gpencil_primitive_done(bContext *C, wmOperator 
*op, wmWindow *win, t
        BLI_movelisttolist(&gpf->strokes, &tgpi->gpf->strokes);
        BLI_assert(BLI_listbase_is_empty(&tgpi->gpf->strokes));
 
+       /* add weights if required */
+       if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (is_weight)) {
+               for (int i = 0; i < gps->totpoints; i++) {
+                       MDeformVert *ve = &gps->dvert[i];
+                       BKE_gpencil_vgroup_add_point_weight(ve, def_nr, 
ts->vgroup_weight);
+               }
+       }
+
        /* clean up temp data */
        gpencil_primitive_exit(C, op);
 }
diff --git a/source/blender/makesdna/DNA_scene_types.h 
b/source/blender/makesdna/DNA_scene_types.h
index 6425871b7dd..5c4bc116932 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -2069,6 +2069,8 @@ typedef enum eGPencil_Flags {
        GP_TOOL_FLAG_PAINT_ONBACK           = (1 << 2),
        /* Show compact list of colors */
        GP_TOOL_FLAG_THUMBNAIL_LIST           = (1 << 3),
+       /* Generate wheight data for new strokes */
+       GP_TOOL_FLAG_CREATE_WEIGHTS           = (1 << 4),
 } eGPencil_Flags;
 
 /* scene->r.simplify_gpencil */
diff --git a/source/blender/makesrna/intern/rna_scene.c 
b/source/blender/makesrna/intern/rna_scene.c
index 21731a54aa1..fe7145fbeb2 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2451,6 +2451,13 @@ static void rna_def_tool_settings(BlenderRNA  *brna)
                "Show compact list of color instead of thumbnails");
        RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
 
+       prop = RNA_def_property(srna, "add_gpencil_weight_data", PROP_BOOLEAN, 
PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "gpencil_flags", 
GP_TOOL_FLAG_CREATE_WEIGHTS);
+       RNA_def_property_ui_text(prop, "Add weight data for new strokes",
+               "When creating new strokes, the weight data is added according 
to the current vertex group and weight, "
+               "if no vertex group selected, weight is not added");
+       RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
+
        prop = RNA_def_property(srna, "gpencil_sculpt", PROP_POINTER, 
PROP_NONE);
        RNA_def_property_pointer_sdna(prop, NULL, "gp_sculpt");
        RNA_def_property_struct_type(prop, "GPencilSculptSettings");

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to