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; } } }
/* slot -1 for first free ID */ MTex *add_mtex_id(ID *id, int slot) { MTex **mtex_ar; short act; give_active_mtex(id, &mtex_ar, &act); if (mtex_ar == NULL) { return NULL; } if (slot == -1) { /* find first free */ int i; for (i = 0; i < MAX_MTEX; i++) { if (!mtex_ar[i]) { slot = i; break; } } if (slot == -1) { return NULL; } } else { /* make sure slot is valid */ if (slot < 0 || slot >= MAX_MTEX) { return NULL; } } if (mtex_ar[slot]) { id_us_min((ID *)mtex_ar[slot]->tex); MEM_freeN(mtex_ar[slot]); mtex_ar[slot] = NULL; } mtex_ar[slot] = add_mtex(); return mtex_ar[slot]; }
void set_current_lamp_texture(Lamp *la, Tex *newtex) { int act = la->texact; if (la->mtex[act] && la->mtex[act]->tex) id_us_min(&la->mtex[act]->tex->id); if (newtex) { if (!la->mtex[act]) { la->mtex[act] = add_mtex(); la->mtex[act]->texco = TEXCO_GLOB; } la->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } else if (la->mtex[act]) { MEM_freeN(la->mtex[act]); la->mtex[act] = NULL; } }
void set_current_world_texture(World *wo, Tex *newtex) { int act = wo->texact; if (wo->mtex[act] && wo->mtex[act]->tex) id_us_min(&wo->mtex[act]->tex->id); if (newtex) { if (!wo->mtex[act]) { wo->mtex[act] = add_mtex(); wo->mtex[act]->texco = TEXCO_VIEW; } wo->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } else if (wo->mtex[act]) { MEM_freeN(wo->mtex[act]); wo->mtex[act] = NULL; } }
void set_current_linestyle_texture(FreestyleLineStyle *linestyle, Tex *newtex) { int act = linestyle->texact; if (linestyle->mtex[act] && linestyle->mtex[act]->tex) id_us_min(&linestyle->mtex[act]->tex->id); if (newtex) { if (!linestyle->mtex[act]) { linestyle->mtex[act] = add_mtex(); linestyle->mtex[act]->texco = TEXCO_STROKE; } linestyle->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } else if (linestyle->mtex[act]) { MEM_freeN(linestyle->mtex[act]); linestyle->mtex[act] = NULL; } }
void set_current_particle_texture(ParticleSettings *part, Tex *newtex) { int act = part->texact; if (part->mtex[act] && part->mtex[act]->tex) id_us_min(&part->mtex[act]->tex->id); if (newtex) { if (!part->mtex[act]) { part->mtex[act] = add_mtex(); part->mtex[act]->texco = TEXCO_ORCO; part->mtex[act]->blendtype = MTEX_MUL; } part->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } else if (part->mtex[act]) { MEM_freeN(part->mtex[act]); part->mtex[act] = NULL; } }
// create mtex, create texture, set texture image MTex* DocumentImporter::create_texture(COLLADAFW::EffectCommon *ef, COLLADAFW::Texture &ctex, Material *ma, int i, TexIndexTextureArrayMap &texindex_texarray_map) { COLLADAFW::SamplerPointerArray& samp_array = ef->getSamplerPointerArray(); COLLADAFW::Sampler *sampler = samp_array[ctex.getSamplerId()]; const COLLADAFW::UniqueId& ima_uid = sampler->getSourceImage(); if (uid_image_map.find(ima_uid) == uid_image_map.end()) { fprintf(stderr, "Couldn't find an image by UID.\n"); return NULL; } ma->mtex[i] = add_mtex(); ma->mtex[i]->texco = TEXCO_UV; ma->mtex[i]->tex = add_texture("Texture"); ma->mtex[i]->tex->type = TEX_IMAGE; ma->mtex[i]->tex->imaflag &= ~TEX_USEALPHA; ma->mtex[i]->tex->ima = uid_image_map[ima_uid]; texindex_texarray_map[ctex.getTextureMapId()].push_back(ma->mtex[i]); return ma->mtex[i]; }