diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-10-01 21:51:47 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-10-01 21:51:47 +0400 |
commit | 738491555d4e831186de337800dce4f14c56d252 (patch) | |
tree | edf2dad1eb8599f63990156337541b5edc12a01b /source/blender/blenkernel | |
parent | 975c4e717798e71af3d46f06c3e25ae54e11fcca (diff) |
BKE material api function: assign_material_id, like assign_material but takes the object data rather then the object.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_material.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 42 |
2 files changed, 43 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index cb6a0b9ab37..0e0348e78e9 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -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); diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index a25da56d573..6e1303e375e 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -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; |