[Bf-blender-cvs] [7343845d7b3] xr-controller-support: Update with changes from D10943

Peter Kim noreply at git.blender.org
Tue May 18 15:07:12 CEST 2021


Commit: 7343845d7b36f5d931043f5123a57fc9b6f4cd96
Author: Peter Kim
Date:   Tue May 18 18:47:17 2021 +0900
Branches: xr-controller-support
https://developer.blender.org/rB7343845d7b36f5d931043f5123a57fc9b6f4cd96

Update with changes from D10943

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

M	source/blender/makesdna/DNA_xr_types.h
M	source/blender/makesrna/intern/rna_xr.c
M	source/blender/windowmanager/CMakeLists.txt
R100	source/blender/windowmanager/xr/intern/wm_xr_actions.c	source/blender/windowmanager/xr/intern/wm_xr_action.c
M	source/creator/creator.c

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

diff --git a/source/blender/makesdna/DNA_xr_types.h b/source/blender/makesdna/DNA_xr_types.h
index 149e15f891d..7ba66503c10 100644
--- a/source/blender/makesdna/DNA_xr_types.h
+++ b/source/blender/makesdna/DNA_xr_types.h
@@ -28,6 +28,8 @@ extern "C" {
 
 struct XrActionConfig;
 
+/* -------------------------------------------------------------------- */
+
 typedef struct XrSessionSettings {
   /** Shading settings, struct shared with 3D-View so settings are the same. */
   struct View3DShading shading;
@@ -74,6 +76,49 @@ typedef struct XrSessionSettings {
   char _pad3[5];
 } XrSessionSettings;
 
+/** XR action type. Enum values match those in GHOST_XrActionType enum for consistency. */
+typedef enum eXrActionType {
+  XR_BOOLEAN_INPUT = 1,
+  XR_FLOAT_INPUT = 2,
+  XR_VECTOR2F_INPUT = 3,
+  XR_POSE_INPUT = 4,
+  XR_VIBRATION_OUTPUT = 100,
+} eXrActionType;
+
+typedef enum eXrOpFlag {
+  XR_OP_PRESS = 0,
+  XR_OP_RELEASE = 1,
+  XR_OP_MODAL = 2,
+} eXrOpFlag;
+
+typedef enum eXrSessionFlag {
+  XR_SESSION_USE_POSITION_TRACKING = (1 << 0),
+  XR_SESSION_USE_ABSOLUTE_TRACKING = (1 << 1),
+} eXrSessionFlag;
+
+typedef enum eXRSessionBasePoseType {
+  XR_BASE_POSE_SCENE_CAMERA = 0,
+  XR_BASE_POSE_OBJECT = 1,
+  XR_BASE_POSE_CUSTOM = 2,
+} eXRSessionBasePoseType;
+
+typedef enum eXrSessionControllerDrawStyle {
+  XR_CONTROLLER_DRAW_AXES = 0,
+  XR_CONTROLLER_DRAW_RAY = 1,
+} eXrSessionControllerDrawStyle;
+
+typedef enum eXrSessionEye {
+  XR_EYE_LEFT = 0,
+  XR_EYE_RIGHT = 1,
+} eXrSessionEye;
+
+typedef enum eXrSessionObjectFlag {
+  XR_OBJECT_ENABLE = (1 << 0),
+  XR_OBJECT_AUTOKEY = (1 << 1),
+} eXrSessionObjectFlag;
+
+/* -------------------------------------------------------------------- */
+
 typedef struct XrActionMapItem {
   struct XrActionMapItem *next, *prev;
 
@@ -120,6 +165,10 @@ enum {
   XR_AMI_UPDATE = (1 << 0),
 };
 
+#define XR_AMI_MAX_NAME 64
+
+/* -------------------------------------------------------------------- */
+
 typedef struct XrActionMap {
   struct XrActionMap *next, *prev;
 
@@ -139,6 +188,10 @@ enum {
   XR_ACTIONMAP_UPDATE = (1 << 0),
 };
 
+#define XR_ACTIONMAP_MAX_NAME 64
+
+/* -------------------------------------------------------------------- */
+
 typedef struct XrActionConfig {
   struct XrActionConfig *next, *prev;
 
@@ -158,49 +211,8 @@ enum {
 };
 
 #define XR_ACTIONCONF_MAX_NAME 64
-#define XR_ACTIONMAP_MAX_NAME 64
-#define XR_AMI_MAX_NAME 64
 
-/** XR action type. Enum values match those in GHOST_XrActionType enum for consistency. */
-typedef enum eXrActionType {
-  XR_BOOLEAN_INPUT = 1,
-  XR_FLOAT_INPUT = 2,
-  XR_VECTOR2F_INPUT = 3,
-  XR_POSE_INPUT = 4,
-  XR_VIBRATION_OUTPUT = 100,
-} eXrActionType;
-
-typedef enum eXrOpFlag {
-  XR_OP_PRESS = 0,
-  XR_OP_RELEASE = 1,
-  XR_OP_MODAL = 2,
-} eXrOpFlag;
-
-typedef enum eXrSessionFlag {
-  XR_SESSION_USE_POSITION_TRACKING = (1 << 0),
-  XR_SESSION_USE_ABSOLUTE_TRACKING = (1 << 1),
-} eXrSessionFlag;
-
-typedef enum eXRSessionBasePoseType {
-  XR_BASE_POSE_SCENE_CAMERA = 0,
-  XR_BASE_POSE_OBJECT = 1,
-  XR_BASE_POSE_CUSTOM = 2,
-} eXRSessionBasePoseType;
-
-typedef enum eXrSessionControllerDrawStyle {
-  XR_CONTROLLER_DRAW_AXES = 0,
-  XR_CONTROLLER_DRAW_RAY = 1,
-} eXrSessionControllerDrawStyle;
-
-typedef enum eXrSessionEye {
-  XR_EYE_LEFT = 0,
-  XR_EYE_RIGHT = 1,
-} eXrSessionEye;
-
-typedef enum eXrSessionObjectFlag {
-  XR_OBJECT_ENABLE = (1 << 0),
-  XR_OBJECT_AUTOKEY = (1 << 1),
-} eXrSessionObjectFlag;
+/* -------------------------------------------------------------------- */
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index 8269ad3fcee..8b4e7f1b083 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -37,299 +37,403 @@
 
 #  include "WM_api.h"
 
-#  ifdef WITH_XR_OPENXR
+/* -------------------------------------------------------------------- */
+/** \name XR Action Configuration
+ * \{ */
 
-static wmXrData *rna_XrSession_wm_xr_data_get(PointerRNA *ptr)
+static XrActionMapItem *rna_XrActionMapItem_new(XrActionMap *am,
+                                                const char *idname,
+                                                bool replace_existing)
 {
-  /* Callers could also get XrSessionState pointer through ptr->data, but prefer if we just
-   * consistently pass wmXrData pointers to the WM_xr_xxx() API. */
-
-  BLI_assert((ptr->type == &RNA_XrSessionSettings) || (ptr->type == &RNA_XrSessionState));
-
-  wmWindowManager *wm = (wmWindowManager *)ptr->owner_id;
-  BLI_assert(wm && (GS(wm->id.name) == ID_WM));
-
-  return &wm->xr;
-}
+#  ifdef WITH_XR_OPENXR
+  return WM_xr_actionmap_item_new(am, idname, replace_existing);
+#  else
+  UNUSED_VARS(am, idname, replace_existing);
+  return NULL;
 #  endif
+}
 
-static bool rna_XrSessionSettings_use_positional_tracking_get(PointerRNA *ptr)
+static XrActionMapItem *rna_XrActionMapItem_new_from_item(XrActionMap *am,
+                                                          XrActionMapItem *ami_src)
 {
 #  ifdef WITH_XR_OPENXR
-  const wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
-  return (xr->session_settings.flag & XR_SESSION_USE_POSITION_TRACKING) != 0;
+  return WM_xr_actionmap_item_add_copy(am, ami_src);
 #  else
-  UNUSED_VARS(ptr);
-  return false;
+  UNUSED_VARS(am, ami_src);
+  return NULL;
 #  endif
 }
 
-static void rna_XrSessionSettings_use_positional_tracking_set(PointerRNA *ptr, bool value)
+static void rna_XrActionMapItem_remove(XrActionMap *am, ReportList *reports, PointerRNA *ami_ptr)
 {
 #  ifdef WITH_XR_OPENXR
-  wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
-  if (value) {
-    xr->session_settings.flag |= XR_SESSION_USE_POSITION_TRACKING;
-  }
-  else {
-    xr->session_settings.flag &= (~XR_SESSION_USE_POSITION_TRACKING);
+  XrActionMapItem *ami = ami_ptr->data;
+  if (WM_xr_actionmap_item_remove(am, ami) == false) {
+    BKE_reportf(reports,
+                RPT_ERROR,
+                "ActionMapItem '%s' cannot be removed from '%s'",
+                ami->idname,
+                am->idname);
+    return;
   }
+  RNA_POINTER_INVALIDATE(ami_ptr);
 #  else
-  UNUSED_VARS(ptr, value);
+  UNUSED_VARS(am, reports, ami_ptr);
 #  endif
 }
 
-static bool rna_XrSessionSettings_use_absolute_tracking_get(PointerRNA *ptr)
+static XrActionMapItem *rna_XrActionMapItem_find(XrActionMap *am, const char *idname)
 {
 #  ifdef WITH_XR_OPENXR
-  const wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
-  return (xr->session_settings.flag & XR_SESSION_USE_ABSOLUTE_TRACKING) != 0;
+  return WM_xr_actionmap_item_list_find(&am->items, idname);
 #  else
-  UNUSED_VARS(ptr);
-  return false;
+  UNUSED_VARS(am, idname);
+  return NULL;
 #  endif
 }
 
-static void rna_XrSessionSettings_use_absolute_tracking_set(PointerRNA *ptr, bool value)
+static void rna_XrActionMapItem_op_name_get(PointerRNA *ptr, char *value)
 {
 #  ifdef WITH_XR_OPENXR
-  wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
-  if (value) {
-    xr->session_settings.flag |= XR_SESSION_USE_ABSOLUTE_TRACKING;
-  }
-  else {
-    xr->session_settings.flag &= (~XR_SESSION_USE_ABSOLUTE_TRACKING);
+  XrActionMapItem *ami = ptr->data;
+  if (ami->op[0]) {
+    if (ami->op_properties_ptr) {
+      wmOperatorType *ot = WM_operatortype_find(ami->op, 1);
+      if (ot) {
+        strcpy(value, WM_operatortype_name(ot, ami->op_properties_ptr));
+        return;
+      }
+    }
+    strcpy(value, ami->op);
+    return;
   }
 #  else
-  UNUSED_VARS(ptr, value);
+  UNUSED_VARS(ptr);
 #  endif
+  value[0] = '\0';
 }
 
-static void rna_XrSessionSettings_headset_object_set(PointerRNA *ptr,
-                                                     PointerRNA value,
-                                                     struct ReportList *UNUSED(reports))
+static int rna_XrActionMapItem_op_name_length(PointerRNA *ptr)
 {
 #  ifdef WITH_XR_OPENXR
-  wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
-  Object *ob = value.data;
-
-  if (xr->session_settings.headset_object) {
-    /* Restore previous object's original pose. */
-    WM_xr_session_state_viewer_object_get(xr, xr->session_settings.headset_object);
-  }
-  if (ob) {
-    /* Store new object's original pose. */
-    WM_xr_session_state_viewer_object_set(xr, ob);
+  XrActionMapItem *ami = ptr->data;
+  if (ami->op[0]) {
+    if (ami->op_properties_ptr) {
+      wmOperatorType *ot = WM_operatortype_find(ami->op, 1);
+      if (ot) {
+        return strlen(WM_operatortype_name(ot, ami->op_properties_ptr));
+      }
+    }
+    return strlen(ami->op);
   }
-
-  xr->session_settings.headset_object = ob;
 #  else
-  UNUSED_VARS(ptr, value);
+  UNUSED_VARS(ptr);
 #  endif
+  return 0;
 }
 
-static bool rna_XrSessionSettings_headset_object_enable_get(PointerRNA *ptr)
+static PointerRNA rna_XrActionMapItem_op_properties_get(PointerRNA *ptr)
 {
 #  ifdef WITH_XR_OPENXR
-  const wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
-  return (xr->session_settings.headset_flag & XR_OBJECT_ENABLE) != 0;
+  XrActionMapItem *ami = ptr->data;
+  if (ami->op_properties_ptr) {
+    return *(ami->op_properties_ptr);
+  }
 #  else
   UNUSED_VARS(ptr);
-  return false;
 #  endif
+  return PointerRNA_NULL;
 }
 
-static void rna_XrSessionSettings_headset_object_enable_set(PointerRNA *ptr, bool value)
+static void rna_XrActionMapItem_name_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
 {
 #  ifdef WITH_XR_OPENXR
-  wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
-  if (value) {
-    xr->session_settings.headset_flag |= XR_OBJECT_ENABLE;
-  }
-  else {
-    xr->session_settings.headset_flag &= (~XR_OBJECT_ENABLE);
-  }
-
-  /* Store/restore object's original pose. */
-  Object *ob = xr->session_settings.headset_object;
-  if (ob) {
-    if (value) {
-      WM_xr_session_state_viewer_object_set(xr, ob);
-    }
-    else {
-      WM_xr_session_state_viewer_object_get(xr, ob);
+  wmWindowManager *wm = bmain->wm.first;
+  if (wm) {
+    XrSessionSettings *settings = &wm->xr.session_settings;
+    XrActionConfig *actionconf = WM_xr_actionconfig_active_get(settings);
+    if (actionconf) {
+      XrActionMap *actionmap = BLI_findlink(&actionconf->actionmaps, actionconf->selactio

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list