Commit: 297decbe1f5c605182ca57d1dccec2c90c3af431 Author: Peter Kim Date: Tue Oct 20 00:52:49 2020 +0900 Branches: xr-actions-D9124 https://developer.blender.org/rB297decbe1f5c605182ca57d1dccec2c90c3af431
XR: Add input threshold for float actions Fixes button release events not being sent due to non-zero state. =================================================================== M intern/ghost/GHOST_Types.h M source/blender/makesrna/intern/rna_xr.c M source/blender/windowmanager/xr/intern/wm_xr_actions.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 822da627e74..8c3efa33b03 100644 --- a/intern/ghost/GHOST_Types.h +++ b/intern/ghost/GHOST_Types.h @@ -712,6 +712,9 @@ typedef struct GHOST_XrActionInfo { /* Previous states, stored to determine XR events. */ void *states_prev; + /* Input threshold for float actions. */ + float threshold; + /* wmOperatorType and wmXrOpFlag, only used by wm. */ void *ot; char op_flag; diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c index 56b7c7f3031..857d95901e6 100644 --- a/source/blender/makesrna/intern/rna_xr.c +++ b/source/blender/makesrna/intern/rna_xr.c @@ -82,6 +82,7 @@ static bool rna_XrSessionState_action_create(bContext *C, int type, const char *user_path0, const char *user_path1, + float threshold, const char *op, int op_flag) { @@ -91,6 +92,7 @@ static bool rna_XrSessionState_action_create(bContext *C, .name = name, .type = type, .count_subaction_paths = 0, + .threshold = threshold, .ot = NULL, .op_flag = 0, }; @@ -651,6 +653,16 @@ static void rna_def_xr_session_state(BlenderRNA *brna) RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); parm = RNA_def_string(func, "user_path1", NULL, 64, "User Path 1", "User path 1"); RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); + parm = RNA_def_float(func, + "threshold", + 0.3f, + 0.0f, + 1.0f, + "Threshold", + "Input threshold for button actions", + 0.0f, + 1.0f); + RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); parm = RNA_def_string(func, "op", NULL, OP_MAX_TYPENAME, "Operator", "Operator to execute"); RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); parm = RNA_def_enum(func, diff --git a/source/blender/windowmanager/xr/intern/wm_xr_actions.c b/source/blender/windowmanager/xr/intern/wm_xr_actions.c index c7dafcf19ab..5d0ccaa7526 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_actions.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_actions.c @@ -115,6 +115,9 @@ static wmXrAction *action_create(const GHOST_XrActionInfo *info) action->states = MEM_calloc_arrayN(count, size, __func__); action->states_prev = MEM_calloc_arrayN(count, size, __func__); + action->threshold = info->threshold; + CLAMP(action->threshold, 0.0f, 1.0f); + action->ot = info->ot; action->op_flag = info->op_flag; diff --git a/source/blender/windowmanager/xr/intern/wm_xr_intern.h b/source/blender/windowmanager/xr/intern/wm_xr_intern.h index 31ad0bf3a03..c00b8f30424 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_intern.h +++ b/source/blender/windowmanager/xr/intern/wm_xr_intern.h @@ -131,6 +131,9 @@ typedef struct wmXrAction { /** Previous states, stored to determine XR events. */ void *states_prev; + /** Input threshold for float actions. */ + float threshold; + /** Operator to be called on XR events. */ struct wmOperatorType *ot; char op_flag; /* wmXrOpFlag */ diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c index 180c0513910..412502ca972 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_session.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c @@ -587,8 +587,8 @@ static void wm_xr_session_events_dispatch(const XrSessionSettings *settings, case GHOST_kXrActionTypeFloatInput: { const float *state = &((float *)action->states)[i]; float *state_prev = &((float *)action->states_prev)[i]; - if (*state) { - if (!*state_prev) { + if (*state > action->threshold) { + if (*state_prev <= action->threshold) { if (modal || action->op_flag == XR_OP_PRESS) { val = KM_PRESS; press_start = true; @@ -599,7 +599,7 @@ static void wm_xr_session_events_dispatch(const XrSessionSettings *settings, press_start = false; } } - else if (*state_prev) { + else if (*state_prev > action->threshold) { if (modal || action->op_flag == XR_OP_RELEASE) { val = KM_RELEASE; press_start = false; @@ -611,8 +611,8 @@ static void wm_xr_session_events_dispatch(const XrSessionSettings *settings, case GHOST_kXrActionTypeVector2fInput: { const float(*state)[2] = &((float(*)[2])action->states)[i]; float(*state_prev)[2] = &((float(*)[2])action->states_prev)[i]; - if (*state[0] || *state[1]) { - if (!*state_prev[0] && !*state_prev[1]) { + if ((*state)[0] > action->threshold || (*state)[1] > action->threshold) { + if ((*state_prev)[0] <= action->threshold && (*state_prev)[1] <= action->threshold) { if (modal || action->op_flag == XR_OP_PRESS) { val = KM_PRESS; press_start = true; @@ -623,7 +623,8 @@ static void wm_xr_session_events_dispatch(const XrSessionSettings *settings, press_start = false; } } - else if (*state_prev[0] || *state_prev[1]) { + else if ((*state_prev)[0] > action->threshold || + (*state_prev)[1] > action->threshold) { if (modal || action->op_flag == XR_OP_RELEASE) { val = KM_RELEASE; press_start = false; _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs