Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/xr/intern/wm_xr_action.c
- This file was moved from source/blender/windowmanager/xr/intern/wm_xr_actions.c.
| Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| return GHOST_XrGetActionSetCustomdata(xr->runtime->context, action_set_name); | return GHOST_XrGetActionSetCustomdata(xr->runtime->context, action_set_name); | ||||
| } | } | ||||
| static wmXrAction *action_create(const char *action_name, | static wmXrAction *action_create(const char *action_name, | ||||
| eXrActionType type, | eXrActionType type, | ||||
| unsigned int count_subaction_paths, | unsigned int count_subaction_paths, | ||||
| const char **subaction_paths, | const char **subaction_paths, | ||||
| const float *float_threshold, | |||||
| wmOperatorType *ot, | wmOperatorType *ot, | ||||
| IDProperty *op_properties, | IDProperty *op_properties, | ||||
| eXrOpFlag op_flag) | eXrOpFlag op_flag) | ||||
| { | { | ||||
| wmXrAction *action = MEM_callocN(sizeof(*action), __func__); | wmXrAction *action = MEM_callocN(sizeof(*action), __func__); | ||||
| action->name = MEM_mallocN(strlen(action_name) + 1, "XrAction_Name"); | action->name = MEM_mallocN(strlen(action_name) + 1, "XrAction_Name"); | ||||
| strcpy(action->name, action_name); | strcpy(action->name, action_name); | ||||
| action->type = type; | action->type = type; | ||||
| Show All 24 Lines | case XR_POSE_INPUT: | ||||
| size = sizeof(GHOST_XrPose); | size = sizeof(GHOST_XrPose); | ||||
| break; | break; | ||||
| case XR_VIBRATION_OUTPUT: | case XR_VIBRATION_OUTPUT: | ||||
| return action; | return action; | ||||
| } | } | ||||
| action->states = MEM_calloc_arrayN(count, size, "XrAction_States"); | action->states = MEM_calloc_arrayN(count, size, "XrAction_States"); | ||||
| action->states_prev = MEM_calloc_arrayN(count, size, "XrAction_StatesPrev"); | action->states_prev = MEM_calloc_arrayN(count, size, "XrAction_StatesPrev"); | ||||
| if (float_threshold) { | const bool is_float_action = (type == XR_FLOAT_INPUT || type == XR_VECTOR2F_INPUT); | ||||
| BLI_assert(type == XR_FLOAT_INPUT || type == XR_VECTOR2F_INPUT); | const bool is_button_action = (is_float_action || type == XR_BOOLEAN_INPUT); | ||||
| action->float_threshold = *float_threshold; | if (is_float_action) { | ||||
| CLAMP(action->float_threshold, 0.0f, 1.0f); | 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; | action->ot = ot; | ||||
| action->op_properties = op_properties; | action->op_properties = op_properties; | ||||
| action->op_flag = op_flag; | action->op_flag = op_flag; | ||||
| return action; | return action; | ||||
| } | } | ||||
| Show All 11 Lines | for (unsigned int i = 0; i < count; ++i) { | ||||
| MEM_SAFE_FREE(subaction_paths[i]); | MEM_SAFE_FREE(subaction_paths[i]); | ||||
| } | } | ||||
| MEM_freeN(subaction_paths); | MEM_freeN(subaction_paths); | ||||
| } | } | ||||
| MEM_SAFE_FREE(action->states); | MEM_SAFE_FREE(action->states); | ||||
| MEM_SAFE_FREE(action->states_prev); | MEM_SAFE_FREE(action->states_prev); | ||||
| MEM_SAFE_FREE(action->float_thresholds); | |||||
| MEM_SAFE_FREE(action->axis_flags); | |||||
| MEM_freeN(action); | MEM_freeN(action); | ||||
| } | } | ||||
| static wmXrAction *action_find(wmXrData *xr, const char *action_set_name, const char *action_name) | static wmXrAction *action_find(wmXrData *xr, const char *action_set_name, const char *action_name) | ||||
| { | { | ||||
| return GHOST_XrGetActionCustomdata(xr->runtime->context, action_set_name, action_name); | return GHOST_XrGetActionCustomdata(xr->runtime->context, action_set_name, action_name); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| bool WM_xr_action_create(wmXrData *xr, | bool WM_xr_action_create(wmXrData *xr, | ||||
| const char *action_set_name, | const char *action_set_name, | ||||
| const char *action_name, | const char *action_name, | ||||
| eXrActionType type, | eXrActionType type, | ||||
| unsigned int count_subaction_paths, | unsigned int count_subaction_paths, | ||||
| const char **subaction_paths, | const char **subaction_paths, | ||||
| const float *float_threshold, | |||||
| wmOperatorType *ot, | wmOperatorType *ot, | ||||
| IDProperty *op_properties, | IDProperty *op_properties, | ||||
| eXrOpFlag op_flag) | eXrOpFlag op_flag) | ||||
| { | { | ||||
| if (action_find(xr, action_set_name, action_name)) { | if (action_find(xr, action_set_name, action_name)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| wmXrAction *action = action_create(action_name, | wmXrAction *action = action_create(action_name, | ||||
| type, | type, | ||||
| count_subaction_paths, | count_subaction_paths, | ||||
| subaction_paths, | subaction_paths, | ||||
| float_threshold, | |||||
| ot, | ot, | ||||
| op_properties, | op_properties, | ||||
| op_flag); | op_flag); | ||||
| GHOST_XrActionInfo info = { | GHOST_XrActionInfo info = { | ||||
| .name = action_name, | .name = action_name, | ||||
| .count_subaction_paths = count_subaction_paths, | .count_subaction_paths = count_subaction_paths, | ||||
| .subaction_paths = subaction_paths, | .subaction_paths = subaction_paths, | ||||
| .states = action->states, | .states = action->states, | ||||
| .float_thresholds = action->float_thresholds, | |||||
| .axis_flags = (int16_t *)action->axis_flags, | |||||
| .customdata_free_fn = action_destroy, | .customdata_free_fn = action_destroy, | ||||
| .customdata = action, | .customdata = action, | ||||
| }; | }; | ||||
| switch (type) { | switch (type) { | ||||
| case XR_BOOLEAN_INPUT: | case XR_BOOLEAN_INPUT: | ||||
| info.type = GHOST_kXrActionTypeBooleanInput; | info.type = GHOST_kXrActionTypeBooleanInput; | ||||
| break; | break; | ||||
| Show All 20 Lines | |||||
| void WM_xr_action_destroy(wmXrData *xr, const char *action_set_name, const char *action_name) | void WM_xr_action_destroy(wmXrData *xr, const char *action_set_name, const char *action_name) | ||||
| { | { | ||||
| wmXrActionSet *action_set = action_set_find(xr, action_set_name); | wmXrActionSet *action_set = action_set_find(xr, action_set_name); | ||||
| if (!action_set) { | if (!action_set) { | ||||
| return; | return; | ||||
| } | } | ||||
| wmXrAction *action = action_find(xr, action_set_name, action_name); | |||||
| if (!action) { | |||||
| return; | |||||
| } | |||||
| if (action_set->controller_pose_action && | if (action_set->controller_pose_action && | ||||
| STREQ(action_set->controller_pose_action->name, action_name)) { | STREQ(action_set->controller_pose_action->name, action_name)) { | ||||
| if (action_set == xr->runtime->session_state.active_action_set) { | if (action_set == xr->runtime->session_state.active_action_set) { | ||||
| wm_xr_session_controller_data_clear(&xr->runtime->session_state); | wm_xr_session_controller_data_clear(&xr->runtime->session_state); | ||||
| } | } | ||||
| action_set->controller_pose_action = NULL; | action_set->controller_pose_action = NULL; | ||||
| } | } | ||||
| if (action_set->active_modal_action && | if (action_set->active_modal_action && | ||||
| STREQ(action_set->active_modal_action->name, action_name)) { | STREQ(action_set->active_modal_action->name, action_name)) { | ||||
| action_set->active_modal_action = NULL; | action_set->active_modal_action = NULL; | ||||
| } | } | ||||
| wmXrAction *action = action_find(xr, action_set_name, action_name); | GHOST_XrDestroyActions(xr->runtime->context, action_set_name, 1, &action_name); | ||||
| if (!action) { | |||||
| return; | |||||
| } | |||||
| } | } | ||||
| bool WM_xr_action_space_create(wmXrData *xr, | |||||
| bool WM_xr_action_binding_create(wmXrData *xr, | |||||
| const char *action_set_name, | const char *action_set_name, | ||||
| const char *action_name, | const char *action_name, | ||||
| const char *profile_path, | |||||
| unsigned int count_subaction_paths, | unsigned int count_subaction_paths, | ||||
| const char **subaction_paths, | const char **subaction_paths, | ||||
| const wmXrPose *poses) | const char **component_paths, | ||||
| const float *float_thresholds, | |||||
| const eXrAxisFlag *axis_flags, | |||||
| const struct wmXrPose *poses) | |||||
| { | { | ||||
| GHOST_XrActionSpaceInfo info = { | GHOST_XrActionBindingInfo *binding_infos = MEM_calloc_arrayN( | ||||
| .action_name = action_name, | count_subaction_paths, sizeof(*binding_infos), __func__); | ||||
| .count_subaction_paths = count_subaction_paths, | |||||
| .subaction_paths = subaction_paths, | |||||
| }; | |||||
| GHOST_XrPose *ghost_poses = MEM_malloc_arrayN( | |||||
| count_subaction_paths, sizeof(*ghost_poses), __func__); | |||||
| for (unsigned int i = 0; i < count_subaction_paths; ++i) { | for (unsigned int i = 0; i < count_subaction_paths; ++i) { | ||||
| const wmXrPose *pose = &poses[i]; | GHOST_XrActionBindingInfo *binding_info = &binding_infos[i]; | ||||
| GHOST_XrPose *ghost_pose = &ghost_poses[i]; | binding_info->component_path = component_paths[i]; | ||||
| copy_v3_v3(ghost_pose->position, pose->position); | if (float_thresholds) { | ||||
| copy_qt_qt(ghost_pose->orientation_quat, pose->orientation_quat); | 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, | GHOST_XrActionProfileInfo profile_info = { | ||||
| const char *action_set_name, | |||||
| const char *action_name, | |||||
| unsigned int count_subaction_paths, | |||||
| const char **subaction_paths) | |||||
| { | |||||
| GHOST_XrActionSpaceInfo info = { | |||||
| .action_name = action_name, | .action_name = action_name, | ||||
| .profile_path = profile_path, | |||||
| .count_subaction_paths = count_subaction_paths, | .count_subaction_paths = count_subaction_paths, | ||||
| .subaction_paths = 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, | void WM_xr_action_binding_destroy(wmXrData *xr, | ||||
| const char *action_set_name, | const char *action_set_name, | ||||
| const char *profile_path, | |||||
| const char *action_name, | const char *action_name, | ||||
| unsigned int count_interaction_paths, | const char *profile_path) | ||||
| const char **interaction_paths) | |||||
| { | { | ||||
| GHOST_XrActionBindingInfo binding_info = { | GHOST_XrDestroyActionBindings( | ||||
| .action_name = action_name, | xr->runtime->context, action_set_name, 1, &action_name, &profile_path); | ||||
| .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); | |||||
| } | } | ||||
| bool WM_xr_active_action_set_set(wmXrData *xr, const char *action_set_name) | bool WM_xr_active_action_set_set(wmXrData *xr, const char *action_set_name) | ||||
| { | { | ||||
| wmXrActionSet *action_set = action_set_find(xr, action_set_name); | wmXrActionSet *action_set = action_set_find(xr, action_set_name); | ||||
| if (!action_set) { | if (!action_set) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | bool WM_xr_action_state_get(const wmXrData *xr, | ||||
| const char *subaction_path, | const char *subaction_path, | ||||
| wmXrActionState *r_state) | wmXrActionState *r_state) | ||||
| { | { | ||||
| const wmXrAction *action = action_find((wmXrData *)xr, action_set_name, action_name); | const wmXrAction *action = action_find((wmXrData *)xr, action_set_name, action_name); | ||||
| if (!action) { | if (!action) { | ||||
| return false; | 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. */ | /* Find the action state corresponding to the subaction path. */ | ||||
| for (unsigned int i = 0; i < action->count_subaction_paths; ++i) { | for (unsigned int i = 0; i < action->count_subaction_paths; ++i) { | ||||
| if (STREQ(subaction_path, action->subaction_paths[i])) { | if (STREQ(subaction_path, action->subaction_paths[i])) { | ||||
| switch ((eXrActionType)r_state->type) { | switch (action->type) { | ||||
| case XR_BOOLEAN_INPUT: | case XR_BOOLEAN_INPUT: | ||||
| r_state->state_boolean = ((bool *)action->states)[i]; | r_state->state_boolean = ((bool *)action->states)[i]; | ||||
| break; | break; | ||||
| case XR_FLOAT_INPUT: | case XR_FLOAT_INPUT: | ||||
| r_state->state_float = ((float *)action->states)[i]; | r_state->state_float = ((float *)action->states)[i]; | ||||
| break; | break; | ||||
| case XR_VECTOR2F_INPUT: | case XR_VECTOR2F_INPUT: | ||||
| copy_v2_v2(r_state->state_vector2f, ((float(*)[2])action->states)[i]); | copy_v2_v2(r_state->state_vector2f, ((float(*)[2])action->states)[i]); | ||||
| Show All 37 Lines | |||||