2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-18 17:38:21 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2018-06-01 18:19:39 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2008-12-18 17:38:21 +00:00
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-18 17:38:21 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
2018-06-01 18:19:39 +02:00
|
|
|
*
|
2008-12-18 17:38:21 +00:00
|
|
|
* Contributor(s): Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/space_view3d/view3d_view.c
|
|
|
|
|
* \ingroup spview3d
|
|
|
|
|
*/
|
|
|
|
|
|
2008-12-18 17:38:21 +00:00
|
|
|
#include "DNA_camera_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_object_types.h"
|
2008-12-18 17:38:21 +00:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
2010-10-25 07:28:57 +00:00
|
|
|
#include "BLI_rect.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2008-12-18 17:38:21 +00:00
|
|
|
|
|
|
|
|
#include "BKE_action.h"
|
2011-11-14 03:54:23 +00:00
|
|
|
#include "BKE_camera.h"
|
2008-12-21 11:05:43 +00:00
|
|
|
#include "BKE_context.h"
|
2008-12-18 17:38:21 +00:00
|
|
|
#include "BKE_object.h"
|
|
|
|
|
#include "BKE_global.h"
|
2018-11-25 09:50:34 -02:00
|
|
|
#include "BKE_layer.h"
|
2008-12-19 12:14:58 +00:00
|
|
|
#include "BKE_main.h"
|
2009-10-22 23:22:05 +00:00
|
|
|
#include "BKE_report.h"
|
2008-12-18 17:38:21 +00:00
|
|
|
#include "BKE_scene.h"
|
|
|
|
|
|
2017-04-26 10:46:55 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
2018-05-25 11:05:51 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2017-04-26 10:46:55 +02:00
|
|
|
|
2017-08-25 22:22:50 +10:00
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
2017-08-21 01:39:03 +10:00
|
|
|
#include "GPU_glew.h"
|
2014-07-23 15:24:07 +02:00
|
|
|
#include "GPU_select.h"
|
2017-03-21 17:49:21 -04:00
|
|
|
#include "GPU_matrix.h"
|
2018-06-27 19:07:23 -06:00
|
|
|
#include "GPU_state.h"
|
2010-10-25 07:28:57 +00:00
|
|
|
|
2008-12-18 17:38:21 +00:00
|
|
|
#include "WM_api.h"
|
2008-12-26 18:15:46 +00:00
|
|
|
#include "WM_types.h"
|
2008-12-18 17:38:21 +00:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
#include "ED_object.h"
|
2008-12-18 17:38:21 +00:00
|
|
|
#include "ED_screen.h"
|
2009-03-17 21:44:58 +00:00
|
|
|
|
2017-04-26 04:39:25 +10:00
|
|
|
#include "DRW_engine.h"
|
|
|
|
|
|
2012-07-08 20:36:00 +00:00
|
|
|
#include "view3d_intern.h" /* own include */
|
2008-12-18 17:38:21 +00:00
|
|
|
|
2018-01-28 16:22:34 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Smooth View Operator & Utilities
|
|
|
|
|
*
|
|
|
|
|
* Use for view transitions to have smooth (animated) transitions.
|
|
|
|
|
* \{ */
|
2008-12-21 11:05:43 +00:00
|
|
|
|
2009-11-22 23:11:32 +00:00
|
|
|
/* This operator is one of the 'timer refresh' ones like animation playback */
|
2008-12-26 18:15:46 +00:00
|
|
|
|
2013-01-17 08:05:48 +00:00
|
|
|
struct SmoothView3DState {
|
|
|
|
|
float dist;
|
|
|
|
|
float lens;
|
|
|
|
|
float quat[4];
|
|
|
|
|
float ofs[3];
|
|
|
|
|
};
|
|
|
|
|
|
2012-08-12 01:07:31 +00:00
|
|
|
struct SmoothView3DStore {
|
2013-01-17 08:05:48 +00:00
|
|
|
/* source*/
|
|
|
|
|
struct SmoothView3DState src; /* source */
|
|
|
|
|
struct SmoothView3DState dst; /* destination */
|
|
|
|
|
struct SmoothView3DState org; /* original */
|
|
|
|
|
|
|
|
|
|
bool to_camera;
|
2015-08-26 10:12:36 +10:00
|
|
|
|
2015-12-23 05:04:52 +11:00
|
|
|
bool use_dyn_ofs;
|
|
|
|
|
float dyn_ofs[3];
|
|
|
|
|
|
2015-08-26 10:12:36 +10:00
|
|
|
/* When smooth-view is enabled, store the 'rv3d->view' here,
|
|
|
|
|
* assign back when the view motion is completed. */
|
2013-01-17 08:05:48 +00:00
|
|
|
char org_view;
|
|
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
double time_allowed;
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-17 08:05:48 +00:00
|
|
|
static void view3d_smooth_view_state_backup(struct SmoothView3DState *sms_state,
|
|
|
|
|
const View3D *v3d, const RegionView3D *rv3d)
|
|
|
|
|
{
|
|
|
|
|
copy_v3_v3(sms_state->ofs, rv3d->ofs);
|
|
|
|
|
copy_qt_qt(sms_state->quat, rv3d->viewquat);
|
|
|
|
|
sms_state->dist = rv3d->dist;
|
|
|
|
|
sms_state->lens = v3d->lens;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void view3d_smooth_view_state_restore(const struct SmoothView3DState *sms_state,
|
|
|
|
|
View3D *v3d, RegionView3D *rv3d)
|
|
|
|
|
{
|
|
|
|
|
copy_v3_v3(rv3d->ofs, sms_state->ofs);
|
|
|
|
|
copy_qt_qt(rv3d->viewquat, sms_state->quat);
|
|
|
|
|
rv3d->dist = sms_state->dist;
|
|
|
|
|
v3d->lens = sms_state->lens;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
/* will start timer if appropriate */
|
|
|
|
|
/* the arguments are the desired situation */
|
2014-04-17 22:54:10 +10:00
|
|
|
void ED_view3d_smooth_view_ex(
|
|
|
|
|
/* avoid passing in the context */
|
2018-05-20 19:10:16 +02:00
|
|
|
const Depsgraph *depsgraph, wmWindowManager *wm, wmWindow *win, ScrArea *sa,
|
2015-12-23 02:47:34 +11:00
|
|
|
View3D *v3d, ARegion *ar, const int smooth_viewtx,
|
|
|
|
|
const V3D_SmoothParams *sview)
|
2014-04-17 22:54:10 +10:00
|
|
|
{
|
2012-03-25 23:54:33 +00:00
|
|
|
RegionView3D *rv3d = ar->regiondata;
|
2013-01-17 08:05:48 +00:00
|
|
|
struct SmoothView3DStore sms = {{0}};
|
|
|
|
|
bool ok = false;
|
2018-05-20 19:10:16 +02:00
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
/* initialize sms */
|
2013-01-17 08:05:48 +00:00
|
|
|
view3d_smooth_view_state_backup(&sms.dst, v3d, rv3d);
|
|
|
|
|
view3d_smooth_view_state_backup(&sms.src, v3d, rv3d);
|
2013-01-17 08:46:46 +00:00
|
|
|
/* if smoothview runs multiple times... */
|
|
|
|
|
if (rv3d->sms == NULL) {
|
|
|
|
|
view3d_smooth_view_state_backup(&sms.org, v3d, rv3d);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sms.org = rv3d->sms->org;
|
|
|
|
|
}
|
2015-08-26 10:12:36 +10:00
|
|
|
sms.org_view = rv3d->view;
|
|
|
|
|
|
2013-01-17 08:46:46 +00:00
|
|
|
/* sms.to_camera = false; */ /* initizlized to zero anyway */
|
2011-05-14 17:50:33 +00:00
|
|
|
|
|
|
|
|
/* note on camera locking, this is a little confusing but works ok.
|
2012-05-20 21:23:26 +00:00
|
|
|
* we may be changing the view 'as if' there is no active camera, but in fact
|
2011-05-14 17:50:33 +00:00
|
|
|
* there is an active camera which is locked to the view.
|
|
|
|
|
*
|
2012-03-18 07:38:51 +00:00
|
|
|
* In the case where smooth view is moving _to_ a camera we don't want that
|
2011-05-14 17:50:33 +00:00
|
|
|
* 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.
|
|
|
|
|
*/
|
2015-12-23 02:47:34 +11:00
|
|
|
if (sview->camera == NULL && sview->camera_old == NULL) {
|
2018-11-30 12:16:19 +01:00
|
|
|
ED_view3d_camera_lock_init(depsgraph, v3d, rv3d);
|
2011-05-14 17:50:33 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
/* store the options we want to end with */
|
2015-12-23 02:47:34 +11:00
|
|
|
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;
|
|
|
|
|
|
2015-12-23 05:04:52 +11:00
|
|
|
if (sview->dyn_ofs) {
|
|
|
|
|
BLI_assert(sview->ofs == NULL);
|
|
|
|
|
BLI_assert(sview->quat != NULL);
|
|
|
|
|
|
|
|
|
|
copy_v3_v3(sms.dyn_ofs, sview->dyn_ofs);
|
|
|
|
|
sms.use_dyn_ofs = true;
|
|
|
|
|
|
2016-07-08 00:48:03 +10:00
|
|
|
/* calculate the final destination offset */
|
2015-12-23 05:04:52 +11:00
|
|
|
view3d_orbit_apply_dyn_ofs(sms.dst.ofs, sms.src.ofs, sms.src.quat, sms.dst.quat, sms.dyn_ofs);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 02:47:34 +11:00
|
|
|
if (sview->camera) {
|
2018-05-22 07:48:12 +02:00
|
|
|
Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, sview->camera);
|
|
|
|
|
sms.dst.dist = ED_view3d_offset_distance(ob_camera_eval->obmat, sview->ofs, VIEW3D_DIST_FALLBACK);
|
|
|
|
|
ED_view3d_from_object(ob_camera_eval, sms.dst.ofs, sms.dst.quat, &sms.dst.dist, &sms.dst.lens);
|
2013-01-17 08:05:48 +00:00
|
|
|
sms.to_camera = true; /* restore view3d values in end */
|
2008-12-26 18:15:46 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
Blender Internal Render in viewport
Because of our release soon, feature has been added behind the Debug Menu.
CTRL+ALT+D and set it to -1. Or commandline --debug-value -1.
When debug set to -1, you can put the viewport to 'render' mode, just like
for Cycles. Notes for testers: (and please no bugs in tracker for this :)
- It renders without AA, MBlur, Panorama, Sequence, Composite
- Only active render layer gets rendered. Select another layer will re-render.
- But yes: it works for FreeStyle renders!
- Also does great for local view.
- BI is not well suited for incremental renders on view changes. This only
works for non-raytrace scenes, or zoom in ortho or camera mode, or for
Material changes. In most cases a full re-render is being done.
- ESC works to stop the preview render.
- Borders render as well. (CTRL+B)
- Force a refresh with arrow key left/right. A lot of settings don't trigger
re-render yet.
Tech notes:
- FreeStyle is adding a lot of temp objects/meshes in the Main database. This
caused DepsGraph to trigger changes (and redraws). I've prepended the names
for these temp objects with char number 27 (ESC), and made these names be
ignored for tag update checking.
- Fixed some bugs that were noticable with such excessive re-renders, like
for opening file window, quit during renders.
2013-04-16 17:39:20 +00:00
|
|
|
/* skip smooth viewing for render engine draw */
|
2018-07-11 14:20:39 +02:00
|
|
|
if (smooth_viewtx && v3d->shading.type != OB_RENDER) {
|
2013-01-17 08:05:48 +00:00
|
|
|
bool changed = false; /* zero means no difference */
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2015-12-23 02:47:34 +11:00
|
|
|
if (sview->camera_old != sview->camera)
|
2013-01-17 08:05:48 +00:00
|
|
|
changed = true;
|
|
|
|
|
else if (sms.dst.dist != rv3d->dist)
|
|
|
|
|
changed = true;
|
|
|
|
|
else if (sms.dst.lens != v3d->lens)
|
|
|
|
|
changed = true;
|
|
|
|
|
else if (!equals_v3v3(sms.dst.ofs, rv3d->ofs))
|
|
|
|
|
changed = true;
|
|
|
|
|
else if (!equals_v4v4(sms.dst.quat, rv3d->viewquat))
|
|
|
|
|
changed = true;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
/* The new view is different from the old one
|
2012-03-03 16:31:46 +00:00
|
|
|
* so animate the view */
|
2008-12-26 18:15:46 +00:00
|
|
|
if (changed) {
|
|
|
|
|
/* original values */
|
2015-12-23 02:47:34 +11:00
|
|
|
if (sview->camera_old) {
|
2018-05-22 07:48:12 +02:00
|
|
|
Object *ob_camera_old_eval = DEG_get_evaluated_object(depsgraph, sview->camera_old);
|
|
|
|
|
sms.src.dist = ED_view3d_offset_distance(ob_camera_old_eval->obmat, rv3d->ofs, 0.0f);
|
2013-01-17 08:05:48 +00:00
|
|
|
/* this */
|
2018-05-22 07:48:12 +02:00
|
|
|
ED_view3d_from_object(ob_camera_old_eval, sms.src.ofs, sms.src.quat, &sms.src.dist, &sms.src.lens);
|
2008-12-26 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
/* grid draw as floor */
|
2012-03-25 23:54:33 +00:00
|
|
|
if ((rv3d->viewlock & RV3D_LOCKED) == 0) {
|
2019-01-15 23:24:20 +11:00
|
|
|
/* use existing if exists, means multiple calls to smooth view
|
|
|
|
|
* wont loose the original 'view' setting */
|
2012-03-25 23:54:33 +00:00
|
|
|
rv3d->view = RV3D_VIEW_USER;
|
2010-01-30 18:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
2013-09-16 04:04:44 +00:00
|
|
|
sms.time_allowed = (double)smooth_viewtx / 1000.0;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-07-27 04:56:24 +00:00
|
|
|
/* if this is view rotation only
|
2012-03-03 16:31:46 +00:00
|
|
|
* we can decrease the time allowed by
|
2018-06-04 09:31:30 +02:00
|
|
|
* the angle between quats
|
2012-03-03 16:31:46 +00:00
|
|
|
* this means small rotations wont lag */
|
2015-12-23 02:47:34 +11:00
|
|
|
if (sview->quat && !sview->ofs && !sview->dist) {
|
2010-07-27 04:56:24 +00:00
|
|
|
/* scale the time allowed by the rotation */
|
2019-01-15 23:24:20 +11:00
|
|
|
/* 180deg == 1.0 */
|
|
|
|
|
sms.time_allowed *= (double)fabsf(angle_signed_normalized_qtqt(sms.dst.quat, sms.src.quat)) / M_PI;
|
2010-07-27 04:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
/* ensure it shows correct */
|
2013-01-17 08:05:48 +00:00
|
|
|
if (sms.to_camera) {
|
2014-02-25 00:57:10 +11:00
|
|
|
/* use ortho if we move from an ortho view to an ortho camera */
|
2018-05-22 07:48:12 +02:00
|
|
|
Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, sview->camera);
|
2014-02-25 00:57:10 +11:00
|
|
|
rv3d->persp = (((rv3d->is_persp == false) &&
|
2018-05-22 07:48:12 +02:00
|
|
|
(ob_camera_eval->type == OB_CAMERA) &&
|
|
|
|
|
(((Camera *)ob_camera_eval->data)->type == CAM_ORTHO)) ?
|
2014-02-25 00:57:10 +11:00
|
|
|
RV3D_ORTHO : RV3D_PERSP);
|
2013-01-17 08:05:48 +00:00
|
|
|
}
|
2009-11-25 14:13:43 +00:00
|
|
|
|
|
|
|
|
rv3d->rflag |= RV3D_NAVIGATING;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-01-15 23:24:20 +11:00
|
|
|
/* 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' */
|
2013-01-17 08:05:48 +00:00
|
|
|
view3d_smooth_view_state_restore(&sms.src, v3d, rv3d);
|
|
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
/* keep track of running timer! */
|
2013-01-17 08:05:48 +00:00
|
|
|
if (rv3d->sms == NULL) {
|
2012-08-12 01:07:31 +00:00
|
|
|
rv3d->sms = MEM_mallocN(sizeof(struct SmoothView3DStore), "smoothview v3d");
|
2013-01-17 08:05:48 +00:00
|
|
|
}
|
2012-03-25 23:54:33 +00:00
|
|
|
*rv3d->sms = sms;
|
2013-01-17 08:05:48 +00:00
|
|
|
if (rv3d->smooth_timer) {
|
2011-04-28 07:55:29 +00:00
|
|
|
WM_event_remove_timer(wm, win, rv3d->smooth_timer);
|
2013-01-17 08:05:48 +00:00
|
|
|
}
|
2008-12-26 18:15:46 +00:00
|
|
|
/* TIMER1 is hardcoded in keymap */
|
2019-01-15 23:24:20 +11:00
|
|
|
/* max 30 frs/sec */
|
|
|
|
|
rv3d->smooth_timer = WM_event_add_timer(wm, win, TIMER1, 1.0 / 100.0);
|
2013-01-17 08:05:48 +00:00
|
|
|
|
|
|
|
|
ok = true;
|
2008-12-26 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
/* if we get here nothing happens */
|
2013-01-17 08:05:48 +00:00
|
|
|
if (ok == false) {
|
|
|
|
|
if (sms.to_camera == false) {
|
|
|
|
|
copy_v3_v3(rv3d->ofs, sms.dst.ofs);
|
|
|
|
|
copy_qt_qt(rv3d->viewquat, sms.dst.quat);
|
|
|
|
|
rv3d->dist = sms.dst.dist;
|
|
|
|
|
v3d->lens = sms.dst.lens;
|
2010-11-08 03:44:52 +00:00
|
|
|
|
2018-05-21 20:29:00 +02:00
|
|
|
ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d);
|
2012-11-10 02:45:56 +00:00
|
|
|
}
|
2012-10-10 12:30:47 +00:00
|
|
|
|
2013-01-17 08:05:48 +00:00
|
|
|
if (rv3d->viewlock & RV3D_BOXVIEW) {
|
2011-04-28 07:55:29 +00:00
|
|
|
view3d_boxview_copy(sa, ar);
|
2013-01-17 08:05:48 +00:00
|
|
|
}
|
2010-11-08 03:44:52 +00:00
|
|
|
|
|
|
|
|
ED_region_tag_redraw(ar);
|
2008-12-26 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-17 22:54:10 +10:00
|
|
|
void ED_view3d_smooth_view(
|
|
|
|
|
bContext *C,
|
2015-12-23 02:47:34 +11:00
|
|
|
View3D *v3d, ARegion *ar, const int smooth_viewtx,
|
|
|
|
|
const struct V3D_SmoothParams *sview)
|
2014-04-17 22:54:10 +10:00
|
|
|
{
|
2018-05-20 19:10:16 +02:00
|
|
|
const Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2014-04-17 22:54:10 +10:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
|
wmWindow *win = CTX_wm_window(C);
|
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
|
|
|
|
|
|
ED_view3d_smooth_view_ex(
|
2018-05-20 19:10:16 +02:00
|
|
|
depsgraph,
|
2014-04-17 22:54:10 +10:00
|
|
|
wm, win, sa,
|
2015-12-23 02:47:34 +11:00
|
|
|
v3d, ar, smooth_viewtx,
|
|
|
|
|
sview);
|
2014-04-17 22:54:10 +10:00
|
|
|
}
|
|
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
/* only meant for timer usage */
|
2016-05-04 03:38:20 +10:00
|
|
|
static void view3d_smoothview_apply(bContext *C, View3D *v3d, ARegion *ar, bool sync_boxview)
|
2008-12-26 18:15:46 +00:00
|
|
|
{
|
2018-05-21 20:29:00 +02:00
|
|
|
const Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2016-05-04 03:38:20 +10:00
|
|
|
RegionView3D *rv3d = ar->regiondata;
|
2012-08-12 01:07:31 +00:00
|
|
|
struct SmoothView3DStore *sms = rv3d->sms;
|
2011-03-27 15:57:27 +00:00
|
|
|
float step, step_inv;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-02-22 16:52:06 +00:00
|
|
|
if (sms->time_allowed != 0.0)
|
2012-03-25 23:54:33 +00:00
|
|
|
step = (float)((rv3d->smooth_timer->duration) / sms->time_allowed);
|
2010-08-12 17:48:25 +00:00
|
|
|
else
|
|
|
|
|
step = 1.0f;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
/* end timer */
|
2012-02-22 16:52:06 +00:00
|
|
|
if (step >= 1.0f) {
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
/* if we went to camera, store the original */
|
2012-02-22 16:52:06 +00:00
|
|
|
if (sms->to_camera) {
|
2012-03-25 23:54:33 +00:00
|
|
|
rv3d->persp = RV3D_CAMOB;
|
2013-01-17 08:05:48 +00:00
|
|
|
view3d_smooth_view_state_restore(&sms->org, v3d, rv3d);
|
2008-12-26 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-01-17 08:05:48 +00:00
|
|
|
view3d_smooth_view_state_restore(&sms->dst, v3d, rv3d);
|
2011-05-15 02:39:36 +00:00
|
|
|
|
2018-05-21 20:29:00 +02:00
|
|
|
ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d);
|
2014-11-24 00:27:50 +01:00
|
|
|
ED_view3d_camera_lock_autokey(v3d, rv3d, C, true, true);
|
2008-12-26 18:15:46 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
if ((rv3d->viewlock & RV3D_LOCKED) == 0) {
|
2013-01-17 08:05:48 +00:00
|
|
|
rv3d->view = sms->org_view;
|
2010-01-30 18:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
MEM_freeN(rv3d->sms);
|
2012-03-25 23:54:33 +00:00
|
|
|
rv3d->sms = NULL;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-11-01 00:06:53 +00:00
|
|
|
WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), rv3d->smooth_timer);
|
2012-03-25 23:54:33 +00:00
|
|
|
rv3d->smooth_timer = NULL;
|
2009-11-25 14:13:43 +00:00
|
|
|
rv3d->rflag &= ~RV3D_NAVIGATING;
|
2008-12-26 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* ease in/out */
|
2012-08-12 01:07:31 +00:00
|
|
|
step = (3.0f * step * step - 2.0f * step * step * step);
|
2008-12-26 18:15:46 +00:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
step_inv = 1.0f - step;
|
2008-12-26 18:15:46 +00:00
|
|
|
|
2013-01-17 08:05:48 +00:00
|
|
|
interp_qt_qtqt(rv3d->viewquat, sms->src.quat, sms->dst.quat, step);
|
2015-12-23 05:04:52 +11:00
|
|
|
|
|
|
|
|
if (sms->use_dyn_ofs) {
|
|
|
|
|
view3d_orbit_apply_dyn_ofs(rv3d->ofs, sms->src.ofs, sms->src.quat, rv3d->viewquat, sms->dyn_ofs);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
interp_v3_v3v3(rv3d->ofs, sms->src.ofs, sms->dst.ofs, step);
|
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-01-17 08:05:48 +00:00
|
|
|
rv3d->dist = sms->dst.dist * step + sms->src.dist * step_inv;
|
|
|
|
|
v3d->lens = sms->dst.lens * step + sms->src.lens * step_inv;
|
2011-05-14 17:50:33 +00:00
|
|
|
|
2018-05-21 20:29:00 +02:00
|
|
|
ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d);
|
2014-11-24 00:27:50 +01:00
|
|
|
if (ED_screen_animation_playing(CTX_wm_manager(C))) {
|
|
|
|
|
ED_view3d_camera_lock_autokey(v3d, rv3d, C, true, true);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 14:06:32 +11:00
|
|
|
/* Event handling won't know if a UI item has been moved under the pointer. */
|
|
|
|
|
WM_event_add_mousemove(C);
|
2008-12-26 18:15:46 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-05-04 03:38:20 +10:00
|
|
|
if (sync_boxview && (rv3d->viewlock & RV3D_BOXVIEW)) {
|
|
|
|
|
view3d_boxview_copy(CTX_wm_area(C), ar);
|
|
|
|
|
}
|
2012-11-30 06:39:24 +00:00
|
|
|
|
|
|
|
|
/* note: this doesn't work right because the v3d->lens is now used in ortho mode r51636,
|
2013-01-17 08:46:46 +00:00
|
|
|
* when switching camera in quad-view the other ortho views would zoom & reset.
|
|
|
|
|
*
|
|
|
|
|
* For now only redraw all regions when smoothview finishes.
|
|
|
|
|
*/
|
|
|
|
|
if (step >= 1.0f) {
|
|
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2016-05-04 03:38:20 +10:00
|
|
|
ED_region_tag_redraw(ar);
|
2013-01-17 08:46:46 +00:00
|
|
|
}
|
2016-05-04 03:38:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int view3d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
|
RegionView3D *rv3d = ar->regiondata;
|
|
|
|
|
|
|
|
|
|
/* escape if not our timer */
|
|
|
|
|
if (rv3d->smooth_timer == NULL || rv3d->smooth_timer != event->customdata) {
|
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
view3d_smoothview_apply(C, v3d, ar, true);
|
|
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-05 01:51:25 +10:00
|
|
|
/**
|
|
|
|
|
* Apply the smoothview immediately, use when we need to start a new view operation.
|
|
|
|
|
* (so we don't end up half-applying a view operation when pressing keys quickly).
|
|
|
|
|
*/
|
|
|
|
|
void ED_view3d_smooth_view_force_finish(
|
2016-05-04 03:38:20 +10:00
|
|
|
bContext *C,
|
|
|
|
|
View3D *v3d, ARegion *ar)
|
|
|
|
|
{
|
|
|
|
|
RegionView3D *rv3d = ar->regiondata;
|
|
|
|
|
|
|
|
|
|
if (rv3d && rv3d->sms) {
|
|
|
|
|
rv3d->sms->time_allowed = 0.0; /* force finishing */
|
|
|
|
|
view3d_smoothview_apply(C, v3d, ar, false);
|
|
|
|
|
|
|
|
|
|
/* force update of view matrix so tools that run immediately after
|
|
|
|
|
* can use them without redrawing first */
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2016-05-04 03:38:20 +10:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2018-04-06 12:07:27 +02:00
|
|
|
ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, NULL, NULL, NULL);
|
2016-05-04 03:38:20 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
void VIEW3D_OT_smoothview(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Smooth View";
|
|
|
|
|
ot->idname = "VIEW3D_OT_smoothview";
|
2018-01-28 16:22:34 +11:00
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = view3d_smoothview_invoke;
|
2018-01-28 16:22:34 +11:00
|
|
|
|
2013-09-30 05:50:41 +00:00
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_INTERNAL;
|
|
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = ED_operator_view3d_active;
|
2008-12-26 18:15:46 +00:00
|
|
|
}
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
|
2018-01-28 16:22:34 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Camera to View Operator
|
|
|
|
|
* \{ */
|
2009-11-22 23:11:32 +00:00
|
|
|
|
2011-11-19 01:24:40 +00:00
|
|
|
static int view3d_camera_to_view_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-10-22 23:22:05 +00:00
|
|
|
{
|
2018-05-21 20:29:00 +02:00
|
|
|
const Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2014-02-27 11:33:27 +11:00
|
|
|
View3D *v3d;
|
|
|
|
|
ARegion *ar;
|
|
|
|
|
RegionView3D *rv3d;
|
|
|
|
|
|
2011-11-11 05:34:07 +00:00
|
|
|
ObjectTfmProtectedChannels obtfm;
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2014-02-27 11:33:27 +11:00
|
|
|
ED_view3d_context_user_region(C, &v3d, &ar);
|
|
|
|
|
rv3d = ar->regiondata;
|
|
|
|
|
|
2014-03-25 14:21:50 +11:00
|
|
|
ED_view3d_lastview_store(rv3d);
|
2010-09-07 05:47:34 +00:00
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
BKE_object_tfm_protected_backup(v3d->camera, &obtfm);
|
2011-11-11 05:34:07 +00:00
|
|
|
|
2018-05-21 20:29:00 +02:00
|
|
|
ED_view3d_to_object(depsgraph, v3d->camera, rv3d->ofs, rv3d->viewquat, rv3d->dist);
|
2011-11-11 05:34:07 +00:00
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
BKE_object_tfm_protected_restore(v3d->camera, &obtfm, v3d->camera->protectflag);
|
2011-11-11 05:34:07 +00:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&v3d->camera->id, ID_RECALC_TRANSFORM);
|
2009-10-27 02:54:25 +00:00
|
|
|
rv3d->persp = RV3D_CAMOB;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, v3d->camera);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-06 00:19:47 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
|
|
|
|
|
}
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool view3d_camera_to_view_poll(bContext *C)
|
2009-10-22 23:22:05 +00:00
|
|
|
{
|
2014-02-27 11:33:27 +11:00
|
|
|
View3D *v3d;
|
|
|
|
|
ARegion *ar;
|
|
|
|
|
|
|
|
|
|
if (ED_view3d_context_user_region(C, &v3d, &ar)) {
|
|
|
|
|
RegionView3D *rv3d = ar->regiondata;
|
2017-11-06 17:17:10 +01:00
|
|
|
if (v3d && v3d->camera && !ID_IS_LINKED(v3d->camera)) {
|
2014-02-27 11:33:27 +11:00
|
|
|
if (rv3d && (rv3d->viewlock & RV3D_LOCKED) == 0) {
|
|
|
|
|
if (rv3d->persp != RV3D_CAMOB) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-02 08:55:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2011-06-02 08:55:26 +00:00
|
|
|
return 0;
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-14 03:54:23 +00:00
|
|
|
void VIEW3D_OT_camera_to_view(wmOperatorType *ot)
|
2009-01-06 00:19:47 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Align Camera To View";
|
|
|
|
|
ot->description = "Set camera view to active view";
|
|
|
|
|
ot->idname = "VIEW3D_OT_camera_to_view";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-06 00:19:47 +00:00
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = view3d_camera_to_view_exec;
|
|
|
|
|
ot->poll = view3d_camera_to_view_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
2012-03-25 23:54:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-01-06 00:19:47 +00:00
|
|
|
}
|
2008-12-26 18:15:46 +00:00
|
|
|
|
2018-01-28 16:22:34 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Camera Fit Frame to Selected Operator
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2011-11-14 03:54:23 +00:00
|
|
|
/* unlike VIEW3D_OT_view_selected this is for framing a render and not
|
|
|
|
|
* meant to take into account vertex/bone selection for eg. */
|
2013-08-13 04:35:14 +00:00
|
|
|
static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op)
|
2011-11-14 03:54:23 +00:00
|
|
|
{
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2012-03-25 23:54:33 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2013-08-13 04:35:14 +00:00
|
|
|
View3D *v3d = CTX_wm_view3d(C); /* can be NULL */
|
|
|
|
|
Object *camera_ob = v3d ? v3d->camera : scene->camera;
|
2018-05-25 11:05:51 +02:00
|
|
|
Object *camera_ob_eval = DEG_get_evaluated_object(depsgraph, camera_ob);
|
2011-11-14 03:54:23 +00:00
|
|
|
|
|
|
|
|
float r_co[3]; /* the new location to apply */
|
2015-01-03 12:05:16 +01:00
|
|
|
float r_scale; /* only for ortho cameras */
|
2011-11-14 03:54:23 +00:00
|
|
|
|
2018-05-25 11:05:51 +02:00
|
|
|
if (camera_ob_eval == NULL) {
|
2013-08-13 04:35:14 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "No active camera");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-14 03:54:23 +00:00
|
|
|
/* this function does all the important stuff */
|
2018-06-22 07:54:55 +02:00
|
|
|
if (BKE_camera_view_frame_fit_to_scene(depsgraph, scene, camera_ob_eval, r_co, &r_scale)) {
|
2011-11-14 03:54:23 +00:00
|
|
|
ObjectTfmProtectedChannels obtfm;
|
|
|
|
|
float obmat_new[4][4];
|
|
|
|
|
|
2018-05-25 11:05:51 +02:00
|
|
|
if ((camera_ob_eval->type == OB_CAMERA) && (((Camera *)camera_ob_eval->data)->type == CAM_ORTHO)) {
|
2015-01-03 12:05:16 +01:00
|
|
|
((Camera *)camera_ob->data)->ortho_scale = r_scale;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-25 11:05:51 +02:00
|
|
|
copy_m4_m4(obmat_new, camera_ob_eval->obmat);
|
2011-11-14 03:54:23 +00:00
|
|
|
copy_v3_v3(obmat_new[3], r_co);
|
|
|
|
|
|
|
|
|
|
/* only touch location */
|
2012-05-05 14:03:12 +00:00
|
|
|
BKE_object_tfm_protected_backup(camera_ob, &obtfm);
|
2013-03-20 23:14:18 +00:00
|
|
|
BKE_object_apply_mat4(camera_ob, obmat_new, true, true);
|
2012-05-05 14:03:12 +00:00
|
|
|
BKE_object_tfm_protected_restore(camera_ob, &obtfm, OB_LOCK_SCALE | OB_LOCK_ROT4D);
|
2011-11-14 03:54:23 +00:00
|
|
|
|
|
|
|
|
/* notifiers */
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&camera_ob->id, ID_RECALC_TRANSFORM);
|
2012-03-25 23:54:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, camera_ob);
|
2011-11-14 03:54:23 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_camera_to_view_selected(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Camera Fit Frame to Selected";
|
|
|
|
|
ot->description = "Move the camera so selected objects are framed";
|
|
|
|
|
ot->idname = "VIEW3D_OT_camera_to_view_selected";
|
2011-11-14 03:54:23 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = view3d_camera_to_view_selected_exec;
|
2013-08-13 04:35:14 +00:00
|
|
|
ot->poll = ED_operator_scene_editable;
|
2011-11-14 03:54:23 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
2012-03-25 23:54:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-11-14 03:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-28 16:22:34 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Object as Camera Operator
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2016-10-10 14:47:03 +02:00
|
|
|
static void sync_viewport_camera_smoothview(bContext *C, View3D *v3d, Object *ob, const int smooth_viewtx)
|
|
|
|
|
{
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
for (bScreen *screen = bmain->screen.first; screen != NULL; screen = screen->id.next) {
|
|
|
|
|
for (ScrArea *area = screen->areabase.first; area != NULL; area = area->next) {
|
|
|
|
|
for (SpaceLink *space_link = area->spacedata.first; space_link != NULL; space_link = space_link->next) {
|
|
|
|
|
if (space_link->spacetype == SPACE_VIEW3D) {
|
|
|
|
|
View3D *other_v3d = (View3D *)space_link;
|
|
|
|
|
if (other_v3d == v3d) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (other_v3d->camera == ob) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (v3d->scenelock) {
|
|
|
|
|
ListBase *lb = (space_link == area->spacedata.first)
|
|
|
|
|
? &area->regionbase
|
|
|
|
|
: &space_link->regionbase;
|
|
|
|
|
for (ARegion *other_ar = lb->first; other_ar != NULL; other_ar = other_ar->next) {
|
|
|
|
|
if (other_ar->regiontype == RGN_TYPE_WINDOW) {
|
|
|
|
|
if (other_ar->regiondata) {
|
|
|
|
|
RegionView3D *other_rv3d = other_ar->regiondata;
|
|
|
|
|
if (other_rv3d->persp == RV3D_CAMOB) {
|
|
|
|
|
Object *other_camera_old = other_v3d->camera;
|
|
|
|
|
other_v3d->camera = ob;
|
|
|
|
|
ED_view3d_lastview_store(other_rv3d);
|
|
|
|
|
ED_view3d_smooth_view(
|
|
|
|
|
C, other_v3d, other_ar, smooth_viewtx,
|
|
|
|
|
&(const V3D_SmoothParams) {
|
|
|
|
|
.camera_old = other_camera_old,
|
|
|
|
|
.camera = other_v3d->camera,
|
|
|
|
|
.ofs = other_rv3d->ofs,
|
|
|
|
|
.quat = other_rv3d->viewquat,
|
|
|
|
|
.dist = &other_rv3d->dist,
|
2019-01-07 00:58:10 +11:00
|
|
|
.lens = &other_v3d->lens,
|
|
|
|
|
});
|
2016-10-10 14:47:03 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
other_v3d->camera = ob;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-11-22 23:11:32 +00:00
|
|
|
|
2013-09-16 04:04:44 +00:00
|
|
|
static int view3d_setobjectascamera_exec(bContext *C, wmOperator *op)
|
2018-01-28 16:22:34 +11:00
|
|
|
{
|
2012-01-14 12:24:25 +00:00
|
|
|
View3D *v3d;
|
|
|
|
|
ARegion *ar;
|
|
|
|
|
RegionView3D *rv3d;
|
|
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2010-10-05 13:15:58 +00:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
|
|
2013-09-16 04:04:44 +00:00
|
|
|
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
|
|
|
|
|
|
2012-01-14 12:24:25 +00:00
|
|
|
/* no NULL check is needed, poll checks */
|
|
|
|
|
ED_view3d_context_user_region(C, &v3d, &ar);
|
|
|
|
|
rv3d = ar->regiondata;
|
|
|
|
|
|
2012-02-22 16:52:06 +00:00
|
|
|
if (ob) {
|
2012-03-25 23:54:33 +00:00
|
|
|
Object *camera_old = (rv3d->persp == RV3D_CAMOB) ? V3D_CAMERA_SCENE(scene, v3d) : NULL;
|
|
|
|
|
rv3d->persp = RV3D_CAMOB;
|
|
|
|
|
v3d->camera = ob;
|
2012-02-22 16:52:06 +00:00
|
|
|
if (v3d->scenelock)
|
2012-03-25 23:54:33 +00:00
|
|
|
scene->camera = ob;
|
2010-10-05 13:15:58 +00:00
|
|
|
|
2014-04-30 07:04:38 +10:00
|
|
|
/* unlikely but looks like a glitch when set to the same */
|
|
|
|
|
if (camera_old != ob) {
|
|
|
|
|
ED_view3d_lastview_store(rv3d);
|
|
|
|
|
|
2015-12-23 02:47:34 +11:00
|
|
|
ED_view3d_smooth_view(
|
|
|
|
|
C, v3d, ar, smooth_viewtx,
|
2015-12-29 01:08:13 +11:00
|
|
|
&(const V3D_SmoothParams) {
|
2015-12-23 02:47:34 +11:00
|
|
|
.camera_old = camera_old, .camera = v3d->camera,
|
|
|
|
|
.ofs = rv3d->ofs, .quat = rv3d->viewquat,
|
2019-01-07 00:58:10 +11:00
|
|
|
.dist = &rv3d->dist, .lens = &v3d->lens,
|
|
|
|
|
});
|
2013-09-16 04:04:44 +00:00
|
|
|
}
|
2010-10-05 13:15:58 +00:00
|
|
|
|
2016-09-28 00:44:31 +02:00
|
|
|
if (v3d->scenelock) {
|
2016-10-10 14:47:03 +02:00
|
|
|
sync_viewport_camera_smoothview(C, v3d, ob, smooth_viewtx);
|
2016-09-28 00:44:31 +02:00
|
|
|
WM_event_add_notifier(C, NC_SCENE, scene);
|
|
|
|
|
}
|
|
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, scene);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
bool ED_operator_rv3d_user_region_poll(bContext *C)
|
2011-02-05 19:07:54 +00:00
|
|
|
{
|
2012-01-14 12:24:25 +00:00
|
|
|
View3D *v3d_dummy;
|
|
|
|
|
ARegion *ar_dummy;
|
|
|
|
|
|
|
|
|
|
return ED_view3d_context_user_region(C, &v3d_dummy, &ar_dummy);
|
2011-02-05 19:07:54 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-24 01:32:03 +00:00
|
|
|
void VIEW3D_OT_object_as_camera(wmOperatorType *ot)
|
2009-10-22 23:22:05 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Set Active Object as Camera";
|
|
|
|
|
ot->description = "Set the active object as the active camera for this view or scene";
|
|
|
|
|
ot->idname = "VIEW3D_OT_object_as_camera";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = view3d_setobjectascamera_exec;
|
|
|
|
|
ot->poll = ED_operator_rv3d_user_region_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
/* flags */
|
2012-03-25 23:54:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
2009-11-22 23:11:32 +00:00
|
|
|
|
2018-01-28 16:22:34 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Window and View Matrix Calculation
|
|
|
|
|
* \{ */
|
2008-12-26 18:15:46 +00:00
|
|
|
|
2014-04-22 21:59:43 +10:00
|
|
|
/**
|
2018-12-12 12:50:58 +11:00
|
|
|
* \param rect: optional for picking (can be NULL).
|
2012-10-27 10:42:28 +00:00
|
|
|
*/
|
2018-04-06 12:07:27 +02:00
|
|
|
void view3d_winmatrix_set(Depsgraph *depsgraph, ARegion *ar, const View3D *v3d, const rcti *rect)
|
2008-12-18 17:38:21 +00:00
|
|
|
{
|
2012-03-25 23:54:33 +00:00
|
|
|
RegionView3D *rv3d = ar->regiondata;
|
2008-12-18 17:38:21 +00:00
|
|
|
rctf viewplane;
|
2014-06-19 17:00:19 +10:00
|
|
|
float clipsta, clipend;
|
2014-02-03 18:55:59 +11:00
|
|
|
bool is_ortho;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-01-18 15:58:02 +01:00
|
|
|
is_ortho = ED_view3d_viewplane_get(depsgraph, v3d, rv3d, ar->winx, ar->winy, &viewplane, &clipsta, &clipend, NULL);
|
2014-02-03 18:55:59 +11:00
|
|
|
rv3d->is_persp = !is_ortho;
|
2011-05-18 17:52:26 +00:00
|
|
|
|
2012-01-19 16:04:44 +00:00
|
|
|
#if 0
|
|
|
|
|
printf("%s: %d %d %f %f %f %f %f %f\n", __func__, winx, winy,
|
|
|
|
|
viewplane.xmin, viewplane.ymin, viewplane.xmax, viewplane.ymax,
|
|
|
|
|
clipsta, clipend);
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
if (rect) { /* picking */
|
2014-06-19 17:00:19 +10:00
|
|
|
rctf r;
|
|
|
|
|
r.xmin = viewplane.xmin + (BLI_rctf_size_x(&viewplane) * (rect->xmin / (float)ar->winx));
|
|
|
|
|
r.ymin = viewplane.ymin + (BLI_rctf_size_y(&viewplane) * (rect->ymin / (float)ar->winy));
|
|
|
|
|
r.xmax = viewplane.xmin + (BLI_rctf_size_x(&viewplane) * (rect->xmax / (float)ar->winx));
|
|
|
|
|
r.ymax = viewplane.ymin + (BLI_rctf_size_y(&viewplane) * (rect->ymax / (float)ar->winy));
|
|
|
|
|
viewplane = r;
|
|
|
|
|
}
|
2012-10-27 10:42:28 +00:00
|
|
|
|
2014-06-19 17:00:19 +10:00
|
|
|
if (is_ortho) {
|
2018-07-15 15:27:15 +02:00
|
|
|
GPU_matrix_ortho_set(viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
|
2008-12-18 17:38:21 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2018-07-15 15:27:15 +02:00
|
|
|
GPU_matrix_frustum_set(viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
|
2008-12-18 17:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-01 15:32:55 +00:00
|
|
|
/* update matrix in 3d view region */
|
2018-07-15 15:27:15 +02:00
|
|
|
GPU_matrix_projection_get(rv3d->winmat);
|
2008-12-18 17:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-27 16:39:00 +00:00
|
|
|
static void obmat_to_viewmat(RegionView3D *rv3d, Object *ob)
|
2008-12-18 17:38:21 +00:00
|
|
|
{
|
2015-10-24 21:02:42 -02:00
|
|
|
float bmat[4][4];
|
|
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
rv3d->view = RV3D_VIEW_USER; /* don't show the grid */
|
2015-10-24 21:02:42 -02:00
|
|
|
|
2015-10-25 17:30:16 +11:00
|
|
|
normalize_m4_m4(bmat, ob->obmat);
|
2015-10-24 21:02:42 -02:00
|
|
|
invert_m4_m4(rv3d->viewmat, bmat);
|
|
|
|
|
|
|
|
|
|
/* view quat calculation, needed for add object */
|
2015-10-25 17:30:16 +11:00
|
|
|
mat4_normalized_to_quat(rv3d->viewquat, rv3d->viewmat);
|
2008-12-18 17:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-22 20:11:34 +11:00
|
|
|
/**
|
|
|
|
|
* Sets #RegionView3D.viewmat
|
|
|
|
|
*
|
2018-04-06 12:07:27 +02:00
|
|
|
* \param depsgraph: Depsgraph.
|
2018-01-22 20:11:34 +11:00
|
|
|
* \param scene: Scene for camera and cursor location.
|
|
|
|
|
* \param v3d: View 3D space data.
|
|
|
|
|
* \param rv3d: 3D region which stores the final matrices.
|
|
|
|
|
* \param rect_scale: Optional 2D scale argument,
|
|
|
|
|
* Use when displaying a sub-region, eg: when #view3d_winmatrix_set takes a 'rect' argument.
|
|
|
|
|
*
|
|
|
|
|
* \note don't set windows active in here, is used by renderwin too.
|
2018-01-23 11:24:44 +11:00
|
|
|
*/
|
|
|
|
|
void view3d_viewmatrix_set(
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph, Scene *scene,
|
2018-01-23 11:24:44 +11:00
|
|
|
const View3D *v3d, RegionView3D *rv3d, const float rect_scale[2])
|
2008-12-18 17:38:21 +00:00
|
|
|
{
|
2012-03-25 23:54:33 +00:00
|
|
|
if (rv3d->persp == RV3D_CAMOB) { /* obs/camera */
|
2012-02-22 16:52:06 +00:00
|
|
|
if (v3d->camera) {
|
2018-05-22 07:48:12 +02:00
|
|
|
Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, v3d->camera);
|
|
|
|
|
obmat_to_viewmat(rv3d, ob_camera_eval);
|
2008-12-18 17:38:21 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-03-25 23:54:33 +00:00
|
|
|
quat_to_mat4(rv3d->viewmat, rv3d->viewquat);
|
|
|
|
|
rv3d->viewmat[3][2] -= rv3d->dist;
|
2008-12-18 17:38:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2013-07-19 10:54:02 +00:00
|
|
|
bool use_lock_ofs = false;
|
|
|
|
|
|
|
|
|
|
|
2009-01-20 18:31:11 +00:00
|
|
|
/* should be moved to better initialize later on XXX */
|
2014-02-04 21:04:36 +11:00
|
|
|
if (rv3d->viewlock & RV3D_LOCKED)
|
2011-03-08 07:44:30 +00:00
|
|
|
ED_view3d_lock(rv3d);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
quat_to_mat4(rv3d->viewmat, rv3d->viewquat);
|
|
|
|
|
if (rv3d->persp == RV3D_PERSP) rv3d->viewmat[3][2] -= rv3d->dist;
|
2012-02-22 16:52:06 +00:00
|
|
|
if (v3d->ob_centre) {
|
2018-05-20 18:41:03 +02:00
|
|
|
Object *ob_eval = DEG_get_evaluated_object(depsgraph, v3d->ob_centre);
|
2008-12-18 17:38:21 +00:00
|
|
|
float vec[3];
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-05-20 18:41:03 +02:00
|
|
|
copy_v3_v3(vec, ob_eval->obmat[3]);
|
|
|
|
|
if (ob_eval->type == OB_ARMATURE && v3d->ob_centre_bone[0]) {
|
|
|
|
|
bPoseChannel *pchan = BKE_pose_channel_find_name(ob_eval->pose, v3d->ob_centre_bone);
|
2012-02-22 16:52:06 +00:00
|
|
|
if (pchan) {
|
2010-07-26 06:34:56 +00:00
|
|
|
copy_v3_v3(vec, pchan->pose_mat[3]);
|
2018-05-20 18:41:03 +02:00
|
|
|
mul_m4_v3(ob_eval->obmat, vec);
|
2008-12-18 17:38:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-03-25 23:54:33 +00:00
|
|
|
translate_m4(rv3d->viewmat, -vec[0], -vec[1], -vec[2]);
|
2013-07-19 10:54:02 +00:00
|
|
|
use_lock_ofs = true;
|
2008-12-18 17:38:21 +00:00
|
|
|
}
|
2010-10-31 01:18:26 +00:00
|
|
|
else if (v3d->ob_centre_cursor) {
|
|
|
|
|
float vec[3];
|
2018-11-26 13:49:17 +11:00
|
|
|
copy_v3_v3(vec, scene->cursor.location);
|
2010-10-31 01:18:26 +00:00
|
|
|
translate_m4(rv3d->viewmat, -vec[0], -vec[1], -vec[2]);
|
2013-07-19 10:54:02 +00:00
|
|
|
use_lock_ofs = true;
|
2010-10-31 01:18:26 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
|
translate_m4(rv3d->viewmat, rv3d->ofs[0], rv3d->ofs[1], rv3d->ofs[2]);
|
|
|
|
|
}
|
2013-07-19 10:54:02 +00:00
|
|
|
|
|
|
|
|
/* lock offset */
|
|
|
|
|
if (use_lock_ofs) {
|
|
|
|
|
float persmat[4][4], persinv[4][4];
|
|
|
|
|
float vec[3];
|
|
|
|
|
|
|
|
|
|
/* we could calculate the real persmat/persinv here
|
|
|
|
|
* but it would be unreliable so better to later */
|
|
|
|
|
mul_m4_m4m4(persmat, rv3d->winmat, rv3d->viewmat);
|
|
|
|
|
invert_m4_m4(persinv, persmat);
|
|
|
|
|
|
|
|
|
|
mul_v2_v2fl(vec, rv3d->ofs_lock, rv3d->is_persp ? rv3d->dist : 1.0f);
|
|
|
|
|
vec[2] = 0.0f;
|
2018-01-22 20:11:34 +11:00
|
|
|
|
|
|
|
|
if (rect_scale) {
|
2018-01-23 17:36:51 +11:00
|
|
|
/* Since 'RegionView3D.winmat' has been calculated and this function doesn't take the 'ARegion'
|
|
|
|
|
* we don't know about the region size.
|
|
|
|
|
* Use 'rect_scale' when drawing a sub-region to apply 2D offset,
|
|
|
|
|
* scaled by the difference between the sub-region and the region size.
|
|
|
|
|
*/
|
2018-01-22 20:11:34 +11:00
|
|
|
vec[0] /= rect_scale[0];
|
|
|
|
|
vec[1] /= rect_scale[1];
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 10:54:02 +00:00
|
|
|
mul_mat3_m4_v3(persinv, vec);
|
|
|
|
|
translate_m4(rv3d->viewmat, vec[0], vec[1], vec[2]);
|
|
|
|
|
}
|
|
|
|
|
/* end lock offset */
|
2008-12-18 17:38:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-28 16:22:34 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name OpenGL Select Utilities
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2017-03-09 20:47:37 +11:00
|
|
|
/**
|
|
|
|
|
* Optionally cache data for multiple calls to #view3d_opengl_select
|
|
|
|
|
*
|
|
|
|
|
* just avoid GPU_select headers outside this file
|
|
|
|
|
*/
|
|
|
|
|
void view3d_opengl_select_cache_begin(void)
|
|
|
|
|
{
|
|
|
|
|
GPU_select_cache_begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void view3d_opengl_select_cache_end(void)
|
|
|
|
|
{
|
|
|
|
|
GPU_select_cache_end();
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 16:31:36 +11:00
|
|
|
struct DrawSelectLoopUserData {
|
|
|
|
|
uint pass;
|
|
|
|
|
uint hits;
|
|
|
|
|
uint *buffer;
|
|
|
|
|
uint buffer_len;
|
|
|
|
|
const rcti *rect;
|
|
|
|
|
char gpu_select_mode;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static bool drw_select_loop_pass(eDRWSelectStage stage, void *user_data)
|
|
|
|
|
{
|
|
|
|
|
bool continue_pass = false;
|
|
|
|
|
struct DrawSelectLoopUserData *data = user_data;
|
|
|
|
|
if (stage == DRW_SELECT_PASS_PRE) {
|
|
|
|
|
GPU_select_begin(data->buffer, data->buffer_len, data->rect, data->gpu_select_mode, data->hits);
|
|
|
|
|
/* always run POST after PRE. */
|
|
|
|
|
continue_pass = true;
|
|
|
|
|
}
|
|
|
|
|
else if (stage == DRW_SELECT_PASS_POST) {
|
|
|
|
|
int hits = GPU_select_end();
|
|
|
|
|
if (data->pass == 0) {
|
|
|
|
|
/* quirk of GPU_select_end, only take hits value from first call. */
|
|
|
|
|
data->hits = hits;
|
|
|
|
|
}
|
|
|
|
|
if (data->gpu_select_mode == GPU_SELECT_NEAREST_FIRST_PASS) {
|
|
|
|
|
data->gpu_select_mode = GPU_SELECT_NEAREST_SECOND_PASS;
|
2018-03-01 22:01:46 +11:00
|
|
|
continue_pass = (hits > 0);
|
2018-03-01 16:31:36 +11:00
|
|
|
}
|
|
|
|
|
data->pass += 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_assert(0);
|
|
|
|
|
}
|
|
|
|
|
return continue_pass;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-23 10:00:28 +11:00
|
|
|
eV3DSelectObjectFilter ED_view3d_select_filter_from_mode(const Scene *scene, const Object *obact)
|
|
|
|
|
{
|
|
|
|
|
if (scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK) {
|
2018-11-23 18:12:28 +11:00
|
|
|
if (obact && (obact->mode & OB_MODE_WEIGHT_PAINT) &&
|
2018-11-23 10:00:28 +11:00
|
|
|
BKE_object_pose_armature_get((Object *)obact))
|
|
|
|
|
{
|
|
|
|
|
return VIEW3D_SELECT_FILTER_WPAINT_POSE_MODE_LOCK;
|
|
|
|
|
}
|
|
|
|
|
return VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK;
|
|
|
|
|
}
|
|
|
|
|
return VIEW3D_SELECT_FILTER_NOP;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 16:41:18 +02:00
|
|
|
/** Implement #VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK. */
|
|
|
|
|
static bool drw_select_filter_object_mode_lock(Object *ob, void *user_data)
|
|
|
|
|
{
|
|
|
|
|
const Object *obact = user_data;
|
|
|
|
|
return BKE_object_is_mode_compat(ob, obact->mode);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-23 10:00:28 +11:00
|
|
|
/** Implement #VIEW3D_SELECT_FILTER_WPAINT_POSE_MODE_LOCK for special case when
|
|
|
|
|
* we want to select pose bones (this doesn't switch modes). */
|
|
|
|
|
static bool drw_select_filter_object_mode_lock_for_weight_paint(Object *ob, void *user_data)
|
|
|
|
|
{
|
|
|
|
|
const Object *ob_pose = user_data;
|
2018-11-23 10:37:53 +11:00
|
|
|
return (DEG_get_original_object(ob) == ob_pose);
|
2018-11-23 10:00:28 +11:00
|
|
|
}
|
|
|
|
|
|
2013-10-15 02:23:28 +00:00
|
|
|
/**
|
|
|
|
|
* \warning be sure to account for a negative return value
|
|
|
|
|
* This is an error, "Too many objects in select buffer"
|
|
|
|
|
* and no action should be taken (can crash blender) if this happens
|
|
|
|
|
*
|
|
|
|
|
* \note (vc->obedit == NULL) can be set to explicitly skip edit-object selection.
|
2012-03-03 16:31:46 +00:00
|
|
|
*/
|
2017-03-09 05:17:55 +11:00
|
|
|
int view3d_opengl_select(
|
2018-04-06 12:07:27 +02:00
|
|
|
ViewContext *vc, unsigned int *buffer, unsigned int bufsize, const rcti *input,
|
2018-06-19 16:41:18 +02:00
|
|
|
eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter)
|
2008-12-19 12:14:58 +00:00
|
|
|
{
|
2017-08-25 22:22:50 +10:00
|
|
|
struct bThemeState theme_state;
|
2018-05-29 12:01:07 +02:00
|
|
|
Depsgraph *depsgraph = vc->depsgraph;
|
2012-03-25 23:54:33 +00:00
|
|
|
Scene *scene = vc->scene;
|
|
|
|
|
View3D *v3d = vc->v3d;
|
|
|
|
|
ARegion *ar = vc->ar;
|
2017-03-08 23:22:42 +11:00
|
|
|
rcti rect;
|
2018-09-04 17:14:46 +02:00
|
|
|
int hits = 0;
|
2018-04-05 18:20:27 +02:00
|
|
|
const bool use_obedit_skip = (OBEDIT_FROM_VIEW_LAYER(vc->view_layer) != NULL) && (vc->obedit == NULL);
|
2017-03-09 05:17:55 +11:00
|
|
|
const bool is_pick_select = (U.gpu_select_pick_deph != 0);
|
|
|
|
|
const bool do_passes = (
|
|
|
|
|
(is_pick_select == false) &&
|
2019-01-16 15:18:44 +01:00
|
|
|
(select_mode == VIEW3D_SELECT_PICK_NEAREST));
|
2017-03-10 03:15:58 +11:00
|
|
|
const bool use_nearest = (is_pick_select && select_mode == VIEW3D_SELECT_PICK_NEAREST);
|
2018-09-04 17:14:46 +02:00
|
|
|
bool draw_surface = true;
|
2017-03-09 05:17:55 +11:00
|
|
|
|
|
|
|
|
char gpu_select_mode;
|
2014-07-23 15:24:07 +02:00
|
|
|
|
2018-10-05 10:27:04 +10:00
|
|
|
/* case not a box select */
|
2012-03-25 23:54:33 +00:00
|
|
|
if (input->xmin == input->xmax) {
|
2017-03-05 20:51:23 +11:00
|
|
|
/* seems to be default value for bones only now */
|
2017-03-08 23:22:42 +11:00
|
|
|
BLI_rcti_init_pt_radius(&rect, (const int[2]){input->xmin, input->ymin}, 12);
|
2008-12-19 12:14:58 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2017-03-08 23:22:42 +11:00
|
|
|
rect = *input;
|
2008-12-19 12:14:58 +00:00
|
|
|
}
|
2017-03-09 05:17:55 +11:00
|
|
|
|
|
|
|
|
if (is_pick_select) {
|
|
|
|
|
if (is_pick_select && select_mode == VIEW3D_SELECT_PICK_NEAREST) {
|
|
|
|
|
gpu_select_mode = GPU_SELECT_PICK_NEAREST;
|
|
|
|
|
}
|
|
|
|
|
else if (is_pick_select && select_mode == VIEW3D_SELECT_PICK_ALL) {
|
|
|
|
|
gpu_select_mode = GPU_SELECT_PICK_ALL;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
gpu_select_mode = GPU_SELECT_ALL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (do_passes) {
|
|
|
|
|
gpu_select_mode = GPU_SELECT_NEAREST_FIRST_PASS;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
gpu_select_mode = GPU_SELECT_ALL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-24 23:06:29 +11:00
|
|
|
/* Important to use 'vc->obact', not 'OBACT(vc->view_layer)' below,
|
|
|
|
|
* so it will be NULL when hidden. */
|
2018-06-19 16:41:18 +02:00
|
|
|
struct {
|
|
|
|
|
DRW_ObjectFilterFn fn;
|
|
|
|
|
void *user_data;
|
|
|
|
|
} object_filter = {NULL, NULL};
|
|
|
|
|
switch (select_filter) {
|
|
|
|
|
case VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK:
|
|
|
|
|
{
|
2019-01-24 23:06:29 +11:00
|
|
|
Object *obact = vc->obact;
|
2018-06-19 16:41:18 +02:00
|
|
|
if (obact && obact->mode != OB_MODE_OBJECT) {
|
|
|
|
|
object_filter.fn = drw_select_filter_object_mode_lock;
|
|
|
|
|
object_filter.user_data = obact;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-11-23 10:00:28 +11:00
|
|
|
case VIEW3D_SELECT_FILTER_WPAINT_POSE_MODE_LOCK:
|
|
|
|
|
{
|
2019-01-24 23:06:29 +11:00
|
|
|
Object *obact = vc->obact;
|
2018-11-23 10:00:28 +11:00
|
|
|
BLI_assert(obact && (obact->mode & OB_MODE_WEIGHT_PAINT));
|
|
|
|
|
Object *ob_pose = BKE_object_pose_armature_get(obact);
|
|
|
|
|
|
|
|
|
|
object_filter.fn = drw_select_filter_object_mode_lock_for_weight_paint;
|
|
|
|
|
object_filter.user_data = ob_pose;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-06-19 16:41:18 +02:00
|
|
|
case VIEW3D_SELECT_FILTER_NOP:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-25 22:22:50 +10:00
|
|
|
/* Tools may request depth outside of regular drawing code. */
|
|
|
|
|
UI_Theme_Store(&theme_state);
|
|
|
|
|
UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
|
|
|
|
|
|
2017-03-09 05:17:55 +11:00
|
|
|
/* Re-use cache (rect must be smaller then the cached)
|
|
|
|
|
* other context is assumed to be unchanged */
|
|
|
|
|
if (GPU_select_is_cached()) {
|
|
|
|
|
GPU_select_begin(buffer, bufsize, &rect, gpu_select_mode, 0);
|
|
|
|
|
GPU_select_cache_load_id();
|
|
|
|
|
hits = GPU_select_end();
|
|
|
|
|
goto finally;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 22:01:46 +11:00
|
|
|
/* All of the queries need to be perform on the drawing context. */
|
|
|
|
|
DRW_opengl_context_enable();
|
|
|
|
|
|
2017-03-09 05:17:55 +11:00
|
|
|
G.f |= G_PICKSEL;
|
|
|
|
|
|
2017-05-26 16:11:32 +10:00
|
|
|
/* Important we use the 'viewmat' and don't re-calculate since
|
|
|
|
|
* the object & bone view locking takes 'rect' into account, see: T51629. */
|
2018-05-29 12:01:07 +02:00
|
|
|
ED_view3d_draw_setup_view(vc->win, depsgraph, scene, ar, v3d, vc->rv3d->viewmat, NULL, &rect);
|
2017-05-10 16:54:01 +02:00
|
|
|
|
2018-07-11 14:20:39 +02:00
|
|
|
if (v3d->shading.type > OB_WIRE) {
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_depth_test(true);
|
2008-12-19 12:14:58 +00:00
|
|
|
}
|
2018-02-26 19:41:17 +01:00
|
|
|
|
2018-09-04 17:14:46 +02:00
|
|
|
if (vc->rv3d->rflag & RV3D_CLIPPING) {
|
2012-02-28 13:03:56 +00:00
|
|
|
ED_view3d_clipping_set(vc->rv3d);
|
2018-09-04 17:14:46 +02:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-09-04 17:14:46 +02:00
|
|
|
/* If in xray mode, we select the wires in priority. */
|
2018-09-27 16:09:04 +02:00
|
|
|
if ((v3d->shading.flag & V3D_XRAY_FLAG(v3d)) && use_nearest) {
|
2018-09-04 17:14:46 +02:00
|
|
|
/* We need to call "GPU_select_*" API's inside DRW_draw_select_loop
|
|
|
|
|
* because the OpenGL context created & destroyed inside this function. */
|
|
|
|
|
struct DrawSelectLoopUserData drw_select_loop_user_data = {
|
|
|
|
|
.pass = 0,
|
|
|
|
|
.hits = 0,
|
|
|
|
|
.buffer = buffer,
|
|
|
|
|
.buffer_len = bufsize,
|
|
|
|
|
.rect = &rect,
|
|
|
|
|
.gpu_select_mode = gpu_select_mode,
|
|
|
|
|
};
|
|
|
|
|
draw_surface = false;
|
|
|
|
|
DRW_draw_select_loop(
|
|
|
|
|
depsgraph, ar, v3d,
|
|
|
|
|
use_obedit_skip, draw_surface, use_nearest, &rect,
|
|
|
|
|
drw_select_loop_pass, &drw_select_loop_user_data,
|
|
|
|
|
object_filter.fn, object_filter.user_data);
|
|
|
|
|
hits = drw_select_loop_user_data.hits;
|
2018-09-05 12:53:14 +02:00
|
|
|
/* FIX: This cleanup the state before doing another selection pass.
|
|
|
|
|
* (see T56695) */
|
|
|
|
|
GPU_select_cache_end();
|
2017-04-26 04:39:25 +10:00
|
|
|
}
|
2018-09-04 17:14:46 +02:00
|
|
|
|
|
|
|
|
if (hits == 0) {
|
2018-03-01 16:31:36 +11:00
|
|
|
/* We need to call "GPU_select_*" API's inside DRW_draw_select_loop
|
|
|
|
|
* because the OpenGL context created & destroyed inside this function. */
|
|
|
|
|
struct DrawSelectLoopUserData drw_select_loop_user_data = {
|
|
|
|
|
.pass = 0,
|
|
|
|
|
.hits = 0,
|
|
|
|
|
.buffer = buffer,
|
|
|
|
|
.buffer_len = bufsize,
|
|
|
|
|
.rect = &rect,
|
|
|
|
|
.gpu_select_mode = gpu_select_mode,
|
|
|
|
|
};
|
2018-09-04 17:14:46 +02:00
|
|
|
draw_surface = true;
|
2018-02-06 16:10:03 +11:00
|
|
|
DRW_draw_select_loop(
|
2018-05-29 12:01:07 +02:00
|
|
|
depsgraph, ar, v3d,
|
2018-09-04 17:14:46 +02:00
|
|
|
use_obedit_skip, draw_surface, use_nearest, &rect,
|
2018-06-19 16:41:18 +02:00
|
|
|
drw_select_loop_pass, &drw_select_loop_user_data,
|
|
|
|
|
object_filter.fn, object_filter.user_data);
|
2018-03-01 16:31:36 +11:00
|
|
|
hits = drw_select_loop_user_data.hits;
|
2017-04-26 04:39:25 +10:00
|
|
|
}
|
2014-07-23 15:24:07 +02:00
|
|
|
|
2008-12-19 12:14:58 +00:00
|
|
|
G.f &= ~G_PICKSEL;
|
2018-05-29 12:01:07 +02:00
|
|
|
ED_view3d_draw_setup_view(vc->win, depsgraph, scene, ar, v3d, vc->rv3d->viewmat, NULL, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-07-11 14:20:39 +02:00
|
|
|
if (v3d->shading.type > OB_WIRE) {
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_depth_test(false);
|
2008-12-19 12:14:58 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-02-22 16:52:06 +00:00
|
|
|
if (vc->rv3d->rflag & RV3D_CLIPPING)
|
2012-02-28 13:03:56 +00:00
|
|
|
ED_view3d_clipping_disable();
|
2017-03-09 05:17:55 +11:00
|
|
|
|
2018-02-26 19:41:17 +01:00
|
|
|
DRW_opengl_context_disable();
|
|
|
|
|
|
2018-03-01 22:01:46 +11:00
|
|
|
finally:
|
|
|
|
|
|
2012-07-08 20:36:00 +00:00
|
|
|
if (hits < 0) printf("Too many objects in select buffer\n"); /* XXX make error message */
|
|
|
|
|
|
2017-08-25 22:22:50 +10:00
|
|
|
UI_Theme_Restore(&theme_state);
|
2009-02-14 10:03:24 +00:00
|
|
|
|
2008-12-19 12:14:58 +00:00
|
|
|
return hits;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-28 16:22:34 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Local View Operators
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
static unsigned int free_localbit(Main *bmain)
|
|
|
|
|
{
|
|
|
|
|
ScrArea *sa;
|
|
|
|
|
bScreen *sc;
|
|
|
|
|
|
|
|
|
|
unsigned short local_view_bits = 0;
|
|
|
|
|
|
|
|
|
|
/* sometimes we loose a localview: when an area is closed */
|
|
|
|
|
/* check all areas: which localviews are in use? */
|
|
|
|
|
for (sc = bmain->screen.first; sc; sc = sc->id.next) {
|
|
|
|
|
for (sa = sc->areabase.first; sa; sa = sa->next) {
|
|
|
|
|
SpaceLink *sl = sa->spacedata.first;
|
|
|
|
|
for (; sl; sl = sl->next) {
|
|
|
|
|
if (sl->spacetype == SPACE_VIEW3D) {
|
|
|
|
|
View3D *v3d = (View3D *) sl;
|
|
|
|
|
if (v3d->localvd) {
|
|
|
|
|
local_view_bits |= v3d->local_view_uuid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
|
if ((local_view_bits & (1 << i)) == 0) {
|
|
|
|
|
return (1 << i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool view3d_localview_init(
|
|
|
|
|
const Depsgraph *depsgraph,
|
|
|
|
|
wmWindowManager *wm,
|
|
|
|
|
wmWindow *win,
|
|
|
|
|
Main *bmain,
|
|
|
|
|
ViewLayer *view_layer,
|
|
|
|
|
ScrArea *sa,
|
|
|
|
|
const int smooth_viewtx,
|
|
|
|
|
ReportList *reports)
|
|
|
|
|
{
|
|
|
|
|
View3D *v3d = sa->spacedata.first;
|
|
|
|
|
Base *base;
|
|
|
|
|
float min[3], max[3], box[3], mid[3];
|
|
|
|
|
float size = 0.0f;
|
|
|
|
|
unsigned int local_view_bit;
|
|
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
|
|
if (v3d->localvd) {
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
|
|
|
|
|
local_view_bit = free_localbit(bmain);
|
|
|
|
|
|
|
|
|
|
if (local_view_bit == 0) {
|
|
|
|
|
/* TODO(dfelinto): We can kick one of the other 3D views out of local view
|
|
|
|
|
specially if it is not being used. */
|
|
|
|
|
BKE_report(reports, RPT_ERROR, "No more than 16 local views");
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
|
|
|
|
|
if (obedit) {
|
|
|
|
|
FOREACH_BASE_IN_EDIT_MODE_BEGIN(view_layer, v3d, base_iter) {
|
|
|
|
|
BKE_object_minmax(base_iter->object, min, max, false);
|
|
|
|
|
base_iter->local_view_bits |= local_view_bit;
|
|
|
|
|
ok = true;
|
|
|
|
|
} FOREACH_BASE_IN_EDIT_MODE_END;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (base = FIRSTBASE(view_layer); base; base = base->next) {
|
2019-01-08 18:19:12 +01:00
|
|
|
if (BASE_SELECTED(v3d, base)) {
|
2018-11-25 09:50:34 -02:00
|
|
|
BKE_object_minmax(base->object, min, max, false);
|
|
|
|
|
base->local_view_bits |= local_view_bit;
|
|
|
|
|
ok = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub_v3_v3v3(box, max, min);
|
|
|
|
|
size = max_fff(box[0], box[1], box[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ok == true) {
|
|
|
|
|
ARegion *ar;
|
|
|
|
|
|
|
|
|
|
v3d->localvd = MEM_mallocN(sizeof(View3D), "localview");
|
|
|
|
|
|
|
|
|
|
memcpy(v3d->localvd, v3d, sizeof(View3D));
|
|
|
|
|
|
|
|
|
|
mid_v3_v3v3(mid, min, max);
|
|
|
|
|
|
|
|
|
|
for (ar = sa->regionbase.first; ar; ar = ar->next) {
|
|
|
|
|
if (ar->regiontype == RGN_TYPE_WINDOW) {
|
|
|
|
|
RegionView3D *rv3d = ar->regiondata;
|
|
|
|
|
bool ok_dist = true;
|
|
|
|
|
|
|
|
|
|
/* New view values. */
|
|
|
|
|
Object *camera_old = NULL;
|
|
|
|
|
float dist_new, ofs_new[3];
|
|
|
|
|
|
|
|
|
|
rv3d->localvd = MEM_mallocN(sizeof(RegionView3D), "localview region");
|
|
|
|
|
memcpy(rv3d->localvd, rv3d, sizeof(RegionView3D));
|
|
|
|
|
|
|
|
|
|
negate_v3_v3(ofs_new, mid);
|
|
|
|
|
|
|
|
|
|
if (rv3d->persp == RV3D_CAMOB) {
|
|
|
|
|
rv3d->persp = RV3D_PERSP;
|
|
|
|
|
camera_old = v3d->camera;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rv3d->persp == RV3D_ORTHO) {
|
|
|
|
|
if (size < 0.0001f) {
|
|
|
|
|
ok_dist = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ok_dist) {
|
|
|
|
|
dist_new = ED_view3d_radius_to_dist(v3d, ar, depsgraph, rv3d->persp, true, (size / 2) * VIEW3D_MARGIN);
|
|
|
|
|
|
|
|
|
|
if (rv3d->persp == RV3D_PERSP) {
|
|
|
|
|
/* Don't zoom closer than the near clipping plane. */
|
|
|
|
|
dist_new = max_ff(dist_new, v3d->near * 1.5f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ED_view3d_smooth_view_ex(
|
|
|
|
|
depsgraph,
|
|
|
|
|
wm, win, sa, v3d, ar, smooth_viewtx,
|
|
|
|
|
&(const V3D_SmoothParams) {
|
|
|
|
|
.camera_old = camera_old,
|
|
|
|
|
.ofs = ofs_new, .quat = rv3d->viewquat,
|
2019-01-07 00:58:10 +11:00
|
|
|
.dist = ok_dist ? &dist_new : NULL, .lens = &v3d->lens,
|
|
|
|
|
});
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v3d->local_view_uuid = local_view_bit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEG_on_visible_update(bmain, false);
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void restore_localviewdata(
|
|
|
|
|
const Depsgraph *depsgraph,
|
|
|
|
|
wmWindowManager *wm,
|
|
|
|
|
wmWindow *win,
|
|
|
|
|
Main *bmain,
|
|
|
|
|
ScrArea *sa,
|
|
|
|
|
const int smooth_viewtx)
|
|
|
|
|
{
|
|
|
|
|
const bool free = true;
|
|
|
|
|
ARegion *ar;
|
|
|
|
|
View3D *v3d = sa->spacedata.first;
|
|
|
|
|
Object *camera_old, *camera_new;
|
|
|
|
|
|
|
|
|
|
if (v3d->localvd == NULL) return;
|
|
|
|
|
|
|
|
|
|
camera_old = v3d->camera;
|
|
|
|
|
camera_new = v3d->localvd->camera;
|
|
|
|
|
|
|
|
|
|
v3d->local_view_uuid = 0;
|
|
|
|
|
v3d->camera = v3d->localvd->camera;
|
|
|
|
|
|
|
|
|
|
if (free) {
|
|
|
|
|
MEM_freeN(v3d->localvd);
|
|
|
|
|
v3d->localvd = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (ar = sa->regionbase.first; ar; ar = ar->next) {
|
|
|
|
|
if (ar->regiontype == RGN_TYPE_WINDOW) {
|
|
|
|
|
RegionView3D *rv3d = ar->regiondata;
|
|
|
|
|
|
|
|
|
|
if (rv3d->localvd) {
|
|
|
|
|
Object *camera_old_rv3d, *camera_new_rv3d;
|
|
|
|
|
|
|
|
|
|
camera_old_rv3d = (rv3d->persp == RV3D_CAMOB) ? camera_old : NULL;
|
|
|
|
|
camera_new_rv3d = (rv3d->localvd->persp == RV3D_CAMOB) ? camera_new : NULL;
|
|
|
|
|
|
|
|
|
|
rv3d->view = rv3d->localvd->view;
|
|
|
|
|
rv3d->persp = rv3d->localvd->persp;
|
|
|
|
|
rv3d->camzoom = rv3d->localvd->camzoom;
|
|
|
|
|
|
|
|
|
|
ED_view3d_smooth_view_ex(
|
|
|
|
|
depsgraph,
|
|
|
|
|
wm, win, sa,
|
|
|
|
|
v3d, ar, smooth_viewtx,
|
|
|
|
|
&(const V3D_SmoothParams) {
|
|
|
|
|
.camera_old = camera_old_rv3d, .camera = camera_new_rv3d,
|
|
|
|
|
.ofs = rv3d->localvd->ofs, .quat = rv3d->localvd->viewquat,
|
2019-01-07 00:58:10 +11:00
|
|
|
.dist = &rv3d->localvd->dist,
|
|
|
|
|
});
|
2018-11-25 09:50:34 -02:00
|
|
|
|
|
|
|
|
if (free) {
|
|
|
|
|
MEM_freeN(rv3d->localvd);
|
|
|
|
|
rv3d->localvd = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ED_view3d_shade_update(bmain, v3d, sa);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool view3d_localview_exit(
|
|
|
|
|
const Depsgraph *depsgraph,
|
|
|
|
|
wmWindowManager *wm,
|
|
|
|
|
wmWindow *win,
|
|
|
|
|
Main *bmain,
|
|
|
|
|
ViewLayer *view_layer,
|
|
|
|
|
ScrArea *sa,
|
|
|
|
|
const int smooth_viewtx)
|
|
|
|
|
{
|
|
|
|
|
View3D *v3d = sa->spacedata.first;
|
|
|
|
|
struct Base *base;
|
|
|
|
|
unsigned int local_view_bit;
|
|
|
|
|
|
|
|
|
|
if (v3d->localvd) {
|
|
|
|
|
|
|
|
|
|
local_view_bit = v3d->local_view_uuid;
|
|
|
|
|
|
|
|
|
|
restore_localviewdata(depsgraph, wm, win, bmain, sa, smooth_viewtx);
|
|
|
|
|
|
|
|
|
|
Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
|
|
|
|
|
for (base = FIRSTBASE(view_layer); base; base = base->next) {
|
|
|
|
|
if (base->local_view_bits & local_view_bit) {
|
|
|
|
|
base->local_view_bits &= ~local_view_bit;
|
|
|
|
|
if (base->object != obedit) {
|
|
|
|
|
ED_object_base_select(base, BA_SELECT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEG_on_visible_update(bmain, false);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int localview_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
const Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
|
|
|
|
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
|
|
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
|
wmWindow *win = CTX_wm_window(C);
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
|
bool changed;
|
|
|
|
|
|
|
|
|
|
if (v3d->localvd) {
|
|
|
|
|
changed = view3d_localview_exit(depsgraph, wm, win, bmain, view_layer, sa, smooth_viewtx);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
changed = view3d_localview_init(depsgraph, wm, win, bmain, view_layer, sa, smooth_viewtx, op->reports);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
|
DEG_id_type_tag(bmain, ID_OB);
|
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
|
|
|
|
|
|
/* Unselected objects become selected when exiting. */
|
|
|
|
|
if (v3d->localvd == NULL) {
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&scene->id, ID_RECALC_SELECT);
|
2018-11-25 09:50:34 -02:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&scene->id, ID_RECALC_BASE_FLAGS);
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_localview(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Local View";
|
|
|
|
|
ot->description = "Toggle display of selected object(s) separately and centered in view";
|
|
|
|
|
ot->idname = "VIEW3D_OT_localview";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = localview_exec;
|
|
|
|
|
ot->flag = OPTYPE_UNDO; /* localview changes object layer bitflags */
|
|
|
|
|
|
|
|
|
|
ot->poll = ED_operator_view3d_active;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-29 23:44:37 -02:00
|
|
|
static int localview_remove_from_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
|
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
|
|
for (Base *base = FIRSTBASE(view_layer); base; base = base->next) {
|
2019-01-08 18:19:12 +01:00
|
|
|
if (BASE_SELECTED(v3d, base)) {
|
2018-11-29 23:44:37 -02:00
|
|
|
base->local_view_bits &= ~v3d->local_view_uuid;
|
|
|
|
|
ED_object_base_select(base, BA_DESELECT);
|
|
|
|
|
|
|
|
|
|
if (base == BASACT(view_layer)) {
|
|
|
|
|
view_layer->basact = NULL;
|
|
|
|
|
}
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
|
DEG_on_visible_update(bmain, false);
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&scene->id, ID_RECALC_SELECT);
|
2018-11-29 23:44:37 -02:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
|
|
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "No object selected");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool localview_remove_from_poll(bContext *C)
|
|
|
|
|
{
|
|
|
|
|
if (CTX_data_edit_object(C) != NULL) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
|
return v3d && v3d->localvd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_localview_remove_from(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Remove from Local View";
|
|
|
|
|
ot->description = "Move selected objects out of local view";
|
|
|
|
|
ot->idname = "VIEW3D_OT_localview_remove_from";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = localview_remove_from_exec;
|
|
|
|
|
ot->invoke = WM_operator_confirm;
|
|
|
|
|
ot->poll = localview_remove_from_poll;
|
|
|
|
|
ot->flag = OPTYPE_UNDO;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
/** \} */
|
|
|
|
|
|
2018-01-28 16:22:34 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
2018-01-28 16:40:23 +11:00
|
|
|
/** \name View Layer Utilities
|
2018-01-28 16:22:34 +11:00
|
|
|
* \{ */
|
2009-02-14 10:03:24 +00:00
|
|
|
|
2018-07-01 16:22:06 +02:00
|
|
|
int ED_view3d_view_layer_set(int lay, const bool *values, int *active)
|
2009-12-03 09:49:21 +00:00
|
|
|
{
|
2012-03-25 23:54:33 +00:00
|
|
|
int i, tot = 0;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-12-03 09:49:21 +00:00
|
|
|
/* ensure we always have some layer selected */
|
2012-03-25 23:54:33 +00:00
|
|
|
for (i = 0; i < 20; i++)
|
2012-02-22 16:52:06 +00:00
|
|
|
if (values[i])
|
2009-12-03 09:49:21 +00:00
|
|
|
tot++;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
if (tot == 0)
|
2009-12-03 09:49:21 +00:00
|
|
|
return lay;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
for (i = 0; i < 20; i++) {
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-06-04 01:39:34 +00:00
|
|
|
if (active) {
|
|
|
|
|
/* if this value has just been switched on, make that layer active */
|
2012-03-25 23:54:33 +00:00
|
|
|
if (values[i] && (lay & (1 << i)) == 0) {
|
|
|
|
|
*active = (1 << i);
|
2010-06-04 01:39:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
if (values[i]) lay |= (1 << i);
|
|
|
|
|
else lay &= ~(1 << i);
|
2009-12-03 09:49:21 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-06-04 01:39:34 +00:00
|
|
|
/* ensure always an active layer */
|
2012-03-25 23:54:33 +00:00
|
|
|
if (active && (lay & *active) == 0) {
|
|
|
|
|
for (i = 0; i < 20; i++) {
|
|
|
|
|
if (lay & (1 << i)) {
|
|
|
|
|
*active = 1 << i;
|
2010-06-04 01:39:34 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-12-03 09:49:21 +00:00
|
|
|
return lay;
|
|
|
|
|
}
|
2008-12-19 12:14:58 +00:00
|
|
|
|
2018-01-28 16:22:34 +11:00
|
|
|
/** \} */
|