Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_edit.c')
-rw-r--r--source/blender/editors/gpencil/gpencil_edit.c57
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);
}
}
}