Tex *give_current_material_texture(Material *ma) { MTex *mtex = NULL; Tex *tex = NULL; bNode *node; if (ma && ma->use_nodes && ma->nodetree) { /* first check texture, then material, this works together * with a hack that clears the active ID flag for textures on * making a material node active */ node = nodeGetActiveID(ma->nodetree, ID_TE); if (node) { tex = (Tex *)node->id; ma = NULL; } } if (ma) { mtex = ma->mtex[(int)(ma->texact)]; if (mtex) tex = mtex->tex; } return tex; }
void set_current_material_texture(Material *ma, Tex *newtex) { Tex *tex= NULL; bNode *node; if(ma && ma->use_nodes && ma->nodetree) { node= nodeGetActiveID(ma->nodetree, ID_TE); if(node) { tex= (Tex *)node->id; id_us_min(&tex->id); node->id= &newtex->id; id_us_plus(&newtex->id); ma= NULL; } } if(ma) { int act= (int)ma->texact; tex= (ma->mtex[act])? ma->mtex[act]->tex: NULL; id_us_min(&tex->id); if(newtex) { if(!ma->mtex[act]) ma->mtex[act]= add_mtex(); ma->mtex[act]->tex= newtex; id_us_plus(&newtex->id); } else if(ma->mtex[act]) { MEM_freeN(ma->mtex[act]); ma->mtex[act]= NULL; } } }
bNode *give_current_material_texture_node(Material *ma) { if (ma && ma->use_nodes && ma->nodetree) return nodeGetActiveID(ma->nodetree, ID_TE); return NULL; }
int has_current_material_texture(Material *ma) { bNode *node; if (ma && ma->use_nodes && ma->nodetree) { node = nodeGetActiveID(ma->nodetree, ID_TE); if (node) return 1; } return (ma != NULL); }
void set_current_material_texture(Material *ma, Tex *newtex) { Tex *tex = NULL; bNode *node; if ((ma->use_nodes && ma->nodetree) && (node = nodeGetActiveID(ma->nodetree, ID_TE))) { tex = (Tex *)node->id; id_us_min(&tex->id); if (newtex) { node->id = &newtex->id; id_us_plus(&newtex->id); } else { node->id = NULL; } } else { int act = (int)ma->texact; tex = (ma->mtex[act]) ? ma->mtex[act]->tex : NULL; id_us_min(&tex->id); if (newtex) { if (!ma->mtex[act]) { ma->mtex[act] = BKE_texture_mtex_add(); /* Reset this slot's ON/OFF toggle, for materials, when slot was empty. */ ma->septex &= ~(1 << act); /* For volumes the default UV texture coordinates are not available. */ if (ma->material_type == MA_TYPE_VOLUME) { ma->mtex[act]->texco = TEXCO_ORCO; } } ma->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } else if (ma->mtex[act]) { MEM_freeN(ma->mtex[act]); ma->mtex[act] = NULL; } } }