/* slot -1 for first free ID */ MTex *BKE_texture_mtex_add_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; } else if (GS(id->name) == ID_MA) { /* Reset this slot's ON/OFF toggle, for materials, when slot was empty. */ ((Material *)id)->septex &= ~(1 << slot); } mtex_ar[slot] = BKE_texture_mtex_add(); return mtex_ar[slot]; }
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; } } }
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] = BKE_texture_mtex_add(); 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] = BKE_texture_mtex_add(); 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_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] = BKE_texture_mtex_add(); 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_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] = BKE_texture_mtex_add(); 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] = BKE_texture_mtex_add(); ma->mtex[i]->texco = TEXCO_UV; ma->mtex[i]->tex = BKE_texture_add(G.main, "Texture"); ma->mtex[i]->tex->type = TEX_IMAGE; ma->mtex[i]->tex->ima = uid_image_map[ima_uid]; texindex_texarray_map[ctex.getTextureMapId()].push_back(ma->mtex[i]); return ma->mtex[i]; }