From e188a798c64ec538fa598ea50a16d311e517aa85 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Wed, 12 Aug 2020 19:46:15 +0200 Subject: GPencil: Clean material list when convert a curve Now the list of materials is cleanup and any duplicated material is removed. --- source/blender/blenkernel/intern/gpencil_curve.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c index d2c9ef0b3bc..429faefd923 100644 --- a/source/blender/blenkernel/intern/gpencil_curve.c +++ b/source/blender/blenkernel/intern/gpencil_curve.c @@ -447,7 +447,6 @@ static void gpencil_convert_spline(Main *bmain, } } /* Cyclic curve, close stroke. */ - // if ((cyclic) && (!do_stroke)) { if (cyclic) { BKE_gpencil_stroke_close(gps); } @@ -523,8 +522,29 @@ void BKE_gpencil_convert_curve(Main *bmain, bmain, ob_gp, ob_cu, gpencil_lines, only_stroke, scale_thickness, sample, gpf, nu); } + /* Merge any similar material. */ + int removed = 0; + BKE_gpencil_merge_materials(ob_gp, 0.001f, 0.001f, 0.001f, &removed); + + /* Remove any unused slot. */ + int actcol = ob_gp->actcol; + + for (int slot = 1; slot <= ob_gp->totcol; slot++) { + while (slot <= ob_gp->totcol && !BKE_object_material_slot_used(ob_gp->data, slot)) { + ob_gp->actcol = slot; + BKE_object_material_slot_remove(bmain, ob_gp); + + if (actcol >= slot) { + actcol--; + } + } + } + + ob_gp->actcol = actcol; + /* Tag for recalculation */ DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE); + DEG_id_tag_update(&ob_gp->id, ID_RECALC_GEOMETRY); } /** \} */ -- cgit v1.2.3