BKE material api function: assign_material_id, like assign_material but takes the...
authorCampbell Barton <ideasman42@gmail.com>
Sat, 1 Oct 2011 17:51:47 +0000 (17:51 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 1 Oct 2011 17:51:47 +0000 (17:51 +0000)
source/blender/blenkernel/BKE_material.h
source/blender/blenkernel/intern/material.c

index cb6a0b9ab37df77b145239ec95a401b0de8b2f3b..0e0348e78e9d7591c86705afb1f7bb775ed3dc9d 100644 (file)
@@ -71,6 +71,7 @@ short *give_totcolp_id(struct ID *id);
 
 struct Material *give_current_material(struct Object *ob, short act);
 struct ID *material_from(struct Object *ob, short act);
+void assign_material_id(struct ID *id, struct Material *ma, short act);
 void assign_material(struct Object *ob, struct Material *ma, short act);
 void assign_matarar(struct Object *ob, struct Material ***matar, short totcol);
 
index a25da56d573db0a3fc46fdf92437f99d2fc8007f..6e1303e375efb3ad1e6fce230fbda1e3841dd2fd 100644 (file)
@@ -723,6 +723,48 @@ void test_object_materials(ID *id)
        }
 }
 
+void assign_material_id(ID *id, Material *ma, short act)
+{
+       Material *mao, **matar, ***matarar;
+       short *totcolp;
+
+       if(act>MAXMAT) return;
+       if(act<1) act= 1;
+
+       /* prevent crashing when using accidentally */
+       BLI_assert(id->lib == NULL);
+       if(id->lib) return;
+
+       /* test arraylens */
+
+       totcolp= give_totcolp_id(id);
+       matarar= give_matarar_id(id);
+
+       if(totcolp==NULL || matarar==NULL) return;
+
+       if(act > *totcolp) {
+               matar= MEM_callocN(sizeof(void *)*act, "matarray1");
+
+               if(*totcolp) {
+                       memcpy(matar, *matarar, sizeof(void *)*(*totcolp));
+                       MEM_freeN(*matarar);
+               }
+
+               *matarar= matar;
+               *totcolp= act;
+       }
+
+       /* in data */
+       mao= (*matarar)[act-1];
+       if(mao) mao->id.us--;
+       (*matarar)[act-1]= ma;
+
+       if(ma)
+               id_us_plus((ID *)ma);
+
+       test_object_materials(id);
+}
+
 void assign_material(Object *ob, Material *ma, short act)
 {
        Material *mao, **matar, ***matarar;