Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kim <pk15950@gmail.com>2021-08-05 07:14:26 +0300
committerPeter Kim <pk15950@gmail.com>2021-08-05 07:14:26 +0300
commitd3d4be1db3a09084eb2ff329bb7a530a87481480 (patch)
tree176e8363ec94a58a070b93bc694abf264f20aec5 /source/blender/windowmanager
parentd1c5e2e050a57216f9555098313d65511455e042 (diff)
XR: Action Binding Improvements
Provides several important improvements to the runtime action bindings operation and internal API. Moves input-specific action data (input thresholds, input regions, pose offsets/spaces) from actions to more granular action bindings. This allows a single action to be mapped to a variety of inputs, without having to share a single input threshold, region, or space. Also removes the need for action space creation API, as spaces for pose actions will be automatically created with the bindings. The correct action data for the current inputs is set by calling xrGetCurrentInteractionProfile() to get the current profile and then retrieving the corresponding mapped data. Does not bring about any changes for users since only internal runtime functionality is currently affected. Reviewed By: Julian Eisel Differential Revision: http://developer.blender.org/D12077
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/CMakeLists.txt2
-rw-r--r--source/blender/windowmanager/WM_api.h26
-rw-r--r--source/blender/windowmanager/xr/intern/wm_xr_action.c (renamed from source/blender/windowmanager/xr/intern/wm_xr_actions.c)138
-rw-r--r--source/blender/windowmanager/xr/intern/wm_xr_intern.h5
4 files changed, 68 insertions, 103 deletions
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index e513c49c11b..8b0ceb02b5f 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -203,7 +203,7 @@ if(WITH_XR_OPENXR)
list(APPEND SRC
xr/intern/wm_xr.c
- xr/intern/wm_xr_actions.c
+ xr/intern/wm_xr_action.c
xr/intern/wm_xr_draw.c
xr/intern/wm_xr_session.c
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 136c639caea..fb973592a57 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -978,34 +978,24 @@ bool WM_xr_action_create(wmXrData *xr,
eXrActionType type,
unsigned int count_subaction_paths,
const char **subaction_paths,
- const float *float_threshold,
struct wmOperatorType *ot,
struct IDProperty *op_properties,
eXrOpFlag op_flag);
void WM_xr_action_destroy(wmXrData *xr, const char *action_set_name, const char *action_name);
-bool WM_xr_action_space_create(wmXrData *xr,
- const char *action_set_name,
- const char *action_name,
- unsigned int count_subaction_paths,
- const char **subaction_paths,
- const struct wmXrPose *poses);
-void WM_xr_action_space_destroy(wmXrData *xr,
- const char *action_set_name,
- const char *action_name,
- unsigned int count_subaction_paths,
- const char **subaction_paths);
bool WM_xr_action_binding_create(wmXrData *xr,
const char *action_set_name,
- const char *profile_path,
const char *action_name,
- unsigned int count_interaction_paths,
- const char **interaction_paths);
+ const char *profile_path,
+ unsigned int count_subaction_paths,
+ const char **subaction_paths,
+ const char **component_paths,
+ const float *float_thresholds,
+ const eXrAxisFlag *axis_flags,
+ const struct wmXrPose *poses);
void WM_xr_action_binding_destroy(wmXrData *xr,
const char *action_set_name,
- const char *profile_path,
const char *action_name,
- unsigned int count_interaction_paths,
- const char **interaction_paths);
+ const char *profile_path);
/* If action_set_name is NULL, then all action sets will be treated as active. */
bool WM_xr_active_action_set_set(wmXrData *xr, const char *action_set_name);
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_actions.c b/source/blender/windowmanager/xr/intern/wm_xr_action.c
index 7eabd29baa0..ee4cfcccaa7 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_actions.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_action.c
@@ -68,7 +68,6 @@ static wmXrAction *action_create(const char *action_name,
eXrActionType type,
unsigned int count_subaction_paths,
const char **subaction_paths,
- const float *float_threshold,
wmOperatorType *ot,
IDProperty *op_properties,
eXrOpFlag op_flag)
@@ -109,10 +108,15 @@ static wmXrAction *action_create(const char *action_name,
action->states = MEM_calloc_arrayN(count, size, "XrAction_States");
action->states_prev = MEM_calloc_arrayN(count, size, "XrAction_StatesPrev");
- if (float_threshold) {
- BLI_assert(type == XR_FLOAT_INPUT || type == XR_VECTOR2F_INPUT);
- action->float_threshold = *float_threshold;
- CLAMP(action->float_threshold, 0.0f, 1.0f);
+ const bool is_float_action = (type == XR_FLOAT_INPUT || type == XR_VECTOR2F_INPUT);
+ const bool is_button_action = (is_float_action || type == XR_BOOLEAN_INPUT);
+ if (is_float_action) {
+ action->float_thresholds = MEM_calloc_arrayN(
+ count, sizeof(*action->float_thresholds), "XrAction_FloatThresholds");
+ }
+ if (is_button_action) {
+ action->axis_flags = MEM_calloc_arrayN(
+ count, sizeof(*action->axis_flags), "XrAction_AxisFlags");
}
action->ot = ot;
@@ -140,6 +144,9 @@ static void action_destroy(void *val)
MEM_SAFE_FREE(action->states);
MEM_SAFE_FREE(action->states_prev);
+ MEM_SAFE_FREE(action->float_thresholds);
+ MEM_SAFE_FREE(action->axis_flags);
+
MEM_freeN(action);
}
@@ -198,7 +205,6 @@ bool WM_xr_action_create(wmXrData *xr,
eXrActionType type,
unsigned int count_subaction_paths,
const char **subaction_paths,
- const float *float_threshold,
wmOperatorType *ot,
IDProperty *op_properties,
eXrOpFlag op_flag)
@@ -211,7 +217,6 @@ bool WM_xr_action_create(wmXrData *xr,
type,
count_subaction_paths,
subaction_paths,
- float_threshold,
ot,
op_properties,
op_flag);
@@ -221,6 +226,8 @@ bool WM_xr_action_create(wmXrData *xr,
.count_subaction_paths = count_subaction_paths,
.subaction_paths = subaction_paths,
.states = action->states,
+ .float_thresholds = action->float_thresholds,
+ .axis_flags = (int16_t *)action->axis_flags,
.customdata_free_fn = action_destroy,
.customdata = action,
};
@@ -257,6 +264,11 @@ void WM_xr_action_destroy(wmXrData *xr, const char *action_set_name, const char
return;
}
+ wmXrAction *action = action_find(xr, action_set_name, action_name);
+ if (!action) {
+ return;
+ }
+
if (action_set->controller_pose_action &&
STREQ(action_set->controller_pose_action->name, action_name)) {
if (action_set == xr->runtime->session_state.active_action_set) {
@@ -269,98 +281,60 @@ void WM_xr_action_destroy(wmXrData *xr, const char *action_set_name, const char
action_set->active_modal_action = NULL;
}
- wmXrAction *action = action_find(xr, action_set_name, action_name);
- if (!action) {
- return;
- }
+ GHOST_XrDestroyActions(xr->runtime->context, action_set_name, 1, &action_name);
}
-bool WM_xr_action_space_create(wmXrData *xr,
- const char *action_set_name,
- const char *action_name,
- unsigned int count_subaction_paths,
- const char **subaction_paths,
- const wmXrPose *poses)
+
+bool WM_xr_action_binding_create(wmXrData *xr,
+ const char *action_set_name,
+ const char *action_name,
+ const char *profile_path,
+ unsigned int count_subaction_paths,
+ const char **subaction_paths,
+ const char **component_paths,
+ const float *float_thresholds,
+ const eXrAxisFlag *axis_flags,
+ const struct wmXrPose *poses)
{
- GHOST_XrActionSpaceInfo info = {
- .action_name = action_name,
- .count_subaction_paths = count_subaction_paths,
- .subaction_paths = subaction_paths,
- };
+ GHOST_XrActionBindingInfo *binding_infos = MEM_calloc_arrayN(
+ count_subaction_paths, sizeof(*binding_infos), __func__);
- GHOST_XrPose *ghost_poses = MEM_malloc_arrayN(
- count_subaction_paths, sizeof(*ghost_poses), __func__);
for (unsigned int i = 0; i < count_subaction_paths; ++i) {
- const wmXrPose *pose = &poses[i];
- GHOST_XrPose *ghost_pose = &ghost_poses[i];
- copy_v3_v3(ghost_pose->position, pose->position);
- copy_qt_qt(ghost_pose->orientation_quat, pose->orientation_quat);
+ GHOST_XrActionBindingInfo *binding_info = &binding_infos[i];
+ binding_info->component_path = component_paths[i];
+ if (float_thresholds) {
+ binding_info->float_threshold = float_thresholds[i];
+ }
+ if (axis_flags) {
+ binding_info->axis_flag = axis_flags[i];
+ }
+ if (poses) {
+ copy_v3_v3(binding_info->pose.position, poses[i].position);
+ copy_qt_qt(binding_info->pose.orientation_quat, poses[i].orientation_quat);
+ }
}
- info.poses = ghost_poses;
- bool ret = GHOST_XrCreateActionSpaces(xr->runtime->context, action_set_name, 1, &info) ? true :
- false;
- MEM_freeN(ghost_poses);
- return ret;
-}
-
-void WM_xr_action_space_destroy(wmXrData *xr,
- const char *action_set_name,
- const char *action_name,
- unsigned int count_subaction_paths,
- const char **subaction_paths)
-{
- GHOST_XrActionSpaceInfo info = {
+ GHOST_XrActionProfileInfo profile_info = {
.action_name = action_name,
+ .profile_path = profile_path,
.count_subaction_paths = count_subaction_paths,
.subaction_paths = subaction_paths,
+ .bindings = binding_infos,
};
- GHOST_XrDestroyActionSpaces(xr->runtime->context, action_set_name, 1, &info);
-}
+ bool ret = GHOST_XrCreateActionBindings(xr->runtime->context, action_set_name, 1, &profile_info);
-bool WM_xr_action_binding_create(wmXrData *xr,
- const char *action_set_name,
- const char *profile_path,
- const char *action_name,
- unsigned int count_interaction_paths,
- const char **interaction_paths)
-{
- GHOST_XrActionBindingInfo binding_info = {
- .action_name = action_name,
- .count_interaction_paths = count_interaction_paths,
- .interaction_paths = interaction_paths,
- };
-
- GHOST_XrActionProfileInfo profile_info = {
- .profile_path = profile_path,
- .count_bindings = 1,
- .bindings = &binding_info,
- };
-
- return GHOST_XrCreateActionBindings(xr->runtime->context, action_set_name, 1, &profile_info);
+ MEM_freeN(binding_infos);
+ return ret;
}
void WM_xr_action_binding_destroy(wmXrData *xr,
const char *action_set_name,
- const char *profile_path,
const char *action_name,
- unsigned int count_interaction_paths,
- const char **interaction_paths)
+ const char *profile_path)
{
- GHOST_XrActionBindingInfo binding_info = {
- .action_name = action_name,
- .count_interaction_paths = count_interaction_paths,
- .interaction_paths = interaction_paths,
- };
-
- GHOST_XrActionProfileInfo profile_info = {
- .profile_path = profile_path,
- .count_bindings = 1,
- .bindings = &binding_info,
- };
-
- GHOST_XrDestroyActionBindings(xr->runtime->context, action_set_name, 1, &profile_info);
+ GHOST_XrDestroyActionBindings(
+ xr->runtime->context, action_set_name, 1, &action_name, &profile_path);
}
bool WM_xr_active_action_set_set(wmXrData *xr, const char *action_set_name)
@@ -427,12 +401,12 @@ bool WM_xr_action_state_get(const wmXrData *xr,
return false;
}
- BLI_assert(action->type == (eXrActionType)r_state->type);
+ r_state->type = (int)action->type;
/* Find the action state corresponding to the subaction path. */
for (unsigned int i = 0; i < action->count_subaction_paths; ++i) {
if (STREQ(subaction_path, action->subaction_paths[i])) {
- switch ((eXrActionType)r_state->type) {
+ switch (action->type) {
case XR_BOOLEAN_INPUT:
r_state->state_boolean = ((bool *)action->states)[i];
break;
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_intern.h b/source/blender/windowmanager/xr/intern/wm_xr_intern.h
index 6415f96e322..4530aeaa428 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_intern.h
+++ b/source/blender/windowmanager/xr/intern/wm_xr_intern.h
@@ -122,8 +122,9 @@ typedef struct wmXrAction {
/** Previous states, stored to determine XR events. */
void *states_prev;
- /** Input threshold for float/vector2f actions. */
- float float_threshold;
+ /** Input thresholds/regions for each subaction path. */
+ float *float_thresholds;
+ eXrAxisFlag *axis_flags;
/** The currently active subaction path (if any) for modal actions. */
char **active_modal_path;