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; }
void *BKE_libblock_copy(ID *id) { return BKE_libblock_copy_ex(G.main, id); }