[Bf-blender-cvs] [d3b07d5ad5e] xr-actions-D9124: XR: Support axis (vector2f) input actions

Peter Kim noreply at git.blender.org
Sun Nov 15 15:53:19 CET 2020


Commit: d3b07d5ad5eb4dab543fcf2903dc1d993b6639f2
Author: Peter Kim
Date:   Sat Nov 14 15:52:41 2020 +0900
Branches: xr-actions-D9124
https://developer.blender.org/rBd3b07d5ad5eb4dab543fcf2903dc1d993b6639f2

XR: Support axis (vector2f) input actions

===================================================================

M	source/blender/makesrna/intern/rna_wm.c
M	source/blender/makesrna/intern/rna_xr.c
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/xr/intern/wm_xr_session.c

===================================================================

diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index 38c35dbcd9c..ecdd2ac0009 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -2278,7 +2278,7 @@ static void rna_def_event(BlenderRNA *brna)
   static const EnumPropertyItem xr_types[] = {
       {1, "BOOLEAN", 0, "Boolean", "Boolean value"},
       {2, "FLOAT", 0, "Float", "Float value"},
-      {3, "VEC2F", 0, "Vector2f", "2D float vector value"},
+      {3, "VECTOR2F", 0, "Vector2f", "2D float vector value"},
       {0, NULL, 0, NULL, NULL},
   };
 #  ifdef WITH_XR_OPENXR
diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index edfd024cb77..8c8623e14e3 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -317,7 +317,8 @@ static bool rna_XrSessionState_action_create(bContext *C,
       .threshold = threshold,
   };
 
-  if (op[0] && (type == GHOST_kXrActionTypeFloatInput)) {
+  if (op[0] &&
+      ((type == GHOST_kXrActionTypeFloatInput) || type == GHOST_kXrActionTypeVector2fInput)) {
     char idname[OP_MAX_TYPENAME];
     WM_operator_bl_idname(idname, op);
     wmOperatorType *ot = WM_operatortype_find(idname, true);
@@ -877,7 +878,8 @@ static void rna_def_xr_session_state(BlenderRNA *brna)
   PropertyRNA *parm, *prop;
 
   static const EnumPropertyItem action_types[] = {
-      {2, "BUTTON", 0, "Button", "Button state action"},
+      {2, "BUTTON", 0, "Button", "Button action"},
+      {3, "AXIS", 0, "Axis", "2D axis action"},
       {4, "POSE", 0, "Pose", "3D pose action"},
       {100, "HAPTIC", 0, "Haptic", "Haptic output action"},
       {0, NULL, 0, NULL, NULL},
@@ -885,6 +887,8 @@ static void rna_def_xr_session_state(BlenderRNA *brna)
 #  ifdef WITH_XR_OPENXR
   BLI_STATIC_ASSERT(GHOST_kXrActionTypeFloatInput == 2,
                     "Float action type does not match GHOST_XrActionType value");
+  BLI_STATIC_ASSERT(GHOST_kXrActionTypeVector2fInput == 3,
+                    "Vector2f action type does not match GHOST_XrActionType value");
   BLI_STATIC_ASSERT(GHOST_kXrActionTypePoseInput == 4,
                     "Pose action type does not match GHOST_XrActionType value");
   BLI_STATIC_ASSERT(GHOST_kXrActionTypeVibrationOutput == 100,
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 3847822f171..487218bb0ef 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -4911,7 +4911,7 @@ void wm_event_add_xrevent(const char *action_set_name,
 
   switch (action->type) {
     case GHOST_kXrActionTypeBooleanInput: {
-      data->state[0] = (float)((bool *)action->states)[subaction_idx]; /* Cast bool to float. */
+      data->state[0] = ((bool *)action->states)[subaction_idx] ? 1.0f : 0.0f;
       break;
     }
     case GHOST_kXrActionTypeFloatInput: {
@@ -4919,7 +4919,7 @@ void wm_event_add_xrevent(const char *action_set_name,
       break;
     }
     case GHOST_kXrActionTypeVector2fInput: {
-      memcpy(data->state, ((float(*)[2])action->states)[subaction_idx], sizeof(float[2]));
+      copy_v2_v2(data->state, ((float(*)[2])action->states)[subaction_idx]);
       break;
     }
     default: {
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c
index 3255d71af14..69b2cb6f8e6 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_session.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c
@@ -689,9 +689,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 (fabsf((*state)[0]) > action->threshold || fabsf((*state)[1]) > action->threshold) {
-              if (fabsf((*state_prev)[0]) <= action->threshold &&
-                  fabsf((*state_prev)[1]) <= action->threshold) {
+            if (len_v2(*state) > action->threshold) {
+              if (len_v2(*state_prev) <= action->threshold) {
                 if (modal || action->op_flag == XR_OP_PRESS) {
                   val = KM_PRESS;
                   press_start = true;
@@ -702,14 +701,13 @@ static void wm_xr_session_events_dispatch(const XrSessionSettings *settings,
                 press_start = false;
               }
             }
-            else if (fabsf((*state_prev)[0]) > action->threshold ||
-                     fabsf((*state_prev)[1]) > action->threshold) {
+            else if (len_v2(*state_prev) > action->threshold) {
               if (modal || action->op_flag == XR_OP_RELEASE) {
                 val = KM_RELEASE;
                 press_start = false;
               }
             }
-            memcpy(state_prev, state, sizeof(float[2]));
+            copy_v2_v2(*state_prev, *state);
             break;
           }
           default: {



More information about the Bf-blender-cvs mailing list