From d5d3dc418912863b172ef9f79f9991bb9d46bea8 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Fri, 30 Aug 2019 14:19:07 +0200 Subject: GPencil: Use default material when slot material is empty When a material slot is empty, the default material is used. The default color used is Gray to get a good contrast in dense scenes with dark and white background. Reviewers: brecht, dfelinto, mendio, pepeland Differential Revision: https://developer.blender.org/D5625 --- source/blender/blenkernel/intern/gpencil.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'source/blender/blenkernel/intern/gpencil.c') diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index d4bf76ea44a..456bc0c88f9 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -1161,38 +1161,34 @@ Material *BKE_gpencil_object_material_ensure_from_active_input_brush(Main *bmain brush->gpencil_settings->flag &= ~GP_BRUSH_MATERIAL_PINNED; } } - return BKE_gpencil_object_material_ensure_from_active_input_material(bmain, ob); + return BKE_gpencil_object_material_ensure_from_active_input_material(ob); } /** * Guaranteed to return a material assigned to object. Returns never NULL. * Only use this for materials unrelated to user input. */ -Material *BKE_gpencil_object_material_ensure_from_active_input_material(Main *bmain, Object *ob) +Material *BKE_gpencil_object_material_ensure_from_active_input_material(Object *ob) { Material *ma = give_current_material(ob, ob->actcol); if (ma) { return ma; } - /* If the slot is empty, remove because will be added again, - * if not, we will get an empty slot. */ - if ((ob->totcol > 0) && (ob->actcol == ob->totcol)) { - BKE_object_material_slot_remove(bmain, ob); - } - return BKE_gpencil_object_material_new(bmain, ob, "Material", NULL); + + return &defgpencil_material; } /* Get active color, and add all default settings if we don't find anything */ -Material *BKE_gpencil_object_material_ensure_active(Main *bmain, Object *ob) +Material *BKE_gpencil_object_material_ensure_active(Object *ob) { Material *ma = NULL; /* sanity checks */ - if (ELEM(NULL, bmain, ob)) { + if (ob == NULL) { return NULL; } - ma = BKE_gpencil_object_material_ensure_from_active_input_material(bmain, ob); + ma = BKE_gpencil_object_material_ensure_from_active_input_material(ob); if (ma->gp_style == NULL) { BKE_material_init_gpencil_settings(ma); } @@ -2008,6 +2004,7 @@ void BKE_gpencil_material_index_reassign(bGPdata *gpd, int totcol, int index) /* reassign strokes */ if ((gps->mat_nr > index) || (gps->mat_nr > totcol - 1)) { gps->mat_nr--; + CLAMP_MIN(gps->mat_nr, 0); } } } -- cgit v1.2.3