Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh.c
| Show First 20 Lines • Show All 653 Lines • ▼ Show 20 Lines | Mesh *BKE_mesh_new_nomain( | ||||
| mesh->totpoly = polys_len; | mesh->totpoly = polys_len; | ||||
| mesh_ensure_cdlayers_primary(mesh, true); | mesh_ensure_cdlayers_primary(mesh, true); | ||||
| BKE_mesh_update_customdata_pointers(mesh, false); | BKE_mesh_update_customdata_pointers(mesh, false); | ||||
| return mesh; | return mesh; | ||||
| } | } | ||||
| /* Copy user editable settings that we want to preserve through the modifier stack | |||||
| * or operations where a mesh with new topology is created based on another mesh. */ | |||||
| void BKE_mesh_copy_settings(Mesh *me_dst, const Mesh *me_src) | |||||
| { | |||||
| /* Copy general settings. */ | |||||
| me_dst->editflag = me_src->editflag; | |||||
| me_dst->flag = me_src->flag; | |||||
| me_dst->smoothresh = me_src->smoothresh; | |||||
| me_dst->remesh_voxel_size = me_src->remesh_voxel_size; | |||||
| me_dst->remesh_mode = me_src->remesh_mode; | |||||
| /* Copy texture space. */ | |||||
| me_dst->texflag = me_src->texflag; | |||||
| if (me_dst->bb) { | |||||
mont29: I’d also check that this is not same pointer as `me_src->bb` (and same below with `mat` one)… | |||||
| MEM_freeN(me_dst->bb); | |||||
| } | |||||
| me_dst->bb = MEM_dupallocN(me_src->bb); | |||||
| copy_v3_v3(me_dst->loc, me_src->loc); | |||||
| copy_v3_v3(me_dst->rot, me_src->rot); | |||||
| copy_v3_v3(me_dst->size, me_src->size); | |||||
| /* Copy materials. */ | |||||
| if (me_dst->mat != NULL) { | |||||
| MEM_freeN(me_dst->mat); | |||||
| } | |||||
| me_dst->mat = MEM_dupallocN(me_src->mat); | |||||
| me_dst->totcol = me_src->totcol; | |||||
| } | |||||
| Mesh *BKE_mesh_new_nomain_from_template_ex(const Mesh *me_src, | Mesh *BKE_mesh_new_nomain_from_template_ex(const Mesh *me_src, | ||||
| int verts_len, | int verts_len, | ||||
| int edges_len, | int edges_len, | ||||
| int tessface_len, | int tessface_len, | ||||
| int loops_len, | int loops_len, | ||||
| int polys_len, | int polys_len, | ||||
| CustomData_MeshMasks 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 || ((me_src->totface != 0) && (me_src->totpoly == 0))); | const bool do_tessface = (tessface_len || ((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->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; | ||||
| me_dst->editflag = me_src->editflag; | BKE_mesh_copy_settings(me_dst, me_src); | ||||
| me_dst->texflag = me_src->texflag; | |||||
| CustomData_copy(&me_src->vdata, &me_dst->vdata, mask.vmask, 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.emask, 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.lmask, 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.pmask, 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.fmask, CD_CALLOC, tessface_len); | CustomData_copy(&me_src->fdata, &me_dst->fdata, mask.fmask, CD_CALLOC, tessface_len); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | return BKE_mesh_to_bmesh_ex(me, | ||||
| &(struct BMeshFromMeshParams){ | &(struct BMeshFromMeshParams){ | ||||
| .calc_face_normal = false, | .calc_face_normal = false, | ||||
| .add_key_index = add_key_index, | .add_key_index = add_key_index, | ||||
| .use_shapekey = true, | .use_shapekey = true, | ||||
| .active_shapekey = ob->shapenr, | .active_shapekey = ob->shapenr, | ||||
| }); | }); | ||||
| } | } | ||||
| Mesh *BKE_mesh_from_bmesh_nomain(BMesh *bm, const struct BMeshToMeshParams *params) | Mesh *BKE_mesh_from_bmesh_nomain(BMesh *bm, | ||||
| const struct BMeshToMeshParams *params, | |||||
| const Mesh *me_settings) | |||||
| { | { | ||||
| 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); | ||||
| BKE_mesh_copy_settings(mesh, me_settings); | |||||
| return mesh; | return mesh; | ||||
| } | } | ||||
| Mesh *BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const CustomData_MeshMasks *cd_mask_extra) | Mesh *BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, | ||||
| const CustomData_MeshMasks *cd_mask_extra, | |||||
| const Mesh *me_settings) | |||||
| { | { | ||||
| 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); | ||||
| BKE_mesh_copy_settings(mesh, me_settings); | |||||
| 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(BMEditMesh *em, | Mesh *BKE_mesh_from_editmesh_with_coords_thin_wrap(BMEditMesh *em, | ||||
| const CustomData_MeshMasks *data_mask, | const CustomData_MeshMasks *data_mask, | ||||
| float (*vertexCos)[3]) | float (*vertexCos)[3], | ||||
| const Mesh *me_settings) | |||||
| { | { | ||||
| 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, me_settings); | ||||
| /* 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_vert_coords_apply(me, vertexCos); | BKE_mesh_vert_coords_apply(me, vertexCos); | ||||
| MEM_freeN(vertexCos); | MEM_freeN(vertexCos); | ||||
| me->runtime.is_original = false; | me->runtime.is_original = false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,138 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* **** Depsgraph evaluation **** */ | /* **** Depsgraph evaluation **** */ | ||||
| void BKE_mesh_eval_geometry(Depsgraph *depsgraph, Mesh *mesh) | void BKE_mesh_eval_geometry(Depsgraph *depsgraph, Mesh *mesh) | ||||
| { | { | ||||
| DEG_debug_print_eval(depsgraph, __func__, mesh->id.name, mesh); | DEG_debug_print_eval(depsgraph, __func__, mesh->id.name, mesh); | ||||
| BKE_mesh_texspace_calc(mesh); | BKE_mesh_texspace_calc(mesh); | ||||
| /* Clear autospace flag in evaluated mesh, so that texspace does not get recomputed when bbox is | |||||
| * (e.g. after modifiers, etc.) */ | |||||
| mesh->texflag &= ~ME_AUTOSPACE; | |||||
| /* We are here because something did change in the mesh. This means we can not trust the existing | /* We are here because something did change in the mesh. This means we can not trust the existing | ||||
| * evaluated mesh, and we don't know what parts of the mesh did change. So we simply delete the | * evaluated mesh, and we don't know what parts of the mesh did change. So we simply delete the | ||||
| * evaluated mesh and let objects to re-create it with updated settings. */ | * evaluated mesh and let objects to re-create it with updated settings. */ | ||||
| if (mesh->runtime.mesh_eval != NULL) { | if (mesh->runtime.mesh_eval != NULL) { | ||||
| mesh->runtime.mesh_eval->edit_mesh = NULL; | mesh->runtime.mesh_eval->edit_mesh = NULL; | ||||
| BKE_id_free(NULL, mesh->runtime.mesh_eval); | BKE_id_free(NULL, mesh->runtime.mesh_eval); | ||||
| mesh->runtime.mesh_eval = NULL; | mesh->runtime.mesh_eval = NULL; | ||||
| } | } | ||||
| Show All 14 Lines | |||||
I’d also check that this is not same pointer as me_src->bb (and same below with mat one), you never know… Or at least an assert.
Also consistency, thought we agreed on not doing implicit NULL pointer check (i.e. me_dst->bb != NULL, just like below with mat)?
[EDIT] Done as rB658d7eeed274…