Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_view.c
| Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | static void view3d_smooth_view_state_restore(const struct SmoothView3DState *sms_state, | ||||
| rv3d->dist = sms_state->dist; | rv3d->dist = sms_state->dist; | ||||
| v3d->lens = sms_state->lens; | v3d->lens = sms_state->lens; | ||||
| } | } | ||||
| /* will start timer if appropriate */ | /* will start timer if appropriate */ | ||||
| /* the arguments are the desired situation */ | /* the arguments are the desired situation */ | ||||
| void ED_view3d_smooth_view_ex( | void ED_view3d_smooth_view_ex( | ||||
| /* avoid passing in the context */ | /* avoid passing in the context */ | ||||
| wmWindowManager *wm, wmWindow *win, ScrArea *sa, | const Depsgraph *depsgraph, wmWindowManager *wm, wmWindow *win, ScrArea *sa, | ||||
| View3D *v3d, ARegion *ar, const int smooth_viewtx, | View3D *v3d, ARegion *ar, const int smooth_viewtx, | ||||
| const V3D_SmoothParams *sview) | const V3D_SmoothParams *sview) | ||||
| { | { | ||||
| RegionView3D *rv3d = ar->regiondata; | RegionView3D *rv3d = ar->regiondata; | ||||
| struct SmoothView3DStore sms = {{0}}; | struct SmoothView3DStore sms = {{0}}; | ||||
| bool ok = false; | bool ok = false; | ||||
| /* initialize sms */ | /* initialize sms */ | ||||
| view3d_smooth_view_state_backup(&sms.dst, v3d, rv3d); | view3d_smooth_view_state_backup(&sms.dst, v3d, rv3d); | ||||
| view3d_smooth_view_state_backup(&sms.src, v3d, rv3d); | view3d_smooth_view_state_backup(&sms.src, v3d, rv3d); | ||||
| /* if smoothview runs multiple times... */ | /* if smoothview runs multiple times... */ | ||||
| if (rv3d->sms == NULL) { | if (rv3d->sms == NULL) { | ||||
| view3d_smooth_view_state_backup(&sms.org, v3d, rv3d); | view3d_smooth_view_state_backup(&sms.org, v3d, rv3d); | ||||
| } | } | ||||
| else { | else { | ||||
| Show All 32 Lines | if (sview->dyn_ofs) { | ||||
| copy_v3_v3(sms.dyn_ofs, sview->dyn_ofs); | copy_v3_v3(sms.dyn_ofs, sview->dyn_ofs); | ||||
| sms.use_dyn_ofs = true; | sms.use_dyn_ofs = true; | ||||
| /* calculate the final destination offset */ | /* calculate the final destination offset */ | ||||
| view3d_orbit_apply_dyn_ofs(sms.dst.ofs, sms.src.ofs, sms.src.quat, sms.dst.quat, sms.dyn_ofs); | view3d_orbit_apply_dyn_ofs(sms.dst.ofs, sms.src.ofs, sms.src.quat, sms.dst.quat, sms.dyn_ofs); | ||||
| } | } | ||||
| if (sview->camera) { | if (sview->camera) { | ||||
| sms.dst.dist = ED_view3d_offset_distance(sview->camera->obmat, sview->ofs, VIEW3D_DIST_FALLBACK); | Object* camera_eval = DEG_get_evaluated_object(depsgraph, sview->camera); | ||||
| ED_view3d_from_object(sview->camera, sms.dst.ofs, sms.dst.quat, &sms.dst.dist, &sms.dst.lens); | sms.dst.dist = ED_view3d_offset_distance(camera_eval->obmat, sview->ofs, VIEW3D_DIST_FALLBACK); | ||||
| ED_view3d_from_object(camera_eval, sms.dst.ofs, sms.dst.quat, &sms.dst.dist, &sms.dst.lens); | |||||
| sms.to_camera = true; /* restore view3d values in end */ | sms.to_camera = true; /* restore view3d values in end */ | ||||
| } | } | ||||
| /* skip smooth viewing for render engine draw */ | /* skip smooth viewing for render engine draw */ | ||||
| if (smooth_viewtx && v3d->drawtype != OB_RENDER) { | if (smooth_viewtx && v3d->drawtype != OB_RENDER) { | ||||
| bool changed = false; /* zero means no difference */ | bool changed = false; /* zero means no difference */ | ||||
| if (sview->camera_old != sview->camera) | if (sview->camera_old != sview->camera) | ||||
| changed = true; | changed = true; | ||||
| else if (sms.dst.dist != rv3d->dist) | else if (sms.dst.dist != rv3d->dist) | ||||
| changed = true; | changed = true; | ||||
| else if (sms.dst.lens != v3d->lens) | else if (sms.dst.lens != v3d->lens) | ||||
| changed = true; | changed = true; | ||||
| else if (!equals_v3v3(sms.dst.ofs, rv3d->ofs)) | else if (!equals_v3v3(sms.dst.ofs, rv3d->ofs)) | ||||
| changed = true; | changed = true; | ||||
| else if (!equals_v4v4(sms.dst.quat, rv3d->viewquat)) | else if (!equals_v4v4(sms.dst.quat, rv3d->viewquat)) | ||||
| changed = true; | changed = true; | ||||
| /* The new view is different from the old one | /* The new view is different from the old one | ||||
| * so animate the view */ | * so animate the view */ | ||||
| if (changed) { | if (changed) { | ||||
| /* original values */ | /* original values */ | ||||
| if (sview->camera_old) { | if (sview->camera_old) { | ||||
| sms.src.dist = ED_view3d_offset_distance(sview->camera_old->obmat, rv3d->ofs, 0.0f); | Object* camera_old_eval = DEG_get_evaluated_object(depsgraph, sview->camera_old); | ||||
| sms.src.dist = ED_view3d_offset_distance(camera_old_eval->obmat, rv3d->ofs, 0.0f); | |||||
| /* this */ | /* this */ | ||||
| ED_view3d_from_object(sview->camera_old, sms.src.ofs, sms.src.quat, &sms.src.dist, &sms.src.lens); | ED_view3d_from_object(camera_old_eval, sms.src.ofs, sms.src.quat, &sms.src.dist, &sms.src.lens); | ||||
| } | } | ||||
| /* grid draw as floor */ | /* grid draw as floor */ | ||||
| if ((rv3d->viewlock & RV3D_LOCKED) == 0) { | if ((rv3d->viewlock & RV3D_LOCKED) == 0) { | ||||
| /* use existing if exists, means multiple calls to smooth view wont loose the original 'view' setting */ | /* use existing if exists, means multiple calls to smooth view wont loose the original 'view' setting */ | ||||
| rv3d->view = RV3D_VIEW_USER; | rv3d->view = RV3D_VIEW_USER; | ||||
| } | } | ||||
| sms.time_allowed = (double)smooth_viewtx / 1000.0; | sms.time_allowed = (double)smooth_viewtx / 1000.0; | ||||
| /* if this is view rotation only | /* if this is view rotation only | ||||
| * we can decrease the time allowed by | * we can decrease the time allowed by | ||||
| * the angle between quats | * the angle between quats | ||||
| * this means small rotations wont lag */ | * this means small rotations wont lag */ | ||||
| if (sview->quat && !sview->ofs && !sview->dist) { | if (sview->quat && !sview->ofs && !sview->dist) { | ||||
| /* scale the time allowed by the rotation */ | /* scale the time allowed by the rotation */ | ||||
| sms.time_allowed *= (double)fabsf(angle_signed_normalized_qtqt(sms.dst.quat, sms.src.quat)) / M_PI; /* 180deg == 1.0 */ | sms.time_allowed *= (double)fabsf(angle_signed_normalized_qtqt(sms.dst.quat, sms.src.quat)) / M_PI; /* 180deg == 1.0 */ | ||||
| } | } | ||||
| /* ensure it shows correct */ | /* ensure it shows correct */ | ||||
| if (sms.to_camera) { | if (sms.to_camera) { | ||||
| /* use ortho if we move from an ortho view to an ortho camera */ | /* use ortho if we move from an ortho view to an ortho camera */ | ||||
| Object* camera_eval = DEG_get_evaluated_object(depsgraph, sview->camera); | |||||
| rv3d->persp = (((rv3d->is_persp == false) && | rv3d->persp = (((rv3d->is_persp == false) && | ||||
| (sview->camera->type == OB_CAMERA) && | (camera_eval->type == OB_CAMERA) && | ||||
| (((Camera *)sview->camera->data)->type == CAM_ORTHO)) ? | (((Camera *)camera_eval->data)->type == CAM_ORTHO)) ? | ||||
| RV3D_ORTHO : RV3D_PERSP); | RV3D_ORTHO : RV3D_PERSP); | ||||
| } | } | ||||
| rv3d->rflag |= RV3D_NAVIGATING; | rv3d->rflag |= RV3D_NAVIGATING; | ||||
| /* not essential but in some cases the caller will tag the area for redraw, | /* not essential but in some cases the caller will tag the area for redraw, | ||||
| * and in that case we can get a flicker of the 'org' user view but we want to see 'src' */ | * and in that case we can get a flicker of the 'org' user view but we want to see 'src' */ | ||||
| view3d_smooth_view_state_restore(&sms.src, v3d, rv3d); | view3d_smooth_view_state_restore(&sms.src, v3d, rv3d); | ||||
| Show All 32 Lines | void ED_view3d_smooth_view_ex( | ||||
| } | } | ||||
| } | } | ||||
| void ED_view3d_smooth_view( | void ED_view3d_smooth_view( | ||||
| bContext *C, | bContext *C, | ||||
| View3D *v3d, ARegion *ar, const int smooth_viewtx, | View3D *v3d, ARegion *ar, const int smooth_viewtx, | ||||
| const struct V3D_SmoothParams *sview) | const struct V3D_SmoothParams *sview) | ||||
| { | { | ||||
| const Depsgraph *depsgraph = CTX_data_depsgraph(C); | |||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| ED_view3d_smooth_view_ex( | ED_view3d_smooth_view_ex( | ||||
| depsgraph, | |||||
| wm, win, sa, | wm, win, sa, | ||||
| v3d, ar, smooth_viewtx, | v3d, ar, smooth_viewtx, | ||||
| sview); | sview); | ||||
| } | } | ||||
| /* only meant for timer usage */ | /* only meant for timer usage */ | ||||
| static void view3d_smoothview_apply(bContext *C, View3D *v3d, ARegion *ar, bool sync_boxview) | static void view3d_smoothview_apply(bContext *C, View3D *v3d, ARegion *ar, bool sync_boxview) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 791 Lines • Show Last 20 Lines | |||||