diff options
author | Antonioya <blendergit@gmail.com> | 2019-03-25 19:02:42 +0300 |
---|---|---|
committer | Antonioya <blendergit@gmail.com> | 2019-03-25 19:06:07 +0300 |
commit | 7021bd527380b4d87cf48057f0039509326b03dd (patch) | |
tree | 55126437da17d736a789d236c8a98d199a1e6260 /source/blender/editors/gpencil/gpencil_edit.c | |
parent | 84240ebb3ebde58f6bfba256e49d37697fb6bc9f (diff) |
GPencil: Only brushes with pinned materials have materials
Using GP_BRUSH_MATERIAL_PINNED to switch between active material and brush material, instead of updating all brushes on active material changes. This will allow brushes to have no material and therefore to not inflate the user count.
This fix T62465.
Patch contributed by @matc
Reviewers: @brecht @antoniov @billreynish @mendio
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_edit.c')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_edit.c | 57 |
1 files changed, 9 insertions, 48 deletions
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index a6b6fc2cbe7..259c9468e76 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -1074,10 +1074,7 @@ GHash *gp_copybuf_validate_colormap(bContext *C) char *ma_name = BLI_ghashIterator_getValue(&gh_iter); Material *ma = BLI_ghash_lookup(name_to_ma, ma_name); - if (ma != NULL && BKE_gpencil_get_material_index(ob, ma) == 0) { - BKE_object_material_slot_add(bmain, ob); - assign_material(bmain, ob, ma, ob->totcol, BKE_MAT_ASSIGN_USERPREF); - } + BKE_gpencil_handle_material(bmain, ob, ma); /* Store this mapping (for use later when pasting) */ if (!BLI_ghash_haskey(new_colors, POINTER_FROM_INT(*key))) { @@ -1331,14 +1328,8 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op) /* Remap material */ Material *ma = BLI_ghash_lookup(new_colors, POINTER_FROM_INT(new_stroke->mat_nr)); - if ((ma) && (BKE_gpencil_get_material_index(ob, ma) > 0)) { - new_stroke->mat_nr = BKE_gpencil_get_material_index(ob, ma) - 1; - CLAMP_MIN(new_stroke->mat_nr, 0); - } - else { - new_stroke->mat_nr = 0; /* only if the color is not found */ - } - + new_stroke->mat_nr = BKE_gpencil_get_material_index(ob, ma); + BLI_assert(new_stroke >= 0); /* have to add the material first */ } } } @@ -3914,10 +3905,7 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op) /* create new grease pencil datablock */ gpd_dst = BKE_gpencil_data_addnew(bmain, gpd_src->id.name + 2); ob_dst->data = (bGPdata *)gpd_dst; - - int totslots = ob_dst->totcol; - int totadd = 0; - + /* loop old datablock and separate parts */ if ((mode == GP_SEPARATE_POINT) || (mode == GP_SEPARATE_STROKE)) { CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers) @@ -3962,21 +3950,8 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op) } /* add duplicate materials */ - ma = give_current_material(ob, gps->mat_nr + 1); - idx = BKE_gpencil_get_material_index(ob_dst, ma); - if (idx == 0) { - - totadd++; - ob_dst->actcol = totadd; - ob_dst->totcol = totadd; - - if (totadd > totslots) { - BKE_object_material_slot_add(bmain, ob_dst); - } - - assign_material(bmain, ob_dst, ma, ob_dst->totcol, BKE_MAT_ASSIGN_USERPREF); - idx = totadd; - } + ma = give_current_material(ob, gps->mat_nr + 1); /* XXX same material can be in multiple slots */ + idx = BKE_gpencil_handle_material(bmain, ob_dst, ma); /* selected points mode */ if (mode == GP_SEPARATE_POINT) { @@ -3984,7 +3959,7 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op) bGPDstroke *gps_dst = BKE_gpencil_stroke_duplicate(gps); /* reasign material */ - gps_dst->mat_nr = idx - 1; + gps_dst->mat_nr = idx; /* link to destination frame */ BLI_addtail(&gpf_dst->strokes, gps_dst); @@ -4010,7 +3985,7 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op) /* relink to destination frame */ BLI_addtail(&gpf_dst->strokes, gps); /* reasign material */ - gps->mat_nr = idx - 1; + gps->mat_nr = idx; } } } @@ -4048,21 +4023,7 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op) continue; } ma = give_current_material(ob, gps->mat_nr + 1); - idx = BKE_gpencil_get_material_index(ob_dst, ma); - if (idx == 0) { - totadd++; - ob_dst->actcol = totadd; - ob_dst->totcol = totadd; - - if (totadd > totslots) { - BKE_object_material_slot_add(bmain, ob_dst); - } - - assign_material(bmain, ob_dst, ma, ob_dst->totcol, BKE_MAT_ASSIGN_USERPREF); - idx = totadd; - } - /* reasign material */ - gps->mat_nr = idx - 1; + gps->mat_nr = BKE_gpencil_handle_material(bmain, ob_dst, ma); } } } |