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-14 18:36:43 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-08-14 18:36:43 +0400
commit7a6f3d9e43cec6ac2b00b01279820d8b8dce290d (patch)
treebfe261911eb60fa830b14c56a660bfcf85b63625 /source/blender/blenkernel/intern/material.c
parent503b7d5b9a385fdcd220df3142857300d912d80c (diff)
fix [#36349] Separate mesh by material creates meshes with all the materials from the original
Diffstat (limited to 'source/blender/blenkernel/intern/material.c')
-rw-r--r--source/blender/blenkernel/intern/material.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 1bda662a8b0..c23b4ac4408 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -573,6 +573,34 @@ static void material_data_index_clear_id(ID *id)
}
}
+void BKE_material_resize_id(struct ID *id, short totcol, bool do_id_user)
+{
+ Material ***matar = give_matarar_id(id);
+ short *totcolp = give_totcolp_id(id);
+
+ if (matar == NULL) {
+ return;
+ }
+
+ if (do_id_user && totcol < (*totcolp)) {
+ short i;
+ for (i = totcol; i < (*totcolp); i++) {
+ id_us_min((ID *)(*matar)[i]);
+ }
+ }
+
+ if (totcol == 0) {
+ if (*totcolp) {
+ MEM_freeN(*matar);
+ *matar = NULL;
+ }
+ }
+ else {
+ *matar = MEM_recallocN(*matar, sizeof(void *) * totcol);
+ }
+ *totcolp = totcol;
+}
+
void BKE_material_append_id(ID *id, Material *ma)
{
Material ***matar;
@@ -708,11 +736,18 @@ Material *give_node_material(Material *ma)
return NULL;
}
-void resize_object_material(Object *ob, const short totcol)
+void BKE_material_resize_object(Object *ob, const short totcol, bool do_id_user)
{
Material **newmatar;
char *newmatbits;
+ if (do_id_user && totcol < ob->totcol) {
+ short i;
+ for (i = totcol; i < ob->totcol; i++) {
+ id_us_min((ID *)ob->mat[i]);
+ }
+ }
+
if (totcol == 0) {
if (ob->totcol) {
MEM_freeN(ob->mat);
@@ -733,6 +768,8 @@ void resize_object_material(Object *ob, const short totcol)
ob->mat = newmatar;
ob->matbits = newmatbits;
}
+ /* XXX, why not realloc on shrink? - campbell */
+
ob->totcol = totcol;
if (ob->totcol && ob->actcol == 0) ob->actcol = 1;
if (ob->actcol > ob->totcol) ob->actcol = ob->totcol;
@@ -750,7 +787,7 @@ void test_object_materials(Main *bmain, ID *id)
for (ob = bmain->object.first; ob; ob = ob->id.next) {
if (ob->data == id) {
- resize_object_material(ob, *totcol);
+ BKE_material_resize_object(ob, *totcol, false);
}
}
}