forked from bartvdbraak/blender
minor refactor, move view selected rv3d specific logic into its own static function.
This commit is contained in:
parent
495e3f3f36
commit
dac3ddc531
@ -2282,23 +2282,78 @@ void VIEW3D_OT_view_all(wmOperatorType *ot)
|
||||
RNA_def_boolean(ot->srna, "center", 0, "Center", "");
|
||||
}
|
||||
|
||||
static void viewselected_rv3d_from_minmax(bContext *C, View3D *v3d, ARegion *ar,
|
||||
const float min[3], const float max[3],
|
||||
int ok_dist)
|
||||
{
|
||||
RegionView3D *rv3d = ar->regiondata;
|
||||
float afm[3];
|
||||
float size;
|
||||
|
||||
/* SMOOTHVIEW */
|
||||
float new_ofs[3];
|
||||
float new_dist;
|
||||
|
||||
sub_v3_v3v3(afm, max, min);
|
||||
size = MAX3(afm[0], afm[1], afm[2]);
|
||||
|
||||
if (ok_dist) {
|
||||
/* fix up zoom distance if needed */
|
||||
|
||||
if (rv3d->is_persp) {
|
||||
if (size <= v3d->near * 1.5f) {
|
||||
/* do not zoom closer than the near clipping plane */
|
||||
size = v3d->near * 1.5f;
|
||||
}
|
||||
}
|
||||
else { /* ortho */
|
||||
if (size < 0.0001f) {
|
||||
/* bounding box was a single point so do not zoom */
|
||||
ok_dist = 0;
|
||||
}
|
||||
else {
|
||||
/* adjust zoom so it looks nicer */
|
||||
size *= 0.7f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add_v3_v3v3(new_ofs, min, max);
|
||||
mul_v3_fl(new_ofs, -0.5f);
|
||||
|
||||
new_dist = size;
|
||||
|
||||
/* correction for window aspect ratio */
|
||||
if (ar->winy > 2 && ar->winx > 2) {
|
||||
size = (float)ar->winx / (float)ar->winy;
|
||||
if (size < 1.0f) size = 1.0f / size;
|
||||
new_dist *= size;
|
||||
}
|
||||
|
||||
if (rv3d->persp == RV3D_CAMOB && !ED_view3d_camera_lock_check(v3d, rv3d)) {
|
||||
rv3d->persp = RV3D_PERSP;
|
||||
view3d_smooth_view(C, v3d, ar, v3d->camera, NULL, new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL);
|
||||
}
|
||||
else {
|
||||
view3d_smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL);
|
||||
}
|
||||
|
||||
/* smooth view does viewlock RV3D_BOXVIEW copy */
|
||||
}
|
||||
|
||||
/* like a localview without local!, was centerview() in 2.4x */
|
||||
static int viewselected_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
{
|
||||
ARegion *ar = CTX_wm_region(C);
|
||||
View3D *v3d = CTX_wm_view3d(C);
|
||||
RegionView3D *rv3d = CTX_wm_region_view3d(C);
|
||||
RegionView3D *rv3d = ar->regiondata;
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
Object *ob = OBACT;
|
||||
Object *obedit = CTX_data_edit_object(C);
|
||||
float size, min[3], max[3], afm[3];
|
||||
float min[3], max[3];
|
||||
int ok = 0, ok_dist = 1;
|
||||
const short skip_camera = ED_view3d_camera_lock_check(v3d, rv3d);
|
||||
|
||||
/* SMOOTHVIEW */
|
||||
float new_ofs[3];
|
||||
float new_dist;
|
||||
|
||||
INIT_MINMAX(min, max);
|
||||
|
||||
if (ob && (ob->mode & OB_MODE_WEIGHT_PAINT)) {
|
||||
@ -2368,53 +2423,11 @@ static int viewselected_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
}
|
||||
}
|
||||
|
||||
if (ok == 0) return OPERATOR_FINISHED;
|
||||
|
||||
sub_v3_v3v3(afm, max, min);
|
||||
size = MAX3(afm[0], afm[1], afm[2]);
|
||||
|
||||
if (ok_dist) {
|
||||
/* fix up zoom distance if needed */
|
||||
|
||||
if (rv3d->is_persp) {
|
||||
if (size <= v3d->near * 1.5f) {
|
||||
/* do not zoom closer than the near clipping plane */
|
||||
size = v3d->near * 1.5f;
|
||||
}
|
||||
}
|
||||
else { /* ortho */
|
||||
if (size < 0.0001f) {
|
||||
/* bounding box was a single point so do not zoom */
|
||||
ok_dist = 0;
|
||||
}
|
||||
else {
|
||||
/* adjust zoom so it looks nicer */
|
||||
size *= 0.7f;
|
||||
}
|
||||
}
|
||||
if (ok == 0) {
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
add_v3_v3v3(new_ofs, min, max);
|
||||
mul_v3_fl(new_ofs, -0.5f);
|
||||
|
||||
new_dist = size;
|
||||
|
||||
/* correction for window aspect ratio */
|
||||
if (ar->winy > 2 && ar->winx > 2) {
|
||||
size = (float)ar->winx / (float)ar->winy;
|
||||
if (size < 1.0f) size = 1.0f / size;
|
||||
new_dist *= size;
|
||||
}
|
||||
|
||||
if (rv3d->persp == RV3D_CAMOB && !ED_view3d_camera_lock_check(v3d, rv3d)) {
|
||||
rv3d->persp = RV3D_PERSP;
|
||||
view3d_smooth_view(C, v3d, ar, v3d->camera, NULL, new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL);
|
||||
}
|
||||
else {
|
||||
view3d_smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL);
|
||||
}
|
||||
|
||||
/* smooth view does viewlock RV3D_BOXVIEW copy */
|
||||
viewselected_rv3d_from_minmax(C, v3d, ar, min, max, ok_dist);
|
||||
|
||||
// XXX BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
|
||||
|
||||
|
@ -125,7 +125,7 @@ struct SmoothView3DStore {
|
||||
/* will start timer if appropriate */
|
||||
/* the arguments are the desired situation */
|
||||
void view3d_smooth_view(bContext *C, View3D *v3d, ARegion *ar, Object *oldcamera, Object *camera,
|
||||
float *ofs, float *quat, float *dist, float *lens)
|
||||
float *ofs, float *quat, float *dist, float *lens)
|
||||
{
|
||||
wmWindowManager *wm = CTX_wm_manager(C);
|
||||
wmWindow *win = CTX_wm_window(C);
|
||||
@ -140,7 +140,7 @@ void view3d_smooth_view(bContext *C, View3D *v3d, ARegion *ar, Object *oldcamera
|
||||
copy_qt_qt(sms.new_quat, rv3d->viewquat);
|
||||
sms.new_dist = rv3d->dist;
|
||||
sms.new_lens = v3d->lens;
|
||||
sms.to_camera = 0;
|
||||
sms.to_camera = FALSE;
|
||||
|
||||
/* note on camera locking, this is a little confusing but works ok.
|
||||
* we may be changing the view 'as if' there is no active camera, but in fact
|
||||
@ -162,22 +162,22 @@ void view3d_smooth_view(bContext *C, View3D *v3d, ARegion *ar, Object *oldcamera
|
||||
|
||||
if (camera) {
|
||||
ED_view3d_from_object(camera, sms.new_ofs, sms.new_quat, &sms.new_dist, &sms.new_lens);
|
||||
sms.to_camera = 1; /* restore view3d values in end */
|
||||
sms.to_camera = TRUE; /* restore view3d values in end */
|
||||
}
|
||||
|
||||
if (C && U.smooth_viewtx) {
|
||||
int changed = 0; /* zero means no difference */
|
||||
int changed = FALSE; /* zero means no difference */
|
||||
|
||||
if (oldcamera != camera)
|
||||
changed = 1;
|
||||
changed = TRUE;
|
||||
else if (sms.new_dist != rv3d->dist)
|
||||
changed = 1;
|
||||
changed = TRUE;
|
||||
else if (sms.new_lens != v3d->lens)
|
||||
changed = 1;
|
||||
changed = TRUE;
|
||||
else if (!equals_v3v3(sms.new_ofs, rv3d->ofs))
|
||||
changed = 1;
|
||||
changed = TRUE;
|
||||
else if (!equals_v4v4(sms.new_quat, rv3d->viewquat))
|
||||
changed = 1;
|
||||
changed = TRUE;
|
||||
|
||||
/* The new view is different from the old one
|
||||
* so animate the view */
|
||||
@ -241,7 +241,7 @@ void view3d_smooth_view(bContext *C, View3D *v3d, ARegion *ar, Object *oldcamera
|
||||
|
||||
/* if we get here nothing happens */
|
||||
if (ok == FALSE) {
|
||||
if (sms.to_camera == 0) {
|
||||
if (sms.to_camera == FALSE) {
|
||||
copy_v3_v3(rv3d->ofs, sms.new_ofs);
|
||||
copy_qt_qt(rv3d->viewquat, sms.new_quat);
|
||||
rv3d->dist = sms.new_dist;
|
||||
|
Loading…
Reference in New Issue
Block a user