Transform: support snapping origins onto the objects geometry

Normally it wouldn't make sense for the object to snap onto it's self,
when moving origins this is a common use-case.
This commit is contained in:
Campbell Barton 2019-08-26 14:40:00 +10:00
parent 7b61fe1638
commit db851c78b4
Notes: blender-bot 2023-02-14 01:04:18 +01:00
Referenced by issue #69132, Transform object origins design task
2 changed files with 23 additions and 12 deletions

View File

@ -6536,11 +6536,14 @@ static void flush_trans_object_base_deps_flag(Depsgraph *depsgraph, Object *obje
depsgraph, &object->id, DEG_OB_COMP_TRANSFORM, set_trans_object_base_deps_flag_cb, NULL);
}
static void trans_object_base_deps_flag_finish(ViewLayer *view_layer)
static void trans_object_base_deps_flag_finish(const TransInfo *t, ViewLayer *view_layer)
{
for (Base *base = view_layer->object_bases.first; base; base = base->next) {
if (base->object->id.tag & LIB_TAG_DOIT) {
base->flag_legacy |= BA_SNAP_FIX_DEPS_FIASCO;
if ((t->flag & T_OBJECT_DATA_IN_OBJECT_MODE) == 0) {
for (Base *base = view_layer->object_bases.first; base; base = base->next) {
if (base->object->id.tag & LIB_TAG_DOIT) {
base->flag_legacy |= BA_SNAP_FIX_DEPS_FIASCO;
}
}
}
}
@ -6602,7 +6605,7 @@ static void set_trans_object_base_flags(TransInfo *t)
/* Store temporary bits in base indicating that base is being modified
* (directly or indirectly) by transforming objects.
*/
trans_object_base_deps_flag_finish(view_layer);
trans_object_base_deps_flag_finish(t, view_layer);
}
static bool mark_children(Object *ob)
@ -6670,7 +6673,7 @@ static int count_proportional_objects(TransInfo *t)
/* Store temporary bits in base indicating that base is being modified
* (directly or indirectly) by transforming objects.
*/
trans_object_base_deps_flag_finish(view_layer);
trans_object_base_deps_flag_finish(t, view_layer);
return total;
}

View File

@ -632,12 +632,20 @@ static void initSnappingMode(TransInfo *t)
else if (t->tsnap.applySnap != NULL && // A snapping function actually exist
(obedit_type == -1)) // Object Mode
{
/* In "Edit Strokes" mode,
* snap tool can perform snap to selected or active objects (see T49632)
* TODO: perform self snap in gpencil_strokes */
t->tsnap.modeSelect = (((t->options & (CTX_GPENCIL_STROKES | CTX_CURSOR)) != 0) ?
SNAP_ALL :
SNAP_NOT_SELECTED);
if (t->options & (CTX_GPENCIL_STROKES | CTX_CURSOR)) {
/* In "Edit Strokes" mode,
* snap tool can perform snap to selected or active objects (see T49632)
* TODO: perform self snap in gpencil_strokes */
t->tsnap.modeSelect = SNAP_ALL;
}
else if (t->flag & T_OBJECT_DATA_IN_OBJECT_MODE) {
/* When we're moving the origins, allow snapping onto our own geometry (see T69132). */
t->tsnap.modeSelect = SNAP_ALL;
}
else {
t->tsnap.modeSelect = SNAP_NOT_SELECTED;
}
}
else {
/* Grid if snap is not possible */