2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2008 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2008-12-18 17:38:21 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup spview3d
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
2008-12-18 17:38:21 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_linklist.h"
|
2019-08-19 14:25:29 -03:00
|
|
|
#include "BLI_listbase.h"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_matrix.h"
|
|
|
|
|
#include "BLI_math_rotation.h"
|
|
|
|
|
#include "BLI_math_vector.h"
|
2010-10-25 07:28:57 +00:00
|
|
|
#include "BLI_rect.h"
|
2008-12-18 17:38:21 +00:00
|
|
|
|
2024-09-10 14:55:47 +02:00
|
|
|
#include "BKE_action.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2025-01-26 20:08:00 +01:00
|
|
|
#ifdef WITH_XR_OPENXR
|
|
|
|
|
# include "BKE_idprop.hh"
|
|
|
|
|
#endif
|
2024-02-10 18:25:14 +01:00
|
|
|
#include "BKE_global.hh"
|
2024-01-23 15:18:09 -05:00
|
|
|
#include "BKE_layer.hh"
|
2024-01-15 12:44:04 -05:00
|
|
|
#include "BKE_lib_id.hh"
|
2023-12-01 19:43:16 +01:00
|
|
|
#include "BKE_main.hh"
|
2023-11-14 09:30:40 +01:00
|
|
|
#include "BKE_modifier.hh"
|
2023-10-09 23:41:53 +02:00
|
|
|
#include "BKE_object.hh"
|
2024-02-10 18:34:29 +01:00
|
|
|
#include "BKE_report.hh"
|
2024-02-10 19:16:25 +01:00
|
|
|
#include "BKE_scene.hh"
|
2008-12-18 17:38:21 +00:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph_query.hh"
|
2017-04-26 10:46:55 +02:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_resources.hh"
|
2017-08-25 22:22:50 +10:00
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
#include "GPU_matrix.hh"
|
2023-12-01 03:39:03 +01:00
|
|
|
#include "GPU_select.hh"
|
2024-03-23 01:24:18 +01:00
|
|
|
#include "GPU_state.hh"
|
2010-10-25 07:28:57 +00:00
|
|
|
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "WM_api.hh"
|
2008-12-18 17:38:21 +00:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "ED_object.hh"
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "ED_screen.hh"
|
2009-03-17 21:44:58 +00:00
|
|
|
|
2024-01-05 11:16:57 -05:00
|
|
|
#include "DRW_engine.hh"
|
2017-04-26 04:39:25 +10:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
|
|
|
|
#include "RNA_define.hh"
|
2019-02-20 18:30:13 +01:00
|
|
|
|
2024-03-26 20:34:48 -04:00
|
|
|
#include "view3d_intern.hh" /* own include */
|
2023-07-10 21:48:38 +02:00
|
|
|
#include "view3d_navigate.hh"
|
2018-01-28 16:22:34 +11:00
|
|
|
|
2025-02-05 09:48:00 +01:00
|
|
|
#include "DNA_camera_types.h"
|
|
|
|
|
|
2018-01-28 16:22:34 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Camera to View Operator
|
|
|
|
|
* \{ */
|
2009-11-22 23:11:32 +00:00
|
|
|
|
2023-07-10 21:48:38 +02:00
|
|
|
static int view3d_camera_to_view_exec(bContext *C, wmOperator * /*op*/)
|
2009-10-22 23:22:05 +00:00
|
|
|
{
|
2019-07-25 16:36:22 +02:00
|
|
|
const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
2014-02-27 11:33:27 +11:00
|
|
|
View3D *v3d;
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region;
|
2014-02-27 11:33:27 +11:00
|
|
|
RegionView3D *rv3d;
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2014-02-27 11:33:27 +11:00
|
|
|
ObjectTfmProtectedChannels obtfm;
|
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_view3d_context_user_region(C, &v3d, ®ion);
|
2023-07-10 21:48:38 +02:00
|
|
|
rv3d = static_cast<RegionView3D *>(region->regiondata);
|
2010-09-07 05:47:34 +00:00
|
|
|
|
2025-01-29 11:41:22 +11:00
|
|
|
ED_view3d_smooth_view_force_finish(C, v3d, region);
|
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
ED_view3d_lastview_store(rv3d);
|
2011-11-11 05:34:07 +00:00
|
|
|
|
2018-05-21 20:29:00 +02:00
|
|
|
BKE_object_tfm_protected_backup(v3d->camera, &obtfm);
|
2011-11-11 05:34:07 +00:00
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
ED_view3d_to_object(depsgraph, v3d->camera, rv3d->ofs, rv3d->viewquat, rv3d->dist);
|
2011-11-11 05:34:07 +00:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
BKE_object_tfm_protected_restore(v3d->camera, &obtfm, v3d->camera->protectflag);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
DEG_id_tag_update(&v3d->camera->id, ID_RECALC_TRANSFORM);
|
|
|
|
|
rv3d->persp = RV3D_CAMOB;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-06 00:19:47 +00:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, v3d->camera);
|
|
|
|
|
|
2011-11-14 03:54:23 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2009-01-06 00:19:47 +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-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;
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
if (ED_view3d_context_user_region(C, &v3d, ®ion)) {
|
2023-07-10 21:48:38 +02:00
|
|
|
RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
|
2022-03-28 17:34:36 +02:00
|
|
|
if (v3d && v3d->camera && BKE_id_is_editable(CTX_data_main(C), &v3d->camera->id)) {
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
if (rv3d && (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM) == 0) {
|
2014-02-27 11:33:27 +11:00
|
|
|
if (rv3d->persp != RV3D_CAMOB) {
|
2020-09-02 19:10:18 +02:00
|
|
|
return true;
|
2014-02-27 11:33:27 +11:00
|
|
|
}
|
|
|
|
|
}
|
2011-06-02 08:55:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-02 19:10:18 +02:00
|
|
|
return false;
|
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 */
|
2019-09-20 14:31:24 +02:00
|
|
|
ot->name = "Align Camera to View";
|
2012-03-22 07:26:09 +00:00
|
|
|
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
|
|
|
{
|
2020-12-14 12:48:16 +01:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2019-07-25 16:36:22 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
2012-03-25 23:54:33 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2023-07-10 21:48:38 +02:00
|
|
|
View3D *v3d = CTX_wm_view3d(C); /* can be nullptr */
|
2013-08-13 04:35:14 +00:00
|
|
|
Object *camera_ob = v3d ? v3d->camera : scene->camera;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-10 21:48:38 +02:00
|
|
|
if (camera_ob == nullptr) {
|
2013-08-13 04:35:14 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "No active camera");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-14 12:48:16 +01:00
|
|
|
if (ED_view3d_camera_to_view_selected(bmain, depsgraph, scene, camera_ob)) {
|
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;
|
|
|
|
|
}
|
2020-07-03 17:18:56 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2011-11-14 03:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2023-07-10 21:48:38 +02:00
|
|
|
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
|
|
|
|
|
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
|
|
|
|
LISTBASE_FOREACH (SpaceLink *, space_link, &area->spacedata) {
|
2016-10-10 14:47:03 +02:00
|
|
|
if (space_link->spacetype == SPACE_VIEW3D) {
|
2023-07-10 21:48:38 +02:00
|
|
|
View3D *other_v3d = reinterpret_cast<View3D *>(space_link);
|
2016-10-10 14:47:03 +02:00
|
|
|
if (other_v3d == v3d) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (other_v3d->camera == ob) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-04-12 10:10:12 +02:00
|
|
|
/* Checking the other view is needed to prevent local cameras being modified. */
|
|
|
|
|
if (v3d->scenelock && other_v3d->scenelock) {
|
2016-10-10 14:47:03 +02:00
|
|
|
ListBase *lb = (space_link == area->spacedata.first) ? &area->regionbase :
|
|
|
|
|
&space_link->regionbase;
|
2023-07-10 21:48:38 +02:00
|
|
|
LISTBASE_FOREACH (ARegion *, other_region, lb) {
|
2020-04-03 12:51:03 +02:00
|
|
|
if (other_region->regiontype == RGN_TYPE_WINDOW) {
|
|
|
|
|
if (other_region->regiondata) {
|
2023-07-10 21:48:38 +02:00
|
|
|
RegionView3D *other_rv3d = static_cast<RegionView3D *>(other_region->regiondata);
|
2016-10-10 14:47:03 +02:00
|
|
|
if (other_rv3d->persp == RV3D_CAMOB) {
|
|
|
|
|
Object *other_camera_old = other_v3d->camera;
|
|
|
|
|
other_v3d->camera = ob;
|
2023-07-10 21:48:38 +02:00
|
|
|
|
|
|
|
|
V3D_SmoothParams sview_params = {};
|
|
|
|
|
sview_params.camera_old = other_camera_old;
|
|
|
|
|
sview_params.camera = other_v3d->camera;
|
|
|
|
|
sview_params.ofs = other_rv3d->ofs;
|
|
|
|
|
sview_params.quat = other_rv3d->viewquat;
|
|
|
|
|
sview_params.dist = &other_rv3d->dist;
|
|
|
|
|
sview_params.lens = &other_v3d->lens;
|
|
|
|
|
/* No undo because this switches cameras. */
|
|
|
|
|
sview_params.undo_str = nullptr;
|
|
|
|
|
|
2016-10-10 14:47:03 +02:00
|
|
|
ED_view3d_lastview_store(other_rv3d);
|
2023-07-10 21:48:38 +02:00
|
|
|
ED_view3d_smooth_view(
|
|
|
|
|
C, other_v3d, other_region, smooth_viewtx, &sview_params);
|
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;
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region;
|
2012-01-14 12:24:25 +00:00
|
|
|
RegionView3D *rv3d;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
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);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-09-16 04:04:44 +00:00
|
|
|
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-10 21:48:38 +02:00
|
|
|
/* no nullptr check is needed, poll checks */
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_view3d_context_user_region(C, &v3d, ®ion);
|
2023-07-10 21:48:38 +02:00
|
|
|
rv3d = static_cast<RegionView3D *>(region->regiondata);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-01-29 11:41:22 +11:00
|
|
|
ED_view3d_smooth_view_force_finish(C, v3d, region);
|
|
|
|
|
|
2012-02-22 16:52:06 +00:00
|
|
|
if (ob) {
|
2023-07-10 21:48:38 +02:00
|
|
|
Object *camera_old = (rv3d->persp == RV3D_CAMOB) ? V3D_CAMERA_SCENE(scene, v3d) : nullptr;
|
2012-03-25 23:54:33 +00:00
|
|
|
rv3d->persp = RV3D_CAMOB;
|
|
|
|
|
v3d->camera = ob;
|
2019-03-08 12:11:42 +01:00
|
|
|
if (v3d->scenelock && scene->camera != ob) {
|
2012-03-25 23:54:33 +00:00
|
|
|
scene->camera = ob;
|
2024-02-19 15:54:08 +01:00
|
|
|
DEG_id_tag_update(&scene->id, ID_RECALC_SYNC_TO_EVAL);
|
2023-07-15 18:32:53 +03:00
|
|
|
DEG_relations_tag_update(CTX_data_main(C));
|
2019-03-08 12:11:42 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-30 07:04:38 +10:00
|
|
|
/* unlikely but looks like a glitch when set to the same */
|
|
|
|
|
if (camera_old != ob) {
|
2023-07-10 21:48:38 +02:00
|
|
|
V3D_SmoothParams sview_params = {};
|
|
|
|
|
sview_params.camera_old = camera_old;
|
|
|
|
|
sview_params.camera = v3d->camera;
|
|
|
|
|
sview_params.ofs = rv3d->ofs;
|
|
|
|
|
sview_params.quat = rv3d->viewquat;
|
|
|
|
|
sview_params.dist = &rv3d->dist;
|
|
|
|
|
sview_params.lens = &v3d->lens;
|
|
|
|
|
/* No undo because this switches cameras. */
|
|
|
|
|
sview_params.undo_str = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-10 21:48:38 +02:00
|
|
|
ED_view3d_lastview_store(rv3d);
|
|
|
|
|
ED_view3d_smooth_view(C, v3d, region, smooth_viewtx, &sview_params);
|
2013-09-16 04:04:44 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
|
|
}
|
2019-04-17 06:17:24 +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;
|
2020-04-03 12:51:03 +02:00
|
|
|
ARegion *region_dummy;
|
2012-01-14 12:24:25 +00:00
|
|
|
|
2020-04-03 12:51:03 +02:00
|
|
|
return ED_view3d_context_user_region(C, &v3d_dummy, ®ion_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
|
|
|
|
2024-09-10 17:31:02 +10:00
|
|
|
void view3d_winmatrix_set(const Depsgraph *depsgraph,
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region,
|
|
|
|
|
const View3D *v3d,
|
|
|
|
|
const rcti *rect)
|
2008-12-18 17:38:21 +00:00
|
|
|
{
|
2023-07-10 21:48:38 +02:00
|
|
|
RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
|
2021-12-08 15:40:09 +01:00
|
|
|
rctf full_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
|
|
|
|
2023-07-10 21:48:38 +02:00
|
|
|
is_ortho = ED_view3d_viewplane_get(depsgraph,
|
|
|
|
|
v3d,
|
|
|
|
|
rv3d,
|
|
|
|
|
region->winx,
|
|
|
|
|
region->winy,
|
|
|
|
|
&full_viewplane,
|
|
|
|
|
&clipsta,
|
|
|
|
|
&clipend,
|
|
|
|
|
nullptr);
|
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
|
2019-04-17 08:24:14 +02:00
|
|
|
printf("%s: %d %d %f %f %f %f %f %f\n",
|
|
|
|
|
__func__,
|
|
|
|
|
winx,
|
|
|
|
|
winy,
|
2021-12-08 15:40:09 +01:00
|
|
|
full_viewplane.xmin,
|
|
|
|
|
full_viewplane.ymin,
|
|
|
|
|
full_viewplane.xmax,
|
|
|
|
|
full_viewplane.ymax,
|
2019-04-17 08:24:14 +02:00
|
|
|
clipsta,
|
|
|
|
|
clipend);
|
2012-01-19 16:04:44 +00:00
|
|
|
#endif
|
|
|
|
|
|
2023-02-12 14:37:16 +11:00
|
|
|
/* Note the code here was tweaked to avoid an apparent compiler bug in clang 13 (see #91680). */
|
2021-12-08 15:40:09 +01:00
|
|
|
rctf viewplane;
|
|
|
|
|
if (rect) {
|
|
|
|
|
/* Smaller viewplane subset for selection picking. */
|
|
|
|
|
viewplane.xmin = full_viewplane.xmin +
|
2023-07-10 21:48:38 +02:00
|
|
|
(BLI_rctf_size_x(&full_viewplane) * (rect->xmin / float(region->winx)));
|
2021-12-08 15:40:09 +01:00
|
|
|
viewplane.ymin = full_viewplane.ymin +
|
2023-07-10 21:48:38 +02:00
|
|
|
(BLI_rctf_size_y(&full_viewplane) * (rect->ymin / float(region->winy)));
|
2021-12-08 15:40:09 +01:00
|
|
|
viewplane.xmax = full_viewplane.xmin +
|
2023-07-10 21:48:38 +02:00
|
|
|
(BLI_rctf_size_x(&full_viewplane) * (rect->xmax / float(region->winx)));
|
2021-12-08 15:40:09 +01:00
|
|
|
viewplane.ymax = full_viewplane.ymin +
|
2023-07-10 21:48:38 +02:00
|
|
|
(BLI_rctf_size_y(&full_viewplane) * (rect->ymax / float(region->winy)));
|
2021-12-08 15:40:09 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
viewplane = full_viewplane;
|
2014-06-19 17:00:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
|
|
|
2024-02-14 16:14:49 +01:00
|
|
|
normalize_m4_m4(bmat, ob->object_to_world().ptr());
|
2015-10-24 21:02:42 -02:00
|
|
|
invert_m4_m4(rv3d->viewmat, bmat);
|
|
|
|
|
|
|
|
|
|
/* view quat calculation, needed for add object */
|
2022-08-25 12:45:43 +10:00
|
|
|
mat4_normalized_to_quat(rv3d->viewquat, rv3d->viewmat);
|
2008-12-18 17:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-10 17:31:02 +10:00
|
|
|
void view3d_viewmatrix_set(const Depsgraph *depsgraph,
|
2020-03-13 17:27:11 +11:00
|
|
|
const 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;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-20 18:31:11 +00:00
|
|
|
/* should be moved to better initialize later on XXX */
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
if (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) {
|
2011-03-08 07:44:30 +00:00
|
|
|
ED_view3d_lock(rv3d);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
quat_to_mat4(rv3d->viewmat, rv3d->viewquat);
|
2019-03-26 21:16:47 +11:00
|
|
|
if (rv3d->persp == RV3D_PERSP) {
|
|
|
|
|
rv3d->viewmat[3][2] -= rv3d->dist;
|
|
|
|
|
}
|
2020-03-17 11:32:03 +11:00
|
|
|
if (v3d->ob_center) {
|
|
|
|
|
Object *ob_eval = DEG_get_evaluated_object(depsgraph, v3d->ob_center);
|
2008-12-18 17:38:21 +00:00
|
|
|
float vec[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-02-14 16:14:49 +01:00
|
|
|
copy_v3_v3(vec, ob_eval->object_to_world().location());
|
2020-03-17 11:32:03 +11:00
|
|
|
if (ob_eval->type == OB_ARMATURE && v3d->ob_center_bone[0]) {
|
|
|
|
|
bPoseChannel *pchan = BKE_pose_channel_find_name(ob_eval->pose, v3d->ob_center_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]);
|
2024-02-14 16:14:49 +01:00
|
|
|
mul_m4_v3(ob_eval->object_to_world().ptr(), vec);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
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
|
|
|
}
|
2020-03-17 11:32:03 +11:00
|
|
|
else if (v3d->ob_center_cursor) {
|
2010-10-31 01:18:26 +00:00
|
|
|
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]);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-19 10:54:02 +00:00
|
|
|
/* lock offset */
|
|
|
|
|
if (use_lock_ofs) {
|
|
|
|
|
float persmat[4][4], persinv[4][4];
|
|
|
|
|
float vec[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-19 10:54:02 +00:00
|
|
|
/* 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);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-19 10:54:02 +00:00
|
|
|
mul_v2_v2fl(vec, rv3d->ofs_lock, rv3d->is_persp ? rv3d->dist : 1.0f);
|
|
|
|
|
vec[2] = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-22 20:11:34 +11:00
|
|
|
if (rect_scale) {
|
2019-04-22 00:18:34 +10:00
|
|
|
/* Since 'RegionView3D.winmat' has been calculated and this function doesn't take the
|
|
|
|
|
* 'ARegion' we don't know about the region size.
|
2018-01-23 17:36:51 +11:00
|
|
|
* 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];
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
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
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
2025-02-04 21:17:14 +11:00
|
|
|
/** \name GPU Select Utilities
|
2018-01-28 16:22:34 +11:00
|
|
|
* \{ */
|
|
|
|
|
|
2025-02-04 21:17:14 +11:00
|
|
|
void view3d_gpu_select_cache_begin()
|
2017-03-09 20:47:37 +11:00
|
|
|
{
|
|
|
|
|
GPU_select_cache_begin();
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-04 21:17:14 +11:00
|
|
|
void view3d_gpu_select_cache_end()
|
2017-03-09 20:47:37 +11:00
|
|
|
{
|
|
|
|
|
GPU_select_cache_end();
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 16:31:36 +11:00
|
|
|
struct DrawSelectLoopUserData {
|
|
|
|
|
uint pass;
|
|
|
|
|
uint hits;
|
2023-11-30 21:27:15 +01:00
|
|
|
GPUSelectBuffer *buffer;
|
2018-03-01 16:31:36 +11:00
|
|
|
const rcti *rect;
|
2022-01-31 13:01:27 +11:00
|
|
|
eGPUSelectMode gpu_select_mode;
|
2018-03-01 16:31:36 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static bool drw_select_loop_pass(eDRWSelectStage stage, void *user_data)
|
|
|
|
|
{
|
|
|
|
|
bool continue_pass = false;
|
2023-07-10 21:48:38 +02:00
|
|
|
DrawSelectLoopUserData *data = static_cast<DrawSelectLoopUserData *>(user_data);
|
2018-03-01 16:31:36 +11:00
|
|
|
if (stage == DRW_SELECT_PASS_PRE) {
|
2023-11-30 21:27:15 +01:00
|
|
|
GPU_select_begin_next(data->buffer, data->rect, data->gpu_select_mode, data->hits);
|
2018-03-01 16:31:36 +11:00
|
|
|
/* 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;
|
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-09-03 14:59:34 +02:00
|
|
|
if (obact && (obact->mode & OB_MODE_ALL_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)
|
|
|
|
|
{
|
2023-07-10 21:48:38 +02:00
|
|
|
const Object *obact = static_cast<const Object *>(user_data);
|
|
|
|
|
return BKE_object_is_mode_compat(ob, eObjectMode(obact->mode));
|
2018-06-19 16:41:18 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-25 01:14:39 +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).
|
|
|
|
|
*/
|
2018-11-23 10:00:28 +11:00
|
|
|
static bool drw_select_filter_object_mode_lock_for_weight_paint(Object *ob, void *user_data)
|
|
|
|
|
{
|
2023-07-10 21:48:38 +02:00
|
|
|
LinkNode *ob_pose_list = static_cast<LinkNode *>(user_data);
|
2019-07-18 15:31:04 +10:00
|
|
|
return ob_pose_list && (BLI_linklist_index(ob_pose_list, DEG_get_original_object(ob)) != -1);
|
2018-11-23 10:00:28 +11:00
|
|
|
}
|
|
|
|
|
|
2025-02-04 21:17:14 +11:00
|
|
|
int view3d_gpu_select_ex(const ViewContext *vc,
|
|
|
|
|
GPUSelectBuffer *buffer,
|
|
|
|
|
const rcti *input,
|
|
|
|
|
eV3DSelectMode select_mode,
|
|
|
|
|
eV3DSelectObjectFilter select_filter,
|
|
|
|
|
const bool do_material_slot_selection)
|
2008-12-19 12:14:58 +00:00
|
|
|
{
|
2023-07-10 21:48:38 +02:00
|
|
|
bThemeState theme_state;
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
const wmWindowManager *wm = CTX_wm_manager(vc->C);
|
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;
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = vc->region;
|
2017-03-08 23:22:42 +11:00
|
|
|
rcti rect;
|
2018-09-04 17:14:46 +02:00
|
|
|
int hits = 0;
|
2022-09-14 21:33:51 +02:00
|
|
|
BKE_view_layer_synced_ensure(scene, vc->view_layer);
|
2023-07-10 21:48:38 +02:00
|
|
|
const bool use_obedit_skip = (BKE_view_layer_edit_object_get(vc->view_layer) != nullptr) &&
|
|
|
|
|
(vc->obedit == nullptr);
|
2024-12-04 19:09:41 +01:00
|
|
|
const bool use_nearest = select_mode == VIEW3D_SELECT_PICK_NEAREST;
|
2018-09-04 17:14:46 +02:00
|
|
|
bool draw_surface = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-04 19:09:41 +01:00
|
|
|
eGPUSelectMode gpu_select_mode = GPU_SELECT_INVALID;
|
2019-04-17 06:17:24 +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) {
|
2023-07-10 21:48:38 +02:00
|
|
|
const int xy[2] = {input->xmin, input->ymin};
|
2017-03-05 20:51:23 +11:00
|
|
|
/* seems to be default value for bones only now */
|
2023-07-10 21:48:38 +02:00
|
|
|
BLI_rcti_init_pt_radius(&rect, xy, 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
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-04 19:09:41 +01:00
|
|
|
if (select_mode == VIEW3D_SELECT_PICK_NEAREST) {
|
|
|
|
|
gpu_select_mode = GPU_SELECT_PICK_NEAREST;
|
|
|
|
|
}
|
|
|
|
|
else if (select_mode == VIEW3D_SELECT_PICK_ALL) {
|
|
|
|
|
gpu_select_mode = GPU_SELECT_PICK_ALL;
|
2017-03-09 05:17:55 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2024-12-04 19:09:41 +01:00
|
|
|
gpu_select_mode = GPU_SELECT_ALL;
|
2017-03-09 05:17:55 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-10 21:48:38 +02:00
|
|
|
/* Important to use 'vc->obact', not 'BKE_view_layer_active_object_get(vc->view_layer)' below,
|
|
|
|
|
* so it will be nullptr when hidden. */
|
|
|
|
|
struct {
|
|
|
|
|
DRW_ObjectFilterFn fn;
|
|
|
|
|
void *user_data;
|
|
|
|
|
} object_filter = {nullptr, nullptr};
|
|
|
|
|
|
2022-02-02 18:10:27 +11:00
|
|
|
/* Re-use cache (rect must be smaller than the cached)
|
|
|
|
|
* other context is assumed to be unchanged */
|
|
|
|
|
if (GPU_select_is_cached()) {
|
2023-11-30 21:27:15 +01:00
|
|
|
GPU_select_begin_next(buffer, &rect, gpu_select_mode, 0);
|
2022-02-02 18:10:27 +11:00
|
|
|
GPU_select_cache_load_id();
|
|
|
|
|
hits = GPU_select_end();
|
|
|
|
|
goto finally;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 16:41:18 +02:00
|
|
|
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;
|
2020-09-03 14:59:34 +02:00
|
|
|
BLI_assert(obact && (obact->mode & OB_MODE_ALL_WEIGHT_PAINT));
|
2019-07-18 15:31:04 +10:00
|
|
|
/* While this uses 'alloca' in a loop (which we typically avoid),
|
|
|
|
|
* the number of items is nearly always 1, maybe 2..3 in rare cases. */
|
2023-07-10 21:48:38 +02:00
|
|
|
LinkNode *ob_pose_list = nullptr;
|
2024-07-29 10:37:29 +02:00
|
|
|
VirtualModifierData virtual_modifier_data;
|
2024-11-27 14:44:26 +01:00
|
|
|
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(obact, &virtual_modifier_data);
|
2024-07-29 10:37:29 +02:00
|
|
|
for (; md; md = md->next) {
|
|
|
|
|
if (md->type == eModifierType_Armature) {
|
2024-11-27 14:44:26 +01:00
|
|
|
ArmatureModifierData *amd = reinterpret_cast<ArmatureModifierData *>(md);
|
|
|
|
|
if (amd->object && (amd->object->mode & OB_MODE_POSE)) {
|
|
|
|
|
BLI_linklist_prepend_alloca(&ob_pose_list, amd->object);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (md->type == eModifierType_GreasePencilArmature) {
|
|
|
|
|
GreasePencilArmatureModifierData *amd =
|
|
|
|
|
reinterpret_cast<GreasePencilArmatureModifierData *>(md);
|
2024-07-29 10:37:29 +02:00
|
|
|
if (amd->object && (amd->object->mode & OB_MODE_POSE)) {
|
|
|
|
|
BLI_linklist_prepend_alloca(&ob_pose_list, amd->object);
|
2019-07-18 15:31:04 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-23 10:00:28 +11:00
|
|
|
object_filter.fn = drw_select_filter_object_mode_lock_for_weight_paint;
|
2019-07-18 15:31:04 +10:00
|
|
|
object_filter.user_data = ob_pose_list;
|
2018-11-23 10:00:28 +11:00
|
|
|
break;
|
|
|
|
|
}
|
2018-06-19 16:41:18 +02:00
|
|
|
case VIEW3D_SELECT_FILTER_NOP:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
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);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-01 22:01:46 +11:00
|
|
|
/* All of the queries need to be perform on the drawing context. */
|
2023-06-08 15:46:53 +02:00
|
|
|
DRW_gpu_context_enable();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-02 13:39:51 +11:00
|
|
|
G.f |= G_FLAG_PICKSEL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-26 16:11:32 +10:00
|
|
|
/* Important we use the 'viewmat' and don't re-calculate since
|
2023-02-12 14:37:16 +11:00
|
|
|
* the object & bone view locking takes 'rect' into account, see: #51629. */
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_view3d_draw_setup_view(
|
2023-07-10 21:48:38 +02:00
|
|
|
wm, vc->win, depsgraph, scene, region, v3d, vc->rv3d->viewmat, nullptr, &rect);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-09 12:29:02 +02:00
|
|
|
if (!XRAY_ACTIVE(v3d)) {
|
2020-08-20 16:38:34 +02:00
|
|
|
GPU_depth_test(GPU_DEPTH_LESS_EQUAL);
|
2008-12-19 12:14:58 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-03-14 12:36:49 +11:00
|
|
|
/* If in X-ray mode, we select the wires in priority. */
|
2019-04-09 12:29:02 +02:00
|
|
|
if (XRAY_ACTIVE(v3d) && use_nearest) {
|
2018-09-04 17:14:46 +02:00
|
|
|
/* We need to call "GPU_select_*" API's inside DRW_draw_select_loop
|
2025-02-04 21:17:14 +11:00
|
|
|
* because the GPU context created & destroyed inside this function. */
|
2023-07-10 21:48:38 +02:00
|
|
|
DrawSelectLoopUserData drw_select_loop_user_data = {};
|
|
|
|
|
drw_select_loop_user_data.pass = 0;
|
|
|
|
|
drw_select_loop_user_data.hits = 0;
|
|
|
|
|
drw_select_loop_user_data.buffer = buffer;
|
|
|
|
|
drw_select_loop_user_data.rect = ▭
|
|
|
|
|
drw_select_loop_user_data.gpu_select_mode = gpu_select_mode;
|
|
|
|
|
|
2018-09-04 17:14:46 +02:00
|
|
|
draw_surface = false;
|
|
|
|
|
DRW_draw_select_loop(depsgraph,
|
2020-03-06 16:56:42 +01:00
|
|
|
region,
|
2018-09-04 17:14:46 +02:00
|
|
|
v3d,
|
|
|
|
|
use_obedit_skip,
|
|
|
|
|
draw_surface,
|
|
|
|
|
use_nearest,
|
2021-09-08 08:39:03 +02:00
|
|
|
do_material_slot_selection,
|
2018-09-04 17:14:46 +02:00
|
|
|
&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.
|
2023-02-12 14:37:16 +11:00
|
|
|
* (see #56695) */
|
2018-09-05 12:53:14 +02:00
|
|
|
GPU_select_cache_end();
|
2017-04-26 04:39:25 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
2025-02-04 21:17:14 +11:00
|
|
|
* because the GPU context created & destroyed inside this function. */
|
2023-07-10 21:48:38 +02:00
|
|
|
DrawSelectLoopUserData drw_select_loop_user_data = {};
|
|
|
|
|
drw_select_loop_user_data.pass = 0;
|
|
|
|
|
drw_select_loop_user_data.hits = 0;
|
|
|
|
|
drw_select_loop_user_data.buffer = buffer;
|
|
|
|
|
drw_select_loop_user_data.rect = ▭
|
|
|
|
|
drw_select_loop_user_data.gpu_select_mode = gpu_select_mode;
|
|
|
|
|
|
2019-04-09 12:29:02 +02:00
|
|
|
/* If are not in wireframe mode, we need to use the mesh surfaces to check for hits */
|
|
|
|
|
draw_surface = (v3d->shading.type > OB_WIRE) || !XRAY_ENABLED(v3d);
|
2018-02-06 16:10:03 +11:00
|
|
|
DRW_draw_select_loop(depsgraph,
|
2020-03-06 16:56:42 +01:00
|
|
|
region,
|
2018-05-29 12:01:07 +02:00
|
|
|
v3d,
|
2018-09-04 17:14:46 +02:00
|
|
|
use_obedit_skip,
|
|
|
|
|
draw_surface,
|
|
|
|
|
use_nearest,
|
2021-09-08 08:39:03 +02:00
|
|
|
do_material_slot_selection,
|
2018-09-04 17:14:46 +02:00
|
|
|
&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
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-02 13:39:51 +11:00
|
|
|
G.f &= ~G_FLAG_PICKSEL;
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
ED_view3d_draw_setup_view(
|
2023-07-10 21:48:38 +02:00
|
|
|
wm, vc->win, depsgraph, scene, region, v3d, vc->rv3d->viewmat, nullptr, nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-09 12:29:02 +02:00
|
|
|
if (!XRAY_ACTIVE(v3d)) {
|
2020-08-20 16:38:34 +02:00
|
|
|
GPU_depth_test(GPU_DEPTH_NONE);
|
2008-12-19 12:14:58 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-06-08 15:46:53 +02:00
|
|
|
DRW_gpu_context_disable();
|
2018-02-26 19:41:17 +01:00
|
|
|
|
2022-02-02 18:10:27 +11:00
|
|
|
UI_Theme_Restore(&theme_state);
|
|
|
|
|
|
2018-03-01 22:01:46 +11:00
|
|
|
finally:
|
2008-12-19 12:14:58 +00:00
|
|
|
return hits;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-04 21:17:14 +11:00
|
|
|
int view3d_gpu_select(const ViewContext *vc,
|
|
|
|
|
GPUSelectBuffer *buffer,
|
|
|
|
|
const rcti *input,
|
|
|
|
|
eV3DSelectMode select_mode,
|
|
|
|
|
eV3DSelectObjectFilter select_filter)
|
2021-09-08 08:39:03 +02:00
|
|
|
{
|
2025-02-04 21:17:14 +11:00
|
|
|
return view3d_gpu_select_ex(vc, buffer, input, select_mode, select_filter, false);
|
2021-09-08 08:39:03 +02:00
|
|
|
}
|
|
|
|
|
|
2025-02-04 21:17:14 +11:00
|
|
|
int view3d_gpu_select_with_id_filter(const ViewContext *vc,
|
|
|
|
|
GPUSelectBuffer *buffer,
|
|
|
|
|
const rcti *input,
|
|
|
|
|
eV3DSelectMode select_mode,
|
|
|
|
|
eV3DSelectObjectFilter select_filter,
|
|
|
|
|
uint select_id)
|
2020-06-10 17:50:11 +10:00
|
|
|
{
|
2023-11-30 21:27:15 +01:00
|
|
|
const int64_t start = buffer->storage.size();
|
2025-02-04 21:17:14 +11:00
|
|
|
int hits = view3d_gpu_select(vc, buffer, input, select_mode, select_filter);
|
2020-06-10 17:50:11 +10:00
|
|
|
|
|
|
|
|
/* Selection sometimes uses -1 for an invalid selection ID, remove these as they
|
|
|
|
|
* interfere with detection of actual number of hits in the selection. */
|
|
|
|
|
if (hits > 0) {
|
2023-11-30 21:27:15 +01:00
|
|
|
hits = GPU_select_buffer_remove_by_id(buffer->storage.as_mutable_span().slice(start, hits),
|
|
|
|
|
select_id);
|
|
|
|
|
|
|
|
|
|
/* Trim buffer to the exact size in case selections were removed. */
|
|
|
|
|
buffer->storage.resize(start + hits);
|
2020-06-10 17:50:11 +10:00
|
|
|
}
|
|
|
|
|
return hits;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-28 16:22:34 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Local View Operators
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2019-08-19 14:25:29 -03:00
|
|
|
static uint free_localview_bit(Main *bmain)
|
2018-11-25 09:50:34 -02:00
|
|
|
{
|
2019-03-01 23:43:34 +11:00
|
|
|
ushort local_view_bits = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-14 20:58:04 +11:00
|
|
|
/* Sometimes we lose a local-view: when an area is closed.
|
|
|
|
|
* Check all areas: which local-views are in use? */
|
2023-07-10 21:48:38 +02:00
|
|
|
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
|
|
|
|
|
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
|
|
|
|
SpaceLink *sl = static_cast<SpaceLink *>(area->spacedata.first);
|
2018-11-25 09:50:34 -02:00
|
|
|
for (; sl; sl = sl->next) {
|
|
|
|
|
if (sl->spacetype == SPACE_VIEW3D) {
|
2023-07-10 21:48:38 +02:00
|
|
|
View3D *v3d = reinterpret_cast<View3D *>(sl);
|
2018-11-25 09:50:34 -02:00
|
|
|
if (v3d->localvd) {
|
2024-01-23 16:06:45 +11:00
|
|
|
local_view_bits |= v3d->local_view_uid;
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
|
if ((local_view_bits & (1 << i)) == 0) {
|
|
|
|
|
return (1 << i);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool view3d_localview_init(const Depsgraph *depsgraph,
|
|
|
|
|
wmWindowManager *wm,
|
|
|
|
|
wmWindow *win,
|
|
|
|
|
Main *bmain,
|
2022-09-14 21:30:20 +02:00
|
|
|
const Scene *scene,
|
2018-11-25 09:50:34 -02:00
|
|
|
ViewLayer *view_layer,
|
2020-04-03 13:25:03 +02:00
|
|
|
ScrArea *area,
|
2019-02-20 18:30:13 +01:00
|
|
|
const bool frame_selected,
|
2018-11-25 09:50:34 -02:00
|
|
|
const int smooth_viewtx,
|
|
|
|
|
ReportList *reports)
|
|
|
|
|
{
|
2023-07-10 21:48:38 +02:00
|
|
|
View3D *v3d = static_cast<View3D *>(area->spacedata.first);
|
2024-12-20 19:09:20 -05:00
|
|
|
blender::float3 min, max, box;
|
2018-11-25 09:50:34 -02:00
|
|
|
float size = 0.0f;
|
2019-03-01 23:43:34 +11:00
|
|
|
uint local_view_bit;
|
2024-09-10 17:31:12 +10:00
|
|
|
bool changed = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
if (v3d->localvd) {
|
2024-09-10 17:31:12 +10:00
|
|
|
return changed;
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
INIT_MINMAX(min, max);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-19 14:25:29 -03:00
|
|
|
local_view_bit = free_localview_bit(bmain);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
if (local_view_bit == 0) {
|
|
|
|
|
/* TODO(dfelinto): We can kick one of the other 3D views out of local view
|
2021-06-24 15:56:58 +10:00
|
|
|
* specially if it is not being used. */
|
2018-11-25 09:50:34 -02:00
|
|
|
BKE_report(reports, RPT_ERROR, "No more than 16 local views");
|
2024-09-10 17:31:12 +10:00
|
|
|
changed = false;
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
|
|
|
|
else {
|
2022-09-14 21:33:51 +02:00
|
|
|
BKE_view_layer_synced_ensure(scene, view_layer);
|
2022-09-01 10:00:53 +02:00
|
|
|
Object *obedit = BKE_view_layer_edit_object_get(view_layer);
|
2018-11-25 09:50:34 -02:00
|
|
|
if (obedit) {
|
2022-09-14 21:33:51 +02:00
|
|
|
BKE_view_layer_synced_ensure(scene, view_layer);
|
|
|
|
|
LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) {
|
2019-10-23 13:36:11 -03:00
|
|
|
base->local_view_bits &= ~local_view_bit;
|
|
|
|
|
}
|
2022-09-14 21:30:20 +02:00
|
|
|
FOREACH_BASE_IN_EDIT_MODE_BEGIN (scene, view_layer, v3d, base_iter) {
|
2024-05-08 18:13:00 +02:00
|
|
|
Object *ob_eval = DEG_get_evaluated_object(depsgraph, base_iter->object);
|
|
|
|
|
BKE_object_minmax(ob_eval ? ob_eval : base_iter->object, min, max);
|
2018-11-25 09:50:34 -02:00
|
|
|
base_iter->local_view_bits |= local_view_bit;
|
2024-09-10 17:31:12 +10:00
|
|
|
changed = true;
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
|
|
|
|
FOREACH_BASE_IN_EDIT_MODE_END;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-09-14 21:33:51 +02:00
|
|
|
BKE_view_layer_synced_ensure(scene, view_layer);
|
|
|
|
|
LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) {
|
2019-01-08 18:19:12 +01:00
|
|
|
if (BASE_SELECTED(v3d, base)) {
|
2024-05-08 18:13:00 +02:00
|
|
|
Object *ob_eval = DEG_get_evaluated_object(depsgraph, base->object);
|
|
|
|
|
BKE_object_minmax(ob_eval ? ob_eval : base->object, min, max);
|
2018-11-25 09:50:34 -02:00
|
|
|
base->local_view_bits |= local_view_bit;
|
2024-09-10 17:31:12 +10:00
|
|
|
changed = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-10-23 13:36:11 -03:00
|
|
|
else {
|
|
|
|
|
base->local_view_bits &= ~local_view_bit;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
sub_v3_v3v3(box, max, min);
|
|
|
|
|
size = max_fff(box[0], box[1], box[2]);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-09-10 17:31:12 +10:00
|
|
|
if (changed == false) {
|
2019-02-20 18:30:13 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-09-10 17:31:04 +10:00
|
|
|
/* Apply any running smooth-view values before reading from the viewport. */
|
|
|
|
|
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
|
|
|
|
|
if (region->regiontype == RGN_TYPE_WINDOW) {
|
|
|
|
|
RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
|
|
|
|
|
if (rv3d->sms) {
|
|
|
|
|
ED_view3d_smooth_view_force_finish_no_camera_lock(depsgraph, wm, win, scene, v3d, region);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-10 21:48:38 +02:00
|
|
|
v3d->localvd = static_cast<View3D *>(MEM_mallocN(sizeof(View3D), "localview"));
|
2023-07-11 12:20:35 +10:00
|
|
|
*v3d->localvd = blender::dna::shallow_copy(*v3d);
|
2024-01-23 16:06:45 +11:00
|
|
|
v3d->local_view_uid = local_view_bit;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-10 21:48:38 +02:00
|
|
|
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
|
2020-03-06 16:56:42 +01:00
|
|
|
if (region->regiontype == RGN_TYPE_WINDOW) {
|
2023-07-10 21:48:38 +02:00
|
|
|
RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
|
2019-02-20 18:30:13 +01:00
|
|
|
bool ok_dist = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-20 18:30:13 +01:00
|
|
|
/* New view values. */
|
2023-07-10 21:48:38 +02:00
|
|
|
Object *camera_old = nullptr;
|
2019-02-20 18:30:13 +01:00
|
|
|
float dist_new, ofs_new[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-10 21:48:38 +02:00
|
|
|
rv3d->localvd = static_cast<RegionView3D *>(
|
|
|
|
|
MEM_mallocN(sizeof(RegionView3D), "localview region"));
|
2019-02-20 18:30:13 +01:00
|
|
|
memcpy(rv3d->localvd, rv3d, sizeof(RegionView3D));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-20 18:30:13 +01:00
|
|
|
if (frame_selected) {
|
|
|
|
|
float mid[3];
|
|
|
|
|
mid_v3_v3v3(mid, min, max);
|
2018-11-25 09:50:34 -02:00
|
|
|
negate_v3_v3(ofs_new, mid);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
if (rv3d->persp == RV3D_CAMOB) {
|
|
|
|
|
camera_old = v3d->camera;
|
2025-02-05 09:48:00 +01:00
|
|
|
const Camera &camera = *static_cast<Camera *>(camera_old->data);
|
|
|
|
|
rv3d->persp = (camera.type == CAM_ORTHO) ? RV3D_ORTHO : RV3D_PERSP;
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
if (rv3d->persp == RV3D_ORTHO) {
|
|
|
|
|
if (size < 0.0001f) {
|
|
|
|
|
ok_dist = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
if (ok_dist) {
|
|
|
|
|
dist_new = ED_view3d_radius_to_dist(
|
2020-03-06 16:56:42 +01:00
|
|
|
v3d, region, depsgraph, rv3d->persp, true, (size / 2) * VIEW3D_MARGIN);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
if (rv3d->persp == RV3D_PERSP) {
|
|
|
|
|
/* Don't zoom closer than the near clipping plane. */
|
2019-02-16 12:21:44 +11:00
|
|
|
dist_new = max_ff(dist_new, v3d->clip_start * 1.5f);
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-10 21:48:38 +02:00
|
|
|
V3D_SmoothParams sview_params = {};
|
|
|
|
|
sview_params.camera_old = camera_old;
|
|
|
|
|
sview_params.ofs = ofs_new;
|
|
|
|
|
sview_params.quat = rv3d->viewquat;
|
|
|
|
|
sview_params.dist = ok_dist ? &dist_new : nullptr;
|
|
|
|
|
sview_params.lens = &v3d->lens;
|
|
|
|
|
/* No undo because this doesn't move the camera. */
|
|
|
|
|
sview_params.undo_str = nullptr;
|
|
|
|
|
|
|
|
|
|
ED_view3d_smooth_view_ex(
|
|
|
|
|
depsgraph, wm, win, area, v3d, region, smooth_viewtx, &sview_params);
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-09-10 17:31:12 +10:00
|
|
|
return changed;
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
|
|
|
|
|
2024-09-10 17:31:12 +10:00
|
|
|
static bool view3d_localview_exit(const Depsgraph *depsgraph,
|
2018-11-25 09:50:34 -02:00
|
|
|
wmWindowManager *wm,
|
|
|
|
|
wmWindow *win,
|
2022-09-14 21:33:51 +02:00
|
|
|
const Scene *scene,
|
2019-02-21 11:32:52 +01:00
|
|
|
ViewLayer *view_layer,
|
2020-04-03 13:25:03 +02:00
|
|
|
ScrArea *area,
|
2019-02-20 18:30:13 +01:00
|
|
|
const bool frame_selected,
|
2018-11-25 09:50:34 -02:00
|
|
|
const int smooth_viewtx)
|
|
|
|
|
{
|
2023-07-10 21:48:38 +02:00
|
|
|
View3D *v3d = static_cast<View3D *>(area->spacedata.first);
|
2024-09-10 17:31:12 +10:00
|
|
|
bool changed = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-10 21:48:38 +02:00
|
|
|
if (v3d->localvd == nullptr) {
|
2024-09-10 17:31:12 +10:00
|
|
|
return changed;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2022-09-14 21:33:51 +02:00
|
|
|
BKE_view_layer_synced_ensure(scene, view_layer);
|
|
|
|
|
LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) {
|
2024-01-23 16:06:45 +11:00
|
|
|
if (base->local_view_bits & v3d->local_view_uid) {
|
|
|
|
|
base->local_view_bits &= ~v3d->local_view_uid;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-02-21 11:32:52 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-09-10 17:31:04 +10:00
|
|
|
/* Apply any running smooth-view values before reading from the viewport. */
|
|
|
|
|
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
|
|
|
|
|
if (region->regiontype == RGN_TYPE_WINDOW) {
|
|
|
|
|
RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
|
|
|
|
|
if (rv3d->localvd == nullptr) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (rv3d->sms) {
|
|
|
|
|
ED_view3d_smooth_view_force_finish_no_camera_lock(depsgraph, wm, win, scene, v3d, region);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 11:32:52 +01:00
|
|
|
Object *camera_old = v3d->camera;
|
|
|
|
|
Object *camera_new = v3d->localvd->camera;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-01-23 16:06:45 +11:00
|
|
|
v3d->local_view_uid = 0;
|
2018-11-25 09:50:34 -02:00
|
|
|
v3d->camera = v3d->localvd->camera;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-20 18:30:13 +01:00
|
|
|
MEM_freeN(v3d->localvd);
|
2023-07-10 21:48:38 +02:00
|
|
|
v3d->localvd = nullptr;
|
2025-02-20 10:37:10 +01:00
|
|
|
/* Cannot use MEM_SAFE_FREE, as #SceneStats type is only forward-declared in `DNA_layer_types.h`
|
|
|
|
|
*/
|
|
|
|
|
if (v3d->runtime.local_stats) {
|
|
|
|
|
MEM_freeN(static_cast<void *>(v3d->runtime.local_stats));
|
|
|
|
|
v3d->runtime.local_stats = nullptr;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
|
2020-03-06 16:56:42 +01:00
|
|
|
if (region->regiontype == RGN_TYPE_WINDOW) {
|
2023-07-10 21:48:38 +02:00
|
|
|
RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-10 21:48:38 +02:00
|
|
|
if (rv3d->localvd == nullptr) {
|
2019-02-20 18:30:13 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-07-23 18:23:02 +02:00
|
|
|
if (frame_selected && depsgraph) {
|
2018-11-25 09:50:34 -02:00
|
|
|
Object *camera_old_rv3d, *camera_new_rv3d;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-10 21:48:38 +02:00
|
|
|
camera_old_rv3d = (rv3d->persp == RV3D_CAMOB) ? camera_old : nullptr;
|
|
|
|
|
camera_new_rv3d = (rv3d->localvd->persp == RV3D_CAMOB) ? camera_new : nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
rv3d->view = rv3d->localvd->view;
|
2024-09-10 17:31:06 +10:00
|
|
|
rv3d->view_axis_roll = rv3d->localvd->view_axis_roll;
|
2018-11-25 09:50:34 -02:00
|
|
|
rv3d->persp = rv3d->localvd->persp;
|
|
|
|
|
rv3d->camzoom = rv3d->localvd->camzoom;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-10 21:48:38 +02:00
|
|
|
V3D_SmoothParams sview_params = {};
|
|
|
|
|
sview_params.camera_old = camera_old_rv3d;
|
|
|
|
|
sview_params.camera = camera_new_rv3d;
|
|
|
|
|
sview_params.ofs = rv3d->localvd->ofs;
|
|
|
|
|
sview_params.quat = rv3d->localvd->viewquat;
|
|
|
|
|
sview_params.dist = &rv3d->localvd->dist;
|
|
|
|
|
/* No undo because this doesn't move the camera. */
|
|
|
|
|
sview_params.undo_str = nullptr;
|
|
|
|
|
|
|
|
|
|
ED_view3d_smooth_view_ex(
|
|
|
|
|
depsgraph, wm, win, area, v3d, region, smooth_viewtx, &sview_params);
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-20 18:30:13 +01:00
|
|
|
MEM_freeN(rv3d->localvd);
|
2023-07-10 21:48:38 +02:00
|
|
|
rv3d->localvd = nullptr;
|
2024-09-10 17:31:12 +10:00
|
|
|
changed = true;
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
|
|
|
|
}
|
2024-09-10 17:31:12 +10:00
|
|
|
return changed;
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
|
|
|
|
|
2024-07-23 18:23:02 +02:00
|
|
|
bool ED_localview_exit_if_empty(const Depsgraph *depsgraph,
|
|
|
|
|
Scene *scene,
|
|
|
|
|
ViewLayer *view_layer,
|
|
|
|
|
wmWindowManager *wm,
|
|
|
|
|
wmWindow *win,
|
|
|
|
|
View3D *v3d,
|
|
|
|
|
ScrArea *area,
|
|
|
|
|
const bool frame_selected,
|
|
|
|
|
const int smooth_viewtx)
|
|
|
|
|
{
|
|
|
|
|
if (v3d->localvd == nullptr) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v3d->localvd->runtime.flag &= ~V3D_RUNTIME_LOCAL_MAYBE_EMPTY;
|
|
|
|
|
|
|
|
|
|
BKE_view_layer_synced_ensure(scene, view_layer);
|
|
|
|
|
LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) {
|
|
|
|
|
if (base->local_view_bits & v3d->local_view_uid) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-10 17:31:12 +10:00
|
|
|
return view3d_localview_exit(
|
2024-07-23 18:23:02 +02:00
|
|
|
depsgraph, wm, win, scene, view_layer, area, frame_selected, smooth_viewtx);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
static int localview_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2019-07-25 16:36:22 +02:00
|
|
|
const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
2018-11-25 09:50:34 -02:00
|
|
|
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);
|
2020-04-03 13:25:03 +02:00
|
|
|
ScrArea *area = CTX_wm_area(C);
|
2018-11-25 09:50:34 -02:00
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
2019-02-20 18:30:13 +01:00
|
|
|
bool frame_selected = RNA_boolean_get(op->ptr, "frame_selected");
|
2018-11-25 09:50:34 -02:00
|
|
|
bool changed;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
if (v3d->localvd) {
|
2024-09-10 17:31:12 +10:00
|
|
|
changed = view3d_localview_exit(
|
2022-09-14 21:33:51 +02:00
|
|
|
depsgraph, wm, win, scene, view_layer, area, frame_selected, smooth_viewtx);
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
|
|
|
|
else {
|
2022-09-14 21:30:20 +02:00
|
|
|
changed = view3d_localview_init(depsgraph,
|
|
|
|
|
wm,
|
|
|
|
|
win,
|
|
|
|
|
bmain,
|
|
|
|
|
scene,
|
|
|
|
|
view_layer,
|
|
|
|
|
area,
|
|
|
|
|
frame_selected,
|
|
|
|
|
smooth_viewtx,
|
|
|
|
|
op->reports);
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
if (changed) {
|
|
|
|
|
DEG_id_type_tag(bmain, ID_OB);
|
2020-04-03 13:25:03 +02:00
|
|
|
ED_area_tag_redraw(area);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
/* Unselected objects become selected when exiting. */
|
2023-07-10 21:48:38 +02:00
|
|
|
if (v3d->localvd == nullptr) {
|
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
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
2020-07-03 17:18:56 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = localview_exec;
|
2025-01-04 16:26:39 +11:00
|
|
|
/* Use undo because local-view changes object layer bit-flags. */
|
|
|
|
|
ot->flag = OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
ot->poll = ED_operator_view3d_active;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-20 18:30:13 +01:00
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
|
"frame_selected",
|
|
|
|
|
true,
|
|
|
|
|
"Frame Selected",
|
|
|
|
|
"Move the view to frame the selected objects");
|
2018-11-25 09:50:34 -02:00
|
|
|
}
|
|
|
|
|
|
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;
|
2022-09-14 21:33:51 +02:00
|
|
|
BKE_view_layer_synced_ensure(scene, view_layer);
|
|
|
|
|
LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) {
|
2019-01-08 18:19:12 +01:00
|
|
|
if (BASE_SELECTED(v3d, base)) {
|
2024-01-23 16:06:45 +11:00
|
|
|
base->local_view_bits &= ~v3d->local_view_uid;
|
2024-03-28 01:30:38 +01:00
|
|
|
blender::ed::object::base_select(base, blender::ed::object::BA_DESELECT);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-01 10:00:53 +02:00
|
|
|
if (base == view_layer->basact) {
|
2023-07-10 21:48:38 +02:00
|
|
|
view_layer->basact = nullptr;
|
2018-11-29 23:44:37 -02:00
|
|
|
}
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-07-23 18:23:02 +02:00
|
|
|
/* If some object was removed from the local view, exit the local view if it is now empty. */
|
|
|
|
|
if (changed) {
|
|
|
|
|
ED_localview_exit_if_empty(CTX_data_ensure_evaluated_depsgraph(C),
|
|
|
|
|
scene,
|
|
|
|
|
view_layer,
|
|
|
|
|
CTX_wm_manager(C),
|
|
|
|
|
CTX_wm_window(C),
|
|
|
|
|
v3d,
|
|
|
|
|
CTX_wm_area(C),
|
|
|
|
|
true,
|
|
|
|
|
WM_operator_smooth_viewtx_get(op));
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-29 23:44:37 -02:00
|
|
|
if (changed) {
|
2021-06-21 14:05:13 +02:00
|
|
|
DEG_tag_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;
|
|
|
|
|
}
|
2020-07-03 17:18:56 +02:00
|
|
|
|
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "No object selected");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
2018-11-29 23:44:37 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool localview_remove_from_poll(bContext *C)
|
|
|
|
|
{
|
2023-07-10 21:48:38 +02:00
|
|
|
if (CTX_data_edit_object(C) != nullptr) {
|
2018-11-29 23:44:37 -02:00
|
|
|
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";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-29 23:44:37 -02:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = localview_remove_from_exec;
|
|
|
|
|
ot->poll = localview_remove_from_poll;
|
|
|
|
|
ot->flag = OPTYPE_UNDO;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-25 09:50:34 -02:00
|
|
|
/** \} */
|
2019-08-19 14:25:29 -03:00
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Local Collections
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2024-03-20 22:41:58 -03:00
|
|
|
static uint free_localcollection_bit(const Main *bmain,
|
|
|
|
|
ushort local_collections_uid,
|
|
|
|
|
bool *r_reset)
|
2019-08-19 14:25:29 -03:00
|
|
|
{
|
|
|
|
|
ushort local_view_bits = 0;
|
|
|
|
|
|
2021-07-05 12:47:46 +10:00
|
|
|
/* Check all areas: which local-views are in use? */
|
2023-07-10 21:48:38 +02:00
|
|
|
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
|
|
|
|
|
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
|
|
|
|
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
|
2019-08-19 14:25:29 -03:00
|
|
|
if (sl->spacetype == SPACE_VIEW3D) {
|
2023-07-10 21:48:38 +02:00
|
|
|
View3D *v3d = reinterpret_cast<View3D *>(sl);
|
2019-08-19 14:25:29 -03:00
|
|
|
if (v3d->flag & V3D_LOCAL_COLLECTIONS) {
|
2024-01-23 16:06:45 +11:00
|
|
|
local_view_bits |= v3d->local_collections_uid;
|
2019-08-19 14:25:29 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* First try to keep the old uuid. */
|
2024-01-23 16:06:45 +11:00
|
|
|
if (local_collections_uid && ((local_collections_uid & local_view_bits) == 0)) {
|
|
|
|
|
return local_collections_uid;
|
2019-08-19 14:25:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Otherwise get the first free available. */
|
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
|
if ((local_view_bits & (1 << i)) == 0) {
|
2020-03-25 17:58:58 +11:00
|
|
|
*r_reset = true;
|
2019-08-19 14:25:29 -03:00
|
|
|
return (1 << i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void local_collections_reset_uuid(LayerCollection *layer_collection,
|
2020-04-03 16:21:24 +11:00
|
|
|
const ushort local_view_bit)
|
2019-08-19 14:25:29 -03:00
|
|
|
{
|
2019-10-03 19:22:36 -03:00
|
|
|
if (layer_collection->flag & LAYER_COLLECTION_HIDE) {
|
|
|
|
|
layer_collection->local_collections_bits &= ~local_view_bit;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
layer_collection->local_collections_bits |= local_view_bit;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-19 14:25:29 -03:00
|
|
|
LISTBASE_FOREACH (LayerCollection *, child, &layer_collection->layer_collections) {
|
|
|
|
|
local_collections_reset_uuid(child, local_view_bit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-20 22:41:58 -03:00
|
|
|
static void view3d_local_collections_reset(const Main *bmain, const uint local_view_bit)
|
2019-08-19 14:25:29 -03:00
|
|
|
{
|
|
|
|
|
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
|
|
|
|
|
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
|
|
|
|
|
LISTBASE_FOREACH (LayerCollection *, layer_collection, &view_layer->layer_collections) {
|
|
|
|
|
local_collections_reset_uuid(layer_collection, local_view_bit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-20 22:41:58 -03:00
|
|
|
bool ED_view3d_local_collections_set(const Main *bmain, View3D *v3d)
|
2019-08-19 14:25:29 -03:00
|
|
|
{
|
|
|
|
|
if ((v3d->flag & V3D_LOCAL_COLLECTIONS) == 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool reset = false;
|
|
|
|
|
v3d->flag &= ~V3D_LOCAL_COLLECTIONS;
|
2024-01-23 16:06:45 +11:00
|
|
|
uint local_view_bit = free_localcollection_bit(bmain, v3d->local_collections_uid, &reset);
|
2019-08-19 14:25:29 -03:00
|
|
|
|
|
|
|
|
if (local_view_bit == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-23 16:06:45 +11:00
|
|
|
v3d->local_collections_uid = local_view_bit;
|
2019-08-19 14:25:29 -03:00
|
|
|
v3d->flag |= V3D_LOCAL_COLLECTIONS;
|
|
|
|
|
|
|
|
|
|
if (reset) {
|
|
|
|
|
view3d_local_collections_reset(bmain, local_view_bit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-20 22:41:58 -03:00
|
|
|
void ED_view3d_local_collections_reset(const bContext *C, const bool reset_all)
|
2019-08-19 14:25:29 -03:00
|
|
|
{
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
uint local_view_bit = ~(0);
|
|
|
|
|
bool do_reset = false;
|
|
|
|
|
|
|
|
|
|
/* Reset only the ones that are not in use. */
|
|
|
|
|
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
|
|
|
|
|
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
|
|
|
|
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
|
|
|
|
|
if (sl->spacetype == SPACE_VIEW3D) {
|
2023-07-10 21:48:38 +02:00
|
|
|
View3D *v3d = reinterpret_cast<View3D *>(sl);
|
2024-01-23 16:06:45 +11:00
|
|
|
if (v3d->local_collections_uid) {
|
2019-08-19 14:25:29 -03:00
|
|
|
if (v3d->flag & V3D_LOCAL_COLLECTIONS) {
|
2024-01-23 16:06:45 +11:00
|
|
|
local_view_bit &= ~v3d->local_collections_uid;
|
2019-08-19 14:25:29 -03:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
do_reset = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (do_reset) {
|
|
|
|
|
view3d_local_collections_reset(bmain, local_view_bit);
|
|
|
|
|
}
|
|
|
|
|
else if (reset_all && (do_reset || (local_view_bit != ~(0)))) {
|
|
|
|
|
view3d_local_collections_reset(bmain, ~(0));
|
2023-07-10 21:48:38 +02:00
|
|
|
View3D v3d = {};
|
2024-01-23 16:06:45 +11:00
|
|
|
v3d.local_collections_uid = ~(0);
|
2022-09-14 21:30:20 +02:00
|
|
|
BKE_layer_collection_local_sync(CTX_data_scene(C), CTX_data_view_layer(C), &v3d);
|
2019-08-19 14:25:29 -03:00
|
|
|
DEG_id_tag_update(&CTX_data_scene(C)->id, ID_RECALC_BASE_FLAGS);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name XR Functionality
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_XR_OPENXR
|
|
|
|
|
|
|
|
|
|
static void view3d_xr_mirror_begin(RegionView3D *rv3d)
|
|
|
|
|
{
|
|
|
|
|
/* If there is no session yet, changes below should not be applied! */
|
|
|
|
|
BLI_assert(WM_xr_session_exists(&((wmWindowManager *)G_MAIN->wm.first)->xr));
|
|
|
|
|
|
|
|
|
|
rv3d->runtime_viewlock |= RV3D_LOCK_ANY_TRANSFORM;
|
|
|
|
|
/* Force perspective view. This isn't reset but that's not really an issue. */
|
|
|
|
|
rv3d->persp = RV3D_PERSP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void view3d_xr_mirror_end(RegionView3D *rv3d)
|
|
|
|
|
{
|
|
|
|
|
rv3d->runtime_viewlock &= ~RV3D_LOCK_ANY_TRANSFORM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ED_view3d_xr_mirror_update(const ScrArea *area, const View3D *v3d, const bool enable)
|
|
|
|
|
{
|
|
|
|
|
ARegion *region_rv3d;
|
|
|
|
|
|
|
|
|
|
BLI_assert(v3d->spacetype == SPACE_VIEW3D);
|
|
|
|
|
|
|
|
|
|
if (ED_view3d_area_user_region(area, v3d, ®ion_rv3d)) {
|
|
|
|
|
if (enable) {
|
2023-07-10 21:48:38 +02:00
|
|
|
view3d_xr_mirror_begin(static_cast<RegionView3D *>(region_rv3d->regiondata));
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2023-07-10 21:48:38 +02:00
|
|
|
view3d_xr_mirror_end(static_cast<RegionView3D *>(region_rv3d->regiondata));
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ED_view3d_xr_shading_update(wmWindowManager *wm, const View3D *v3d, const Scene *scene)
|
|
|
|
|
{
|
|
|
|
|
if (v3d->runtime.flag & V3D_RUNTIME_XR_SESSION_ROOT) {
|
|
|
|
|
View3DShading *xr_shading = &wm->xr.session_settings.shading;
|
2020-08-14 16:57:57 +02:00
|
|
|
/* Flags that shouldn't be overridden by the 3D View shading. */
|
2021-10-26 13:33:21 +09:00
|
|
|
int flag_copy = 0;
|
2021-11-13 13:07:13 +11:00
|
|
|
if (v3d->shading.type != OB_SOLID) {
|
|
|
|
|
/* Don't set V3D_SHADING_WORLD_ORIENTATION for solid shading since it results in distorted
|
|
|
|
|
* lighting when the view matrix has a scale factor. */
|
2021-10-26 13:33:21 +09:00
|
|
|
flag_copy |= V3D_SHADING_WORLD_ORIENTATION;
|
|
|
|
|
}
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
|
|
|
|
|
BLI_assert(WM_xr_session_exists(&wm->xr));
|
|
|
|
|
|
|
|
|
|
if (v3d->shading.type == OB_RENDER) {
|
|
|
|
|
if (!(BKE_scene_uses_blender_workbench(scene) || BKE_scene_uses_blender_eevee(scene))) {
|
|
|
|
|
/* Keep old shading while using Cycles or another engine, they are typically not usable in
|
|
|
|
|
* VR. */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (xr_shading->prop) {
|
|
|
|
|
IDP_FreeProperty(xr_shading->prop);
|
2023-07-10 21:48:38 +02:00
|
|
|
xr_shading->prop = nullptr;
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Copy shading from View3D to VR view. */
|
2020-08-14 16:57:57 +02:00
|
|
|
const int old_xr_shading_flag = xr_shading->flag;
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
*xr_shading = v3d->shading;
|
2020-08-14 16:57:57 +02:00
|
|
|
xr_shading->flag = (xr_shading->flag & ~flag_copy) | (old_xr_shading_flag & flag_copy);
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
if (v3d->shading.prop) {
|
|
|
|
|
xr_shading->prop = IDP_CopyProperty(xr_shading->prop);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ED_view3d_is_region_xr_mirror_active(const wmWindowManager *wm,
|
|
|
|
|
const View3D *v3d,
|
|
|
|
|
const ARegion *region)
|
|
|
|
|
{
|
|
|
|
|
return (v3d->flag & V3D_XR_SESSION_MIRROR) &&
|
2020-10-14 15:24:42 +11:00
|
|
|
/* The free region (e.g. the camera region in quad-view) is always
|
|
|
|
|
* the last in the list base. We don't want any other to be affected. */
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
!region->next && //
|
|
|
|
|
WM_xr_session_is_ready(&wm->xr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/** \} */
|