[Bf-blender-cvs] [6a8709ba136] master: XR: Allow variable count of action map subactions

Peter Kim noreply at git.blender.org
Thu Feb 17 07:52:22 CET 2022


Commit: 6a8709ba136ef4e8522555f279294a886595e34c
Author: Peter Kim
Date:   Thu Feb 17 15:41:53 2022 +0900
Branches: master
https://developer.blender.org/rB6a8709ba136ef4e8522555f279294a886595e34c

XR: Allow variable count of action map subactions

Previously, the number of action map subactions was limited to two per
action (identified by user_path0, user_path1), however for devices with
more than two user paths (e.g. Vive Tracker) it will be useful to
support a variable amount instead.

For example, a single pose action could then be used to query the
positions of all connected trackers, with each tracker having its own
subaction tracking space.

NOTE: This introduces breaking changes for the XR Python API as follows:
- XrActionMapItem: The new `user_paths` collection property
replaces the `user_path0`/`user_path1` properties.
- XrActionMapBinding: The new `component_paths` collection property
replaces the `component_path0`/`component_path1` properties.

Reviewed By: Severin

Differential Revision: https://developer.blender.org/D13949

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

M	source/blender/makesdna/DNA_xr_types.h
M	source/blender/makesrna/intern/rna_xr.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/xr/intern/wm_xr_action.c
M	source/blender/windowmanager/xr/intern/wm_xr_actionmap.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/makesdna/DNA_xr_types.h b/source/blender/makesdna/DNA_xr_types.h
index bf77339a494..09eab0d7bf7 100644
--- a/source/blender/makesdna/DNA_xr_types.h
+++ b/source/blender/makesdna/DNA_xr_types.h
@@ -106,8 +106,23 @@ typedef enum eXrPoseFlag {
   XR_POSE_AIM = (1 << 1),
 } eXrPoseFlag;
 
+/**
+ * The following user and component path lengths are dependent on OpenXR's XR_MAX_PATH_LENGTH
+ * (256). A user path will be combined with a component path to identify an action binding, and
+ * that combined path should also have a max of XR_MAX_PATH_LENGTH (e.g. user_path =
+ * /user/hand/left, component_path = /input/trigger/value, full_path =
+ * /user/hand/left/input/trigger/value).
+ */
+#define XR_MAX_USER_PATH_LENGTH 64
+#define XR_MAX_COMPONENT_PATH_LENGTH 192
+
 /* -------------------------------------------------------------------- */
 
