diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-12-19 12:51:04 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-12-19 12:57:51 +0300 |
commit | f7dc6a63fb5a62eb6141fee375e30d94c1d83fa8 (patch) | |
tree | cdf3a5c3d50bc893a98e52c48a7a71a9a70a7c72 /source/blender/editors/transform | |
parent | 231ea39ed154b8284f45e97b10fbb699e79358c3 (diff) |
Gizmo: optional custom orientations for transform
This aims to resolve a conflict where some users want to keep keyboard
axis setting global, even when the orientation is set to something else.
Move/rotate/scale can optionally each have a separate orientation.
Some UI changes will be made next.
Diffstat (limited to 'source/blender/editors/transform')
7 files changed, 92 insertions, 46 deletions
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 0f555bcc5b7..7509b88ccff 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -2147,10 +2147,11 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op) !RNA_property_is_set(op->ptr, prop) && (t->orientation.user != V3D_MANIP_CUSTOM_MATRIX)) { - t->scene->orientation_type = t->orientation.user; - BLI_assert(((t->scene->orientation_index_custom == -1) && (t->orientation.custom == NULL)) || + TransformOrientationSlot *orient_slot = &t->scene->orientation_slots[SCE_ORIENT_DEFAULT]; + orient_slot->type = t->orientation.user; + BLI_assert(((orient_slot->index_custom == -1) && (t->orientation.custom == NULL)) || (BKE_scene_transform_orientation_get_index( - t->scene, t->orientation.custom) == t->scene->orientation_index_custom)); + t->scene, t->orientation.custom) == orient_slot->index_custom)); } } } diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 75044e77110..3970261ac02 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -509,7 +509,7 @@ typedef struct TransInfo { short user_alt; short index; short *types[2]; - /* this gets used when current_orientation is V3D_MANIP_CUSTOM */ + /* this gets used when custom_orientation is V3D_MANIP_CUSTOM */ TransformOrientation *custom; } orientation; short gizmo_flag; /* backup from view3d, to restore on end */ diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index c1a2eb218cf..f1dc5525dbc 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -1401,9 +1401,9 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve t->around = V3D_AROUND_CURSOR; } - t->orientation.user = t->scene->orientation_type; - t->orientation.custom = BKE_scene_transform_orientation_find( - t->scene, t->scene->orientation_index_custom); + TransformOrientationSlot *orient_slot = &t->scene->orientation_slots[SCE_ORIENT_DEFAULT]; + t->orientation.user = orient_slot->type; + t->orientation.custom = BKE_scene_transform_orientation_find(t->scene, orient_slot->index_custom); t->orientation.index = 0; ARRAY_SET_ITEMS( diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c index 5a26245c14d..b17a345ee09 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.c +++ b/source/blender/editors/transform/transform_gizmo_3d.c @@ -638,19 +638,21 @@ void ED_transform_calc_orientation_from_type( Object *obedit = CTX_data_edit_object(C); RegionView3D *rv3d = ar->regiondata; Object *ob = OBACT(view_layer); - const short orientation_type = scene->orientation_type; + 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 int pivot_point = scene->toolsettings->transform_pivot_point; ED_transform_calc_orientation_from_type_ex( C, r_mat, - scene, rv3d, ob, obedit, orientation_type, pivot_point); + scene, rv3d, ob, obedit, orientation_type, orientation_index_custom, pivot_point); } void ED_transform_calc_orientation_from_type_ex( const bContext *C, float r_mat[3][3], /* extra args (can be accessed from context) */ Scene *scene, RegionView3D *rv3d, Object *ob, Object *obedit, - const short orientation_type, const int pivot_point) + const short orientation_type, int orientation_index_custom, + const int pivot_point) { bool ok = false; @@ -712,7 +714,7 @@ void ED_transform_calc_orientation_from_type_ex( case V3D_MANIP_CUSTOM: { TransformOrientation *custom_orientation = BKE_scene_transform_orientation_find( - scene, scene->orientation_index_custom); + scene, orientation_index_custom); if (applyTransformOrientation(custom_orientation, r_mat, NULL)) { ok = true; } @@ -759,11 +761,14 @@ int ED_transform_calc_gizmo_stats( /* global, local or normal orientation? * if we could check 'totsel' now, this should be skipped with no selection. */ if (ob) { - const short orientation_type = params->orientation_type ? (params->orientation_type - 1) : scene->orientation_type; + 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; float mat[3][3]; ED_transform_calc_orientation_from_type_ex( C, mat, - scene, rv3d, ob, obedit, orientation_type, pivot_point); + scene, rv3d, ob, obedit, orientation_type, orientation_index_custom, pivot_point); copy_m4_m3(rv3d->twmat, mat); } @@ -1206,6 +1211,8 @@ static void gizmo_xform_message_subscribe( wmGizmoGroup *gzgroup, struct wmMsgBus *mbus, Scene *scene, bScreen *UNUSED(screen), ScrArea *UNUSED(sa), ARegion *ar, const void *type_fn) { + GizmoGroup *ggd = gzgroup->customdata; + /* Subscribe to view properties */ wmMsgSubscribeValue msg_sub_value_gz_tag_refresh = { .owner = ar, @@ -1217,10 +1224,10 @@ static void gizmo_xform_message_subscribe( RNA_id_pointer_create(&scene->id, &scene_ptr); { - extern PropertyRNA rna_Scene_transform_orientation; + extern PropertyRNA rna_Scene_transform_orientation_slots; extern PropertyRNA rna_Scene_cursor_location; const PropertyRNA *props[] = { - &rna_Scene_transform_orientation, + &rna_Scene_transform_orientation_slots, (scene->toolsettings->transform_pivot_point == V3D_AROUND_CURSOR) ? &rna_Scene_cursor_location : NULL, }; for (int i = 0; i < ARRAY_SIZE(props); i++) { @@ -1230,15 +1237,30 @@ static void gizmo_xform_message_subscribe( } } + TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get(scene, ggd->twtype_init); + PointerRNA orient_ref_ptr; + RNA_pointer_create(&scene->id, &RNA_TransformOrientationSlot, orient_slot, &orient_ref_ptr); + { + extern PropertyRNA rna_TransformOrientationSlot_type; + extern PropertyRNA rna_TransformOrientationSlot_use; + const PropertyRNA *props[] = { + &rna_TransformOrientationSlot_type, + &rna_TransformOrientationSlot_use, + }; + for (int i = 0; i < ARRAY_SIZE(props); i++) { + if (props[i]) { + WM_msg_subscribe_rna(mbus, &orient_ref_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__); + } + } + } + PointerRNA toolsettings_ptr; RNA_pointer_create(&scene->id, &RNA_ToolSettings, scene->toolsettings, &toolsettings_ptr); if (type_fn == TRANSFORM_GGT_gizmo) { extern PropertyRNA rna_ToolSettings_transform_pivot_point; - extern PropertyRNA rna_ToolSettings_use_gizmo_mode; const PropertyRNA *props[] = { &rna_ToolSettings_transform_pivot_point, - &rna_ToolSettings_use_gizmo_mode, }; for (int i = 0; i < ARRAY_SIZE(props); i++) { WM_msg_subscribe_rna(mbus, &toolsettings_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__); @@ -1610,12 +1632,12 @@ static void WIDGETGROUP_gizmo_setup(const bContext *C, wmGizmoGroup *gzgroup) static void WIDGETGROUP_gizmo_refresh(const bContext *C, wmGizmoGroup *gzgroup) { GizmoGroup *ggd = gzgroup->customdata; + Scene *scene = CTX_data_scene(C); ARegion *ar = CTX_wm_region(C); RegionView3D *rv3d = ar->regiondata; struct TransformBounds tbounds; if (ggd->use_twtype_refresh) { - Scene *scene = CTX_data_scene(C); ggd->twtype = scene->toolsettings->gizmo_flag & ggd->twtype_init; if (ggd->twtype != ggd->twtype_prev) { ggd->twtype_prev = ggd->twtype; @@ -1623,11 +1645,15 @@ static void WIDGETGROUP_gizmo_refresh(const bContext *C, wmGizmoGroup *gzgroup) } } + const TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get(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))) { return; @@ -1757,7 +1783,8 @@ static void WIDGETGROUP_gizmo_draw_prepare(const bContext *C, wmGizmoGroup *gzgr if (!equals_m3m3(viewinv_m3, ggd->prev.viewinv_m3)) { { Scene *scene = CTX_data_scene(C); - switch (scene->orientation_type) { + const TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get(scene, ggd->twtype_init); + switch (orient_slot->type) { case V3D_MANIP_VIEW: { WIDGETGROUP_gizmo_refresh(C, gzgroup); @@ -1774,8 +1801,26 @@ static void WIDGETGROUP_gizmo_invoke_prepare( const bContext *C, wmGizmoGroup *gzgroup, wmGizmo *gz) { - /* Support shift click to constrain axis. */ GizmoGroup *ggd = gzgroup->customdata; + + /* Support gizmo spesific orientation. */ + { + Scene *scene = CTX_data_scene(C); + wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, 0); + PointerRNA *ptr = &gzop->ptr; + PropertyRNA *prop_constraint_orientation = RNA_struct_find_property(ptr, "constraint_orientation"); + const TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get(scene, ggd->twtype_init); + if (orient_slot == &scene->orientation_slots[SCE_ORIENT_DEFAULT]) { + RNA_property_unset(ptr, prop_constraint_orientation); + } + else { + /* TODO: APIfunction */ + int index = BKE_scene_orientation_slot_get_index(orient_slot); + RNA_property_enum_set(ptr, prop_constraint_orientation, index); + } + } + + /* Support shift click to constrain axis. */ const int axis_idx = BLI_array_findindex(ggd->gizmos, ARRAY_SIZE(ggd->gizmos), &gz); int axis = -1; switch (axis_idx) { @@ -1932,15 +1977,20 @@ static void WIDGETGROUP_xform_cage_refresh(const bContext *C, wmGizmoGroup *gzgr { ARegion *ar = CTX_wm_region(C); RegionView3D *rv3d = ar->regiondata; + Scene *scene = CTX_data_scene(C); struct XFormCageWidgetGroup *xgzgroup = gzgroup->customdata; wmGizmo *gz = xgzgroup->gizmo; struct TransformBounds tbounds; + const TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get(scene, SCE_GIZMO_SHOW_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, }, &tbounds) == 0) || equals_v3v3(rv3d->tw_axis_min, rv3d->tw_axis_max)) { @@ -2016,7 +2066,8 @@ static void WIDGETGROUP_xform_cage_draw_prepare(const bContext *C, wmGizmoGroup RegionView3D *rv3d = CTX_wm_region_view3d(C); { Scene *scene = CTX_data_scene(C); - switch (scene->orientation_type) { + const TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get(scene, SCE_GIZMO_SHOW_SCALE); + switch (orient_slot->type) { case V3D_MANIP_VIEW: { float viewinv_m3[3][3]; @@ -2173,7 +2224,9 @@ static void WIDGETGROUP_xform_shear_draw_prepare(const bContext *C, wmGizmoGroup RegionView3D *rv3d = CTX_wm_region_view3d(C); { Scene *scene = CTX_data_scene(C); - switch (scene->orientation_type) { + /* Shear is like rotate, use the rotate setting. */ + const TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get(scene, SCE_GIZMO_SHOW_ROTATE); + switch (orient_slot->type) { case V3D_MANIP_VIEW: { float viewinv_m3[3][3]; diff --git a/source/blender/editors/transform/transform_gizmo_extrude_3d.c b/source/blender/editors/transform/transform_gizmo_extrude_3d.c index 1dc50f476fa..441141e9718 100644 --- a/source/blender/editors/transform/transform_gizmo_extrude_3d.c +++ b/source/blender/editors/transform/transform_gizmo_extrude_3d.c @@ -233,7 +233,7 @@ 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_type; + ggd->data.orientation_type = scene->orientation_slots[SCE_ORIENT_DEFAULT].type; const bool use_normal = ( (ggd->data.orientation_type != V3D_MANIP_NORMAL) || (axis_type == EXTRUDE_AXIS_NORMAL)); @@ -431,7 +431,7 @@ static void gizmo_mesh_extrude_message_subscribe( }; { - WM_msg_subscribe_rna_anon_prop(mbus, Scene, transform_orientation, &msg_sub_value_gz_tag_refresh); + WM_msg_subscribe_rna_anon_prop(mbus, TransformOrientationSlot, type, &msg_sub_value_gz_tag_refresh); } diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index d11cfa8d3d3..5a3575c04d9 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -39,6 +39,7 @@ #include "BKE_global.h" #include "BKE_report.h" #include "BKE_editmesh.h" +#include "BKE_scene.h" #include "RNA_access.h" #include "RNA_define.h" @@ -168,12 +169,12 @@ static int select_orientation_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); int orientation = RNA_enum_get(op->ptr, "orientation"); - BIF_selectTransformOrientationValue(scene, orientation); + BKE_scene_orientation_slot_set_index(&scene->orientation_slots[SCE_ORIENT_DEFAULT], orientation); WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL); struct wmMsgBus *mbus = CTX_wm_message_bus(C); - WM_msg_publish_rna_prop(mbus, &scene->id, scene, Scene, transform_orientation); + WM_msg_publish_rna_prop(mbus, &scene->id, scene, TransformOrientationSlot, type); return OPERATOR_FINISHED; } @@ -215,7 +216,7 @@ static void TRANSFORM_OT_select_orientation(struct wmOperatorType *ot) static int delete_orientation_exec(bContext *C, wmOperator *UNUSED(op)) { Scene *scene = CTX_data_scene(C); - BIF_removeTransformOrientationIndex(C, scene->orientation_index_custom); + BIF_removeTransformOrientationIndex(C, scene->orientation_slots[SCE_ORIENT_DEFAULT].index_custom); WM_event_add_notifier(C, NC_SCENE | NA_EDITED, scene); @@ -234,7 +235,8 @@ static bool delete_orientation_poll(bContext *C) if (ED_operator_areaactive(C) == 0) return 0; - return (scene->orientation_type >= V3D_MANIP_CUSTOM) && (scene->orientation_index_custom != -1); + return ((scene->orientation_slots[SCE_ORIENT_DEFAULT].type >= V3D_MANIP_CUSTOM) && + (scene->orientation_slots[SCE_ORIENT_DEFAULT].index_custom != -1)); } static void TRANSFORM_OT_delete_orientation(struct wmOperatorType *ot) diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index a21882fc206..04999213c63 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -71,9 +71,12 @@ void BIF_clearTransformOrientation(bContext *C) BLI_freelistN(transform_orientations); - if (scene->orientation_type == V3D_MANIP_CUSTOM) { - scene->orientation_type = V3D_MANIP_GLOBAL; /* fallback to global */ - scene->orientation_index_custom = -1; + for (int i = 0; i < ARRAY_SIZE(scene->orientation_slots); i++) { + TransformOrientationSlot *orient_slot = &scene->orientation_slots[i]; + if (orient_slot->type == V3D_MANIP_CUSTOM) { + orient_slot->type = V3D_MANIP_GLOBAL; /* fallback to global */ + orient_slot->index_custom = -1; + } } } @@ -366,21 +369,8 @@ void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target) BLI_assert(index != -1); - scene->orientation_type = V3D_MANIP_CUSTOM; - scene->orientation_index_custom = index; -} - -/** - * Activate a transform orientation in a 3D view based on an enum value. - * - * \param orientation: If this is #V3D_MANIP_CUSTOM or greater, the custom transform orientation - * with index \a orientation - #V3D_MANIP_CUSTOM gets activated. - */ -void BIF_selectTransformOrientationValue(Scene *scene, int orientation) -{ - const bool is_custom = orientation >= V3D_MANIP_CUSTOM; - scene->orientation_type = is_custom ? V3D_MANIP_CUSTOM : orientation; - scene->orientation_index_custom = is_custom ? (orientation - V3D_MANIP_CUSTOM) : -1; + scene->orientation_slots[SCE_ORIENT_DEFAULT].type = V3D_MANIP_CUSTOM; + scene->orientation_slots[SCE_ORIENT_DEFAULT].index_custom = index; } int BIF_countTransformOrientation(const bContext *C) |