diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-06-30 07:37:37 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-06-30 07:37:37 +0400 |
commit | 730a1556a655456248892cfa1f9ea5288791bda0 (patch) | |
tree | ba8cc669a8914ce51983e4d3524379205068e21f /source/blender | |
parent | 5588e45f0197694d14ba92b6097ccdfbb8e1ed66 (diff) |
Fix T40867: Autokeyframe in camera view
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/include/ED_view3d.h | 7 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_camera_control.c | 24 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 73 |
3 files changed, 82 insertions, 22 deletions
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 43059d9af91..76839747076 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -332,6 +332,13 @@ void ED_view3d_camera_lock_init(struct View3D *v3d, struct RegionView3D *rv3d); /* copy the view to the camera, return true if */ bool ED_view3d_camera_lock_sync(struct View3D *v3d, struct RegionView3D *rv3d); +bool ED_view3d_camera_autokey( + struct Scene *scene, struct ID *id_key, + struct bContext *C, const bool do_rotate, const bool do_translate); +bool ED_view3d_camera_lock_autokey( + struct View3D *v3d, struct RegionView3D *rv3d, + struct bContext *C, const bool do_rotate, const bool do_translate); + void ED_view3D_lock_clear(struct View3D *v3d); struct BGpic *ED_view3D_background_image_new(struct View3D *v3d); diff --git a/source/blender/editors/space_view3d/view3d_camera_control.c b/source/blender/editors/space_view3d/view3d_camera_control.c index 230df49f386..e96db2b220f 100644 --- a/source/blender/editors/space_view3d/view3d_camera_control.c +++ b/source/blender/editors/space_view3d/view3d_camera_control.c @@ -272,28 +272,8 @@ void ED_view3d_cameracontrol_update( } /* record the motion */ - if (use_autokey && autokeyframe_cfra_can_key(scene, id_key)) { - ListBase dsources = {NULL, NULL}; - - /* add data-source override for the camera object */ - ANIM_relative_keyingset_add_source(&dsources, id_key, NULL, NULL); - - /* insert keyframes - * 1) on the first frame - * 2) on each subsequent frame - * TODO: need to check in future that frame changed before doing this - */ - if (do_rotate) { - struct KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); - } - if (do_translate) { - struct KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOCATION_ID); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); - } - - /* free temp data */ - BLI_freelistN(&dsources); + if (use_autokey) { + ED_view3d_camera_autokey(scene, id_key, C, do_rotate, do_translate); } } diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 26ede27bb08..cc4aca91318 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -71,6 +71,7 @@ #include "ED_armature.h" #include "ED_particle.h" +#include "ED_keyframing.h" #include "ED_screen.h" #include "ED_transform.h" #include "ED_mesh.h" @@ -183,6 +184,72 @@ bool ED_view3d_camera_lock_sync(View3D *v3d, RegionView3D *rv3d) } } +bool ED_view3d_camera_autokey( + Scene *scene, ID *id_key, + struct bContext *C, const bool do_rotate, const bool do_translate) +{ + if (autokeyframe_cfra_can_key(scene, id_key)) { + ListBase dsources = {NULL, NULL}; + + /* add data-source override for the camera object */ + ANIM_relative_keyingset_add_source(&dsources, id_key, NULL, NULL); + + /* insert keyframes + * 1) on the first frame + * 2) on each subsequent frame + * TODO: need to check in future that frame changed before doing this + */ + if (do_rotate) { + struct KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID); + ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); + } + if (do_translate) { + struct KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOCATION_ID); + ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); + } + + /* free temp data */ + BLI_freelistN(&dsources); + + return true; + } + else { + return false; + } +} + +/** + * Call after modifying a locked view. + * + * \note Not every view edit currently auto-keys (numpad for eg), + * this is complicated because of smoothview. + */ +bool ED_view3d_camera_lock_autokey( + View3D *v3d, RegionView3D *rv3d, + struct bContext *C, const bool do_rotate, const bool do_translate) +{ + /* similar to ED_view3d_cameracontrol_update */ + if (ED_view3d_camera_lock_check(v3d, rv3d)) { + Scene *scene = CTX_data_scene(C); + ID *id_key; + Object *root_parent; + if ((U.uiflag & USER_CAM_LOCK_NO_PARENT) == 0 && (root_parent = v3d->camera->parent)) { + while (root_parent->parent) { + root_parent = root_parent->parent; + } + id_key = &root_parent->id; + } + else { + id_key = &v3d->camera->id; + } + + return ED_view3d_camera_autokey(scene, id_key, C, do_rotate, do_translate); + } + else { + return false; + } +} + /** * For viewport operators that exit camera persp. * @@ -1052,7 +1119,9 @@ static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event) viewrotate_apply(vod, event->x, event->y); } else if (event_code == VIEW_CONFIRM) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, true, true); ED_view3d_depth_tag_update(vod->rv3d); + viewops_data_free(C, op); return OPERATOR_FINISHED; @@ -1860,6 +1929,7 @@ static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event) viewmove_apply(vod, event->x, event->y); } else if (event_code == VIEW_CONFIRM) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); ED_view3d_depth_tag_update(vod->rv3d); viewops_data_free(C, op); @@ -2125,6 +2195,7 @@ static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event) viewzoom_apply(vod, &event->x, U.viewzoom, (U.uiflag & USER_ZOOM_INVERT) != 0); } else if (event_code == VIEW_CONFIRM) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); ED_view3d_depth_tag_update(vod->rv3d); viewops_data_free(C, op); @@ -2385,6 +2456,7 @@ static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event) viewdolly_apply(vod, event->x, event->y, (U.uiflag & USER_ZOOM_INVERT) != 0); } else if (event_code == VIEW_CONFIRM) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); ED_view3d_depth_tag_update(vod->rv3d); viewops_data_free(C, op); @@ -3867,6 +3939,7 @@ static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event) viewroll_apply(vod, event->x, event->y); } else if (event_code == VIEW_CONFIRM) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, true, false); ED_view3d_depth_tag_update(vod->rv3d); viewops_data_free(C, op); |