+typedef struct XrComponentPath {
+  struct XrComponentPath *next, *prev;
+  char path[192]; /* XR_MAX_COMPONENT_PATH_LENGTH */
+} XrComponentPath;
+
 typedef struct XrActionMapBinding {
   struct XrActionMapBinding *next, *prev;
 
@@ -117,8 +132,7 @@ typedef struct XrActionMapBinding {
   /** OpenXR interaction profile path. */
   char profile[256];
   /** OpenXR component paths. */
-  char component_path0[192];
-  char component_path1[192];
+  ListBase component_paths; /* XrComponentPath */
 
   /** Input threshold/region. */
   float float_threshold;
@@ -132,6 +146,11 @@ typedef struct XrActionMapBinding {
 
 /* -------------------------------------------------------------------- */
 
+typedef struct XrUserPath {
+  struct XrUserPath *next, *prev;
+  char path[64]; /* XR_MAX_USER_PATH_LENGTH */
+} XrUserPath;
+
 typedef struct XrActionMapItem {
   struct XrActionMapItem *next, *prev;
 
@@ -142,8 +161,7 @@ typedef struct XrActionMapItem {
   char _pad[7];
 
   /** OpenXR user paths. */
-  char user_path0[64];
-  char user_path1[64];
+  ListBase user_paths; /* XrUserPath */
 
   /** Operator to be called on XR events. */
   char op[64]; /* OP_MAX_TYPENAME */
diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index 87d8bc8d844..9fe3153eb1e 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -46,6 +46,43 @@ static wmXrData *rna_XrSession_wm_xr_data_get(PointerRNA *ptr)
 /** \name XR Action Map
  * \{ */
 
+static XrComponentPath *rna_XrComponentPath_new(XrActionMapBinding *amb, const char *path_str)
+{
+#  ifdef WITH_XR_OPENXR
+  XrComponentPath *component_path = MEM_callocN(sizeof(XrComponentPath), __func__);
+  BLI_strncpy(component_path->path, path_str, sizeof(component_path->path));
+  BLI_addtail(&amb->component_paths, component_path);
+  return component_path;
+#  else
+  UNUSED_VARS(amb, path_str);
+  return NULL;
+#  endif
+}
+
+static void rna_XrComponentPath_remove(XrActionMapBinding *amb, PointerRNA *component_path_ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  XrComponentPath *component_path = component_path_ptr->data;
+  int idx = BLI_findindex(&amb->component_paths, component_path);
+  if (idx != -1) {
+    BLI_freelinkN(&amb->component_paths, component_path);
+  }
+  RNA_POINTER_INVALIDATE(component_path_ptr);
+#  else
+  UNUSED_VARS(amb, component_path_ptr);
+#  endif
+}
+
+static XrComponentPath *rna_XrComponentPath_find(XrActionMapBinding *amb, const char *path_str)
+{
+#  ifdef WITH_XR_OPENXR
+  return BLI_findstring(&amb->component_paths, path_str, offsetof(XrComponentPath, path));
+#  else
+  UNUSED_VARS(amb, path_str);
+  return NULL;
+#  endif
+}
+
 static XrActionMapBinding *rna_XrActionMapBinding_new(XrActionMapItem *ami,
                                                       const char *name,
                                                       bool replace_existing)
@@ -99,6 +136,28 @@ static XrActionMapBinding *rna_XrActionMapBinding_find(XrActionMapItem *ami, con
 #  endif
 }
 
+static void rna_XrActionMapBinding_component_paths_begin(CollectionPropertyIterator *iter,
+                                                         PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  XrActionMapBinding *amb = (XrActionMapBinding *)ptr->data;
+  rna_iterator_listbase_begin(iter, &amb->component_paths, NULL);
+#  else
+  UNUSED_VARS(iter, ptr);
+#  endif
+}
+
+static int rna_XrActionMapBinding_component_paths_length(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  XrActionMapBinding *amb = (XrActionMapBinding *)ptr->data;
+  return BLI_listbase_count(&amb->component_paths);
+#  else
+  UNUSED_VARS(ptr);
+  return 0;
+#  endif
+}
+
 static int rna_XrActionMapBinding_axis0_region_get(PointerRNA *ptr)
 {
 #  ifdef WITH_XR_OPENXR
@@ -174,6 +233,43 @@ static void rna_XrActionMapBinding_name_update(Main *bmain, Scene *UNUSED(scene)
 #  endif
 }
 
+static XrUserPath *rna_XrUserPath_new(XrActionMapItem *ami, const char *path_str)
+{
+#  ifdef WITH_XR_OPENXR
+  XrUserPath *user_path = MEM_callocN(sizeof(XrUserPath), __func__);
+  BLI_strncpy(user_path->path, path_str, sizeof(user_path->path));
+  BLI_addtail(&ami->user_paths, user_path);
+  return user_path;
+#  else
+  UNUSED_VARS(ami, path_str);
+  return NULL;
+#  endif
+}
+
+static void rna_XrUserPath_remove(XrActionMapItem *ami, PointerRNA *user_path_ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  XrUserPath *user_path = user_path_ptr->data;
+  int idx = BLI_findindex(&ami->user_paths, user_path);
+  if (idx != -1) {
+    BLI_freelinkN(&ami->user_paths, user_path);
+  }
+  RNA_POINTER_INVALIDATE(user_path_ptr);
+#  else
+  UNUSED_VARS(ami, user_path_ptr);
+#  endif
+}
+
+static XrUserPath *rna_XrUserPath_find(XrActionMapItem *ami, const char *path_str)
+{
+#  ifdef WITH_XR_OPENXR
+  return BLI_findstring(&ami->user_paths, path_str, offsetof(XrUserPath, path));
+#  else
+  UNUSED_VARS(ami, path_str);
+  return NULL;
+#  endif
+}
+
 static XrActionMapItem *rna_XrActionMapItem_new(XrActionMap *am,
                                                 const char *name,
                                                 bool replace_existing)
@@ -222,6 +318,27 @@ static XrActionMapItem *rna_XrActionMapItem_find(XrActionMap *am, const char *na
 #  endif
 }
 
+static void rna_XrActionMapItem_user_paths_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  XrActionMapItem *ami = (XrActionMapItem *)ptr->data;
+  rna_iterator_listbase_begin(iter, &ami->user_paths, NULL);
+#  else
+  UNUSED_VARS(iter, ptr);
+#  endif
+}
+
+static int rna_XrActionMapItem_user_paths_length(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  XrActionMapItem *ami = (XrActionMapItem *)ptr->data;
+  return BLI_listbase_count(&ami->user_paths);
+#  else
+  UNUSED_VARS(ptr);
+  return 0;
+#  endif
+}
+
 static void rna_XrActionMapItem_op_name_get(PointerRNA *ptr, char *value)
 {
 #  ifdef WITH_XR_OPENXR
@@ -395,6 +512,27 @@ static void rna_XrActionMapItem_pose_is_controller_aim_set(PointerRNA *ptr, bool
 #  endif
 }
 
+static void rna_XrActionMapItem_bindings_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  XrActionMapItem *ami = (XrActionMapItem *)ptr->data;
+  rna_iterator_listbase_begin(iter, &ami->bindings, NULL);
+#  else
+  UNUSED_VARS(iter, ptr);
+#  endif
+}
+
+static int rna_XrActionMapItem_bindings_length(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  XrActionMapItem *ami = (XrActionMapItem *)ptr->data;
+  return BLI_listbase_count(&ami->bindings);
+#  else
+  UNUSED_VARS(ptr);
+  return 0;
+#  endif
+}
+
 static void rna_XrActionMapItem_name_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
 {
 #  ifdef WITH_XR_OPENXR
@@ -471,6 +609,27 @@ static XrActionMap *rna_XrActionMap_find(PointerRNA *ptr, const char *name)
 #  endif
 }
 
+static void rna_XrActionMap_items_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  XrActionMap *actionmap = (XrActionMap *)ptr->data;
+  rna_iterator_listbase_begin(iter, &actionmap->items, NULL);
+#  else
+  UNUSED_VARS(iter, ptr);
+#  endif
+}
+
+static int rna_XrActionMap_items_length(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  XrActionMap *actionmap = (XrActionMap *)ptr->data;
+  return BLI_listbase_count(&actionmap->items);
+#  else
+  UNUSED_VARS(ptr);
+  return 0;
+#  endif
+}
+
 static void rna_XrActionMap_name_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
 {
 #  ifdef WITH_XR_OPENXR
@@ -576,26 +735,8 @@ static bool rna_XrSessionState_action_create(bContext *C,
 {
 #  ifdef WITH_XR_OPENXR
   wmWindowManager *wm = CTX_wm_manager(C);
-  unsigned int count_subaction_paths = 0;
-  const char *subaction_paths[2];
-
-  if (ami->user_path0[0]) {
-    subaction_paths[0] = ami->user_path0;
-    ++count_subaction_paths;
-
-    if (ami->user_path1[0]) {
-      subaction_paths[1] = ami->user_path1;
-      ++count_subaction_paths;
-    }
-  }
-  else {
-    if (ami->user_path1[0]) {
-      subaction_paths[0] = ami->user_path1;
-      ++count_subaction_paths;
-    }
-    else {
-      return false;
-    }
+  if (BLI_listbase_is_empty(&ami->user_paths)) {
+    return false;
   }
 
   const bool is_float_action = (ami->type == XR_FLOAT_INPUT || ami->type == XR_VECTOR2F_INPUT);
@@ -621,8 +762,7 @@ static bool rna_XrSessionState_action_create(bContext *C,
                              actionmap->name,
                              ami->name,
                              ami->type,
-                             count_subaction_paths,
-                             subaction_paths,
+                             &ami->user_paths,
                              ot,
                              op_properties,
                              is_button_action ? ami->haptic_name : NULL,
@@ -645,30 +785,10 @@ static bool rna_XrSessionState_action_binding_create(bContext *C,
 {
 #  ifdef WITH_XR_OPENXR
   wmWindowManager *wm = CTX_wm_manager(C);
-  unsigned int count_subaction_paths = 0;
-  const char *subaction_paths[2];
-  const char *component_paths[2];
-
-  if (ami->user_path0[0]) {
-    subaction_paths[0] = ami->user_path0;
-    component_paths[0] = amb->component_path0;
-    ++count_subaction_paths;
-
-    if (ami->user_path1[0]) {
-      subaction_paths[1] = ami->user_path1;
-      component_paths[1] = amb->component_path1;
-      ++count_subacti

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list