From 10131a6f6238e259ce6732497e6eb045290ad3a3 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 4 Nov 2022 20:19:52 +0100 Subject: Cleanup: Mesh: Remove redundant edge render flag Currently there are both "EDGERENDER" and "EDGEDRAW" flags, which are almost always used together. Both are runtime data and not exposed to RNA, used to skip drawing some edges after the subdivision surface modifier. The render flag is a relic of the Blender internal renderer. This commit removes the render flag and replaces its uses with the draw flag. --- source/blender/editors/object/object_modifier.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender/editors/object/object_modifier.cc') diff --git a/source/blender/editors/object/object_modifier.cc b/source/blender/editors/object/object_modifier.cc index 85a35861329..2838b5829bf 100644 --- a/source/blender/editors/object/object_modifier.cc +++ b/source/blender/editors/object/object_modifier.cc @@ -614,7 +614,7 @@ bool ED_object_modifier_convert_psys_to_mesh(ReportList * /*reports*/, if (k) { medge->v1 = cvert - 1; medge->v2 = cvert; - medge->flag = ME_EDGEDRAW | ME_EDGERENDER | ME_LOOSEEDGE; + medge->flag = ME_EDGEDRAW | ME_LOOSEEDGE; medge++; } else { @@ -633,7 +633,7 @@ bool ED_object_modifier_convert_psys_to_mesh(ReportList * /*reports*/, if (k) { medge->v1 = cvert - 1; medge->v2 = cvert; - medge->flag = ME_EDGEDRAW | ME_EDGERENDER | ME_LOOSEEDGE; + medge->flag = ME_EDGEDRAW | ME_LOOSEEDGE; medge++; } else { -- cgit v1.2.3 From ae3073323e92a1773fb253bd1c5d6c92b826e1e0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 4 Nov 2022 18:37:25 +1100 Subject: Cleanup: use bool instead of short for job stop & do_update arguments Since these values are only ever 0/1, use bool type. --- source/blender/editors/object/object_modifier.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/blender/editors/object/object_modifier.cc') diff --git a/source/blender/editors/object/object_modifier.cc b/source/blender/editors/object/object_modifier.cc index 2838b5829bf..a87e52db129 100644 --- a/source/blender/editors/object/object_modifier.cc +++ b/source/blender/editors/object/object_modifier.cc @@ -3023,7 +3023,7 @@ static bool ocean_bake_poll(bContext *C) struct OceanBakeJob { /* from wmJob */ struct Object *owner; - short *stop, *do_update; + bool *stop, *do_update; float *progress; int current_frame; struct OceanCache *och; @@ -3062,7 +3062,7 @@ static void oceanbake_update(void *customdata, float progress, int *cancel) *(oj->progress) = progress; } -static void oceanbake_startjob(void *customdata, short *stop, short *do_update, float *progress) +static void oceanbake_startjob(void *customdata, bool *stop, bool *do_update, float *progress) { OceanBakeJob *oj = static_cast(customdata); @@ -3075,7 +3075,7 @@ static void oceanbake_startjob(void *customdata, short *stop, short *do_update, BKE_ocean_bake(oj->ocean, oj->och, oceanbake_update, (void *)oj); *do_update = true; - *stop = 0; + *stop = false; } static void oceanbake_endjob(void *customdata) -- cgit v1.2.3 From c26d49e854b345094828ecf908e050a4d9c637cf Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 8 Nov 2022 14:02:29 +0100 Subject: Fix T101906: Modifier apply not working if target object is in excluded collection The issue was introduced by the optimization of hidden objects and modifiers in the f12f7800c296. The solution here detects that either an object is hidden or the modifier is disabled and does special tricks to ensure the dependencies are evaluated. This is done by constructing a separate minimal dependency graph needed for the object on which the modifier is being applied on. This minimal dependency graph will not perform visibility optimization, making it so modifier dependencies are ensured to be evaluated. The downside of such approach is that some dependencies which are not needed for the modifier are still evaluated. There is no currently an easy way to avoid this. At least not without introducing possible race conditions with other dependency graphs. If the performance of applying modifiers in such cases becomes a problem the possible solution would be to create a temporary object with a single modifier so that only minimal set of dependencies is pulled in the minimal dependency graph. Differential Revision: https://developer.blender.org/D16421 --- source/blender/editors/object/object_modifier.cc | 59 +++++++++++++++++------- 1 file changed, 42 insertions(+), 17 deletions(-) (limited to 'source/blender/editors/object/object_modifier.cc') diff --git a/source/blender/editors/object/object_modifier.cc b/source/blender/editors/object/object_modifier.cc index 85a35861329..37fdcf41815 100644 --- a/source/blender/editors/object/object_modifier.cc +++ b/source/blender/editors/object/object_modifier.cc @@ -942,31 +942,56 @@ bool ED_object_modifier_apply(Main *bmain, Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); ModifierData *md_eval = (ob_eval) ? BKE_modifiers_findby_name(ob_eval, md->name) : md; - /* Allow apply of a non-real-time modifier, by first re-enabling real-time. */ - int prev_mode = md_eval->mode; - md_eval->mode |= eModifierMode_Realtime; + Depsgraph *apply_depsgraph = depsgraph; + Depsgraph *local_depsgraph = nullptr; + + /* If the object is hidden or the modifier is not enabled for the viewport is disabled a special + * handling is required. This is because the viewport dependency graph optimizes out evaluation + * of objects which are used by hidden objects and disabled modifiers. + * + * The idea is to create a dependency graph which does not perform those optimizations. */ + if ((ob_eval->base_flag & BASE_ENABLED_VIEWPORT) == 0 || + (md_eval->mode & eModifierMode_Realtime) == 0) { + ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); + + local_depsgraph = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_VIEWPORT); + DEG_disable_visibility_optimization(local_depsgraph); + + ID *ids[] = {&ob->id}; + + DEG_graph_build_from_ids(local_depsgraph, ids, 1); + DEG_evaluate_on_refresh(local_depsgraph); + + apply_depsgraph = local_depsgraph; + + /* The evaluated object and modifier are now from the different dependency graph. */ + ob_eval = DEG_get_evaluated_object(local_depsgraph, ob); + md_eval = BKE_modifiers_findby_name(ob_eval, md->name); + + /* Force mode on the evaluated modifier, enforcing the modifier evaluation in the apply() + * functions. */ + md_eval->mode |= eModifierMode_Realtime; + } + bool did_apply = false; if (mode == MODIFIER_APPLY_SHAPE) { - if (!modifier_apply_shape(bmain, reports, depsgraph, scene, ob, md_eval)) { - md_eval->mode = prev_mode; - return false; - } + did_apply = modifier_apply_shape(bmain, reports, apply_depsgraph, scene, ob, md_eval); } else { - if (!modifier_apply_obdata(reports, depsgraph, scene, ob, md_eval)) { - md_eval->mode = prev_mode; - return false; - } + did_apply = modifier_apply_obdata(reports, apply_depsgraph, scene, ob, md_eval); } - md_eval->mode = prev_mode; - - if (!keep_modifier) { - BKE_modifier_remove_from_list(ob, md); - BKE_modifier_free(md); + if (did_apply) { + if (!keep_modifier) { + BKE_modifier_remove_from_list(ob, md); + BKE_modifier_free(md); + } + BKE_object_free_derived_caches(ob); } - BKE_object_free_derived_caches(ob); + if (local_depsgraph != nullptr) { + DEG_graph_free(local_depsgraph); + } return true; } -- cgit v1.2.3