[Bf-blender-cvs] [f6a7d5336bb] xr-actions-D9124: XR: Add "selection eye" session setting
Peter Kim
noreply at git.blender.org
Sat Oct 17 16:43:53 CEST 2020
Commit: f6a7d5336bb73224295434a35e6c7e3e14e9d96e
Author: Peter Kim
Date: Sat Oct 17 11:59:50 2020 +0900
Branches: xr-actions-D9124
https://developer.blender.org/rBf6a7d5336bb73224295434a35e6c7e3e14e9d96e
XR: Add "selection eye" session setting
The "selection eye" is the XR eye (view) used for 3D-to-2D projection.
Its parameters are used to override the window view when selecting
with VR controllers.
===================================================================
M intern/ghost/GHOST_Types.h
M intern/ghost/intern/GHOST_XrSession.cpp
M intern/ghost/intern/GHOST_XrSession.h
M source/blender/editors/space_view3d/view3d_draw.c
M source/blender/editors/space_view3d/view3d_select.c
M source/blender/makesdna/DNA_xr_types.h
M source/blender/makesrna/intern/rna_wm.c
M source/blender/makesrna/intern/rna_xr.c
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/WM_types.h
M source/blender/windowmanager/intern/wm_event_query.c
M source/blender/windowmanager/intern/wm_event_system.c
M source/blender/windowmanager/intern/wm_gesture_ops.c
M source/blender/windowmanager/wm_event_system.h
M source/blender/windowmanager/xr/intern/wm_xr_draw.c
M source/blender/windowmanager/xr/intern/wm_xr_intern.h
M source/blender/windowmanager/xr/intern/wm_xr_session.c
===================================================================
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index f7b3004f837..822da627e74 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -670,6 +670,9 @@ typedef struct GHOST_XrDrawViewInfo {
/** Set if the buffer should be submitted with a srgb transfer applied. */
char expects_srgb_buffer;
+
+ /** The eye (left or right) that this view represents. */
+ char view;
} GHOST_XrDrawViewInfo;
typedef struct GHOST_XrError {
diff --git a/intern/ghost/intern/GHOST_XrSession.cpp b/intern/ghost/intern/GHOST_XrSession.cpp
index 371726bbcbd..299e047abdf 100644
--- a/intern/ghost/intern/GHOST_XrSession.cpp
+++ b/intern/ghost/intern/GHOST_XrSession.cpp
@@ -429,6 +429,7 @@ void GHOST_XrSession::drawView(GHOST_XrSwapchain &swapchain,
XrCompositionLayerProjectionView &r_proj_layer_view,
XrSpaceLocation &view_location,
XrView &view,
+ uint32_t view_idx,
void *draw_customdata)
{
XrSwapchainImageBaseHeader *swapchain_image = swapchain.acquireDrawableSwapchainImage();
@@ -439,6 +440,7 @@ void GHOST_XrSession::drawView(GHOST_XrSwapchain &swapchain,
r_proj_layer_view.fov = view.fov;
swapchain.updateCompositionLayerProjectViewSubImage(r_proj_layer_view.subImage);
+ draw_view_info.view = (char)view_idx;
draw_view_info.expects_srgb_buffer = swapchain.isBufferSRGB();
draw_view_info.ofsx = r_proj_layer_view.subImage.imageRect.offset.x;
draw_view_info.ofsy = r_proj_layer_view.subImage.imageRect.offset.y;
@@ -488,6 +490,7 @@ XrCompositionLayerProjection GHOST_XrSession::drawLayer(
r_proj_layer_views[view_idx],
view_location,
m_oxr->views[view_idx],
+ view_idx,
draw_customdata);
}
diff --git a/intern/ghost/intern/GHOST_XrSession.h b/intern/ghost/intern/GHOST_XrSession.h
index 9412aaaca87..3f6e3491c40 100644
--- a/intern/ghost/intern/GHOST_XrSession.h
+++ b/intern/ghost/intern/GHOST_XrSession.h
@@ -120,6 +120,7 @@ class GHOST_XrSession {
XrCompositionLayerProjectionView &r_proj_layer_view,
XrSpaceLocation &view_location,
XrView &view,
+ uint32_t view_idx,
void *draw_customdata);
void beginFrameDrawing();
void endFrameDrawing(std::vector<XrCompositionLayerBaseHeader *> &layers);
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index bc587e5a4b4..32403a98912 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -331,8 +331,13 @@ static void view3d_xr_mirror_setup(const wmWindowManager *wm,
RegionView3D *rv3d = region->regiondata;
float viewmat[4][4];
const float lens_old = v3d->lens;
+ /* Here we need to use the viewmat from the selection eye instead of the eye centroid because
+ * this function may be called from a GPU select operation. In that case we need to match the
+ * selection eye's view, which was used to project 3D to 2D, for a correct result. */
+ const bool from_selection_eye = true;
- if (!WM_xr_session_state_viewer_pose_matrix_info_get(&wm->xr, viewmat, &v3d->lens)) {
+ if (!WM_xr_session_state_viewer_pose_matrix_info_get(
+ &wm->xr, from_selection_eye, viewmat, &v3d->lens)) {
/* Can't get info from XR session, use fallback values. */
copy_m4_m4(viewmat, rv3d->viewmat);
v3d->lens = lens_old;
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 9c12a396ab9..47c92593f59 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -2513,33 +2513,54 @@ static int view3d_select_invoke_3d(bContext *C, wmOperator *op, const wmEvent *e
BLI_assert(event->custom == EVT_DATA_XR);
BLI_assert(event->customdata);
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+ Scene *scene = CTX_data_scene(C);
+ View3D *v3d = CTX_wm_view3d(C);
ARegion *region = CTX_wm_region(C);
RegionView3D *rv3d = region->regiondata;
wmXrActionData *customdata = event->customdata;
+ short winx_prev, winy_prev;
+ rcti winrct_prev;
+ float lens_prev;
float viewmat_prev[4][4];
float winmat_prev[4][4];
int mval[2];
WM_xr_controller_loc_to_mval(customdata->controller_loc,
- customdata->viewmat,
- customdata->winmat,
- region->winx,
- region->winy,
+ customdata->eye_viewmat,
+ customdata->eye_winmat,
+ customdata->eye_width,
+ customdata->eye_height,
mval);
RNA_int_set_array(op->ptr, "location", mval);
/* Since this function is called in a window context, we need to replace the
- * window viewmat and winmat with the XR surface counterparts to get a correct
+ * window view parameters with the XR surface counterparts to get a correct
* result for GPU select. */
+ winx_prev = region->winx;
+ winy_prev = region->winy;
+ winrct_prev = region->winrct;
+ lens_prev = v3d->lens;
copy_m4_m4(viewmat_prev, rv3d->viewmat);
copy_m4_m4(winmat_prev, rv3d->winmat);
- copy_m4_m4(rv3d->viewmat, customdata->viewmat);
- copy_m4_m4(rv3d->winmat, customdata->winmat);
+
+ region->winrct.xmin = 0;
+ region->winrct.ymin = 0;
+ region->winrct.xmax = region->winx = customdata->eye_width;
+ region->winrct.ymax = region->winy = customdata->eye_height;
+ v3d->lens = customdata->eye_lens;
+ copy_m4_m4(rv3d->viewmat, customdata->eye_viewmat);
+ copy_m4_m4(rv3d->winmat, customdata->eye_winmat);
int retval = view3d_select_exec(C, op);
- copy_m4_m4(rv3d->viewmat, viewmat_prev);
- copy_m4_m4(rv3d->winmat, winmat_prev);
+
+ /* Restore window view. */
+ region->winx = winx_prev;
+ region->winy = winy_prev;
+ region->winrct = winrct_prev;
+ v3d->lens = lens_prev;
+ ED_view3d_update_viewmat(depsgraph, scene, v3d, region, viewmat_prev, winmat_prev, NULL, false);
return retval;
}
diff --git a/source/blender/makesdna/DNA_xr_types.h b/source/blender/makesdna/DNA_xr_types.h
index caa5232788a..1a3f4a09c70 100644
--- a/source/blender/makesdna/DNA_xr_types.h
+++ b/source/blender/makesdna/DNA_xr_types.h
@@ -36,7 +36,11 @@ typedef struct XrSessionSettings {
/** View3D draw flags (V3D_OFSDRAW_NONE, V3D_OFSDRAW_SHOW_ANNOTATION, ...). */
char draw_flags;
- char _pad2[3];
+
+ /** The eye (view) that will be used when projecting 3D to 2D (e.g. when performing GPU select).
+ */
+ char selection_eye;
+ char _pad2[2];
/** Clipping distance. */
float clip_start, clip_end;
@@ -53,3 +57,8 @@ typedef enum eXRSessionBasePoseType {
XR_BASE_POSE_OBJECT = 1,
XR_BASE_POSE_CUSTOM = 2,
} eXRSessionBasePoseType;
+
+typedef enum eXrSessionEye {
+ XR_EYE_LEFT = 0,
+ XR_EYE_RIGHT = 1,
+} eXrSessionEye;
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index 949f25fac2d..5cbe1a1cbbf 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -686,7 +686,7 @@ static void rna_Event_xr_action_get(PointerRNA *ptr, char *value)
{
const wmEvent *event = ptr->data;
if (WM_event_is_xr(event)) {
- WM_event_xr_data(event, &value, NULL, NULL, NULL, NULL, NULL, NULL);
+ WM_event_xr_data(event, &value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
else {
value[0] = '\0';
@@ -710,7 +710,7 @@ static int rna_Event_xr_type_get(PointerRNA *ptr)
const wmEvent *event = ptr->data;
if (WM_event_is_xr(event)) {
GHOST_XrActionType type;
- WM_event_xr_data(event, NULL, (char *)&type, NULL, NULL, NULL, NULL, NULL);
+ WM_event_xr_data(event, NULL, (char *)&type, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
return type;
}
else {
@@ -722,7 +722,7 @@ static void rna_Event_xr_state_get(PointerRNA *ptr, float *value)
{
const wmEvent *event = ptr->data;
if (WM_event_is_xr(event)) {
- WM_event_xr_data(event, NULL, NULL, value, NULL, NULL, NULL, NULL);
+ WM_event_xr_data(event, NULL, NULL, value, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
else {
memset(value, 0, sizeof(float[2]));
@@ -733,7 +733,7 @@ static void rna_Event_xr_controller_location_get(PointerRNA *ptr, float *value)
{
const wmEvent *event = ptr->data;
if (WM_event_is_xr(event)) {
- WM_event_xr_data(event, NULL, NULL, NULL, value, NULL, NULL, NULL);
+ WM_event_xr_data(event, NULL, NULL, NULL, value, NULL, NULL, NULL, NULL, NULL, NULL);
}
else {
memset(value, 0, sizeof(float[3]));
@@ -744,7 +744,7 @@ static void rna_Event_xr_controller_rotation_get(PointerRNA *ptr, float *value)
{
const wmEvent *event = ptr->data;
if (WM_event_is_xr(event)) {
- WM_event_xr_data(event, NULL, NULL, NULL, NULL, value, NULL, NULL);
+ WM_event_xr_data(event, NULL, NULL, NULL, NULL, value, NULL, NULL, NULL, NULL, NULL);
}
else {
value[0] = 1.0f;
@@ -752,11 +752,51 @@ static void rna_Event_xr_controller_rotation_get(PointerRNA *ptr, float *value)
}
}
+static int rna_Event_xr_viewport_width_get(PointerRNA *ptr)
+{
+ const wmEvent *event = ptr->data;
+ if (WM_event_is_xr(event)) {
+ int width;
+ WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, &width, NULL, NULL, NULL, NULL);
+ return width;
+ }
+ else {
+ return 0;
+ }
+}
+
+static int rna_Event_xr_viewport_height_get(PointerRNA *ptr)
+{
+ const wmEvent *event = ptr->data;
+ if (WM_event_is_xr(event)) {
+ int height;
+ WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, NULL, &height, NULL, NULL, NULL);
+ return height;
+ }
+ else {
+ return 0;
+ }
+}
+
+static float rna_Event_xr_focal_length_get(PointerRNA *ptr)
+{
+ const wmEvent *event = ptr->data;
+ if (WM_event_is_xr(event)) {
+ float focal_len;
+ WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list