Refactor: Remove pre-2.8 function to reevaluate a single object #106186

Merged
Hans Goudey merged 6 commits from HooglyBoogly/blender:fix-remove-broken-reevaluate-mesh into main 2023-05-30 22:25:12 +02:00
25 changed files with 166 additions and 230 deletions

View File

@ -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,

View File

@ -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
}

View File

@ -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,

View File

@ -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,

View File

@ -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<Mesh *>(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,

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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.

View File

@ -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;

View File

@ -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<RegionView3D *>(region->regiondata);

View File

@ -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! */
}

View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -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");

View File

@ -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<Mesh *>(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<Mesh *>(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);

View File

@ -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<RegionView3D *>(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__);

View File

@ -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);

View File

@ -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 *>(mesh));
std::vector<Imath::V3f> verts;
std::vector<int32_t> 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 *>(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 *>(mesh), verts, norm_values, uv_values, hvertices);
}
}

View File

@ -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)

View File

@ -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) {
HooglyBoogly marked this conversation as resolved Outdated

Here I don't think we can assume the existence of depsgraph, ob_eval or me_eval. I think they could be NULL for objects that are hidden or part of another scene, and crash.

Using context and the depsgraph here at all is dodgy, but that's not something to solve as part of this.

There's probably more cases like this where the object may not have been evaluated, but I didn't have time today to check them all. Probably best to be extra careful and add null pointer checks in various places.

Here I don't think we can assume the existence of `depsgraph`, `ob_eval` or `me_eval`. I think they could be NULL for objects that are hidden or part of another scene, and crash. Using context and the depsgraph here at all is dodgy, but that's not something to solve as part of this. There's probably more cases like this where the object may not have been evaluated, but I didn't have time today to check them all. Probably best to be extra careful and add null pointer checks in various places.
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};

View File

@ -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,

View File

@ -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);
}

This could be a breaking change, it's conceivable a script calls this for a hidden object.

Maybe best to postpone changing this one.

This could be a breaking change, it's conceivable a script calls this for a hidden object. Maybe best to postpone changing this one.
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;

View File

@ -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);

Same here, could be a breaking change.

Same here, could be a breaking change.
}
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 *>(mesh));
}
return bvhtree_CreatePyObject(tree,