Lamp *localize_lamp(Lamp *la) { Lamp *lan; int a; lan = BKE_libblock_copy(&la->id); BLI_remlink(&G.main->lamp, lan); 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; }
/* texture copy without adding to main dbase */ Tex *localize_texture(Tex *tex) { Tex *texn; texn = BKE_libblock_copy(&tex->id); BLI_remlink(&G.main->tex, texn); /* image texture: BKE_texture_free also doesn't decrease */ if (texn->coba) texn->coba = MEM_dupallocN(texn->coba); if (texn->env) { texn->env = BKE_copy_envmap(texn->env); id_us_min(&texn->env->ima->id); } if (texn->pd) texn->pd = BKE_copy_pointdensity(texn->pd); 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_copy_oceantex(tex->ot); } texn->preview = NULL; if (tex->nodetree) { texn->nodetree = ntreeLocalize(tex->nodetree); } return texn; }
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; }
/* XXX (see above) material copy without adding to main dbase */ Material *localize_material(Material *ma) { Material *man; int a; man= copy_libblock(ma); BLI_remlink(&G.main->mat, man); /* no increment for texture ID users, in previewrender.c it prevents decrement */ for(a=0; a<MAX_MTEX; a++) { if(ma->mtex[a]) { man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial"); memcpy(man->mtex[a], ma->mtex[a], sizeof(MTex)); } } if(ma->ramp_col) man->ramp_col= MEM_dupallocN(ma->ramp_col); if(ma->ramp_spec) man->ramp_spec= MEM_dupallocN(ma->ramp_spec); man->preview = NULL; if(ma->nodetree) man->nodetree= ntreeLocalize(ma->nodetree); man->gpumaterial.first= man->gpumaterial.last= NULL; return man; }
Light *BKE_light_localize(Light *la) { /* TODO(bastien): Replace with something like: * * Light *la_copy; * BKE_id_copy_ex(bmain, &la->id, (ID **)&la_copy, * LIB_ID_COPY_NO_MAIN | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_NO_USER_REFCOUNT, * false); * return la_copy; * * NOTE: Only possible once nested node trees are fully converted to that too. */ Light *lan = BKE_libblock_copy_for_localize(&la->id); lan->curfalloff = curvemapping_copy(la->curfalloff); if (la->nodetree) { lan->nodetree = ntreeLocalize(la->nodetree); } lan->preview = NULL; lan->id.tag |= LIB_TAG_LOCALIZED; return lan; }
void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, short compatibility) { /* localize tree to create links for reroute and mute */ bNodeTree *localtree = ntreeLocalize(ntree); bNodeTreeExec *exec; exec = ntreeShaderBeginExecTree(localtree); ntreeExecGPUNodes(exec, mat, 1, compatibility); ntreeShaderEndExecTree(exec); ntreeFreeTree_ex(localtree, false); MEM_freeN(localtree); }
void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, short compatibility) { /* localize tree to create links for reroute and mute */ bNodeTree *localtree = ntreeLocalize(ntree); bNodeTreeExec *exec; /* Perform all needed modifications on the tree in order to support * displacement/bump mapping. */ ntree_shader_relink_displacement(localtree, compatibility); exec = ntreeShaderBeginExecTree(localtree); ntreeExecGPUNodes(exec, mat, 1, compatibility); ntreeShaderEndExecTree(exec); ntreeFreeTree_ex(localtree, false); MEM_freeN(localtree); }
/* 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; }
World *localize_world(World *wrld) { World *wrldn; int a; wrldn = BKE_libblock_copy(&wrld->id); BLI_remlink(&G.main->world, wrldn); 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; return wrldn; }