From ff9de2f7da9dcec96692355a67a7e7e280c223a7 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 8 Aug 2024 16:42:53 +0200 Subject: [PATCH] Fix #125670: Regression: Setting parent to triangle changes object location This fixes two things: * Pass the evaluated object into `BKE_object_as_kdtree` instead of the original one. `BKE_object_as_kdtree` uses functions on the object which are only expected to be executed on evaluated objects, such as `BKE_object_get_mesh_deform_eval`. Note that this is the only place where `BKE_object_as_kdtree` is used. * Tag depsgraph at the end of setting parent. This way, `BKE_object_get_evaluated_mesh` will return the correct mesh instead of null. It was returning null because it the object is not in a fully evaluated state if it just has been tagged as requiring an update. Pull Request: https://projects.blender.org/blender/blender/pulls/126086 --- source/blender/editors/object/object_relations.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/object/object_relations.cc b/source/blender/editors/object/object_relations.cc index 985583fe39e..f4ea28de04a 100644 --- a/source/blender/editors/object/object_relations.cc +++ b/source/blender/editors/object/object_relations.cc @@ -508,8 +508,6 @@ bool parent_set(ReportList *reports, bPoseChannel *pchan_eval = nullptr; Object *parent_eval = DEG_get_evaluated_object(depsgraph, par); - DEG_id_tag_update(&par->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); - /* Preconditions. */ if (ob == par) { /* Parenting an object to itself is impossible. */ @@ -583,7 +581,6 @@ bool parent_set(ReportList *reports, ob->parent = par; /* Always clear parentinv matrix for sake of consistency, see #41950. */ unit_m4(ob->parentinv); - DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM); } /* Handle types. */ @@ -754,6 +751,7 @@ bool parent_set(ReportList *reports, invert_m4_m4(ob->parentinv, BKE_object_calc_parent(depsgraph, scene, ob).ptr()); } + DEG_id_tag_update(&par->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); return true; } @@ -856,7 +854,10 @@ static bool parent_set_vertex_parent(bContext *C, ParentingContext *parenting_co KDTree_3d *tree = nullptr; int tree_tot; - tree = BKE_object_as_kdtree(parenting_context->par, &tree_tot); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + Object *par_eval = DEG_get_evaluated_object(depsgraph, parenting_context->par); + + tree = BKE_object_as_kdtree(par_eval, &tree_tot); BLI_assert(tree != nullptr); if (tree_tot < (parenting_context->is_vertex_tri ? 3 : 1)) {