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/blenkernel/intern/scene.c | |
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/blenkernel/intern/scene.c')
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 3de1ddb1e1e..05603efb2c3 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -864,7 +864,9 @@ void BKE_scene_init(Scene *sce) sce->toolsettings->annotate_v3d_align = GP_PROJECT_VIEWSPACE | GP_PROJECT_CURSOR; sce->toolsettings->annotate_thickness = 3; - sce->orientation_index_custom = -1; + for (int i = 0; i < ARRAY_SIZE(sce->orientation_slots); i++) { + sce->orientation_slots[i].index_custom = -1; + } /* Master Collection */ sce->master_collection = BKE_collection_master_add(); @@ -1321,7 +1323,6 @@ float BKE_scene_frame_get_from_ctime(const Scene *scene, const float frame) return ctime; } - /** * Sets the frame int/float components. */ @@ -1332,6 +1333,52 @@ void BKE_scene_frame_set(struct Scene *scene, double cfra) scene->r.cfra = (int)intpart; } + +/* -------------------------------------------------------------------- */ +/** \name Scene Orientation Slots + * \{ */ + +TransformOrientationSlot *BKE_scene_orientation_slot_get(Scene *scene, int flag) +{ + BLI_assert(flag && !(flag & ~(SCE_GIZMO_SHOW_TRANSLATE | SCE_GIZMO_SHOW_ROTATE | SCE_GIZMO_SHOW_SCALE))); + int index = SCE_ORIENT_DEFAULT; + if (flag & SCE_GIZMO_SHOW_TRANSLATE) { + index = SCE_ORIENT_TRANSLATE; + } + else if (flag & SCE_GIZMO_SHOW_ROTATE) { + index = SCE_ORIENT_ROTATE; + } + else if (flag & SCE_GIZMO_SHOW_SCALE) { + index = SCE_ORIENT_SCALE; + } + + if ((scene->orientation_slots[index].flag & SELECT) == 0) { + index = SCE_ORIENT_DEFAULT; + } + return &scene->orientation_slots[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 BKE_scene_orientation_slot_set_index(TransformOrientationSlot *orient_slot, int orientation) +{ + const bool is_custom = orientation >= V3D_MANIP_CUSTOM; + orient_slot->type = is_custom ? V3D_MANIP_CUSTOM : orientation; + orient_slot->index_custom = is_custom ? (orientation - V3D_MANIP_CUSTOM) : -1; +} + +int BKE_scene_orientation_slot_get_index(const TransformOrientationSlot *orient_slot) +{ + return (orient_slot->type == V3D_MANIP_CUSTOM) ? (orient_slot->type + orient_slot->index_custom) : orient_slot->type; +} + +/** \} */ + + /* That's like really a bummer, because currently animation data for armatures * might want to use pose, and pose might be missing on the object. * This happens when changing visible layers, which leads to situations when @@ -2166,11 +2213,16 @@ void BKE_scene_transform_orientation_remove( Scene *scene, TransformOrientation *orientation) { const int orientation_index = BKE_scene_transform_orientation_get_index(scene, orientation); - if (scene->orientation_index_custom == orientation_index) { - /* could also use orientation_index-- */ - scene->orientation_type = V3D_MANIP_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->index_custom == orientation_index) { + /* could also use orientation_index-- */ + orient_slot->type = V3D_MANIP_GLOBAL; + orient_slot->index_custom = -1; + } } + BLI_freelinkN(&scene->transform_spaces, orientation); } |