diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2021-04-01 17:19:31 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2021-04-01 17:20:32 +0300 |
commit | 6ec463a4b754bf69baf94ba6b3683655f6834ccd (patch) | |
tree | 01e760a04eaf8260ce24d21d083388abf5f50668 /source/blender/editors | |
parent | 952c4e41bb4dae0d1b4a36a316f6cf67c054afe0 (diff) |
Cleanup/Refactor: Transform Orientation: Use 'orient_index' instead 'orient_type'
`orient_index` is a more comprehensive value as it reveals both the type and index.
Differential Revision: https://developer.blender.org/D9595
Diffstat (limited to 'source/blender/editors')
6 files changed, 59 insertions, 71 deletions
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h index 8f1be847e2b..cb6fb0dba60 100644 --- a/source/blender/editors/include/ED_transform.h +++ b/source/blender/editors/include/ED_transform.h @@ -151,8 +151,7 @@ short ED_transform_calc_orientation_from_type_ex(const struct bContext *C, struct RegionView3D *rv3d, struct Object *ob, struct Object *obedit, - const short orientation_type, - int orientation_index_custom, + const short orientation_index, const int pivot_point); /* transform gizmos */ @@ -186,8 +185,7 @@ struct TransformCalcParams { uint use_only_center : 1; uint use_local_axis : 1; /* Use 'Scene.orientation_type' when zero, otherwise subtract one and use. */ - ushort orientation_type; - ushort orientation_index_custom; + ushort orientation_index; }; int ED_transform_calc_gizmo_stats(const struct bContext *C, const struct TransformCalcParams *params, diff --git a/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c b/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c index 3f258a0699a..ad91af73a71 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c @@ -143,7 +143,7 @@ static void WIDGETGROUP_tool_generic_refresh(const bContext *C, wmGizmoGroup *gz const bool hide = ED_transform_calc_gizmo_stats(C, &(struct TransformCalcParams){ .use_only_center = true, - .orientation_type = orientation + 1, + .orientation_index = orientation + 1, }, &tbounds) == 0; diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c index 27df29afd8d..7a780df0def 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.c +++ b/source/blender/editors/transform/transform_gizmo_3d.c @@ -512,11 +512,11 @@ static void protectflag_to_drawflags(short protectflag, short *drawflags) /* for pose mode */ static void protectflag_to_drawflags_pchan(RegionView3D *rv3d, const bPoseChannel *pchan, - short orientation_type) + short orientation_index) { /* Protect-flags apply to local space in pose mode, so only let them influence axis * visibility if we show the global orientation, otherwise it's confusing. */ - if (orientation_type == V3D_ORIENT_LOCAL) { + if (orientation_index == V3D_ORIENT_LOCAL) { protectflag_to_drawflags(pchan->protectflag, &rv3d->twdrawflag); } } @@ -657,12 +657,9 @@ int ED_transform_calc_gizmo_stats(const bContext *C, int a, totsel = 0; const int pivot_point = scene->toolsettings->transform_pivot_point; - const short orientation_type = params->orientation_type ? - (params->orientation_type - 1) : - scene->orientation_slots[SCE_ORIENT_DEFAULT].type; - const short orientation_index_custom = - params->orientation_type ? params->orientation_index_custom : - scene->orientation_slots[SCE_ORIENT_DEFAULT].index_custom; + const short orient_index = params->orientation_index ? + (params->orientation_index - 1) : + BKE_scene_orientation_get_index(scene, SCE_ORIENT_DEFAULT); /* transform widget matrix */ unit_m4(rv3d->twmat); @@ -678,7 +675,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, if (ob) { float mat[3][3]; ED_transform_calc_orientation_from_type_ex( - C, mat, scene, rv3d, ob, obedit, orientation_type, orientation_index_custom, pivot_point); + C, mat, scene, rv3d, ob, obedit, orient_index, pivot_point); copy_m4_m3(rv3d->twmat, mat); } @@ -976,7 +973,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, Bone *bone = pchan->bone; if (bone && (bone->flag & BONE_TRANSFORM)) { calc_tw_center_with_matrix(tbounds, pchan->pose_head, use_mat_local, mat_local); - protectflag_to_drawflags_pchan(rv3d, pchan, orientation_type); + protectflag_to_drawflags_pchan(rv3d, pchan, orient_index); } } totsel += totsel_iter; @@ -1063,7 +1060,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, /* Protect-flags apply to world space in object mode, so only let them influence axis * visibility if we show the global orientation, otherwise it's confusing. */ - if (orientation_type == V3D_ORIENT_GLOBAL) { + if (orient_index == V3D_ORIENT_GLOBAL) { protectflag_to_drawflags(base->object->protectflag, &rv3d->twdrawflag); } totsel++; @@ -1689,18 +1686,15 @@ static void WIDGETGROUP_gizmo_refresh(const bContext *C, wmGizmoGroup *gzgroup) } } - const TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get_from_flag( - scene, ggd->twtype_init); + const int orient_index = BKE_scene_orientation_get_index_from_flag(scene, ggd->twtype_init); /* skip, we don't draw anything anyway */ - if ((ggd->all_hidden = (ED_transform_calc_gizmo_stats( - C, - &(struct TransformCalcParams){ - .use_only_center = true, - .orientation_type = orient_slot->type + 1, - .orientation_index_custom = orient_slot->index_custom, - }, - &tbounds) == 0))) { + if ((ggd->all_hidden = (ED_transform_calc_gizmo_stats(C, + &(struct TransformCalcParams){ + .use_only_center = true, + .orientation_index = orient_index + 1, + }, + &tbounds) == 0))) { return; } @@ -2119,14 +2113,12 @@ static void WIDGETGROUP_xform_cage_refresh(const bContext *C, wmGizmoGroup *gzgr gzgroup->use_fallback_keymap = false; } - const TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get(scene, - SCE_ORIENT_SCALE); + const int orient_index = BKE_scene_orientation_get_index_from_flag(scene, SCE_ORIENT_SCALE); if ((ED_transform_calc_gizmo_stats(C, &(struct TransformCalcParams){ .use_local_axis = true, - .orientation_type = orient_slot->type + 1, - .orientation_index_custom = orient_slot->index_custom, + .orientation_index = orient_index + 1, }, &tbounds) == 0) || equals_v3v3(rv3d->tw_axis_min, rv3d->tw_axis_max)) { @@ -2335,14 +2327,14 @@ static void WIDGETGROUP_xform_shear_refresh(const bContext *C, wmGizmoGroup *gzg /* Needed to test view orientation changes. */ copy_m3_m4(xgzgroup->prev.viewinv_m3, rv3d->viewinv); - const TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get(scene, - SCE_ORIENT_ROTATE); + TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get_from_flag( + scene, SCE_ORIENT_ROTATE); + const int orient_index = BKE_scene_orientation_slot_get_index(orient_slot); if (ED_transform_calc_gizmo_stats(C, &(struct TransformCalcParams){ .use_local_axis = false, - .orientation_type = orient_slot->type + 1, - .orientation_index_custom = orient_slot->index_custom, + .orientation_index = orient_index + 1, }, &tbounds) == 0) { for (int i = 0; i < 3; i++) { diff --git a/source/blender/editors/transform/transform_gizmo_extrude_3d.c b/source/blender/editors/transform/transform_gizmo_extrude_3d.c index 63c8efdd475..ed6c3eb0255 100644 --- a/source/blender/editors/transform/transform_gizmo_extrude_3d.c +++ b/source/blender/editors/transform/transform_gizmo_extrude_3d.c @@ -25,6 +25,7 @@ #include "BKE_context.h" #include "BKE_global.h" +#include "BKE_scene.h" #include "RNA_access.h" #include "RNA_define.h" @@ -88,7 +89,7 @@ typedef struct GizmoExtrudeGroup { struct { float normal_mat3[3][3]; /* use Z axis for normal. */ - int orientation_type; + int orientation_index; } data; wmOperatorType *ot_extrude; @@ -254,8 +255,8 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup) axis_type = RNA_property_enum_get(&ptr, ggd->gzgt_axis_type_prop); } - ggd->data.orientation_type = scene->orientation_slots[SCE_ORIENT_DEFAULT].type; - const bool use_normal = ((ggd->data.orientation_type != V3D_ORIENT_NORMAL) || + ggd->data.orientation_index = BKE_scene_orientation_get_index(scene, SCE_ORIENT_DEFAULT); + const bool use_normal = ((ggd->data.orientation_index != V3D_ORIENT_NORMAL) || (axis_type == EXTRUDE_AXIS_NORMAL)); const int axis_len_used = use_normal ? 4 : 3; @@ -265,7 +266,7 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup) struct TransformBounds tbounds_normal; if (!ED_transform_calc_gizmo_stats(C, &(struct TransformCalcParams){ - .orientation_type = V3D_ORIENT_NORMAL + 1, + .orientation_index = V3D_ORIENT_NORMAL + 1, }, &tbounds_normal)) { unit_m3(tbounds_normal.axis); @@ -276,7 +277,7 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup) /* TODO(campbell): run second since this modifies the 3D view, it should not. */ if (!ED_transform_calc_gizmo_stats(C, &(struct TransformCalcParams){ - .orientation_type = ggd->data.orientation_type + 1, + .orientation_index = ggd->data.orientation_index + 1, }, &tbounds)) { return; @@ -391,7 +392,7 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup) static void gizmo_mesh_extrude_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) { GizmoExtrudeGroup *ggd = gzgroup->customdata; - switch (ggd->data.orientation_type) { + switch (ggd->data.orientation_index) { case V3D_ORIENT_VIEW: { RegionView3D *rv3d = CTX_wm_region_view3d(C); float mat[3][3]; @@ -451,7 +452,7 @@ static void gizmo_mesh_extrude_invoke_prepare(const bContext *UNUSED(C), if (i == 3) { use_normal_matrix = true; } - else if (ggd->data.orientation_type == V3D_ORIENT_NORMAL) { + else if (ggd->data.orientation_index == V3D_ORIENT_NORMAL) { use_normal_matrix = true; } if (use_normal_matrix) { diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 1470d3b7059..5a5f478fc2b 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -492,12 +492,11 @@ void ED_transform_calc_orientation_from_type(const bContext *C, float r_mat[3][3 Object *obedit = CTX_data_edit_object(C); RegionView3D *rv3d = region->regiondata; Object *ob = OBACT(view_layer); - const short orientation_type = scene->orientation_slots[SCE_ORIENT_DEFAULT].type; - const short orientation_index_custom = scene->orientation_slots[SCE_ORIENT_DEFAULT].index_custom; + const short orient_index = BKE_scene_orientation_get_index(scene, SCE_ORIENT_DEFAULT); const int pivot_point = scene->toolsettings->transform_pivot_point; ED_transform_calc_orientation_from_type_ex( - C, r_mat, scene, rv3d, ob, obedit, orientation_type, orientation_index_custom, pivot_point); + C, r_mat, scene, rv3d, ob, obedit, orient_index, pivot_point); } /** @@ -516,11 +515,10 @@ short ED_transform_calc_orientation_from_type_ex(const bContext *C, RegionView3D *rv3d, Object *ob, Object *obedit, - const short orientation_type, - int orientation_index_custom, + const short orientation_index, const int pivot_point) { - switch (orientation_type) { + switch (orientation_index) { case V3D_ORIENT_GIMBAL: { if (ob && gimbal_axis(ob, r_mat)) { break; @@ -577,24 +575,28 @@ short ED_transform_calc_orientation_from_type_ex(const bContext *C, } case V3D_ORIENT_CUSTOM: default: { - BLI_assert(orientation_type >= V3D_ORIENT_CUSTOM); + BLI_assert(orientation_index >= V3D_ORIENT_CUSTOM); + int orientation_index_custom = orientation_index - V3D_ORIENT_CUSTOM; TransformOrientation *custom_orientation = BKE_scene_transform_orientation_find( scene, orientation_index_custom); applyTransformOrientation(custom_orientation, r_mat, NULL); - return V3D_ORIENT_CUSTOM + orientation_index_custom; + break; } } - return orientation_type; + return orientation_index; } /* Sets the matrix of the specified space orientation. * If the matrix cannot be obtained, an orientation different from the one * informed is returned */ -short transform_orientation_matrix_get( - bContext *C, TransInfo *t, short orientation, const float custom[3][3], float r_spacemtx[3][3]) +short transform_orientation_matrix_get(bContext *C, + TransInfo *t, + short orient_index, + const float custom[3][3], + float r_spacemtx[3][3]) { - if (orientation == V3D_ORIENT_CUSTOM_MATRIX) { + if (orient_index == V3D_ORIENT_CUSTOM_MATRIX) { copy_m3_m3(r_spacemtx, custom); return V3D_ORIENT_CUSTOM_MATRIX; } @@ -603,24 +605,20 @@ short transform_orientation_matrix_get( Object *obedit = CTX_data_edit_object(C); Scene *scene = t->scene; RegionView3D *rv3d = NULL; - int orientation_index_custom = 0; - - if (orientation >= V3D_ORIENT_CUSTOM) { - orientation_index_custom = orientation - V3D_ORIENT_CUSTOM; - orientation = V3D_ORIENT_CUSTOM; - } - else if (ob && (ob->mode & OB_MODE_ALL_WEIGHT_PAINT) && !(t->options & CTX_PAINT_CURVE)) { - Object *ob_armature = transform_object_deform_pose_armature_get(t, ob); - if (ob_armature) { - ob = ob_armature; - } - } if ((t->spacetype == SPACE_VIEW3D) && t->region && (t->region->regiontype == RGN_TYPE_WINDOW)) { rv3d = t->region->regiondata; + + if (ob && (ob->mode & OB_MODE_ALL_WEIGHT_PAINT) && !(t->options & CTX_PAINT_CURVE)) { + Object *ob_armature = transform_object_deform_pose_armature_get(t, ob); + if (ob_armature) { + /* The armature matrix is used for GIMBAL, NORMAL and LOCAL orientations. */ + ob = ob_armature; + } + } } - short orient_type = ED_transform_calc_orientation_from_type_ex( + short r_orient_index = ED_transform_calc_orientation_from_type_ex( C, r_spacemtx, /* extra args (can be accessed from context) */ @@ -628,13 +626,12 @@ short transform_orientation_matrix_get( rv3d, ob, obedit, - orientation, - orientation_index_custom, + orient_index, t->around); if (rv3d && (t->options & CTX_PAINT_CURVE)) { /* Screen space in the 3d region. */ - if (orient_type == V3D_ORIENT_VIEW) { + if (r_orient_index == V3D_ORIENT_VIEW) { unit_m3(r_spacemtx); } else { @@ -643,7 +640,7 @@ short transform_orientation_matrix_get( } } - return orient_type; + return r_orient_index; } const char *transform_orientations_spacename_get(TransInfo *t, const short orient_type) diff --git a/source/blender/editors/transform/transform_orientations.h b/source/blender/editors/transform/transform_orientations.h index e9c146a6853..de8c9b165c1 100644 --- a/source/blender/editors/transform/transform_orientations.h +++ b/source/blender/editors/transform/transform_orientations.h @@ -27,7 +27,7 @@ struct TransInfo; short transform_orientation_matrix_get(struct bContext *C, struct TransInfo *t, - short orientation, + short orient_index, const float custom[3][3], float r_spacemtx[3][3]); const char *transform_orientations_spacename_get(struct TransInfo *t, const short orient_type); |