Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh.c
| Show First 20 Lines • Show All 529 Lines • ▼ Show 20 Lines | void BKE_mesh_copy_data(Main *bmain, Mesh *me_dst, const Mesh *me_src, const int flag) | ||||
| if ((me_src->id.tag & LIB_TAG_NO_MAIN) == 0) { | if ((me_src->id.tag & LIB_TAG_NO_MAIN) == 0) { | ||||
| /* This is a direct copy of a main mesh, so for now it has the same topology. */ | /* This is a direct copy of a main mesh, so for now it has the same topology. */ | ||||
| me_dst->runtime.deformed_only = true; | me_dst->runtime.deformed_only = true; | ||||
| } | } | ||||
| /* XXX WHAT? Why? Comment, please! And pretty sure this is not valid for regular Mesh copying? */ | /* XXX WHAT? Why? Comment, please! And pretty sure this is not valid for regular Mesh copying? */ | ||||
| me_dst->runtime.is_original = false; | me_dst->runtime.is_original = false; | ||||
| const bool do_tessface = ((me_src->totface != 0) && (me_src->totpoly == 0)); /* only do tessface if we have no polys */ | const bool do_tessface = ((me_src->totface != 0) && (me_src->totpoly == 0)); /* only do tessface if we have no polys */ | ||||
| CustomDataMask mask = CD_MASK_MESH; | CustomData_MeshMasks mask = CD_MASK_MESH; | ||||
| if (me_src->id.tag & LIB_TAG_NO_MAIN) { | if (me_src->id.tag & LIB_TAG_NO_MAIN) { | ||||
| /* For copies in depsgraph, keep data like origindex and orco. */ | /* For copies in depsgraph, keep data like origindex and orco. */ | ||||
| mask |= CD_MASK_DERIVEDMESH; | CustomData_MeshMasks_update(&mask, &CD_MASK_DERIVEDMESH); | ||||
| } | } | ||||
| me_dst->mat = MEM_dupallocN(me_src->mat); | me_dst->mat = MEM_dupallocN(me_src->mat); | ||||
| const eCDAllocType alloc_type = (flag & LIB_ID_COPY_CD_REFERENCE) ? CD_REFERENCE : CD_DUPLICATE; | const eCDAllocType alloc_type = (flag & LIB_ID_COPY_CD_REFERENCE) ? CD_REFERENCE : CD_DUPLICATE; | ||||
| CustomData_copy(&me_src->vdata, &me_dst->vdata, mask, alloc_type, me_dst->totvert); | CustomData_copy(&me_src->vdata, &me_dst->vdata, mask.vmask, alloc_type, me_dst->totvert); | ||||
| CustomData_copy(&me_src->edata, &me_dst->edata, mask, alloc_type, me_dst->totedge); | CustomData_copy(&me_src->edata, &me_dst->edata, mask.emask, alloc_type, me_dst->totedge); | ||||
| CustomData_copy(&me_src->ldata, &me_dst->ldata, mask, alloc_type, me_dst->totloop); | CustomData_copy(&me_src->ldata, &me_dst->ldata, mask.lmask, alloc_type, me_dst->totloop); | ||||
| CustomData_copy(&me_src->pdata, &me_dst->pdata, mask, alloc_type, me_dst->totpoly); | CustomData_copy(&me_src->pdata, &me_dst->pdata, mask.pmask, alloc_type, me_dst->totpoly); | ||||
| if (do_tessface) { | if (do_tessface) { | ||||
| CustomData_copy(&me_src->fdata, &me_dst->fdata, mask, alloc_type, me_dst->totface); | CustomData_copy(&me_src->fdata, &me_dst->fdata, mask.fmask, alloc_type, me_dst->totface); | ||||
| } | } | ||||
| else { | else { | ||||
| mesh_tessface_clear_intern(me_dst, false); | mesh_tessface_clear_intern(me_dst, false); | ||||
| } | } | ||||
| BKE_mesh_update_customdata_pointers(me_dst, do_tessface); | BKE_mesh_update_customdata_pointers(me_dst, do_tessface); | ||||
| me_dst->edit_mesh = NULL; | me_dst->edit_mesh = NULL; | ||||
| ▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | Mesh *BKE_mesh_new_nomain(int verts_len, int edges_len, int tessface_len, int loops_len, int polys_len) | ||||
| return mesh; | return mesh; | ||||
| } | } | ||||
| static Mesh *mesh_new_nomain_from_template_ex( | static Mesh *mesh_new_nomain_from_template_ex( | ||||
| const Mesh *me_src, | const Mesh *me_src, | ||||
| int verts_len, int edges_len, int tessface_len, | int verts_len, int edges_len, int tessface_len, | ||||
| int loops_len, int polys_len, | int loops_len, int polys_len, | ||||
| CustomDataMask mask) | CustomData_MeshMasks mask) | ||||
| { | { | ||||
| /* Only do tessface if we are creating tessfaces or copying from mesh with only tessfaces. */ | /* Only do tessface if we are creating tessfaces or copying from mesh with only tessfaces. */ | ||||
| const bool do_tessface = (tessface_len || | const bool do_tessface = (tessface_len || | ||||
| ((me_src->totface != 0) && (me_src->totpoly == 0))); | ((me_src->totface != 0) && (me_src->totpoly == 0))); | ||||
| Mesh *me_dst = BKE_id_new_nomain(ID_ME, NULL); | Mesh *me_dst = BKE_id_new_nomain(ID_ME, NULL); | ||||
| me_dst->mat = MEM_dupallocN(me_src->mat); | me_dst->mat = MEM_dupallocN(me_src->mat); | ||||
| me_dst->mselect = MEM_dupallocN(me_dst->mselect); | me_dst->mselect = MEM_dupallocN(me_dst->mselect); | ||||
| me_dst->totvert = verts_len; | me_dst->totvert = verts_len; | ||||
| me_dst->totedge = edges_len; | me_dst->totedge = edges_len; | ||||
| me_dst->totface = tessface_len; | me_dst->totface = tessface_len; | ||||
| me_dst->totloop = loops_len; | me_dst->totloop = loops_len; | ||||
| me_dst->totpoly = polys_len; | me_dst->totpoly = polys_len; | ||||
| me_dst->cd_flag = me_src->cd_flag; | me_dst->cd_flag = me_src->cd_flag; | ||||
| CustomData_copy(&me_src->vdata, &me_dst->vdata, mask, CD_CALLOC, verts_len); | CustomData_copy(&me_src->vdata, &me_dst->vdata, mask.vmask, CD_CALLOC, verts_len); | ||||
| CustomData_copy(&me_src->edata, &me_dst->edata, mask, CD_CALLOC, edges_len); | CustomData_copy(&me_src->edata, &me_dst->edata, mask.emask, CD_CALLOC, edges_len); | ||||
| CustomData_copy(&me_src->ldata, &me_dst->ldata, mask, CD_CALLOC, loops_len); | CustomData_copy(&me_src->ldata, &me_dst->ldata, mask.lmask, CD_CALLOC, loops_len); | ||||
| CustomData_copy(&me_src->pdata, &me_dst->pdata, mask, CD_CALLOC, polys_len); | CustomData_copy(&me_src->pdata, &me_dst->pdata, mask.pmask, CD_CALLOC, polys_len); | ||||
| if (do_tessface) { | if (do_tessface) { | ||||
| CustomData_copy(&me_src->fdata, &me_dst->fdata, mask, CD_CALLOC, tessface_len); | CustomData_copy(&me_src->fdata, &me_dst->fdata, mask.fmask, CD_CALLOC, tessface_len); | ||||
| } | } | ||||
| else { | else { | ||||
| mesh_tessface_clear_intern(me_dst, false); | mesh_tessface_clear_intern(me_dst, false); | ||||
| } | } | ||||
| /* The destination mesh should at least have valid primary CD layers, | /* The destination mesh should at least have valid primary CD layers, | ||||
| * even in cases where the source mesh does not. */ | * even in cases where the source mesh does not. */ | ||||
| mesh_ensure_cdlayers_primary(me_dst, do_tessface); | mesh_ensure_cdlayers_primary(me_dst, do_tessface); | ||||
| ▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | |||||
| Mesh *BKE_mesh_from_bmesh_nomain(BMesh *bm, const struct BMeshToMeshParams *params) | Mesh *BKE_mesh_from_bmesh_nomain(BMesh *bm, const struct BMeshToMeshParams *params) | ||||
| { | { | ||||
| BLI_assert(params->calc_object_remap == false); | BLI_assert(params->calc_object_remap == false); | ||||
| Mesh *mesh = BKE_id_new_nomain(ID_ME, NULL); | Mesh *mesh = BKE_id_new_nomain(ID_ME, NULL); | ||||
| BM_mesh_bm_to_me(NULL, bm, mesh, params); | BM_mesh_bm_to_me(NULL, bm, mesh, params); | ||||
| return mesh; | return mesh; | ||||
| } | } | ||||
| Mesh *BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const int64_t cd_mask_extra) | Mesh *BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const CustomData_MeshMasks *cd_mask_extra) | ||||
| { | { | ||||
| Mesh *mesh = BKE_id_new_nomain(ID_ME, NULL); | Mesh *mesh = BKE_id_new_nomain(ID_ME, NULL); | ||||
| BM_mesh_bm_to_me_for_eval(bm, mesh, cd_mask_extra); | BM_mesh_bm_to_me_for_eval(bm, mesh, cd_mask_extra); | ||||
| return mesh; | return mesh; | ||||
| } | } | ||||
| /** | /** | ||||
| * TODO(campbell): support mesh with only an edit-mesh which is lazy initialized. | * TODO(campbell): support mesh with only an edit-mesh which is lazy initialized. | ||||
| */ | */ | ||||
| Mesh *BKE_mesh_from_editmesh_with_coords_thin_wrap( | Mesh *BKE_mesh_from_editmesh_with_coords_thin_wrap( | ||||
| BMEditMesh *em, CustomDataMask data_mask, float (*vertexCos)[3]) | BMEditMesh *em, const CustomData_MeshMasks *data_mask, float (*vertexCos)[3]) | ||||
| { | { | ||||
| Mesh *me = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, data_mask); | Mesh *me = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, data_mask); | ||||
| /* Use editmesh directly where possible. */ | /* Use editmesh directly where possible. */ | ||||
| me->runtime.is_original = true; | me->runtime.is_original = true; | ||||
| if (vertexCos) { | if (vertexCos) { | ||||
| /* We will own this array in the future. */ | /* We will own this array in the future. */ | ||||
| BKE_mesh_apply_vert_coords(me, vertexCos); | BKE_mesh_apply_vert_coords(me, vertexCos); | ||||
| MEM_freeN(vertexCos); | MEM_freeN(vertexCos); | ||||
| ▲ Show 20 Lines • Show All 1,163 Lines • Show Last 20 Lines | |||||