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; } } }
Mesh *BKE_mesh_copy_ex(Main *bmain, Mesh *me) { Mesh *men; MTFace *tface; MTexPoly *txface; int a, i; const int do_tessface = ((me->totface != 0) && (me->totpoly == 0)); /* only do tessface if we have no polys */ men = BKE_libblock_copy_ex(bmain, &me->id); men->mat = MEM_dupallocN(me->mat); for (a = 0; a < men->totcol; a++) { id_us_plus((ID *)men->mat[a]); } id_us_plus((ID *)men->texcomesh); CustomData_copy(&me->vdata, &men->vdata, CD_MASK_MESH, CD_DUPLICATE, men->totvert); CustomData_copy(&me->edata, &men->edata, CD_MASK_MESH, CD_DUPLICATE, men->totedge); CustomData_copy(&me->ldata, &men->ldata, CD_MASK_MESH, CD_DUPLICATE, men->totloop); CustomData_copy(&me->pdata, &men->pdata, CD_MASK_MESH, CD_DUPLICATE, men->totpoly); if (do_tessface) { CustomData_copy(&me->fdata, &men->fdata, CD_MASK_MESH, CD_DUPLICATE, men->totface); } else { mesh_tessface_clear_intern(men, FALSE); } BKE_mesh_update_customdata_pointers(men, do_tessface); /* ensure indirect linked data becomes lib-extern */ for (i = 0; i < me->fdata.totlayer; i++) { if (me->fdata.layers[i].type == CD_MTFACE) { tface = (MTFace *)me->fdata.layers[i].data; for (a = 0; a < me->totface; a++, tface++) if (tface->tpage) id_lib_extern((ID *)tface->tpage); } } for (i = 0; i < me->pdata.totlayer; i++) { if (me->pdata.layers[i].type == CD_MTEXPOLY) { txface = (MTexPoly *)me->pdata.layers[i].data; for (a = 0; a < me->totpoly; a++, txface++) if (txface->tpage) id_lib_extern((ID *)txface->tpage); } } men->edit_btmesh = NULL; men->mselect = MEM_dupallocN(men->mselect); men->bb = MEM_dupallocN(men->bb); men->key = BKE_key_copy(me->key); if (men->key) men->key->from = (ID *)men; return men; }
bActuator *copy_actuator(bActuator *act, const int flag) { bActuator *actn; act->mynew=actn= MEM_dupallocN(act); actn->flag |= ACT_NEW; if (act->data) { actn->data= MEM_dupallocN(act->data); } switch (act->type) { case ACT_ACTION: case ACT_SHAPEACTION: { bActionActuator *aa = (bActionActuator *)act->data; if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { id_us_plus((ID *)aa->act); } break; } case ACT_SOUND: { bSoundActuator *sa = (bSoundActuator *)act->data; if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { id_us_plus((ID *)sa->sound); } break; } } return actn; }
Brush *BKE_brush_copy(Brush *brush) { Brush *brushn; brushn = BKE_libblock_copy(&brush->id); if (brush->mtex.tex) id_us_plus((ID *)brush->mtex.tex); if (brush->mask_mtex.tex) id_us_plus((ID *)brush->mask_mtex.tex); if (brush->icon_imbuf) brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf); brushn->preview = NULL; brushn->curve = curvemapping_copy(brush->curve); /* enable fake user by default */ if (!(brushn->id.flag & LIB_FAKEUSER)) { brushn->id.flag |= LIB_FAKEUSER; brushn->id.us++; } return brushn; }
bActuator *copy_actuator(bActuator *act) { bActuator *actn; act->mynew=actn= MEM_dupallocN(act); actn->flag |= ACT_NEW; if (act->data) { actn->data= MEM_dupallocN(act->data); } switch (act->type) { case ACT_ACTION: case ACT_SHAPEACTION: { bActionActuator *aa = (bActionActuator *)act->data; if (aa->act) id_us_plus((ID *)aa->act); break; } case ACT_SOUND: { bSoundActuator *sa = (bSoundActuator *)act->data; if (sa->sound) id_us_plus((ID *)sa->sound); break; } } return actn; }
Brush *BKE_brush_copy(Main *bmain, Brush *brush) { Brush *brushn; brushn = BKE_libblock_copy(bmain, &brush->id); if (brush->mtex.tex) id_us_plus((ID *)brush->mtex.tex); if (brush->mask_mtex.tex) id_us_plus((ID *)brush->mask_mtex.tex); if (brush->paint_curve) id_us_plus((ID *)brush->paint_curve); if (brush->icon_imbuf) brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf); brushn->preview = NULL; brushn->curve = curvemapping_copy(brush->curve); /* enable fake user by default */ id_fake_user_set(&brush->id); BKE_id_copy_ensure_local(bmain, &brush->id, &brushn->id); return brushn; }
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; }
World *BKE_world_copy(World *wrld) { World *wrldn; int a; wrldn = BKE_libblock_copy(&wrld->id); for (a = 0; a < MAX_MTEX; a++) { if (wrld->mtex[a]) { wrldn->mtex[a] = MEM_mallocN(sizeof(MTex), "BKE_world_copy"); memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex)); id_us_plus((ID *)wrldn->mtex[a]->tex); } } if (wrld->nodetree) { wrldn->nodetree = ntreeCopyTree(wrld->nodetree); } if (wrld->preview) wrldn->preview = BKE_previewimg_copy(wrld->preview); BLI_listbase_clear(&wrldn->gpumaterial); if (wrld->id.lib) { BKE_id_lib_local_paths(G.main, wrld->id.lib, &wrldn->id); } return wrldn; }
bSound *BKE_sound_new_file_exists_ex(struct Main *bmain, const char *filepath, bool *r_exists) { bSound *sound; char str[FILE_MAX], strtest[FILE_MAX]; BLI_strncpy(str, filepath, sizeof(str)); BLI_path_abs(str, bmain->name); /* first search an identical filepath */ for (sound = bmain->sound.first; sound; sound = sound->id.next) { BLI_strncpy(strtest, sound->name, sizeof(sound->name)); BLI_path_abs(strtest, ID_BLEND_PATH(bmain, &sound->id)); if (BLI_path_cmp(strtest, str) == 0) { id_us_plus(&sound->id); /* officially should not, it doesn't link here! */ if (r_exists) *r_exists = true; return sound; } } if (r_exists) *r_exists = false; return BKE_sound_new_file(bmain, filepath); }
/* XXX keep synced with next function */ Material *copy_material(Material *ma) { Material *man; int a; man= copy_libblock(ma); id_lib_extern((ID *)man->group); 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)); id_us_plus((ID *)man->mtex[a]->tex); } } if(ma->ramp_col) man->ramp_col= MEM_dupallocN(ma->ramp_col); if(ma->ramp_spec) man->ramp_spec= MEM_dupallocN(ma->ramp_spec); if (ma->preview) man->preview = BKE_previewimg_copy(ma->preview); if(ma->nodetree) { man->nodetree= ntreeCopyTree(ma->nodetree); /* 0 == full new tree */ } man->gpumaterial.first= man->gpumaterial.last= NULL; return man; }
Lamp *BKE_lamp_copy(Lamp *la) { Lamp *lan; int a; lan = BKE_libblock_copy(&la->id); for (a = 0; a < MAX_MTEX; a++) { if (lan->mtex[a]) { lan->mtex[a] = MEM_mallocN(sizeof(MTex), "copylamptex"); memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex)); id_us_plus((ID *)lan->mtex[a]->tex); } } lan->curfalloff = curvemapping_copy(la->curfalloff); if (la->nodetree) lan->nodetree = ntreeCopyTree(la->nodetree); if (la->preview) lan->preview = BKE_previewimg_copy(la->preview); return lan; }
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; }
Tex *copy_texture(Tex *tex) { Tex *texn; texn= copy_libblock(tex); if(texn->type==TEX_IMAGE) id_us_plus((ID *)texn->ima); else texn->ima= NULL; if(texn->plugin) { texn->plugin= MEM_dupallocN(texn->plugin); open_plugin_tex(texn->plugin); } if(texn->coba) texn->coba= MEM_dupallocN(texn->coba); if(texn->env) texn->env= BKE_copy_envmap(texn->env); if(texn->pd) texn->pd= BKE_copy_pointdensity(texn->pd); if(texn->vd) texn->vd= MEM_dupallocN(texn->vd); if(tex->preview) texn->preview = BKE_previewimg_copy(tex->preview); if(tex->nodetree) { if (tex->nodetree->execdata) { ntreeTexEndExecTree(tex->nodetree->execdata); } texn->nodetree= ntreeCopyTree(tex->nodetree); } return texn; }
static void copyData(ModifierData *md, ModifierData *target) { WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md; WeightVGEditModifierData *twmd = (WeightVGEditModifierData *) target; BLI_strncpy(twmd->defgrp_name, wmd->defgrp_name, sizeof(twmd->defgrp_name)); twmd->edit_flags = wmd->edit_flags; twmd->falloff_type = wmd->falloff_type; twmd->default_weight = wmd->default_weight; twmd->cmap_curve = curvemapping_copy(wmd->cmap_curve); twmd->add_threshold = wmd->add_threshold; twmd->rem_threshold = wmd->rem_threshold; twmd->mask_constant = wmd->mask_constant; BLI_strncpy(twmd->mask_defgrp_name, wmd->mask_defgrp_name, sizeof(twmd->mask_defgrp_name)); twmd->mask_texture = wmd->mask_texture; twmd->mask_tex_use_channel = wmd->mask_tex_use_channel; twmd->mask_tex_mapping = wmd->mask_tex_mapping; twmd->mask_tex_map_obj = wmd->mask_tex_map_obj; BLI_strncpy(twmd->mask_tex_uvlayer_name, wmd->mask_tex_uvlayer_name, sizeof(twmd->mask_tex_uvlayer_name)); if (twmd->mask_texture) { id_us_plus(&twmd->mask_texture->id); } }
void paint_brush_set(Paint *p, Brush *br) { if (p) { id_us_min((ID *)p->brush); id_us_plus((ID *)br); p->brush = br; } }
static void id_fake_user_set_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem) { ID *id = tselem->id; if ((id) && ((id->flag & LIB_FAKEUSER) == 0)) { id->flag |= LIB_FAKEUSER; id_us_plus(id); } }
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; } } }
RigidBodyWorld *BKE_rigidbody_world_copy(RigidBodyWorld *rbw) { RigidBodyWorld *rbwn = MEM_dupallocN(rbw); if (rbw->effector_weights) rbwn->effector_weights = MEM_dupallocN(rbw->effector_weights); if (rbwn->group) id_us_plus(&rbwn->group->id); if (rbwn->constraints) id_us_plus(&rbwn->constraints->id); rbwn->pointcache = BKE_ptcache_copy_list(&rbwn->ptcaches, &rbw->ptcaches, FALSE); rbwn->objects = NULL; rbwn->physics_world = NULL; rbwn->numbodies = 0; return rbwn; }
void set_current_brush_texture(Brush *br, Tex *newtex) { if (br->mtex.tex) id_us_min(&br->mtex.tex->id); if (newtex) { br->mtex.tex = newtex; id_us_plus(&newtex->id); } }
static void copyData(ModifierData *md, ModifierData *target) { #if 0 UVProjectModifierData *umd = (UVProjectModifierData *) md; #endif UVProjectModifierData *tumd = (UVProjectModifierData *) target; modifier_copyData_generic(md, target); id_us_plus((ID *)tumd->image); }
void MovieClip_grease_pencil_set(PointerRNA *ptr, PointerRNA value) { MovieClip *data = (MovieClip *)(ptr->data); if (data->gpd) id_us_min((ID *)data->gpd); if (value.data) id_us_plus((ID *)value.data); data->gpd = value.data; }
Mesh *copy_mesh(Mesh *me) { Mesh *men; MTFace *tface; int a, i; men= copy_libblock(me); men->mat= MEM_dupallocN(me->mat); for(a=0; a<men->totcol; a++) { id_us_plus((ID *)men->mat[a]); } id_us_plus((ID *)men->texcomesh); CustomData_copy(&me->vdata, &men->vdata, CD_MASK_MESH, CD_DUPLICATE, men->totvert); CustomData_copy(&me->edata, &men->edata, CD_MASK_MESH, CD_DUPLICATE, men->totedge); CustomData_copy(&me->fdata, &men->fdata, CD_MASK_MESH, CD_DUPLICATE, men->totface); mesh_update_customdata_pointers(men); /* ensure indirect linked data becomes lib-extern */ for(i=0; i<me->fdata.totlayer; i++) { if(me->fdata.layers[i].type == CD_MTFACE) { tface= (MTFace*)me->fdata.layers[i].data; for(a=0; a<me->totface; a++, tface++) if(tface->tpage) id_lib_extern((ID*)tface->tpage); } } men->mselect= NULL; men->edit_mesh= NULL; men->pv= NULL; /* looks like this is no-longer supported but NULL just incase */ men->bb= MEM_dupallocN(men->bb); men->key= copy_key(me->key); if(men->key) men->key->from= (ID *)men; return men; }
void BKE_paint_toolslots_brush_update_ex(Paint *paint, Brush *brush) { const uint tool_offset = paint->runtime.tool_offset; UNUSED_VARS_NDEBUG(tool_offset); BLI_assert(tool_offset != 0); const int slot_index = BKE_brush_tool_get(brush, paint); BKE_paint_toolslots_len_ensure(paint, slot_index + 1); PaintToolSlot *tslot = &paint->tool_slots[slot_index]; id_us_plus(&brush->id); id_us_min(&tslot->brush->id); tslot->brush = brush; }
EnvMap *BKE_copy_envmap(EnvMap *env) { EnvMap *envn; int a; envn = MEM_dupallocN(env); envn->ok = 0; for (a = 0; a < 6; a++) envn->cube[a] = NULL; if (envn->ima) id_us_plus((ID *)envn->ima); return envn; }
Object *rna_Main_objects_new(Main *UNUSED(bmain), ReportList *reports, const char *name, ID *data) { Object *ob; int type= OB_EMPTY; if(data) { switch(GS(data->name)) { case ID_ME: type= OB_MESH; break; case ID_CU: type= curve_type((struct Curve *)data); break; case ID_MB: type= OB_MBALL; break; case ID_LA: type= OB_LAMP; break; case ID_SPK: type= OB_SPEAKER; break; case ID_CA: type= OB_CAMERA; break; case ID_LT: type= OB_LATTICE; break; case ID_AR: type= OB_ARMATURE; break; default: { const char *idname; if(RNA_enum_id_from_value(id_type_items, GS(data->name), &idname) == 0) idname= "UNKNOWN"; BKE_reportf(reports, RPT_ERROR, "ID type '%s' is not valid for a object.", idname); return NULL; } } id_us_plus(data); } ob= add_only_object(type, name); id_us_min(&ob->id); ob->data= data; test_object_materials(ob->data); return ob; }
static void copyData(ModifierData *md, ModifierData *target) { #if 0 WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md; #endif WeightVGProximityModifierData *twmd = (WeightVGProximityModifierData *) target; modifier_copyData_generic(md, target); if (twmd->mask_texture) { id_us_plus(&twmd->mask_texture->id); } }
static void copyData(ModifierData *md, ModifierData *target) { WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md; WeightVGEditModifierData *twmd = (WeightVGEditModifierData *) target; modifier_copyData_generic(md, target); twmd->cmap_curve = curvemapping_copy(wmd->cmap_curve); if (twmd->mask_texture) { id_us_plus(&twmd->mask_texture->id); } }
/* helper function for make_local_action() - change references */ static void make_localact_apply_cb(ID *id, AnimData *adt, void *mlac_ptr) { tMakeLocalActionContext *mlac = (tMakeLocalActionContext *)mlac_ptr; if (adt->action == mlac->act) { if (id->lib==0) { adt->action = mlac->actn; id_us_plus(&mlac->actn->id); id_us_min(&mlac->act->id); } } }
static void copyData(ModifierData *md, ModifierData *target) { #if 0 MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md; #endif MeshSeqCacheModifierData *tmcmd = (MeshSeqCacheModifierData *)target; modifier_copyData_generic(md, target); if (tmcmd->cache_file) { id_us_plus(&tmcmd->cache_file->id); } }
static void copyData(ModifierData *md, ModifierData *target) { #if 0 DisplaceModifierData *dmd = (DisplaceModifierData *) md; #endif DisplaceModifierData *tdmd = (DisplaceModifierData *) target; modifier_copyData_generic(md, target); if (tdmd->texture) { id_us_plus(&tdmd->texture->id); } }