diff options
author | Wayde Moss <GuiltyGhost> | 2022-04-15 01:16:23 +0300 |
---|---|---|
committer | Wayde Moss <wbmoss_dev@yahoo.com> | 2022-04-15 03:25:06 +0300 |
commit | db6287873cd2c79741439f4d141c4b2db517d73e (patch) | |
tree | 9c60530681f07a801e9dff7fa9ee02de3c88270d /source/blender/editors/object/object_transform.cc | |
parent | 48ff456a4bda98d73042b0ef85091cf79aad8647 (diff) |
Object: Set Parent (Keep Transform Without Inverse)
**Relevant to Artists:** This patch adds an option to the Parenting
menu, `Object (Keep Transform Without Inverse)`, and Apply menu, `Parent
Inverse`. The operators preserve the child's world transform without
using the parent inverse matrix. Effectively, we set the child's origin
to the parent. When the child has an identity local transform, then the
child is world-space aligned with its parent (scale excluded).
**Technical:** In both cases, the hidden parent inverse matrix is
generally set to identity (cleared or "not used") as long as the parent
has no shear. If the parent has shear, then this matrix will not be
entirely cleared. It will contain shear to counter the parent's shear.
This is required, otherwise the object's local matrix cannot be properly
decomposed into location, rotation and scale, and thus cannot preserve
the world transform.
If the child's world transform has shear, then its world transform is
not preserved. This is currently not supported for consistency in the
handling of shear during the other parenting ops: Parent (Keep
Transform), Clear [Parent] and Keep Transform. If it should work, then
another patch should add the support for all of them.
Reviewed By: sybren, RiggingDojo
Differential Revision: https://developer.blender.org/D14581
Diffstat (limited to 'source/blender/editors/object/object_transform.cc')
-rw-r--r-- | source/blender/editors/object/object_transform.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/source/blender/editors/object/object_transform.cc b/source/blender/editors/object/object_transform.cc index 3d4d543012d..c0ec6c6678e 100644 --- a/source/blender/editors/object/object_transform.cc +++ b/source/blender/editors/object/object_transform.cc @@ -1173,6 +1173,38 @@ void OBJECT_OT_transform_apply(wmOperatorType *ot) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } +static int object_parent_inverse_apply_exec(bContext *C, wmOperator *UNUSED(op)) +{ + CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { + if (ob->parent == NULL) { + continue; + } + + DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM); + BKE_object_apply_parent_inverse(ob); + } + CTX_DATA_END; + + WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_parent_inverse_apply(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Apply Parent Inverse"; + ot->description = "Apply the object's parent inverse to the its data"; + ot->idname = "OBJECT_OT_parent_inverse_apply"; + + /* api callbacks */ + ot->exec = object_parent_inverse_apply_exec; + ot->poll = ED_operator_objectmode; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + /** \} */ /* -------------------------------------------------------------------- */ |