diff options
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 72 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_intern.h | 17 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 77 |
3 files changed, 89 insertions, 77 deletions
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index b09cbedb6fa..069541a3efe 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -2880,14 +2880,16 @@ static void view3d_from_minmax(bContext *C, View3D *v3d, ARegion *ar, if (rv3d->persp == RV3D_CAMOB && !ED_view3d_camera_lock_check(v3d, rv3d)) { rv3d->persp = RV3D_PERSP; - ED_view3d_smooth_view(C, v3d, ar, v3d->camera, NULL, - new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL, - smooth_viewtx); + ED_view3d_smooth_view( + C, v3d, ar, smooth_viewtx, + &(const V3D_SmoothParams){ + .camera_old=v3d->camera, .ofs = new_ofs, + .dist = ok_dist ? &new_dist : NULL}); } else { - ED_view3d_smooth_view(C, v3d, ar, NULL, NULL, - new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL, - smooth_viewtx); + ED_view3d_smooth_view( + C, v3d, ar, smooth_viewtx, + &(const V3D_SmoothParams){.ofs = new_ofs, .dist = ok_dist ? &new_dist : NULL}); } /* smooth view does viewlock RV3D_BOXVIEW copy */ @@ -3196,10 +3198,10 @@ static int viewcenter_cursor_exec(bContext *C, wmOperator *op) /* non camera center */ float new_ofs[3]; negate_v3_v3(new_ofs, ED_view3d_cursor3d_get(scene, v3d)); - ED_view3d_smooth_view(C, v3d, ar, NULL, NULL, - new_ofs, NULL, NULL, NULL, - smooth_viewtx); - + ED_view3d_smooth_view( + C, v3d, ar, smooth_viewtx, + &(const V3D_SmoothParams){.ofs = new_ofs}); + /* smooth view does viewlock RV3D_BOXVIEW copy */ } @@ -3243,9 +3245,9 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev ED_view3d_win_to_3d_int(ar, new_ofs, event->mval, new_ofs); } negate_v3(new_ofs); - ED_view3d_smooth_view(C, v3d, ar, NULL, NULL, - new_ofs, NULL, NULL, NULL, - smooth_viewtx); + ED_view3d_smooth_view( + C, v3d, ar, smooth_viewtx, + &(const V3D_SmoothParams){.ofs = new_ofs}); } return OPERATOR_FINISHED; @@ -3628,9 +3630,9 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) /* clamp after because we may have been zooming out */ CLAMP(new_dist, dist_range[0], dist_range[1]); - ED_view3d_smooth_view(C, v3d, ar, NULL, NULL, - new_ofs, NULL, &new_dist, NULL, - smooth_viewtx); + ED_view3d_smooth_view( + C, v3d, ar, smooth_viewtx, + &(const V3D_SmoothParams){.ofs = new_ofs, .dist = &new_dist}); if (rv3d->viewlock & RV3D_BOXVIEW) view3d_boxview_sync(CTX_wm_area(C), ar); @@ -3785,9 +3787,9 @@ static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar, if (rv3d->persp == RV3D_CAMOB && v3d->camera) { /* to camera */ - ED_view3d_smooth_view(C, v3d, ar, v3d->camera, NULL, - rv3d->ofs, quat, NULL, NULL, - smooth_viewtx); + ED_view3d_smooth_view( + C, v3d, ar, smooth_viewtx, + &(const V3D_SmoothParams){.camera_old = v3d->camera, .ofs = rv3d->ofs, .quat = quat}); } else if (orig_persp == RV3D_CAMOB && v3d->camera) { /* from camera */ @@ -3799,15 +3801,15 @@ static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar, /* so we animate _from_ the camera location */ ED_view3d_from_object(v3d->camera, rv3d->ofs, NULL, &rv3d->dist, NULL); - ED_view3d_smooth_view(C, v3d, ar, NULL, NULL, - ofs, quat, &dist, NULL, - smooth_viewtx); + ED_view3d_smooth_view( + C, v3d, ar, smooth_viewtx, + &(const V3D_SmoothParams){.ofs = ofs, .quat = quat, .dist = &dist}); } else { /* no camera involved */ - ED_view3d_smooth_view(C, v3d, ar, NULL, NULL, - NULL, quat, NULL, NULL, - smooth_viewtx); + ED_view3d_smooth_view( + C, v3d, ar, smooth_viewtx, + &(const V3D_SmoothParams){.quat = quat}); } } @@ -3896,9 +3898,11 @@ static int viewnumpad_exec(bContext *C, wmOperator *op) /* finally do snazzy view zooming */ rv3d->persp = RV3D_CAMOB; - ED_view3d_smooth_view(C, v3d, ar, NULL, v3d->camera, - rv3d->ofs, rv3d->viewquat, &rv3d->dist, &v3d->lens, - smooth_viewtx); + ED_view3d_smooth_view( + C, v3d, ar, smooth_viewtx, + &(const V3D_SmoothParams){ + .camera = v3d->camera, .ofs = rv3d->ofs, .quat = rv3d->viewquat, + .dist = &rv3d->dist, .lens = &v3d->lens}); } else { @@ -4031,9 +4035,9 @@ static int vieworbit_exec(bContext *C, wmOperator *op) smooth_viewtx = 0; } - ED_view3d_smooth_view(C, v3d, ar, NULL, NULL, - ofs_new_pt, quat_new, NULL, NULL, - smooth_viewtx); + ED_view3d_smooth_view( + C, v3d, ar, smooth_viewtx, + &(const V3D_SmoothParams){.ofs = ofs_new_pt, .quat = quat_new}); return OPERATOR_FINISHED; } @@ -4198,9 +4202,9 @@ static int viewroll_exec(bContext *C, wmOperator *op) negate_v3(mousevec); view_roll_angle(ar, quat_new, rv3d->viewquat, mousevec, angle); - ED_view3d_smooth_view(C, v3d, ar, NULL, NULL, - NULL, quat_new, NULL, NULL, - smooth_viewtx); + ED_view3d_smooth_view( + C, v3d, ar, smooth_viewtx, + &(const V3D_SmoothParams){.quat = quat_new}); viewops_data_free(C, op); return OPERATOR_FINISHED; diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index 2c6d76240d9..52b14d67350 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -208,19 +208,20 @@ void VIEW3D_OT_game_start(struct wmOperatorType *ot); bool ED_view3d_boundbox_clip_ex(const RegionView3D *rv3d, const struct BoundBox *bb, float obmat[4][4]); bool ED_view3d_boundbox_clip(RegionView3D *rv3d, const struct BoundBox *bb); +typedef struct V3D_SmoothParams { + struct Object *camera_old, *camera; + const float *ofs, *quat, *dist, *lens; +} V3D_SmoothParams; + void ED_view3d_smooth_view_ex( struct wmWindowManager *wm, struct wmWindow *win, struct ScrArea *sa, - struct View3D *v3d, struct ARegion *ar, - struct Object *camera_old, struct Object *camera, - const float *ofs, const float *quat, const float *dist, const float *lens, - const int smooth_viewtx); + struct View3D *v3d, struct ARegion *ar, const int smooth_viewtx, + const V3D_SmoothParams *sview); void ED_view3d_smooth_view( struct bContext *C, - struct View3D *v3d, struct ARegion *ar, - struct Object *camera_old, struct Object *camera, - const float *ofs, const float *quat, const float *dist, const float *lens, - const int smooth_viewtx); + struct View3D *v3d, struct ARegion *ar, const int smooth_viewtx, + const V3D_SmoothParams *sview); void view3d_winmatrix_set(ARegion *ar, const View3D *v3d, const rctf *rect); void view3d_viewmatrix_set(Scene *scene, const View3D *v3d, RegionView3D *rv3d); diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 2e9dcdc9ba6..1201f70ed94 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -168,10 +168,8 @@ static void view3d_smooth_view_state_restore(const struct SmoothView3DState *sms void ED_view3d_smooth_view_ex( /* avoid passing in the context */ wmWindowManager *wm, wmWindow *win, ScrArea *sa, - - View3D *v3d, ARegion *ar, Object *oldcamera, Object *camera, - const float *ofs, const float *quat, const float *dist, const float *lens, - const int smooth_viewtx) + View3D *v3d, ARegion *ar, const int smooth_viewtx, + const V3D_SmoothParams *sview) { RegionView3D *rv3d = ar->regiondata; struct SmoothView3DStore sms = {{0}}; @@ -199,19 +197,23 @@ void ED_view3d_smooth_view_ex( * camera to be moved or changed, so only when the camera is not being set should * we allow camera option locking to initialize the view settings from the camera. */ - if (camera == NULL && oldcamera == NULL) { + if (sview->camera == NULL && sview->camera_old == NULL) { ED_view3d_camera_lock_init(v3d, rv3d); } /* store the options we want to end with */ - if (ofs) copy_v3_v3(sms.dst.ofs, ofs); - if (quat) copy_qt_qt(sms.dst.quat, quat); - if (dist) sms.dst.dist = *dist; - if (lens) sms.dst.lens = *lens; - - if (camera) { - sms.dst.dist = ED_view3d_offset_distance(camera->obmat, ofs, VIEW3D_DIST_FALLBACK); - ED_view3d_from_object(camera, sms.dst.ofs, sms.dst.quat, &sms.dst.dist, &sms.dst.lens); + if (sview->ofs) + copy_v3_v3(sms.dst.ofs, sview->ofs); + if (sview->quat) + copy_qt_qt(sms.dst.quat, sview->quat); + if (sview->dist) + sms.dst.dist = *sview->dist; + if (sview->lens) + sms.dst.lens = *sview->lens; + + if (sview->camera) { + sms.dst.dist = ED_view3d_offset_distance(sview->camera->obmat, sview->ofs, VIEW3D_DIST_FALLBACK); + ED_view3d_from_object(sview->camera, sms.dst.ofs, sms.dst.quat, &sms.dst.dist, &sms.dst.lens); sms.to_camera = true; /* restore view3d values in end */ } @@ -219,7 +221,7 @@ void ED_view3d_smooth_view_ex( if (smooth_viewtx && v3d->drawtype != OB_RENDER) { bool changed = false; /* zero means no difference */ - if (oldcamera != camera) + if (sview->camera_old != sview->camera) changed = true; else if (sms.dst.dist != rv3d->dist) changed = true; @@ -234,10 +236,10 @@ void ED_view3d_smooth_view_ex( * so animate the view */ if (changed) { /* original values */ - if (oldcamera) { - sms.src.dist = ED_view3d_offset_distance(oldcamera->obmat, rv3d->ofs, 0.0f); + if (sview->camera_old) { + sms.src.dist = ED_view3d_offset_distance(sview->camera_old->obmat, rv3d->ofs, 0.0f); /* this */ - ED_view3d_from_object(oldcamera, sms.src.ofs, sms.src.quat, &sms.src.dist, &sms.src.lens); + ED_view3d_from_object(sview->camera_old, sms.src.ofs, sms.src.quat, &sms.src.dist, &sms.src.lens); } /* grid draw as floor */ if ((rv3d->viewlock & RV3D_LOCKED) == 0) { @@ -251,7 +253,7 @@ void ED_view3d_smooth_view_ex( * we can decrease the time allowed by * the angle between quats * this means small rotations wont lag */ - if (quat && !ofs && !dist) { + if (sview->quat && !sview->ofs && !sview->dist) { float vec1[3] = {0, 0, 1}, vec2[3] = {0, 0, 1}; float q1[4], q2[4]; @@ -269,8 +271,8 @@ void ED_view3d_smooth_view_ex( if (sms.to_camera) { /* use ortho if we move from an ortho view to an ortho camera */ rv3d->persp = (((rv3d->is_persp == false) && - (camera->type == OB_CAMERA) && - (((Camera *)camera->data)->type == CAM_ORTHO)) ? + (sview->camera->type == OB_CAMERA) && + (((Camera *)sview->camera->data)->type == CAM_ORTHO)) ? RV3D_ORTHO : RV3D_PERSP); } @@ -316,9 +318,8 @@ void ED_view3d_smooth_view_ex( void ED_view3d_smooth_view( bContext *C, - View3D *v3d, ARegion *ar, Object *oldcamera, Object *camera, - const float *ofs, const float *quat, const float *dist, const float *lens, - const int smooth_viewtx) + View3D *v3d, ARegion *ar, const int smooth_viewtx, + const struct V3D_SmoothParams *sview) { wmWindowManager *wm = CTX_wm_manager(C); wmWindow *win = CTX_wm_window(C); @@ -326,8 +327,8 @@ void ED_view3d_smooth_view( ED_view3d_smooth_view_ex( wm, win, sa, - v3d, ar, oldcamera, camera, - ofs, quat, dist, lens, smooth_viewtx); + v3d, ar, smooth_viewtx, + sview); } /* only meant for timer usage */ @@ -576,9 +577,12 @@ static int view3d_setobjectascamera_exec(bContext *C, wmOperator *op) if (camera_old != ob) { ED_view3d_lastview_store(rv3d); - ED_view3d_smooth_view(C, v3d, ar, camera_old, v3d->camera, - rv3d->ofs, rv3d->viewquat, &rv3d->dist, &v3d->lens, - smooth_viewtx); + ED_view3d_smooth_view( + C, v3d, ar, smooth_viewtx, + &(const V3D_SmoothParams){ + .camera_old = camera_old, .camera = v3d->camera, + .ofs = rv3d->ofs, .quat = rv3d->viewquat, + .dist = &rv3d->dist, .lens = &v3d->lens}); } WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS | NC_OBJECT | ND_DRAW, CTX_data_scene(C)); @@ -1308,10 +1312,11 @@ static bool view3d_localview_init( } ED_view3d_smooth_view_ex( - wm, win, sa, - v3d, ar, camera_old, NULL, - ofs_new, NULL, ok_dist ? &dist_new : NULL, NULL, - smooth_viewtx); + wm, win, sa, v3d, ar, smooth_viewtx, + &(const V3D_SmoothParams){ + .camera_old = camera_old, + .ofs = ofs_new, .quat = rv3d->viewquat, + .dist = ok_dist ? &dist_new : NULL, .lens = &v3d->lens}); } } @@ -1372,9 +1377,11 @@ static void restore_localviewdata(wmWindowManager *wm, wmWindow *win, Main *bmai ED_view3d_smooth_view_ex( wm, win, sa, - v3d, ar, camera_old_rv3d, camera_new_rv3d, - rv3d->localvd->ofs, rv3d->localvd->viewquat, &rv3d->localvd->dist, NULL, - smooth_viewtx); + v3d, ar, smooth_viewtx, + &(const V3D_SmoothParams){ + .camera_old = camera_old_rv3d, .camera = camera_new_rv3d, + .ofs = rv3d->localvd->ofs, .quat = rv3d->localvd->viewquat, + .dist = &rv3d->localvd->dist}); if (free) { MEM_freeN(rv3d->localvd); |