Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh.c
| Show First 20 Lines • Show All 495 Lines • ▼ Show 20 Lines | Mesh *BKE_mesh_add(Main *bmain, const char *name) | ||||
| me = BKE_libblock_alloc(bmain, ID_ME, name); | me = BKE_libblock_alloc(bmain, ID_ME, name); | ||||
| BKE_mesh_init(me); | BKE_mesh_init(me); | ||||
| return me; | return me; | ||||
| } | } | ||||
| Mesh *BKE_mesh_copy(Main *bmain, const Mesh *me) | /** | ||||
| * Only copy internal data of Mesh ID from source to already allocated/initialized destination. | |||||
| * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs. | |||||
| * | |||||
| * WARNING! This function will not handle ID user count! | |||||
| * | |||||
| * \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more). | |||||
| */ | |||||
| void BKE_mesh_copy_data(Main *bmain, Mesh *me_dst, const Mesh *me_src, const int flag) | |||||
| { | { | ||||
| Mesh *men; | const bool do_tessface = ((me_src->totface != 0) && (me_src->totpoly == 0)); /* only do tessface if we have no polys */ | ||||
| int a; | |||||
| const int do_tessface = ((me->totface != 0) && (me->totpoly == 0)); /* only do tessface if we have no polys */ | |||||
| men = BKE_libblock_copy(bmain, &me->id); | me_dst->mat = MEM_dupallocN(me_src->mat); | ||||
| men->mat = MEM_dupallocN(me->mat); | CustomData_copy(&me_src->vdata, &me_dst->vdata, CD_MASK_MESH, CD_DUPLICATE, me_dst->totvert); | ||||
| for (a = 0; a < men->totcol; a++) { | CustomData_copy(&me_src->edata, &me_dst->edata, CD_MASK_MESH, CD_DUPLICATE, me_dst->totedge); | ||||
| id_us_plus((ID *)men->mat[a]); | CustomData_copy(&me_src->ldata, &me_dst->ldata, CD_MASK_MESH, CD_DUPLICATE, me_dst->totloop); | ||||
| } | CustomData_copy(&me_src->pdata, &me_dst->pdata, CD_MASK_MESH, CD_DUPLICATE, me_dst->totpoly); | ||||
| 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) { | if (do_tessface) { | ||||
| CustomData_copy(&me->fdata, &men->fdata, CD_MASK_MESH, CD_DUPLICATE, men->totface); | CustomData_copy(&me_src->fdata, &me_dst->fdata, CD_MASK_MESH, CD_DUPLICATE, me_dst->totface); | ||||
| } | } | ||||
| else { | else { | ||||
| mesh_tessface_clear_intern(men, false); | mesh_tessface_clear_intern(me_dst, false); | ||||
| } | } | ||||
| BKE_mesh_update_customdata_pointers(men, do_tessface); | BKE_mesh_update_customdata_pointers(me_dst, do_tessface); | ||||
| men->edit_btmesh = NULL; | me_dst->edit_btmesh = NULL; | ||||
| men->mselect = MEM_dupallocN(men->mselect); | me_dst->mselect = MEM_dupallocN(me_dst->mselect); | ||||
| men->bb = MEM_dupallocN(men->bb); | me_dst->bb = MEM_dupallocN(me_dst->bb); | ||||
| if (me->key) { | /* TODO Do we want to add flag to prevent this? */ | ||||
| men->key = BKE_key_copy(bmain, me->key); | if (me_src->key) { | ||||
| men->key->from = (ID *)men; | BKE_id_copy_ex(bmain, &me_src->key->id, (ID **)&me_dst->key, flag, false); | ||||
| } | |||||
| } | } | ||||
| BKE_id_copy_ensure_local(bmain, &me->id, &men->id); | Mesh *BKE_mesh_copy(Main *bmain, const Mesh *me) | ||||
| { | |||||
| return men; | Mesh *me_copy; | ||||
| BKE_id_copy_ex(bmain, &me->id, (ID **)&me_copy, 0, false); | |||||
| return me_copy; | |||||
| } | } | ||||
| BMesh *BKE_mesh_to_bmesh( | BMesh *BKE_mesh_to_bmesh( | ||||
| Mesh *me, Object *ob, | Mesh *me, Object *ob, | ||||
| const bool add_key_index, const struct BMeshCreateParams *params) | const bool add_key_index, const struct BMeshCreateParams *params) | ||||
| { | { | ||||
| BMesh *bm; | BMesh *bm; | ||||
| const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(me); | const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(me); | ||||
| ▲ Show 20 Lines • Show All 1,890 Lines • ▼ Show 20 Lines | switch (ob->type) { | ||||
| case OB_CURVE: | case OB_CURVE: | ||||
| case OB_SURF: | case OB_SURF: | ||||
| { | { | ||||
| ListBase dispbase = {NULL, NULL}; | ListBase dispbase = {NULL, NULL}; | ||||
| DerivedMesh *derivedFinal = NULL; | DerivedMesh *derivedFinal = NULL; | ||||
| int uv_from_orco; | int uv_from_orco; | ||||
| /* copies object and modifiers (but not the data) */ | /* copies object and modifiers (but not the data) */ | ||||
| Object *tmpobj = BKE_object_copy_ex(bmain, ob, true); | Object *tmpobj; | ||||
| /* TODO: make it temp copy outside bmain! */ | |||||
| BKE_id_copy_ex(bmain, &ob->id, (ID **)&tmpobj, LIB_ID_COPY_CACHES, false); | |||||
| tmpcu = (Curve *)tmpobj->data; | tmpcu = (Curve *)tmpobj->data; | ||||
| id_us_min(&tmpcu->id); | id_us_min(&tmpcu->id); | ||||
| /* Copy cached display list, it might be needed by the stack evaluation. | /* Copy cached display list, it might be needed by the stack evaluation. | ||||
| * Ideally stack should be able to use render-time display list, but doing | * Ideally stack should be able to use render-time display list, but doing | ||||
| * so is quite tricky and not safe so close to the release. | * so is quite tricky and not safe so close to the release. | ||||
| * | * | ||||
| * TODO(sergey): Look into more proper solution. | * TODO(sergey): Look into more proper solution. | ||||
| ▲ Show 20 Lines • Show All 221 Lines • Show Last 20 Lines | |||||