diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-08-14 15:29:58 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-08-14 15:29:58 +0400 |
commit | 503b7d5b9a385fdcd220df3142857300d912d80c (patch) | |
tree | d25f1c3c59edd0e8c30faf984cc681af9ada9fc8 /source/blender/blenkernel/intern/material.c | |
parent | 1979720d0324b84e4993557d30ff833f71e688fd (diff) |
add materials.clear() method, matching other python list method.
Diffstat (limited to 'source/blender/blenkernel/intern/material.c')
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index b9114c24091..1bda662a8b0 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -537,17 +537,17 @@ short *give_totcolp_id(ID *id) return NULL; } -static void data_delete_material_index_id(ID *id, short index) +static void material_data_index_remove_id(ID *id, short index) { /* ensure we don't try get materials from non-obdata */ BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name))); switch (GS(id->name)) { case ID_ME: - BKE_mesh_delete_material_index((Mesh *)id, index); + BKE_mesh_material_index_remove((Mesh *)id, index); break; case ID_CU: - BKE_curve_delete_material_index((Curve *)id, index); + BKE_curve_material_index_remove((Curve *)id, index); break; case ID_MB: /* meta-elems don't have materials atm */ @@ -555,7 +555,25 @@ static void data_delete_material_index_id(ID *id, short index) } } -void material_append_id(ID *id, Material *ma) +static void material_data_index_clear_id(ID *id) +{ + /* ensure we don't try get materials from non-obdata */ + BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name))); + + switch (GS(id->name)) { + case ID_ME: + BKE_mesh_material_index_clear((Mesh *)id); + break; + case ID_CU: + BKE_curve_material_index_clear((Curve *)id); + break; + case ID_MB: + /* meta-elems don't have materials atm */ + break; + } +} + +void BKE_material_append_id(ID *id, Material *ma) { Material ***matar; if ((matar = give_matarar_id(id))) { @@ -572,7 +590,7 @@ void material_append_id(ID *id, Material *ma) } } -Material *material_pop_id(ID *id, int index_i, bool remove_material_slot) +Material *BKE_material_pop_id(ID *id, int index_i, bool update_data) { short index = (short)index_i; Material *ret = NULL; @@ -597,9 +615,9 @@ Material *material_pop_id(ID *id, int index_i, bool remove_material_slot) test_object_materials(G.main, id); } - if (remove_material_slot) { + if (update_data) { /* decrease mat_nr index */ - data_delete_material_index_id(id, index); + material_data_index_remove_id(id, index); } } } @@ -607,6 +625,24 @@ Material *material_pop_id(ID *id, int index_i, bool remove_material_slot) return ret; } +void BKE_material_clear_id(struct ID *id, bool update_data) +{ + Material ***matar; + if ((matar = give_matarar_id(id))) { + short *totcol = give_totcolp_id(id); + *totcol = 0; + if (*matar) { + MEM_freeN(*matar); + *matar = NULL; + } + + if (update_data) { + /* decrease mat_nr index */ + material_data_index_clear_id(id); + } + } +} + Material *give_current_material(Object *ob, short act) { Material ***matarar, *ma; @@ -1217,7 +1253,7 @@ int object_remove_material_slot(Object *ob) /* check indices from mesh */ if (ELEM4(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) { - data_delete_material_index_id((ID *)ob->data, actcol - 1); + material_data_index_remove_id((ID *)ob->data, actcol - 1); BKE_displist_free(&ob->disp); } @@ -1693,7 +1729,7 @@ static short mesh_getmaterialnumber(Mesh *me, Material *ma) /* append material */ static short mesh_addmaterial(Mesh *me, Material *ma) { - material_append_id(&me->id, NULL); + BKE_material_append_id(&me->id, NULL); me->mat[me->totcol - 1] = ma; id_us_plus(&ma->id); @@ -1832,7 +1868,7 @@ static void convert_tfacematerial(Main *main, Material *ma) /* remove material from mesh */ for (a = 0; a < me->totcol; ) { if (me->mat[a] == ma) { - material_pop_id(&me->id, a, true); + BKE_material_pop_id(&me->id, a, true); } else { a++; |