diff options
Diffstat (limited to 'source/blender/blenkernel/intern/material.c')
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 102 |
1 files changed, 57 insertions, 45 deletions
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 334f018efc9..aab8e1abbea 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -61,7 +61,7 @@ #include "BKE_material.h" #include "BKE_mesh.h" #include "BKE_node.h" - +#include "BKE_curve.h" #include "GPU_material.h" @@ -515,6 +515,21 @@ short *give_totcolp_id(ID *id) return NULL; } +static void data_delete_material_index_id(ID *id, int index) +{ + switch(GS(id->name)) { + case ID_ME: + mesh_delete_material_index((Mesh *)id, index); + break; + case ID_CU: + curve_delete_material_index((Curve *)id, index); + break; + case ID_MB: + /* meta-elems dont have materials atm */ + break; + } +} + void material_append_id(ID *id, Material *ma) { Material ***matar; @@ -532,7 +547,7 @@ void material_append_id(ID *id, Material *ma) } } -Material *material_pop_id(ID *id, int index) +Material *material_pop_id(ID *id, int index, int remove_material_slot) { Material *ret= NULL; Material ***matar; @@ -540,27 +555,36 @@ Material *material_pop_id(ID *id, int index) short *totcol= give_totcolp_id(id); if(index >= 0 && index < (*totcol)) { ret= (*matar)[index]; - id_us_min((ID *)ret); - if(*totcol <= 1) { - *totcol= 0; - MEM_freeN(*matar); - *matar= NULL; - } - else { - Material **mat; - - if(index + 1 != (*totcol)) - memmove((*matar), (*matar) + 1, (*totcol) - (index + 1)); + id_us_min((ID *)ret); - (*totcol)--; - - mat= MEM_callocN(sizeof(void *) * (*totcol), "newmatar"); - memcpy(mat, *matar, sizeof(void *) * (*totcol)); - MEM_freeN(*matar); + 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(id); + } - *matar= mat; - test_object_materials(id); + /* decrease mat_nr index */ + data_delete_material_index_id(id, index); } + + /* don't remove material slot, only clear it*/ + else + (*matar)[index]= NULL; } } @@ -867,6 +891,10 @@ static void do_init_render_material(Material *ma, int r_mode, float *amb) if(ma->strand_surfnor > 0.0f) ma->mode_l |= MA_STR_SURFDIFF; + + /* parses the geom+tex nodes */ + if(ma->nodetree && ma->use_nodes) + ntreeShaderGetTexcoMode(ma->nodetree, r_mode, &ma->texco, &ma->mode_l); } static void init_render_nodetree(bNodeTree *ntree, Material *basemat, int r_mode, float *amb) @@ -887,8 +915,6 @@ static void init_render_nodetree(bNodeTree *ntree, Material *basemat, int r_mode init_render_nodetree((bNodeTree *)node->id, basemat, r_mode, amb); } } - /* parses the geom+tex nodes */ - ntreeShaderGetTexcoMode(ntree, r_mode, &basemat->texco, &basemat->mode_l); } void init_render_material(Material *mat, int r_mode, float *amb) @@ -899,7 +925,8 @@ void init_render_material(Material *mat, int r_mode, float *amb) if(mat->nodetree && mat->use_nodes) { init_render_nodetree(mat->nodetree, mat, r_mode, amb); - ntreeBeginExecTree(mat->nodetree); /* has internal flag to detect it only does it once */ + if (!mat->nodetree->execdata) + mat->nodetree->execdata = ntreeShaderBeginExecTree(mat->nodetree, 1); } } @@ -931,8 +958,10 @@ void init_render_materials(Main *bmain, int r_mode, float *amb) /* only needed for nodes now */ void end_render_material(Material *mat) { - if(mat && mat->nodetree && mat->use_nodes) - ntreeEndExecTree(mat->nodetree); /* has internal flag to detect it only does it once */ + if(mat && mat->nodetree && mat->use_nodes) { + if (mat->nodetree->execdata) + ntreeShaderEndExecTree(mat->nodetree->execdata, 1); + } } void end_render_materials(Main *bmain) @@ -1023,8 +1052,6 @@ int object_remove_material_slot(Object *ob) { Material *mao, ***matarar; Object *obt; - Curve *cu; - Nurb *nu; short *totcolp; int a, actcol; @@ -1084,23 +1111,8 @@ int object_remove_material_slot(Object *ob) } /* check indices from mesh */ - - if(ob->type==OB_MESH) { - Mesh *me= get_mesh(ob); - mesh_delete_material_index(me, actcol-1); - freedisplist(&ob->disp); - } - else if ELEM(ob->type, OB_CURVE, OB_SURF) { - cu= ob->data; - nu= cu->nurb.first; - - while(nu) { - if(nu->mat_nr && nu->mat_nr>=actcol-1) { - nu->mat_nr--; - if (ob->type == OB_CURVE) nu->charidx--; - } - nu= nu->next; - } + if (ELEM4(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) { + data_delete_material_index_id((ID *)ob->data, actcol-1); freedisplist(&ob->disp); } @@ -1356,7 +1368,7 @@ void ramp_blend(int type, float *r, float *g, float *b, float fac, float *col) } /* copy/paste buffer, if we had a propper py api that would be better */ -Material matcopybuf; +static Material matcopybuf; static short matcopied= 0; void clear_matcopybuf(void) |