Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-08-13 14:21:11 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-08-13 14:21:11 +0400
commita8d1c893e8cea727d24f0bd8c64732fadcbcbcf2 (patch)
tree7ece26514060f98da5e9b900ab1a534daf7928e9 /source/blender/blenkernel/intern/material.c
parent4d5c64372ada6f8dbfd8d89d4bcd515eadbb32d4 (diff)
make materials.pop() and more like pythons list.pop
- allow negative index values. - error when invalid index value are passed in. - remove last item if no index argument is given. also change behavior to remove the material slot, it was only clearning by default but the list length remained the same.
Diffstat (limited to 'source/blender/blenkernel/intern/material.c')
-rw-r--r--source/blender/blenkernel/intern/material.c50
1 files changed, 23 insertions, 27 deletions
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 6dc3c6d7bc6..b9114c24091 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -572,7 +572,7 @@ void material_append_id(ID *id, Material *ma)
}
}
-Material *material_pop_id(ID *id, int index_i, int remove_material_slot)
+Material *material_pop_id(ID *id, int index_i, bool remove_material_slot)
{
short index = (short)index_i;
Material *ret = NULL;
@@ -583,34 +583,24 @@ Material *material_pop_id(ID *id, int index_i, int remove_material_slot)
ret = (*matar)[index];
id_us_min((ID *)ret);
- if (remove_material_slot) {
- if (*totcol <= 1) {
- *totcol = 0;
- MEM_freeN(*matar);
- *matar = NULL;
- }
- else {
- Material **mat;
- if (index + 1 != (*totcol))
- memmove((*matar) + index, (*matar) + (index + 1), sizeof(void *) * ((*totcol) - (index + 1)));
-
- (*totcol)--;
-
- mat = MEM_callocN(sizeof(void *) * (*totcol), "newmatar");
- memcpy(mat, *matar, sizeof(void *) * (*totcol));
- MEM_freeN(*matar);
-
- *matar = mat;
- test_object_materials(G.main, id);
- }
+ if (*totcol <= 1) {
+ *totcol = 0;
+ MEM_freeN(*matar);
+ *matar = NULL;
+ }
+ else {
+ if (index + 1 != (*totcol))
+ memmove((*matar) + index, (*matar) + (index + 1), sizeof(void *) * ((*totcol) - (index + 1)));
+
+ (*totcol)--;
+ *matar = MEM_reallocN(*matar, sizeof(void *) * (*totcol));
+ test_object_materials(G.main, id);
+ }
+ if (remove_material_slot) {
/* decrease mat_nr index */
data_delete_material_index_id(id, index);
}
-
- /* don't remove material slot, only clear it*/
- else
- (*matar)[index] = NULL;
}
}
@@ -1840,8 +1830,14 @@ static void convert_tfacematerial(Main *main, Material *ma)
mf->mat_nr = mat_nr;
}
/* remove material from mesh */
- for (a = 0; a < me->totcol; )
- if (me->mat[a] == ma) material_pop_id(&me->id, a, 1); else a++;
+ for (a = 0; a < me->totcol; ) {
+ if (me->mat[a] == ma) {
+ material_pop_id(&me->id, a, true);
+ }
+ else {
+ a++;
+ }
+ }
}
}