Lamp *localize_lamp(Lamp *la) { Lamp *lan; int a; lan = BKE_libblock_copy_nolib(&la->id, false); for (a = 0; a < MAX_MTEX; a++) { if (lan->mtex[a]) { lan->mtex[a] = MEM_mallocN(sizeof(MTex), "localize_lamp"); memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex)); /* free lamp decrements */ id_us_plus((ID *)lan->mtex[a]->tex); } } lan->curfalloff = curvemapping_copy(la->curfalloff); if (la->nodetree) lan->nodetree = ntreeLocalize(la->nodetree); lan->preview = NULL; return lan; }
World *localize_world(World *wrld) { World *wrldn; int a; wrldn = BKE_libblock_copy_nolib(&wrld->id, false); for (a = 0; a < MAX_MTEX; a++) { if (wrld->mtex[a]) { wrldn->mtex[a] = MEM_mallocN(sizeof(MTex), "localize_world"); memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex)); /* free world decrements */ id_us_plus((ID *)wrldn->mtex[a]->tex); } } if (wrld->nodetree) wrldn->nodetree = ntreeLocalize(wrld->nodetree); wrldn->preview = NULL; BLI_listbase_clear(&wrldn->gpumaterial); return wrldn; }
/* texture copy without adding to main dbase */ Tex *BKE_texture_localize(Tex *tex) { /* TODO replace with something like * Tex *tex_copy; * BKE_id_copy_ex(bmain, &tex->id, (ID **)&tex_copy, LIB_ID_COPY_NO_MAIN | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_NO_USER_REFCOUNT, false); * return tex_copy; * * ... Once f*** nodes are fully converted to that too :( */ Tex *texn; texn = BKE_libblock_copy_nolib(&tex->id, false); /* image texture: BKE_texture_free also doesn't decrease */ if (texn->coba) texn->coba = MEM_dupallocN(texn->coba); if (texn->env) { texn->env = BKE_texture_envmap_copy(texn->env, LIB_ID_CREATE_NO_USER_REFCOUNT); id_us_min(&texn->env->ima->id); } if (texn->pd) texn->pd = BKE_texture_pointdensity_copy(texn->pd, LIB_ID_CREATE_NO_USER_REFCOUNT); if (texn->vd) { texn->vd = MEM_dupallocN(texn->vd); if (texn->vd->dataset) texn->vd->dataset = MEM_dupallocN(texn->vd->dataset); } if (texn->ot) { texn->ot = BKE_texture_ocean_copy(tex->ot, LIB_ID_CREATE_NO_USER_REFCOUNT); } texn->preview = NULL; if (tex->nodetree) { texn->nodetree = ntreeLocalize(tex->nodetree); } return texn; }