[Bf-blender-cvs] [e2893dad4f1] greasepencil-object: Fix separate operator using Materials
Antonio Vazquez
noreply at git.blender.org
Sun Apr 29 12:42:53 CEST 2018
Commit: e2893dad4f1cf4897173cd92309b198adf893503
Author: Antonio Vazquez
Date: Sun Apr 29 12:42:42 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rBe2893dad4f1cf4897173cd92309b198adf893503
Fix separate operator using Materials
===================================================================
M source/blender/editors/gpencil/gpencil_edit.c
M source/blender/editors/object/object_add.c
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 9478b37e6ee..e4d3751953a 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -3012,7 +3012,8 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op)
bGPDlayer *gpl_dst = NULL;
bGPDframe *gpf_dst = NULL;
bGPDspoint *pt;
- int i;
+ Material *mat = NULL;
+ int i, idx;
eGP_SeparateModes mode = RNA_enum_get(op->ptr, "mode");
@@ -3031,6 +3032,9 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op)
gpd_dst = BKE_gpencil_data_addnew(bmain, "GPencil");
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)
@@ -3074,11 +3078,31 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op)
gpf_dst = BKE_gpencil_layer_getframe(gpl_dst, gpf->framenum, GP_GETFRAME_ADD_NEW);
}
+ /* add duplicate materials */
+ mat = give_current_material(ob, gps->mat_nr + 1);
+ idx = BKE_object_material_slot_find_index(ob_dst, mat);
+ if (idx == 0) {
+
+ totadd++;
+ ob_dst->actcol = totadd;
+ ob_dst->totcol = totadd;
+
+ if (totadd > totslots) {
+ BKE_object_material_slot_add(ob_dst);
+ }
+
+ assign_material(ob_dst, mat, ob_dst->totcol, BKE_MAT_ASSIGN_EXISTING);
+ idx = totadd;
+ }
+
/* selected points mode */
if (mode == GP_SEPARATE_POINT) {
/* make copy of source stroke */
bGPDstroke *gps_dst = BKE_gpencil_stroke_duplicate(gps);
-
+
+ /* reasign material */
+ gps_dst->mat_nr = idx - 1;
+
/* link to destination frame */
BLI_addtail(&gpf_dst->strokes, gps_dst);
@@ -3102,6 +3126,8 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op)
gps->prev = gps->next = NULL;
/* relink to destination frame */
BLI_addtail(&gpf_dst->strokes, gps);
+ /* reasign material */
+ gps->mat_nr = idx - 1;
}
}
}
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index 885c661218f..ef479a0c0bc 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -2210,6 +2210,10 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, ViewLayer
ID_NEW_REMAP_US(obn->mat[a])
else {
obn->mat[a] = ID_NEW_SET(obn->mat[a], BKE_material_copy(bmain, obn->mat[a]));
+ /* duplicate grease pencil settings */
+ if (ob->mat[a]->gpcolor) {
+ obn->mat[a]->gpcolor = MEM_dupallocN(ob->mat[a]->gpcolor);
+ }
}
id_us_min(id);
More information about the Bf-blender-cvs
mailing list