Fix T65741: Removing a GPencil Object's Material Slot deletes the strokes assigned to it

This was a design decision, but now we have decided to change it using the active material for the strokes using deleted material.

If the material slot is empty a new material is created to keep the strokes visible.
This commit is contained in:
Antonioya 2019-06-12 15:51:51 +02:00
parent 7a50d078fe
commit d788f5231e
3 changed files with 16 additions and 29 deletions

@ -86,7 +86,7 @@ void BKE_gpencil_make_local(struct Main *bmain, struct bGPdata *gpd, const bool
void BKE_gpencil_frame_delete_laststroke(struct bGPDlayer *gpl, struct bGPDframe *gpf);
/* materials */
void BKE_gpencil_material_index_remove(struct bGPdata *gpd, int index);
void BKE_gpencil_material_index_reassign(struct bGPdata *gpd, int totcol, int index);
void BKE_gpencil_material_remap(struct bGPdata *gpd,
const unsigned int *remap,
unsigned int remap_len);

@ -1640,33 +1640,15 @@ float BKE_gpencil_multiframe_falloff_calc(
return value;
}
/* remove strokes using a material */
void BKE_gpencil_material_index_remove(bGPdata *gpd, int index)
/* reassign strokes using a material */
void BKE_gpencil_material_index_reassign(bGPdata *gpd, int totcol, int index)
{
bGPDstroke *gps, *gpsn;
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
for (gps = gpf->strokes.first; gps; gps = gpsn) {
gpsn = gps->next;
if (gps->mat_nr == index) {
if (gps->points) {
MEM_freeN(gps->points);
}
if (gps->dvert) {
BKE_gpencil_free_stroke_weights(gps);
MEM_freeN(gps->dvert);
}
if (gps->triangles) {
MEM_freeN(gps->triangles);
}
BLI_freelinkN(&gpf->strokes, gps);
}
else {
/* reassign strokes */
if (gps->mat_nr > index) {
gps->mat_nr--;
}
for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
/* reassign strokes */
if ((gps->mat_nr > index) || (gps->mat_nr > totcol - 1)) {
gps->mat_nr--;
}
}
}

@ -361,9 +361,6 @@ static void material_data_index_remove_id(ID *id, short index)
case ID_MB:
/* meta-elems don't have materials atm */
break;
case ID_GD:
BKE_gpencil_material_index_remove((bGPdata *)id, index);
break;
default:
break;
}
@ -1050,12 +1047,20 @@ bool BKE_object_material_slot_remove(Main *bmain, Object *ob)
}
/* check indices from mesh */
if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_GPENCIL)) {
if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) {
material_data_index_remove_id((ID *)ob->data, actcol - 1);
if (ob->runtime.curve_cache) {
BKE_displist_free(&ob->runtime.curve_cache->disp);
}
}
/* check indices from gpencil */
else if (ob->type == OB_GPENCIL) {
/* need one color */
if (ob->totcol == 0) {
BKE_gpencil_object_material_ensure_from_active_input_material(bmain, ob);
}
BKE_gpencil_material_index_reassign((bGPdata *)ob->data, ob->totcol, actcol - 1);
}
return true;
}