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
This commit is contained in:
parent
01162f756a
commit
d5bcc375ba
Notes:
blender-bot
2023-02-14 01:07:44 +01:00
Referenced by issue #74059, align new object to world doesn't work, it always aligns to 3d cursor Referenced by issue #69576, location and rotation with align to 3d cursor
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue