Transform orientation tweaks

If the orietation is setted as a parameter, it is best to refer
to it as a constraint orietation so that it can be reused in
successive axis presses.

This is useful to retrieve the orientation of the extrude for example.
This commit is contained in:
Germano Cavalcante 2020-05-12 15:44:08 -03:00
parent 36e3847093
commit 289242fef9
Notes: blender-bot 2023-02-14 00:29:15 +01:00
Referenced by issue #76933, "Align to transform Orientation" crashes blender for Custom transform orientations
Referenced by issue #76504, Extrusion doesn't take in account the current transform orientation
1 changed files with 39 additions and 35 deletions

View File

@ -1651,20 +1651,17 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
{
TransformOrientationSlot *orient_slot = &t->scene->orientation_slots[SCE_ORIENT_DEFAULT];
TransformOrientation *custom_orientation = NULL;
short orient_type_constraint = orient_slot->type;
if (orient_type_constraint == V3D_ORIENT_CUSTOM) {
short orient_type_set = -1;
short orient_type_matrix_set = -1;
short orient_type_scene = orient_slot->type;
if (orient_type_scene == V3D_ORIENT_CUSTOM) {
const int index_custom = orient_slot->index_custom;
custom_orientation = BKE_scene_transform_orientation_find(t->scene, index_custom);
orient_type_constraint += index_custom;
orient_type_scene += index_custom;
}
short orient_type_default = orient_type_constraint;
short orient_type_matrix_set = -1;
/* Init orientation 0 even if (t->con.mode & CON_APPLY) is true.
* So the extrude can use the orientation defined in the scene when
* changing constrain orientation. */
int orient_index = 0;
short orient_type_default = V3D_ORIENT_GLOBAL;
short orient_type_constraint[2];
if (op && (prop = RNA_struct_find_property(op->ptr, "orient_axis"))) {
t->orient_axis = RNA_property_enum_get(op->ptr, prop);
@ -1672,9 +1669,6 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
/* For transfor modes that require "orient_axis" use
* `V3D_ORIENT_VIEW` as default. */
orient_type_default = V3D_ORIENT_VIEW;
if (t->con.mode & CON_APPLY) {
orient_index = 1;
}
}
if (op && (prop = RNA_struct_find_property(op->ptr, "orient_axis_ortho"))) {
t->orient_axis_ortho = RNA_property_enum_get(op->ptr, prop);
@ -1682,7 +1676,26 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
if (op && ((prop = RNA_struct_find_property(op->ptr, "orient_type")) &&
RNA_property_is_set(op->ptr, prop))) {
orient_type_default = RNA_property_enum_get(op->ptr, prop);
orient_type_set = RNA_property_enum_get(op->ptr, prop);
if (orient_type_set >= V3D_ORIENT_CUSTOM) {
if (orient_type_set >= V3D_ORIENT_CUSTOM + BIF_countTransformOrientation(C)) {
orient_type_set = V3D_ORIENT_GLOBAL;
}
else {
custom_orientation = BKE_scene_transform_orientation_find(
t->scene, orient_type_default - V3D_ORIENT_CUSTOM);
}
}
/* Change the default orientation to be used when redoing. */
orient_type_default = orient_type_set;
orient_type_constraint[0] = orient_type_set;
orient_type_constraint[1] = orient_type_scene;
}
else {
orient_type_constraint[0] = orient_type_scene;
orient_type_constraint[1] = orient_type_scene != V3D_ORIENT_GLOBAL ? V3D_ORIENT_GLOBAL :
V3D_ORIENT_LOCAL;
}
if (op && ((prop = RNA_struct_find_property(op->ptr, "orient_matrix")) &&
@ -1693,36 +1706,27 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
RNA_property_is_set(op->ptr, prop)) {
orient_type_matrix_set = RNA_property_enum_get(op->ptr, prop);
}
else if (orient_type_set != -1) {
orient_type_matrix_set = orient_type_set;
}
else {
orient_type_matrix_set = orient_type_default;
orient_type_matrix_set = orient_type_set = V3D_ORIENT_GLOBAL;
}
if (orient_type_matrix_set == orient_type_default) {
/* Set the original orientation in the contraint to be used for redo. */
orient_type_constraint = orient_type_default;
orient_index = 1;
if (orient_type_matrix_set == orient_type_set) {
/* Constraints are forced to use the custom matrix when redoing. */
orient_type_default = V3D_ORIENT_CUSTOM_MATRIX;
}
}
if (orient_type_default >= V3D_ORIENT_CUSTOM) {
if (orient_type_default >= V3D_ORIENT_CUSTOM + BIF_countTransformOrientation(C)) {
orient_type_default = V3D_ORIENT_GLOBAL;
}
else {
custom_orientation = BKE_scene_transform_orientation_find(
t->scene, orient_type_default - V3D_ORIENT_CUSTOM);
}
}
t->orientation.types[0] = orient_type_default;
t->orientation.types[1] = orient_type_constraint;
t->orientation.types[2] = orient_type_constraint != V3D_ORIENT_GLOBAL ? V3D_ORIENT_GLOBAL :
V3D_ORIENT_LOCAL;
t->orientation.types[1] = orient_type_constraint[0];
t->orientation.types[2] = orient_type_constraint[1];
t->orientation.custom = custom_orientation;
t->orientation.index = orient_index;
if (t->con.mode & CON_APPLY) {
t->orientation.index = 1;
}
}
if (op && ((prop = RNA_struct_find_property(op->ptr, "release_confirm")) &&