[Bf-blender-cvs] [99beac7b3f0] xr-controller-support: XR: Use dynamic arrays for eye, controller data
Peter Kim
noreply at git.blender.org
Sat Jul 24 11:37:56 CEST 2021
Commit: 99beac7b3f03c89cb4e962ca7f7ffeb910e5e4fb
Author: Peter Kim
Date: Sat Jul 24 18:08:29 2021 +0900
Branches: xr-controller-support
https://developer.blender.org/rB99beac7b3f03c89cb4e962ca7f7ffeb910e5e4fb
XR: Use dynamic arrays for eye, controller data
Makes API/functionality more adaptable to different systems.
===================================================================
M source/blender/windowmanager/intern/wm_event_system.c
M source/blender/windowmanager/wm_event_system.h
M source/blender/windowmanager/xr/intern/wm_xr.c
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/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 8a77291a37e..a3835cc5a1c 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -5035,7 +5035,7 @@ void wm_event_add_xrevent(const char *action_set_name,
const wmXrAction *action,
const GHOST_XrPose *controller_aim_pose,
const GHOST_XrPose *controller_aim_pose_other,
- const wmXrEyeData *eye_data,
+ const wmXrEye *selection_eye,
wmSurface *surface,
wmWindow *win,
unsigned int subaction_idx,
@@ -5106,9 +5106,9 @@ void wm_event_add_xrevent(const char *action_set_name,
data->controller_rot_other[0] = 1.0f;
}
- if (eye_data) {
- copy_m4_m4(data->eye_viewmat, eye_data->viewmat);
- data->eye_lens = eye_data->focal_len;
+ if (selection_eye) {
+ copy_m4_m4(data->eye_viewmat, selection_eye->viewmat);
+ data->eye_lens = selection_eye->focal_len;
}
data->ot = action->ot;
diff --git a/source/blender/windowmanager/wm_event_system.h b/source/blender/windowmanager/wm_event_system.h
index 76ee61ed32d..21f2c61ed8f 100644
--- a/source/blender/windowmanager/wm_event_system.h
+++ b/source/blender/windowmanager/wm_event_system.h
@@ -37,7 +37,7 @@ struct ScrArea;
struct GHOST_XrPose;
struct wmSurface;
struct wmXrAction;
-struct wmXrEyeData;
+struct wmXrEye;
#endif
#ifdef __cplusplus
@@ -160,7 +160,7 @@ void wm_event_add_xrevent(const char *action_set_name,
const struct wmXrAction *action,
const struct GHOST_XrPose *controller_aim_pose,
const struct GHOST_XrPose *controller_aim_pose_other,
- const struct wmXrEyeData *eye_data,
+ const struct wmXrEye *selection_eye,
struct wmSurface *surface,
wmWindow *win,
unsigned int subaction_idx,
diff --git a/source/blender/windowmanager/xr/intern/wm_xr.c b/source/blender/windowmanager/xr/intern/wm_xr.c
index cf4580f4c19..071a9797c51 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr.c
@@ -163,12 +163,15 @@ void wm_xr_runtime_data_free(wmXrRuntimeData **runtime)
* that is freed here. */
/* We free all runtime XR data here, so if the context is still alive, destroy it. */
- if ((*runtime)->context != NULL) {
- GHOST_XrContextHandle context = (*runtime)->context;
- /* Prevent recursive GHOST_XrContextDestroy() call by NULL'ing the context pointer before the
- * first call, see comment above. */
- (*runtime)->context = NULL;
- GHOST_XrContextDestroy(context);
+ if (*runtime) {
+ if ((*runtime)->context != NULL) {
+ GHOST_XrContextHandle context = (*runtime)->context;
+ /* Prevent recursive GHOST_XrContextDestroy() call by NULL'ing the context pointer before the
+ * first call, see comment above. */
+ (*runtime)->context = NULL;
+ GHOST_XrContextDestroy(context);
+ }
+ wm_xr_session_data_free(&(*runtime)->session_state);
}
MEM_SAFE_FREE(*runtime);
}
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_draw.c b/source/blender/windowmanager/xr/intern/wm_xr_draw.c
index e1d08e56770..235b298216a 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_draw.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_draw.c
@@ -249,7 +249,6 @@ void wm_xr_draw_controllers(const bContext *UNUSED(C), ARegion *UNUSED(region),
const wmXrData *xr = customdata;
const XrSessionSettings *settings = &xr->session_settings;
wmXrSessionState *state = &xr->runtime->session_state;
- const unsigned int count_controllers = (unsigned int)ARRAY_SIZE(state->controllers);
/* Model. */
{
@@ -271,8 +270,7 @@ void wm_xr_draw_controllers(const bContext *UNUSED(C), ARegion *UNUSED(region),
GPU_depth_test(GPU_DEPTH_NONE);
GPU_blend(GPU_BLEND_ALPHA);
- for (unsigned int controller_idx = 0; controller_idx < count_controllers; ++controller_idx) {
- wmXrControllerData *controller = &state->controllers[controller_idx];
+ LISTBASE_FOREACH (wmXrController *, controller, &state->controllers) {
GPUBatch *model = controller->model;
if (!model) {
model = controller->model = wm_xr_controller_model_batch_create(
@@ -345,8 +343,8 @@ void wm_xr_draw_controllers(const bContext *UNUSED(C), ARegion *UNUSED(region),
immUniformColor4fv(color);
- for (unsigned int controller_idx = 0; controller_idx < count_controllers; ++controller_idx) {
- const float(*mat)[4] = state->controllers[controller_idx].aim_mat;
+ LISTBASE_FOREACH (wmXrController *, controller, &state->controllers) {
+ const float(*mat)[4] = controller->aim_mat;
madd_v3_v3v3fl(ray, mat[3], mat[2], -scale);
immBegin(GPU_PRIM_LINES, 2);
@@ -366,8 +364,8 @@ void wm_xr_draw_controllers(const bContext *UNUSED(C), ARegion *UNUSED(region),
GPU_blend(GPU_BLEND_NONE);
GPU_line_width(3.0f);
- for (unsigned int controller_idx = 0; controller_idx < count_controllers; ++controller_idx) {
- const float(*mat)[4] = state->controllers[controller_idx].aim_mat;
+ LISTBASE_FOREACH (wmXrController *, controller, &state->controllers) {
+ const float(*mat)[4] = controller->aim_mat;
madd_v3_v3v3fl(x_axis, mat[3], mat[0], scale);
madd_v3_v3v3fl(y_axis, mat[3], mat[1], scale);
madd_v3_v3v3fl(z_axis, mat[3], mat[2], scale);
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_intern.h b/source/blender/windowmanager/xr/intern/wm_xr_intern.h
index a90a6f4b49a..c00467ab76a 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_intern.h
+++ b/source/blender/windowmanager/xr/intern/wm_xr_intern.h
@@ -29,34 +29,6 @@
struct GPUBatch;
struct wmXrActionSet;
-typedef struct wmXrEyeData {
- float focal_len;
- float viewmat[4][4];
- /** Viewmat without navigation applied. */
- float viewmat_base[4][4];
-} wmXrEyeData;
-
-typedef struct wmXrControllerData {
- /** OpenXR path identifier. Length is dependent on OpenXR's XR_MAX_PATH_LENGTH (256).
- This subaction path will later be combined with a component path, and that combined path should
- also have a max of XR_MAX_PATH_LENGTH (e.g. subaction_path = /user/hand/left, component_path =
- /input/trigger/value, interaction_path = /user/hand/left/input/trigger/value).
- */
- char subaction_path[64];
-
- /* Pose (in world space) that represents the user's hand when holding the controller.*/
- GHOST_XrPose grip_pose;
- float grip_mat[4][4];
- float grip_mat_base[4][4];
- /* Pose (in world space) that represents the controller's aiming source. */
- GHOST_XrPose aim_pose;
- float aim_mat[4][4];
- float aim_mat_base[4][4];
-
- /** Controller model. */
- struct GPUBatch *model;
-} wmXrControllerData;
-
typedef struct wmXrSessionState {
bool is_started;
@@ -67,10 +39,9 @@ typedef struct wmXrSessionState {
/** The last known viewer matrix, without navigation applied. */
float viewer_mat_base[4][4];
/** Last known eye data. */
- wmXrEyeData eyes[2];
-
+ ListBase eyes; /* wmXrEye */
/** Last known controller data. */
- wmXrControllerData controllers[2];
+ ListBase controllers; /* wmXrController */
/** Copy of XrSessionSettings.base_pose_ data to detect changes that need
* resetting to base pose. */
@@ -163,6 +134,36 @@ typedef struct wmXrDrawData {
float eye_position_ofs[3]; /* Local/view space. */
} wmXrDrawData;
+typedef struct wmXrEye {
+ struct wmXrEye *next, *prev;
+ float focal_len;
+ float viewmat[4][4];
+ /** Viewmat without navigation applied. */
+ float viewmat_base[4][4];
+} wmXrEye;
+
+typedef struct wmXrController {
+ struct wmXrController *next, *prev;
+ /** OpenXR path identifier. Length is dependent on OpenXR's XR_MAX_PATH_LENGTH (256).
+ This subaction path will later be combined with a component path, and that combined path should
+ also have a max of XR_MAX_PATH_LENGTH (e.g. subaction_path = /user/hand/left, component_path =
+ /input/trigger/value, interaction_path = /user/hand/left/input/trigger/value).
+ */
+ char subaction_path[64];
+
+ /* Pose (in world space) that represents the user's hand when holding the controller.*/
+ GHOST_XrPose grip_pose;
+ float grip_mat[4][4];
+ float grip_mat_base[4][4];
+ /* Pose (in world space) that represents the controller's aiming source. */
+ GHOST_XrPose aim_pose;
+ float aim_mat[4][4];
+ float aim_mat_base[4][4];
+
+ /** Controller model. */
+ struct GPUBatch *model;
+} wmXrController;
+
typedef struct wmXrAction {
char *name;
eXrActionType type;
@@ -213,6 +214,7 @@ typedef struct wmXrActionSet {
wmXrRuntimeData *wm_xr_runtime_data_create(void);
void wm_xr_runtime_data_free(wmXrRuntimeData **runtime);
+void wm_xr_session_data_free(wmXrSessionState *state);
wmWindow *wm_xr_session_root_window_or_fallback_get(const wmWindowManager *wm,
const wmXrRuntimeData *runtime_data);
@@ -233,7 +235,6 @@ void wm_xr_session_gpu_binding_context_destroy(GHOST_ContextHandle context);
void wm_xr_session_actions_init(wmXrData *xr);
void wm_xr_session_actions_update(const struct bContext *C);
-void wm_xr_session_actions_uninit(wmXrData *xr);
void wm_xr_session_controller_data_populate(const wmXrAction *grip_action,
const wmXrAction *aim_action,
wmXrData *xr);
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c
index 0af537ed241..2d709430c81 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_session.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c
@@ -136,8 +136,6 @@ static void wm_xr_session_exit_cb(void *customdata)
settings->controller1_object);
}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list