Changeset View
Changeset View
Standalone View
Standalone View
source/blender/bmesh/intern/bmesh_mesh_conv.c
| Show First 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | void BM_mesh_bm_from_me( | ||||
| MLoop *mloop; | MLoop *mloop; | ||||
| MPoly *mp; | MPoly *mp; | ||||
| KeyBlock *actkey, *block; | KeyBlock *actkey, *block; | ||||
| BMVert *v, **vtable = NULL; | BMVert *v, **vtable = NULL; | ||||
| BMEdge *e, **etable = NULL; | BMEdge *e, **etable = NULL; | ||||
| BMFace *f, **ftable = NULL; | BMFace *f, **ftable = NULL; | ||||
| float (*keyco)[3] = NULL; | float (*keyco)[3] = NULL; | ||||
| int totloops, i; | int totloops, i; | ||||
| const int64_t mask = CD_MASK_BMESH | params->cd_mask_extra; | CustomData_MeshMasks mask = CD_MASK_BMESH; | ||||
| const int64_t mask_loop_only = mask & ~CD_MASK_ORIGINDEX; | CustomData_MeshMasks_update(&mask, ¶ms->cd_mask_extra); | ||||
| if (!me || !me->totvert) { | if (!me || !me->totvert) { | ||||
| if (me && is_new) { /*no verts? still copy customdata layout*/ | if (me && is_new) { /*no verts? still copy customdata layout*/ | ||||
| CustomData_copy(&me->vdata, &bm->vdata, mask, CD_ASSIGN, 0); | CustomData_copy(&me->vdata, &bm->vdata, mask.vmask, CD_ASSIGN, 0); | ||||
| CustomData_copy(&me->edata, &bm->edata, mask, CD_ASSIGN, 0); | CustomData_copy(&me->edata, &bm->edata, mask.emask, CD_ASSIGN, 0); | ||||
| CustomData_copy(&me->ldata, &bm->ldata, mask_loop_only, CD_ASSIGN, 0); | CustomData_copy(&me->ldata, &bm->ldata, mask.lmask, CD_ASSIGN, 0); | ||||
| CustomData_copy(&me->pdata, &bm->pdata, mask, CD_ASSIGN, 0); | CustomData_copy(&me->pdata, &bm->pdata, mask.pmask, CD_ASSIGN, 0); | ||||
| CustomData_bmesh_init_pool(&bm->vdata, me->totvert, BM_VERT); | CustomData_bmesh_init_pool(&bm->vdata, me->totvert, BM_VERT); | ||||
| CustomData_bmesh_init_pool(&bm->edata, me->totedge, BM_EDGE); | CustomData_bmesh_init_pool(&bm->edata, me->totedge, BM_EDGE); | ||||
| CustomData_bmesh_init_pool(&bm->ldata, me->totloop, BM_LOOP); | CustomData_bmesh_init_pool(&bm->ldata, me->totloop, BM_LOOP); | ||||
| CustomData_bmesh_init_pool(&bm->pdata, me->totpoly, BM_FACE); | CustomData_bmesh_init_pool(&bm->pdata, me->totpoly, BM_FACE); | ||||
| } | } | ||||
| return; /* sanity check */ | return; /* sanity check */ | ||||
| } | } | ||||
| if (is_new) { | if (is_new) { | ||||
| CustomData_copy(&me->vdata, &bm->vdata, mask, CD_CALLOC, 0); | CustomData_copy(&me->vdata, &bm->vdata, mask.vmask, CD_CALLOC, 0); | ||||
| CustomData_copy(&me->edata, &bm->edata, mask, CD_CALLOC, 0); | CustomData_copy(&me->edata, &bm->edata, mask.emask, CD_CALLOC, 0); | ||||
| CustomData_copy(&me->ldata, &bm->ldata, mask_loop_only, CD_CALLOC, 0); | CustomData_copy(&me->ldata, &bm->ldata, mask.lmask, CD_CALLOC, 0); | ||||
| CustomData_copy(&me->pdata, &bm->pdata, mask, CD_CALLOC, 0); | CustomData_copy(&me->pdata, &bm->pdata, mask.pmask, CD_CALLOC, 0); | ||||
| } | } | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /* Shape Key */ | /* Shape Key */ | ||||
| int tot_shape_keys = me->key ? BLI_listbase_count(&me->key->block) : 0; | int tot_shape_keys = me->key ? BLI_listbase_count(&me->key->block) : 0; | ||||
| if (is_new == false) { | if (is_new == false) { | ||||
| tot_shape_keys = min_ii(tot_shape_keys, CustomData_number_of_layers(&bm->vdata, CD_SHAPEKEY)); | tot_shape_keys = min_ii(tot_shape_keys, CustomData_number_of_layers(&bm->vdata, CD_SHAPEKEY)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 370 Lines • ▼ Show 20 Lines | void BM_mesh_bm_to_me( | ||||
| me->totpoly = bm->totface; | me->totpoly = bm->totface; | ||||
| /* will be overwritten with a valid value if 'dotess' is set, otherwise we | /* will be overwritten with a valid value if 'dotess' is set, otherwise we | ||||
| * end up with 'me->totface' and me->mface == NULL which can crash [#28625] | * end up with 'me->totface' and me->mface == NULL which can crash [#28625] | ||||
| */ | */ | ||||
| me->totface = 0; | me->totface = 0; | ||||
| me->act_face = -1; | me->act_face = -1; | ||||
| { | { | ||||
| const CustomDataMask mask = CD_MASK_MESH | params->cd_mask_extra; | CustomData_MeshMasks mask = CD_MASK_MESH; | ||||
| CustomData_copy(&bm->vdata, &me->vdata, mask, CD_CALLOC, me->totvert); | CustomData_MeshMasks_update(&mask, ¶ms->cd_mask_extra); | ||||
| CustomData_copy(&bm->edata, &me->edata, mask, CD_CALLOC, me->totedge); | CustomData_copy(&bm->vdata, &me->vdata, mask.vmask, CD_CALLOC, me->totvert); | ||||
| CustomData_copy(&bm->ldata, &me->ldata, mask, CD_CALLOC, me->totloop); | CustomData_copy(&bm->edata, &me->edata, mask.emask, CD_CALLOC, me->totedge); | ||||
| CustomData_copy(&bm->pdata, &me->pdata, mask, CD_CALLOC, me->totpoly); | CustomData_copy(&bm->ldata, &me->ldata, mask.lmask, CD_CALLOC, me->totloop); | ||||
| CustomData_copy(&bm->pdata, &me->pdata, mask.pmask, CD_CALLOC, me->totpoly); | |||||
| } | } | ||||
| CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, mvert, me->totvert); | CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, mvert, me->totvert); | ||||
| CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, me->totedge); | CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, me->totedge); | ||||
| CustomData_add_layer(&me->ldata, CD_MLOOP, CD_ASSIGN, mloop, me->totloop); | CustomData_add_layer(&me->ldata, CD_MLOOP, CD_ASSIGN, mloop, me->totloop); | ||||
| CustomData_add_layer(&me->pdata, CD_MPOLY, CD_ASSIGN, mpoly, me->totpoly); | CustomData_add_layer(&me->pdata, CD_MPOLY, CD_ASSIGN, mpoly, me->totpoly); | ||||
| me->cd_flag = BM_mesh_cd_flag_from_bmesh(bm); | me->cd_flag = BM_mesh_cd_flag_from_bmesh(bm); | ||||
| ▲ Show 20 Lines • Show All 325 Lines • ▼ Show 20 Lines | |||||
| * - Ignore shape-keys. | * - Ignore shape-keys. | ||||
| * - Ignore vertex-parents. | * - Ignore vertex-parents. | ||||
| * - Ignore selection history. | * - Ignore selection history. | ||||
| * - Uses simpler method to calculate #ME_EDGEDRAW | * - Uses simpler method to calculate #ME_EDGEDRAW | ||||
| * - Uses #CD_MASK_DERIVEDMESH instead of #CD_MASK_MESH. | * - Uses #CD_MASK_DERIVEDMESH instead of #CD_MASK_MESH. | ||||
| * | * | ||||
| * \note Was `cddm_from_bmesh_ex` in 2.7x, removed `MFace` support. | * \note Was `cddm_from_bmesh_ex` in 2.7x, removed `MFace` support. | ||||
| */ | */ | ||||
| void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const int64_t cd_mask_extra) | void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *cd_mask_extra) | ||||
| { | { | ||||
| /* must be an empty mesh. */ | /* must be an empty mesh. */ | ||||
| BLI_assert(me->totvert == 0); | BLI_assert(me->totvert == 0); | ||||
| BLI_assert((cd_mask_extra & CD_MASK_SHAPEKEY) == 0); | BLI_assert(cd_mask_extra == NULL || (cd_mask_extra->vmask & CD_MASK_SHAPEKEY) == 0); | ||||
| me->totvert = bm->totvert; | me->totvert = bm->totvert; | ||||
| me->totedge = bm->totedge; | me->totedge = bm->totedge; | ||||
| me->totface = 0; | me->totface = 0; | ||||
| me->totloop = bm->totloop; | me->totloop = bm->totloop; | ||||
| me->totpoly = bm->totface; | me->totpoly = bm->totface; | ||||
| CustomData_add_layer(&me->vdata, CD_ORIGINDEX, CD_CALLOC, NULL, bm->totvert); | CustomData_add_layer(&me->vdata, CD_ORIGINDEX, CD_CALLOC, NULL, bm->totvert); | ||||
| CustomData_add_layer(&me->edata, CD_ORIGINDEX, CD_CALLOC, NULL, bm->totedge); | CustomData_add_layer(&me->edata, CD_ORIGINDEX, CD_CALLOC, NULL, bm->totedge); | ||||
| CustomData_add_layer(&me->pdata, CD_ORIGINDEX, CD_CALLOC, NULL, bm->totface); | CustomData_add_layer(&me->pdata, CD_ORIGINDEX, CD_CALLOC, NULL, bm->totface); | ||||
| CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, bm->totvert); | CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, bm->totvert); | ||||
| CustomData_add_layer(&me->edata, CD_MEDGE, CD_CALLOC, NULL, bm->totedge); | CustomData_add_layer(&me->edata, CD_MEDGE, CD_CALLOC, NULL, bm->totedge); | ||||
| CustomData_add_layer(&me->ldata, CD_MLOOP, CD_CALLOC, NULL, bm->totloop); | CustomData_add_layer(&me->ldata, CD_MLOOP, CD_CALLOC, NULL, bm->totloop); | ||||
| CustomData_add_layer(&me->pdata, CD_MPOLY, CD_CALLOC, NULL, bm->totface); | CustomData_add_layer(&me->pdata, CD_MPOLY, CD_CALLOC, NULL, bm->totface); | ||||
| /* don't process shapekeys, we only feed them through the modifier stack as needed, | /* don't process shapekeys, we only feed them through the modifier stack as needed, | ||||
| * e.g. for applying modifiers or the like*/ | * e.g. for applying modifiers or the like*/ | ||||
| const CustomDataMask mask = (CD_MASK_DERIVEDMESH | cd_mask_extra) & ~CD_MASK_SHAPEKEY; | CustomData_MeshMasks mask = CD_MASK_DERIVEDMESH; | ||||
| CustomData_merge(&bm->vdata, &me->vdata, mask, CD_CALLOC, me->totvert); | if (cd_mask_extra != NULL) { | ||||
| CustomData_merge(&bm->edata, &me->edata, mask, CD_CALLOC, me->totedge); | CustomData_MeshMasks_update(&mask, cd_mask_extra); | ||||
| CustomData_merge(&bm->ldata, &me->ldata, mask, CD_CALLOC, me->totloop); | } | ||||
| CustomData_merge(&bm->pdata, &me->pdata, mask, CD_CALLOC, me->totpoly); | mask.vmask &= ~CD_MASK_SHAPEKEY; | ||||
| CustomData_merge(&bm->vdata, &me->vdata, mask.vmask, CD_CALLOC, me->totvert); | |||||
| CustomData_merge(&bm->edata, &me->edata, mask.emask, CD_CALLOC, me->totedge); | |||||
| CustomData_merge(&bm->ldata, &me->ldata, mask.lmask, CD_CALLOC, me->totloop); | |||||
| CustomData_merge(&bm->pdata, &me->pdata, mask.pmask, CD_CALLOC, me->totpoly); | |||||
| BKE_mesh_update_customdata_pointers(me, false); | BKE_mesh_update_customdata_pointers(me, false); | ||||
| BMIter iter; | BMIter iter; | ||||
| BMVert *eve; | BMVert *eve; | ||||
| BMEdge *eed; | BMEdge *eed; | ||||
| BMFace *efa; | BMFace *efa; | ||||
| MVert *mvert = me->mvert; | MVert *mvert = me->mvert; | ||||
| ▲ Show 20 Lines • Show All 97 Lines • Show Last 20 Lines | |||||