From e64b3c821252fc8707b4dcd9f8d1a0dee45c7d3f Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 30 May 2023 22:25:06 +0200 Subject: [PATCH] Refactor: Remove pre-2.8 function to reevaluate a single object This function replaced the evaluated mesh with a new one with the given custom data type mask. That doesn't work in general anymore for a few reasons: the increased dependence on named attributes (a opposed to custom data types), and the "all or nothing" approach to reevaluating the depsgraph. Other objects might depend on the object's evaluated geometry, so it shouldn't just be replaced. Pushed a bit further, this could give nice simplifications to mesh modifier evaluation. There are two breaking changes, `bmesh_from_object` and BVH tree `FromObject` require the source object to have a proper evaluated mesh now. If this causes a regression, it's likely that the object is missing an update tag when a mode is entered that requires extra evaluated data. Pull Request: https://projects.blender.org/blender/blender/pulls/106186 --- source/blender/blenkernel/BKE_data_transfer.h | 3 -- .../blender/blenkernel/BKE_mesh_iterators.h | 4 +- source/blender/blenkernel/BKE_mesh_runtime.h | 5 --- .../blender/blenkernel/intern/DerivedMesh.cc | 34 -------------- .../blenkernel/intern/data_transfer.cc | 32 +++----------- .../blender/blenkernel/intern/mesh_convert.cc | 25 +++++++---- .../blenkernel/intern/mesh_iterators.cc | 4 +- .../blenkernel/intern/multires_reshape.cc | 12 +++-- .../editors/armature/armature_skinning.c | 13 +++--- .../editors/mesh/editmesh_knife_project.cc | 15 ++----- source/blender/editors/mesh/meshtools.cc | 18 +++----- source/blender/editors/object/object_add.cc | 19 ++++---- .../editors/object/object_data_transfer.c | 35 +++++++-------- .../blender/editors/physics/particle_edit.c | 6 +-- .../editors/sculpt_paint/paint_image_proj.cc | 22 ++-------- .../editors/sculpt_paint/paint_utils.cc | 11 +++-- .../editors/sculpt_paint/paint_vertex_proj.cc | 14 +++--- .../sculpt_paint/paint_vertex_weight_ops.cc | 11 ++--- .../editors/space_view3d/view3d_iterators.cc | 8 ++-- .../io/alembic/exporter/abc_writer_hair.cc | 15 ++++--- source/blender/io/collada/collada_utils.cpp | 16 +++---- source/blender/makesrna/intern/rna_modifier.c | 44 ++++++++++++------- .../modifiers/intern/MOD_datatransfer.cc | 2 - source/blender/python/bmesh/bmesh_py_types.c | 7 +-- .../python/mathutils/mathutils_bvhtree.cc | 21 ++++----- 25 files changed, 166 insertions(+), 230 deletions(-) diff --git a/source/blender/blenkernel/BKE_data_transfer.h b/source/blender/blenkernel/BKE_data_transfer.h index 84281bc5736..4fbb041f537 100644 --- a/source/blender/blenkernel/BKE_data_transfer.h +++ b/source/blender/blenkernel/BKE_data_transfer.h @@ -140,7 +140,6 @@ enum { * from \a ob_src, to get (as much as possible) exact copy of source data layout. */ void BKE_object_data_transfer_layout(struct Depsgraph *depsgraph, - struct Scene *scene, struct Object *ob_src, struct Object *ob_dst, int data_types, @@ -149,7 +148,6 @@ void BKE_object_data_transfer_layout(struct Depsgraph *depsgraph, const int tolayers_select[DT_MULTILAYER_INDEX_MAX]); bool BKE_object_data_transfer_mesh(struct Depsgraph *depsgraph, - struct Scene *scene, struct Object *ob_src, struct Object *ob_dst, int data_types, @@ -171,7 +169,6 @@ bool BKE_object_data_transfer_mesh(struct Depsgraph *depsgraph, bool invert_vgroup, struct ReportList *reports); bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, - struct Scene *scene, struct Object *ob_src, struct Object *ob_dst, struct Mesh *me_dst, diff --git a/source/blender/blenkernel/BKE_mesh_iterators.h b/source/blender/blenkernel/BKE_mesh_iterators.h index e3d1f944bd6..c5bbbd82cc0 100644 --- a/source/blender/blenkernel/BKE_mesh_iterators.h +++ b/source/blender/blenkernel/BKE_mesh_iterators.h @@ -51,7 +51,9 @@ void BKE_mesh_foreach_mapped_subdiv_face_center( void *userData, MeshForeachFlag flag); -void BKE_mesh_foreach_mapped_vert_coords_get(struct Mesh *me_eval, float (*r_cos)[3], int totcos); +void BKE_mesh_foreach_mapped_vert_coords_get(const struct Mesh *me_eval, + float (*r_cos)[3], + int totcos); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_mesh_runtime.h b/source/blender/blenkernel/BKE_mesh_runtime.h index aed7b883197..86a36bf4d92 100644 --- a/source/blender/blenkernel/BKE_mesh_runtime.h +++ b/source/blender/blenkernel/BKE_mesh_runtime.h @@ -77,11 +77,6 @@ eMeshWrapperType BKE_mesh_wrapper_type(const struct Mesh *mesh); * They should also be renamed to use conventions from BKE, not old DerivedMesh.cc. * For now keep the names similar to avoid confusion. */ -struct Mesh *mesh_get_eval_final(struct Depsgraph *depsgraph, - const struct Scene *scene, - struct Object *ob, - const struct CustomData_MeshMasks *dataMask); - struct Mesh *mesh_get_eval_deform(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc index 83874191f84..bd7f30c1e79 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.cc +++ b/source/blender/blenkernel/intern/DerivedMesh.cc @@ -1645,40 +1645,6 @@ void makeDerivedMesh(struct Depsgraph *depsgraph, /***/ -Mesh *mesh_get_eval_final(struct Depsgraph *depsgraph, - const Scene *scene, - Object *ob, - const CustomData_MeshMasks *dataMask) -{ - /* This function isn't thread-safe and can't be used during evaluation. */ - BLI_assert(DEG_is_evaluating(depsgraph) == false); - - /* Evaluated meshes aren't supposed to be created on original instances. If you do, - * they aren't cleaned up properly on mode switch, causing crashes, e.g #58150. */ - BLI_assert(ob->id.tag & LIB_TAG_COPIED_ON_WRITE); - - /* if there's no evaluated mesh or the last data mask used doesn't include - * the data we need, rebuild the derived mesh - */ - bool need_mapping; - CustomData_MeshMasks cddata_masks = *dataMask; - object_get_datamask(depsgraph, ob, &cddata_masks, &need_mapping); - - Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob); - if ((mesh_eval == nullptr) || - !CustomData_MeshMasks_are_matching(&(ob->runtime.last_data_mask), &cddata_masks) || - (need_mapping && !ob->runtime.last_need_mapping)) - { - CustomData_MeshMasks_update(&cddata_masks, &ob->runtime.last_data_mask); - - makeDerivedMesh(depsgraph, scene, ob, dataMask); - - mesh_eval = BKE_object_get_evaluated_mesh(ob); - } - - return mesh_eval; -} - Mesh *mesh_get_eval_deform(struct Depsgraph *depsgraph, const Scene *scene, Object *ob, diff --git a/source/blender/blenkernel/intern/data_transfer.cc b/source/blender/blenkernel/intern/data_transfer.cc index e99a8f1d7ae..8cdaedf32a1 100644 --- a/source/blender/blenkernel/intern/data_transfer.cc +++ b/source/blender/blenkernel/intern/data_transfer.cc @@ -5,8 +5,6 @@ * \ingroup bke */ -#include "CLG_log.h" - #include "MEM_guardedalloc.h" #include "DNA_customdata_types.h" @@ -34,9 +32,9 @@ #include "BKE_object_deform.h" #include "BKE_report.h" -#include "data_transfer_intern.h" +#include "DEG_depsgraph_query.h" -static CLG_LogRef LOG = {"bke.data_transfer"}; +#include "data_transfer_intern.h" void BKE_object_data_transfer_dttypes_to_cdmask(const int dtdata_types, CustomData_MeshMasks *r_data_masks) @@ -1172,7 +1170,6 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map, } void BKE_object_data_transfer_layout(struct Depsgraph *depsgraph, - Scene *scene, Object *ob_src, Object *ob_dst, const int data_types, @@ -1180,20 +1177,17 @@ void BKE_object_data_transfer_layout(struct Depsgraph *depsgraph, const int fromlayers_select[DT_MULTILAYER_INDEX_MAX], const int tolayers_select[DT_MULTILAYER_INDEX_MAX]) { - Mesh *me_src; Mesh *me_dst; const bool use_create = true; /* We always create needed layers here. */ - CustomData_MeshMasks me_src_mask = CD_MASK_BAREMESH; - BLI_assert((ob_src != ob_dst) && (ob_src->type == OB_MESH) && (ob_dst->type == OB_MESH)); me_dst = static_cast(ob_dst->data); /* Get source evaluated mesh. */ - BKE_object_data_transfer_dttypes_to_cdmask(data_types, &me_src_mask); - me_src = mesh_get_eval_final(depsgraph, scene, ob_src, &me_src_mask); + const Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); + const Mesh *me_src = BKE_object_get_evaluated_mesh(ob_src_eval); if (!me_src) { return; } @@ -1320,7 +1314,6 @@ void BKE_object_data_transfer_layout(struct Depsgraph *depsgraph, } bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, - Scene *scene, Object *ob_src, Object *ob_dst, Mesh *me_dst, @@ -1367,8 +1360,6 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, const bool use_delete = false; /* We never delete data layers from destination here. */ - CustomData_MeshMasks me_src_mask = CD_MASK_BAREMESH; - BLI_assert((ob_src != ob_dst) && (ob_src->type == OB_MESH) && (ob_dst->type == OB_MESH)); if (me_dst) { @@ -1390,21 +1381,12 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, } /* Get source evaluated mesh. */ - BKE_object_data_transfer_dttypes_to_cdmask(data_types, &me_src_mask); - BKE_mesh_remap_calc_source_cddata_masks_from_map_modes( - map_vert_mode, map_edge_mode, map_loop_mode, map_poly_mode, &me_src_mask); if (is_modifier) { me_src = BKE_modifier_get_evaluated_mesh_from_evaluated_object(ob_src); - - if (me_src == nullptr || - !CustomData_MeshMasks_are_matching(&ob_src->runtime.last_data_mask, &me_src_mask)) - { - CLOG_WARN(&LOG, "Data Transfer: source mesh data is not ready - dependency cycle?"); - return changed; - } } else { - me_src = mesh_get_eval_final(depsgraph, scene, ob_src, &me_src_mask); + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob_src); + me_src = BKE_object_get_evaluated_mesh(ob_eval); } if (!me_src) { return changed; @@ -1827,7 +1809,6 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, } bool BKE_object_data_transfer_mesh(struct Depsgraph *depsgraph, - Scene *scene, Object *ob_src, Object *ob_dst, const int data_types, @@ -1850,7 +1831,6 @@ bool BKE_object_data_transfer_mesh(struct Depsgraph *depsgraph, ReportList *reports) { return BKE_object_data_transfer_ex(depsgraph, - scene, ob_src, ob_dst, nullptr, diff --git a/source/blender/blenkernel/intern/mesh_convert.cc b/source/blender/blenkernel/intern/mesh_convert.cc index 7197db8585b..9a3fd4a5e1b 100644 --- a/source/blender/blenkernel/intern/mesh_convert.cc +++ b/source/blender/blenkernel/intern/mesh_convert.cc @@ -509,10 +509,15 @@ void BKE_mesh_to_curve_nurblist(const Mesh *me, ListBase *nurblist, const int ed void BKE_mesh_to_curve(Main *bmain, Depsgraph *depsgraph, Scene * /*scene*/, Object *ob) { - /* make new mesh data from the original copy */ - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); - Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); - Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_MESH); + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + if (!ob_eval) { + return; + } + const Mesh *me_eval = BKE_object_get_evaluated_mesh_no_subsurf(ob_eval); + if (!me_eval) { + return; + } + ListBase nurblist = {nullptr, nullptr}; BKE_mesh_to_curve_nurblist(me_eval, &nurblist, 0); @@ -535,10 +540,14 @@ void BKE_mesh_to_curve(Main *bmain, Depsgraph *depsgraph, Scene * /*scene*/, Obj void BKE_mesh_to_pointcloud(Main *bmain, Depsgraph *depsgraph, Scene * /*scene*/, Object *ob) { BLI_assert(ob->type == OB_MESH); - - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); - Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); - const Mesh *mesh_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_MESH); + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + if (!ob_eval) { + return; + } + const Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob_eval); + if (!mesh_eval) { + return; + } PointCloud *pointcloud = (PointCloud *)BKE_pointcloud_add(bmain, ob->id.name + 2); diff --git a/source/blender/blenkernel/intern/mesh_iterators.cc b/source/blender/blenkernel/intern/mesh_iterators.cc index 22fd056e0a3..681f59d6a01 100644 --- a/source/blender/blenkernel/intern/mesh_iterators.cc +++ b/source/blender/blenkernel/intern/mesh_iterators.cc @@ -379,7 +379,9 @@ static void get_vertexcos__mapFunc(void *user_data, } } -void BKE_mesh_foreach_mapped_vert_coords_get(Mesh *me_eval, float (*r_cos)[3], const int totcos) +void BKE_mesh_foreach_mapped_vert_coords_get(const Mesh *me_eval, + float (*r_cos)[3], + const int totcos) { MappedVCosData user_data; memset(r_cos, 0, sizeof(*r_cos) * totcos); diff --git a/source/blender/blenkernel/intern/multires_reshape.cc b/source/blender/blenkernel/intern/multires_reshape.cc index 75f28972727..d55989fb827 100644 --- a/source/blender/blenkernel/intern/multires_reshape.cc +++ b/source/blender/blenkernel/intern/multires_reshape.cc @@ -18,6 +18,7 @@ #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" #include "BKE_multires.h" +#include "BKE_object.h" #include "BKE_subdiv.h" #include "BKE_subsurf.h" #include "BLI_math_vector.h" @@ -59,9 +60,14 @@ bool multiresModifier_reshapeFromObject(Depsgraph *depsgraph, Object *dst, Object *src) { - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); - Object *src_eval = DEG_get_evaluated_object(depsgraph, src); - Mesh *src_mesh_eval = mesh_get_eval_final(depsgraph, scene_eval, src_eval, &CD_MASK_BAREMESH); + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, src); + if (!ob_eval) { + return false; + } + const Mesh *src_mesh_eval = BKE_object_get_evaluated_mesh(ob_eval); + if (!src_mesh_eval) { + return false; + } int num_deformed_verts; float(*deformed_verts)[3] = BKE_mesh_vert_coords_alloc(src_mesh_eval, &num_deformed_verts); diff --git a/source/blender/editors/armature/armature_skinning.c b/source/blender/editors/armature/armature_skinning.c index e990a12b7c0..79e29c67681 100644 --- a/source/blender/editors/armature/armature_skinning.c +++ b/source/blender/editors/armature/armature_skinning.c @@ -25,6 +25,7 @@ #include "BKE_mesh_iterators.h" #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" +#include "BKE_object.h" #include "BKE_object_deform.h" #include "BKE_report.h" #include "BKE_subsurf.h" @@ -394,12 +395,12 @@ static void add_verts_to_dgroups(ReportList *reports, if (wpmode) { /* if in weight paint mode, use final verts from evaluated mesh */ - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); - Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); - Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH); - - BKE_mesh_foreach_mapped_vert_coords_get(me_eval, verts, mesh->totvert); - vertsfilled = 1; + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + const Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval); + if (me_eval) { + BKE_mesh_foreach_mapped_vert_coords_get(me_eval, verts, mesh->totvert); + vertsfilled = 1; + } } else if (BKE_modifiers_findby_type(ob, eModifierType_Subsurf)) { /* Is subdivision-surface on? Lets use the verts on the limit surface then. diff --git a/source/blender/editors/mesh/editmesh_knife_project.cc b/source/blender/editors/mesh/editmesh_knife_project.cc index 1c952033478..e7fc50f0bca 100644 --- a/source/blender/editors/mesh/editmesh_knife_project.cc +++ b/source/blender/editors/mesh/editmesh_knife_project.cc @@ -39,10 +39,7 @@ #include "mesh_intern.h" /* own include */ -static LinkNode *knifeproject_poly_from_object(const bContext *C, - Scene *scene, - Object *ob, - LinkNode *polys) +static LinkNode *knifeproject_poly_from_object(const bContext *C, Object *ob, LinkNode *polys) { Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ARegion *region = CTX_wm_region(C); @@ -50,16 +47,12 @@ static LinkNode *knifeproject_poly_from_object(const bContext *C, bool me_eval_needs_free; if (ob->type == OB_MESH || ob->runtime.data_eval) { - Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); me_eval = BKE_object_get_evaluated_mesh(ob_eval); - if (me_eval == nullptr) { - Scene *scene_eval = (Scene *)DEG_get_evaluated_id(depsgraph, &scene->id); - me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH); - } me_eval_needs_free = false; } else if (ELEM(ob->type, OB_FONT, OB_CURVES_LEGACY, OB_SURF)) { - Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); me_eval = BKE_mesh_new_nomain_from_curve(ob_eval); me_eval_needs_free = true; } @@ -118,7 +111,7 @@ static int knifeproject_exec(bContext *C, wmOperator *op) if (BKE_object_is_in_editmode(ob)) { continue; } - polys = knifeproject_poly_from_object(C, scene, ob, polys); + polys = knifeproject_poly_from_object(C, ob, polys); } CTX_DATA_END; diff --git a/source/blender/editors/mesh/meshtools.cc b/source/blender/editors/mesh/meshtools.cc index 279a02d4c38..d18ec5aacd6 100644 --- a/source/blender/editors/mesh/meshtools.cc +++ b/source/blender/editors/mesh/meshtools.cc @@ -1258,14 +1258,13 @@ bool ED_mesh_pick_face_vert( BLI_assert(me && GS(me->id.name) == ID_ME); if (ED_mesh_pick_face(C, ob, mval, dist_px, &poly_index)) { - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); - Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + const Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval); + if (!me_eval) { + return false; + } ARegion *region = CTX_wm_region(C); - /* derived mesh to find deformed locations */ - Mesh *me_eval = mesh_get_eval_final( - depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH_ORIGINDEX); - int v_idx_best = ORIGINDEX_NONE; /* find the vert closest to 'mval' */ @@ -1393,11 +1392,8 @@ bool ED_mesh_pick_vert( (*r_index)--; } else { - Scene *scene_eval = DEG_get_evaluated_scene(vc.depsgraph); - Object *ob_eval = DEG_get_evaluated_object(vc.depsgraph, ob); - - /* derived mesh to find deformed locations */ - Mesh *me_eval = mesh_get_eval_final(vc.depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH); + const Object *ob_eval = DEG_get_evaluated_object(vc.depsgraph, ob); + const Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval); ARegion *region = vc.region; RegionView3D *rv3d = static_cast(region->regiondata); diff --git a/source/blender/editors/object/object_add.cc b/source/blender/editors/object/object_add.cc index 8f1f20b1a21..abeb95a7187 100644 --- a/source/blender/editors/object/object_add.cc +++ b/source/blender/editors/object/object_add.cc @@ -3219,20 +3219,19 @@ static int object_convert_exec(bContext *C, wmOperator *op) /* NOTE: get the mesh from the original, not from the copy in some * cases this doesn't give correct results (when MDEF is used for eg) */ - Scene *scene_eval = (Scene *)DEG_get_evaluated_id(depsgraph, &scene->id); - Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); - Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_MESH); - me_eval = BKE_mesh_copy_for_eval(me_eval); - BKE_object_material_from_eval_data(bmain, newob, &me_eval->id); - Mesh *new_mesh = (Mesh *)newob->data; - BKE_mesh_nomain_to_mesh(me_eval, new_mesh, newob); - + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + const Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob_eval); + Mesh *new_mesh = mesh_eval ? BKE_mesh_copy_for_eval(mesh_eval) : + BKE_mesh_new_nomain(0, 0, 0, 0); + BKE_object_material_from_eval_data(bmain, newob, &new_mesh->id); + /* Anonymous attributes shouldn't be available on the applied geometry. */ + new_mesh->attributes_for_write().remove_anonymous(); if (do_merge_customdata) { BKE_mesh_merge_customdata_for_apply_modifier(new_mesh); } - /* Anonymous attributes shouldn't be available on the applied geometry. */ - new_mesh->attributes_for_write().remove_anonymous(); + Mesh *ob_data_mesh = (Mesh *)newob->data; + BKE_mesh_nomain_to_mesh(new_mesh, ob_data_mesh, newob); BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */ } diff --git a/source/blender/editors/object/object_data_transfer.c b/source/blender/editors/object/object_data_transfer.c index e51faafe33c..ac4b4b1c47d 100644 --- a/source/blender/editors/object/object_data_transfer.c +++ b/source/blender/editors/object/object_data_transfer.c @@ -96,7 +96,7 @@ static const EnumPropertyItem DT_layer_items[] = { {0, NULL, 0, NULL, NULL}, }; -static void dt_add_vcol_layers(CustomData *cdata, +static void dt_add_vcol_layers(const CustomData *cdata, eCustomDataMask mask, EnumPropertyItem **r_item, int *r_totitem) @@ -179,13 +179,14 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(bContext *C, /* TODO */ } else if (data_type == DT_TYPE_UV) { - Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); - Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); - - CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; - cddata_masks.lmask |= CD_MASK_PROP_FLOAT2; - Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + const Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); + const Mesh *me_eval = BKE_object_get_evaluated_mesh_no_subsurf(ob_src_eval); + if (!me_eval) { + RNA_enum_item_end(&item, &totitem); + *r_free = true; + return item; + } int num_data = CustomData_number_of_layers(&me_eval->ldata, CD_PROP_FLOAT2); RNA_enum_item_add_separator(&item, &totitem); @@ -198,9 +199,14 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(bContext *C, } } else if (data_type & DT_TYPE_VCOL_ALL) { - Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); - Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + const Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); + const Mesh *me_eval = BKE_object_get_evaluated_mesh_no_subsurf(ob_src_eval); + if (!me_eval) { + RNA_enum_item_end(&item, &totitem); + *r_free = true; + return item; + } CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; if (data_type & (DT_TYPE_MPROPCOL_VERT)) { @@ -217,8 +223,6 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(bContext *C, cddata_masks.lmask |= CD_MASK_PROP_BYTE_COLOR; } - Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); - if (data_type & (DT_TYPE_MLOOPCOL_VERT | DT_TYPE_MPROPCOL_VERT)) { dt_add_vcol_layers(&me_eval->vdata, cddata_masks.vmask, &item, &totitem); } @@ -419,7 +423,6 @@ static int data_transfer_exec(bContext *C, wmOperator *op) { Object *ob_src = ED_object_active_context(C); Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); ListBase ctx_objects; CollectionPointerLink *ctx_ob_dst; @@ -499,7 +502,6 @@ static int data_transfer_exec(bContext *C, wmOperator *op) } if (BKE_object_data_transfer_mesh(depsgraph, - scene_eval, ob_src_eval, ob_dst, data_type, @@ -828,7 +830,6 @@ static int datalayout_transfer_exec(bContext *C, wmOperator *op) { Object *ob_act = ED_object_active_context(C); Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); DataTransferModifierData *dtmd; dtmd = (DataTransferModifierData *)edit_modifier_property_get( @@ -849,7 +850,6 @@ static int datalayout_transfer_exec(bContext *C, wmOperator *op) Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); BKE_object_data_transfer_layout(depsgraph, - scene_eval, ob_src_eval, ob_dst, dtmd->data_types, @@ -887,7 +887,6 @@ static int datalayout_transfer_exec(bContext *C, wmOperator *op) Object *ob_dst = ctx_ob_dst->ptr.data; if (data_transfer_exec_is_object_valid(op, ob_src, ob_dst, false)) { BKE_object_data_transfer_layout(depsgraph, - scene_eval, ob_src_eval, ob_dst, data_type, diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 6afd2f34dcc..06f865774bb 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -4151,12 +4151,10 @@ static int particle_intersect_mesh(Depsgraph *depsgraph, if (mesh == NULL) { psys_disable_all(ob); - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); - - mesh = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH); + mesh = (Mesh *)BKE_object_get_evaluated_mesh(ob_eval); if (mesh == NULL) { - mesh = mesh_get_eval_deform(depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH); + return 0; } psys_enable_all(ob); diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.cc b/source/blender/editors/sculpt_paint/paint_image_proj.cc index 476fbe78e67..f9cfe353a10 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.cc +++ b/source/blender/editors/sculpt_paint/paint_image_proj.cc @@ -66,6 +66,7 @@ #include "BKE_mesh_runtime.h" #include "BKE_node.hh" #include "BKE_node_runtime.hh" +#include "BKE_object.h" #include "BKE_paint.h" #include "BKE_report.h" #include "BKE_scene.h" @@ -4069,27 +4070,12 @@ static bool proj_paint_state_mesh_eval_init(const bContext *C, ProjPaintState *p Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *ob = ps->ob; - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); - Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); - - if (scene_eval == nullptr || ob_eval == nullptr) { + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + ps->me_eval = BKE_object_get_evaluated_mesh(ob_eval); + if (!ps->me_eval) { return false; } - CustomData_MeshMasks cddata_masks = scene_eval->customdata_mask; - cddata_masks.fmask |= CD_MASK_MTFACE; - cddata_masks.lmask |= CD_MASK_PROP_FLOAT2; - cddata_masks.vmask |= CD_MASK_PROP_ALL | CD_MASK_CREASE; - cddata_masks.emask |= CD_MASK_PROP_ALL | CD_MASK_CREASE; - cddata_masks.pmask |= CD_MASK_PROP_ALL | CD_MASK_CREASE; - cddata_masks.lmask |= CD_MASK_PROP_ALL | CD_MASK_CREASE; - if (ps->do_face_sel) { - cddata_masks.vmask |= CD_MASK_ORIGINDEX; - cddata_masks.emask |= CD_MASK_ORIGINDEX; - cddata_masks.pmask |= CD_MASK_ORIGINDEX; - } - ps->me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &cddata_masks); - if (!CustomData_has_layer(&ps->me_eval->ldata, CD_PROP_FLOAT2)) { ps->me_eval = nullptr; return false; diff --git a/source/blender/editors/sculpt_paint/paint_utils.cc b/source/blender/editors/sculpt_paint/paint_utils.cc index ba021a27f01..1c08e299029 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.cc +++ b/source/blender/editors/sculpt_paint/paint_utils.cc @@ -33,6 +33,7 @@ #include "BKE_material.h" #include "BKE_mesh.h" #include "BKE_mesh_runtime.h" +#include "BKE_object.h" #include "BKE_paint.h" #include "BKE_report.h" @@ -261,8 +262,12 @@ static void imapaint_tri_weights(float matrix[4][4], } /* compute uv coordinates of mouse in face */ -static void imapaint_pick_uv( - Mesh *me_eval, Scene *scene, Object *ob_eval, uint faceindex, const int xy[2], float uv[2]) +static void imapaint_pick_uv(const Mesh *me_eval, + Scene *scene, + Object *ob_eval, + uint faceindex, + const int xy[2], + float uv[2]) { int i, findex; float p[2], w[3], absw, minabsw; @@ -406,7 +411,7 @@ void paint_sample_color( CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; cddata_masks.pmask |= CD_MASK_ORIGINDEX; Mesh *me = (Mesh *)ob->data; - Mesh *me_eval = mesh_get_eval_final(depsgraph, scene, ob_eval, &cddata_masks); + const Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval); const int *material_indices = (const int *)CustomData_get_layer_named( &me_eval->pdata, CD_PROP_INT32, "material_index"); diff --git a/source/blender/editors/sculpt_paint/paint_vertex_proj.cc b/source/blender/editors/sculpt_paint/paint_vertex_proj.cc index 58eea3f5505..85dbb73faec 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_proj.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex_proj.cc @@ -19,6 +19,7 @@ #include "BKE_customdata.h" #include "BKE_mesh_iterators.h" #include "BKE_mesh_runtime.h" +#include "BKE_object.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" @@ -79,12 +80,9 @@ static void vpaint_proj_dm_map_cosnos_init(Depsgraph *depsgraph, Object *ob, VertProjHandle *vp_handle) { - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); - Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); Mesh *me = static_cast(ob->data); - - CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH_ORIGINDEX; - Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &cddata_masks); + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + const Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval); memset(vp_handle->vcosnos, 0, sizeof(*vp_handle->vcosnos) * me->totvert); BKE_mesh_foreach_mapped_vert( @@ -142,12 +140,10 @@ static void vpaint_proj_dm_map_cosnos_update(Depsgraph *depsgraph, VertProjUpdate vp_update = {vp_handle, region, mval_fl}; Object *ob = vp_handle->ob; - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); - Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); Mesh *me = static_cast(ob->data); - CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH_ORIGINDEX; - Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &cddata_masks); + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + const Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval); /* quick sanity check - we shouldn't have to run this if there are no modifiers */ BLI_assert(BLI_listbase_is_empty(&ob->modifiers) == false); diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc index 4ab5065b635..2f54b0a3a62 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc @@ -28,6 +28,7 @@ #include "BKE_mesh_iterators.h" #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" +#include "BKE_object.h" #include "BKE_object_deform.h" #include "BKE_paint.h" #include "BKE_report.h" @@ -856,14 +857,8 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op) ED_view3d_init_mats_rv3d(ob, static_cast(region->regiondata)); - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); - Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); - - CustomData_MeshMasks cddata_masks = scene->customdata_mask; - cddata_masks.vmask |= CD_MASK_ORIGINDEX; - cddata_masks.emask |= CD_MASK_ORIGINDEX; - cddata_masks.pmask |= CD_MASK_ORIGINDEX; - Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &cddata_masks); + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + const Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval); if (data.is_init) { data.vert_visit = BLI_BITMAP_NEW(me->totvert, __func__); diff --git a/source/blender/editors/space_view3d/view3d_iterators.cc b/source/blender/editors/space_view3d/view3d_iterators.cc index fd2eb73c717..eeae5255489 100644 --- a/source/blender/editors/space_view3d/view3d_iterators.cc +++ b/source/blender/editors/space_view3d/view3d_iterators.cc @@ -28,6 +28,7 @@ #include "BKE_mesh_runtime.h" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" +#include "BKE_object.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" @@ -290,12 +291,9 @@ void meshobject_foreachScreenVert(ViewContext *vc, { BLI_assert((clip_flag & V3D_PROJ_TEST_CLIP_CONTENT) == 0); foreachScreenObjectVert_userData data; - Mesh *me; - Scene *scene_eval = DEG_get_evaluated_scene(vc->depsgraph); - Object *ob_eval = DEG_get_evaluated_object(vc->depsgraph, vc->obact); - - me = mesh_get_eval_final(vc->depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH); + const Object *ob_eval = DEG_get_evaluated_object(vc->depsgraph, vc->obact); + const Mesh *me = BKE_object_get_evaluated_mesh(ob_eval); ED_view3d_check_mats_rv3d(vc->rv3d); diff --git a/source/blender/io/alembic/exporter/abc_writer_hair.cc b/source/blender/io/alembic/exporter/abc_writer_hair.cc index 86fb1821bde..fb48596e234 100644 --- a/source/blender/io/alembic/exporter/abc_writer_hair.cc +++ b/source/blender/io/alembic/exporter/abc_writer_hair.cc @@ -20,6 +20,7 @@ #include "BKE_mesh.hh" #include "BKE_mesh_legacy_convert.h" #include "BKE_mesh_runtime.h" +#include "BKE_object.h" #include "BKE_particle.h" #include "CLG_log.h" @@ -63,9 +64,11 @@ bool ABCHairWriter::check_is_animated(const HierarchyContext & /*context*/) cons void ABCHairWriter::do_write(HierarchyContext &context) { - Scene *scene_eval = DEG_get_evaluated_scene(args_.depsgraph); - Mesh *mesh = mesh_get_eval_final(args_.depsgraph, scene_eval, context.object, &CD_MASK_MESH); - BKE_mesh_tessface_ensure(mesh); + const Mesh *mesh = BKE_object_get_evaluated_mesh(context.object); + if (!mesh) { + return; + } + BKE_mesh_tessface_ensure(const_cast(mesh)); std::vector verts; std::vector hvertices; @@ -78,11 +81,13 @@ void ABCHairWriter::do_write(HierarchyContext &context) bool export_children = psys->childcache && part->childtype != 0; if (!export_children || part->draw & PART_DRAW_PARENT) { - write_hair_sample(context, mesh, verts, norm_values, uv_values, hvertices); + write_hair_sample( + context, const_cast(mesh), verts, norm_values, uv_values, hvertices); } if (export_children) { - write_hair_child_sample(context, mesh, verts, norm_values, uv_values, hvertices); + write_hair_child_sample( + context, const_cast(mesh), verts, norm_values, uv_values, hvertices); } } diff --git a/source/blender/io/collada/collada_utils.cpp b/source/blender/io/collada/collada_utils.cpp index 4d369959674..606ab0fafc0 100644 --- a/source/blender/io/collada/collada_utils.cpp +++ b/source/blender/io/collada/collada_utils.cpp @@ -211,8 +211,7 @@ Mesh *bc_get_mesh_copy(BlenderContext &blender_context, bool apply_modifiers, bool triangulate) { - CustomData_MeshMasks mask = CD_MASK_MESH; - Mesh *tmpmesh = nullptr; + const Mesh *tmpmesh = nullptr; if (apply_modifiers) { #if 0 /* Not supported by new system currently... */ switch (export_mesh_type) { @@ -227,22 +226,21 @@ Mesh *bc_get_mesh_copy(BlenderContext &blender_context, } #else Depsgraph *depsgraph = blender_context.get_depsgraph(); - Scene *scene_eval = blender_context.get_evaluated_scene(); - Object *ob_eval = blender_context.get_evaluated_object(ob); - tmpmesh = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &mask); + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + tmpmesh = BKE_object_get_evaluated_mesh(ob_eval); #endif } else { tmpmesh = (Mesh *)ob->data; } - tmpmesh = (Mesh *)BKE_id_copy_ex(nullptr, &tmpmesh->id, nullptr, LIB_ID_COPY_LOCALIZE); + Mesh *mesh = BKE_mesh_copy_for_eval(tmpmesh); if (triangulate) { - bc_triangulate_mesh(tmpmesh); + bc_triangulate_mesh(mesh); } - BKE_mesh_tessface_ensure(tmpmesh); - return tmpmesh; + BKE_mesh_tessface_ensure(mesh); + return mesh; } Object *bc_get_assigned_armature(Object *ob) diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 4f95ae41f11..21f5a001a94 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -1347,16 +1347,22 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_src_itemf( Object *ob_src = dtmd->ob_source; if (ob_src) { - Mesh *me_eval; int num_data, i; Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); - Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob_src); + if (!ob_eval) { + RNA_enum_item_end(&item, &totitem); + *r_free = true; + return item; + } + const Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval); + if (!me_eval) { + RNA_enum_item_end(&item, &totitem); + *r_free = true; + return item; + } - CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; - cddata_masks.lmask |= CD_MASK_PROP_FLOAT2; - me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); num_data = CustomData_number_of_layers(&me_eval->ldata, CD_PROP_FLOAT2); RNA_enum_item_add_separator(&item, &totitem); @@ -1380,21 +1386,25 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_src_itemf( ATTR_DOMAIN_CORNER; Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); - Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); - - CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; - CustomData *cdata; - - Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); + const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob_src); + if (!ob_eval) { + RNA_enum_item_end(&item, &totitem); + *r_free = true; + return item; + } + const Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob_eval); + if (!mesh_eval) { + RNA_enum_item_end(&item, &totitem); + *r_free = true; + return item; + } + const CustomData *cdata; if (domain == ATTR_DOMAIN_POINT) { - cddata_masks.vmask |= CD_MASK_COLOR_ALL; - cdata = &me_eval->vdata; + cdata = &mesh_eval->vdata; } else { - cddata_masks.lmask |= CD_MASK_COLOR_ALL; - cdata = &me_eval->ldata; + cdata = &mesh_eval->ldata; } eCustomDataType types[2] = {CD_PROP_COLOR, CD_PROP_BYTE_COLOR}; diff --git a/source/blender/modifiers/intern/MOD_datatransfer.cc b/source/blender/modifiers/intern/MOD_datatransfer.cc index d96b9b7d6ba..936b360e8dc 100644 --- a/source/blender/modifiers/intern/MOD_datatransfer.cc +++ b/source/blender/modifiers/intern/MOD_datatransfer.cc @@ -152,7 +152,6 @@ static bool isDisabled(const struct Scene * /*scene*/, ModifierData *md, bool /* static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *me_mod) { DataTransferModifierData *dtmd = (DataTransferModifierData *)md; - struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); Mesh *result = me_mod; ReportList reports; @@ -193,7 +192,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* NOTE: no islands precision for now here. */ if (BKE_object_data_transfer_ex(ctx->depsgraph, - scene, ob_source, ctx->object, result, diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index ea723bd592a..fd6fd369a28 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -18,6 +18,7 @@ #include "BKE_lib_id.h" #include "BKE_mesh.h" #include "BKE_mesh_runtime.h" +#include "BKE_object.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" @@ -1079,7 +1080,7 @@ static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject Object *ob, *ob_eval; struct Depsgraph *depsgraph; struct Scene *scene_eval; - Mesh *me_eval; + const Mesh *me_eval; BMesh *bm; bool use_cage = false; bool use_fnorm = true; @@ -1134,7 +1135,7 @@ static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject me_eval = mesh_get_eval_deform(depsgraph, scene_eval, ob_eval, &data_masks); } else { - me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &data_masks); + me_eval = BKE_object_get_evaluated_mesh(ob_eval); } } @@ -1155,7 +1156,7 @@ static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject })); if (need_free) { - BKE_id_free(NULL, me_eval); + BKE_id_free(NULL, (Mesh *)me_eval); } Py_RETURN_NONE; diff --git a/source/blender/python/mathutils/mathutils_bvhtree.cc b/source/blender/python/mathutils/mathutils_bvhtree.cc index de34c802ce7..5cbe2d0e6a6 100644 --- a/source/blender/python/mathutils/mathutils_bvhtree.cc +++ b/source/blender/python/mathutils/mathutils_bvhtree.cc @@ -36,6 +36,7 @@ # include "BKE_lib_id.h" # include "BKE_mesh.hh" # include "BKE_mesh_runtime.h" +# include "BKE_object.h" # include "DEG_depsgraph_query.h" @@ -1017,13 +1018,13 @@ static PyObject *C_BVHTree_FromBMesh(PyObject * /*cls*/, PyObject *args, PyObjec } /* return various derived meshes based on requested settings */ -static Mesh *bvh_get_mesh(const char *funcname, - Depsgraph *depsgraph, - Scene *scene, - Object *ob, - const bool use_deform, - const bool use_cage, - bool *r_free_mesh) +static const Mesh *bvh_get_mesh(const char *funcname, + Depsgraph *depsgraph, + Scene *scene, + Object *ob, + const bool use_deform, + const bool use_cage, + bool *r_free_mesh) { Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); /* we only need minimum mesh data for topology and vertex locations */ @@ -1050,7 +1051,7 @@ static Mesh *bvh_get_mesh(const char *funcname, return mesh_get_eval_deform(depsgraph, scene, ob_eval, &data_masks); } - return mesh_get_eval_final(depsgraph, scene, ob_eval, &data_masks); + return BKE_object_get_evaluated_mesh(ob_eval); } PyErr_Format(PyExc_ValueError, @@ -1108,7 +1109,7 @@ static PyObject *C_BVHTree_FromObject(PyObject * /*cls*/, PyObject *args, PyObje Object *ob; Depsgraph *depsgraph; Scene *scene; - Mesh *mesh; + const Mesh *mesh; bool use_deform = true; bool use_cage = false; bool free_mesh = false; @@ -1190,7 +1191,7 @@ static PyObject *C_BVHTree_FromObject(PyObject * /*cls*/, PyObject *args, PyObje } if (free_mesh) { - BKE_id_free(nullptr, mesh); + BKE_id_free(nullptr, const_cast(mesh)); } return bvhtree_CreatePyObject(tree,