From d5bcc375ba4b7ed6446212c355a26de09d91c36c Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Fri, 21 Feb 2020 23:41:56 +0100 Subject: [PATCH] Fix T69576, T74059: issues with rotation when adding objects This clarifies logic in ED_object_add_generic_get_opts (see comments in code). Also following issues are adressed: - do not enforce setting the op UI to WORLD when rotation is set (e.g. on redo). This is not wrong (happens in world space), but is more confusing than helpful (was added in own rB3b8a14a3c072). - respect setting the User Preference to WORLD properly (could fail when set to something else, then back to WORLD) Maniphest Tasks: T69576 Differential Revision: https://developer.blender.org/D6943 --- source/blender/editors/object/object_add.c | 77 ++++++++++++---------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 7891f59a62e..a8eaa663285 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -410,45 +410,54 @@ bool ED_object_add_generic_get_opts(bContext *C, rot = _rot; } - prop = RNA_struct_find_property(op->ptr, "align"); - int alignment = RNA_property_enum_get(op->ptr, prop); - bool alignment_set = RNA_property_is_set(op->ptr, prop); - if (RNA_struct_property_is_set(op->ptr, "rotation")) { + /* If rotation is set, always use it. Alignment (and corresponding user preference) + * can be ignored since this is in world space anyways. + * To not confuse (e.g. on redo), dont set it to ALIGN_WORLD in the op UI though. */ *is_view_aligned = false; - RNA_property_enum_set(op->ptr, prop, ALIGN_WORLD); - alignment = ALIGN_WORLD; - } - else if (alignment_set) { - *is_view_aligned = alignment == ALIGN_VIEW; + RNA_float_get_array(op->ptr, "rotation", rot); } else { - *is_view_aligned = (U.flag & USER_ADD_VIEWALIGNED) != 0; - if (*is_view_aligned) { - RNA_property_enum_set(op->ptr, prop, ALIGN_VIEW); - alignment = ALIGN_VIEW; - } - else if (U.flag & USER_ADD_CURSORALIGNED) { - RNA_property_enum_set(op->ptr, prop, ALIGN_CURSOR); - alignment = ALIGN_CURSOR; - } - } + int alignment = ALIGN_WORLD; + prop = RNA_struct_find_property(op->ptr, "align"); - switch (alignment) { - case ALIGN_WORLD: - RNA_float_get_array(op->ptr, "rotation", rot); - break; - case ALIGN_VIEW: - ED_object_rotation_from_view(C, rot, view_align_axis); - RNA_float_set_array(op->ptr, "rotation", rot); - break; - case ALIGN_CURSOR: { - const Scene *scene = CTX_data_scene(C); - float tmat[3][3]; - BKE_scene_cursor_rot_to_mat3(&scene->cursor, tmat); - mat3_normalized_to_eul(rot, tmat); - RNA_float_set_array(op->ptr, "rotation", rot); - break; + if (RNA_property_is_set(op->ptr, prop)) { + /* If alignment is set, always use it. */ + *is_view_aligned = alignment == ALIGN_VIEW; + alignment = RNA_property_enum_get(op->ptr, prop); + } + else { + /* If alignment is not set, use User Preferences. */ + *is_view_aligned = (U.flag & USER_ADD_VIEWALIGNED) != 0; + if (*is_view_aligned) { + RNA_property_enum_set(op->ptr, prop, ALIGN_VIEW); + alignment = ALIGN_VIEW; + } + else if ((U.flag & USER_ADD_CURSORALIGNED) != 0) { + RNA_property_enum_set(op->ptr, prop, ALIGN_CURSOR); + alignment = ALIGN_CURSOR; + } + else { + RNA_property_enum_set(op->ptr, prop, ALIGN_WORLD); + alignment = ALIGN_WORLD; + } + } + switch (alignment) { + case ALIGN_WORLD: + RNA_float_get_array(op->ptr, "rotation", rot); + break; + case ALIGN_VIEW: + ED_object_rotation_from_view(C, rot, view_align_axis); + RNA_float_set_array(op->ptr, "rotation", rot); + break; + case ALIGN_CURSOR: { + const Scene *scene = CTX_data_scene(C); + float tmat[3][3]; + BKE_scene_cursor_rot_to_mat3(&scene->cursor, tmat); + mat3_normalized_to_eul(rot, tmat); + RNA_float_set_array(op->ptr, "rotation", rot); + break; + } } } }