[Bf-blender-cvs] [e0da7250750] xr-actions-D9124: Add basic controller visualization.
Peter Kim
noreply at git.blender.org
Tue Oct 13 14:45:00 CEST 2020
Commit: e0da72507509510ce3fadfc6dd6a2e46ae7164fc
Author: Peter Kim
Date: Tue Oct 6 21:37:06 2020 +0900
Branches: xr-actions-D9124
https://developer.blender.org/rBe0da72507509510ce3fadfc6dd6a2e46ae7164fc
Add basic controller visualization.
Differential Revision: https://developer.blender.org/D9124
===================================================================
M intern/ghost/GHOST_C-api.h
M intern/ghost/GHOST_IXrContext.h
M intern/ghost/GHOST_Types.h
M intern/ghost/intern/GHOST_C-api.cpp
M intern/ghost/intern/GHOST_XrContext.cpp
M intern/ghost/intern/GHOST_XrContext.h
M intern/ghost/intern/GHOST_XrException.h
M intern/ghost/intern/GHOST_XrSession.cpp
M intern/ghost/intern/GHOST_XrSession.h
M intern/ghost/intern/GHOST_Xr_intern.h
M source/blender/blenkernel/BKE_callbacks.h
M source/blender/draw/intern/draw_manager.c
M source/blender/editors/space_view3d/view3d_draw.c
M source/blender/makesdna/DNA_view3d_enums.h
M source/blender/makesdna/DNA_view3d_types.h
M source/blender/makesrna/intern/rna_wm.c
M source/blender/makesrna/intern/rna_xr.c
M source/blender/python/intern/bpy_app_handlers.c
M source/blender/windowmanager/CMakeLists.txt
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/WM_types.h
M source/blender/windowmanager/intern/wm_event_query.c
M source/blender/windowmanager/intern/wm_event_system.c
M source/blender/windowmanager/intern/wm_operators.c
M source/blender/windowmanager/wm_event_system.h
M source/blender/windowmanager/wm_event_types.h
M source/blender/windowmanager/wm_surface.h
M source/blender/windowmanager/xr/intern/wm_xr.c
A source/blender/windowmanager/xr/intern/wm_xr_actions.c
M source/blender/windowmanager/xr/intern/wm_xr_draw.c
M source/blender/windowmanager/xr/intern/wm_xr_intern.h
M source/blender/windowmanager/xr/intern/wm_xr_session.c
M source/blender/windowmanager/xr/wm_xr.h
===================================================================
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 2046b55c97f..09734506020 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -1067,6 +1067,115 @@ int GHOST_XrSessionNeedsUpsideDownDrawing(const GHOST_XrContextHandle xr_context
* \returns GHOST_kSuccess if any event was handled, otherwise GHOST_kFailure.
*/
GHOST_TSuccess GHOST_XrEventsHandle(GHOST_XrContextHandle xr_context);
+
+/* actions */
+/**
+ * Create an OpenXR action set for input / output.
+ */
+int GHOST_XrCreateActionSet(GHOST_XrContextHandle xr_context, const GHOST_XrActionSetInfo *info);
+
+/**
+ * Destroy a previously created OpenXR action set.
+ */
+void GHOST_XrDestroyActionSet(GHOST_XrContextHandle xr_context, const char *action_set_name);
+
+/**
+ * Create OpenXR input / output actions.
+ */
+int GHOST_XrCreateActions(GHOST_XrContextHandle xr_context,
+ const char *action_set_name,
+ GHOST_TUns32 count,
+ const GHOST_XrActionInfo *infos);
+
+/**
+ * Destroy previously created OpenXR actions.
+ */
+void GHOST_XrDestroyActions(GHOST_XrContextHandle xr_context,
+ const char *action_set_name,
+ GHOST_TUns32 count,
+ const char *const *action_names);
+
+/**
+ * Create spaces for pose-based OpenXR actions.
+ */
+int GHOST_XrCreateActionSpaces(GHOST_XrContextHandle xr_context,
+ const char *action_set_name,
+ GHOST_TUns32 count,
+ const GHOST_XrActionSpaceInfo *infos);
+
+/**
+ * Destroy previously created spaces for OpenXR actions.
+ */
+void GHOST_XrDestroyActionSpaces(GHOST_XrContextHandle xr_context,
+ const char *action_set_name,
+ GHOST_TUns32 count,
+ const GHOST_XrActionSpaceInfo *infos);
+
+/**
+ * Create input / output path bindings for OpenXR actions.
+ *
+ * \param replace_existing: Whether to replace all existing bindings for the profiles
+ * specified in infos.
+ */
+int GHOST_XrCreateActionBindings(GHOST_XrContextHandle xr_context,
+ const char *action_set_name,
+ GHOST_TUns32 count,
+ const GHOST_XrActionBindingsInfo *infos,
+ int replace_existing);
+
+/**
+ * Destroy previously created bindings for OpenXR actions.
+ */
+void GHOST_XrDestroyActionBindings(GHOST_XrContextHandle xr_context,
+ const char *action_set_name,
+ GHOST_TUns32 count,
+ const GHOST_XrActionBindingsInfo *infos);
+
+/**
+ * Attach all created action sets to the current OpenXR session.
+ */
+int GHOST_XrAttachActionSets(GHOST_XrContextHandle xr_context);
+
+/**
+ * Update button / tracking states for OpenXR actions.
+ *
+ * \param action_set_name: The name of the action set to sync. If NULL, all action sets
+ * attached to the session will be synced.
+ */
+int GHOST_XrSyncActions(GHOST_XrContextHandle xr_context, const char *action_set_name);
+
+/**
+ * Get the states of OpenXR actions.
+ *
+ * \param r_infos: An array of action info pointers (NOT an array of action infos) that will
+ * receive state data. The reason r_infos is an array of pointers is to allow writing to
+ * previously created actions which may not be stored in contiguous memory.
+ */
+int GHOST_XrGetActionStates(GHOST_XrContextHandle xr_context,
+ const char *action_set_name,
+ GHOST_TUns32 count,
+ GHOST_XrActionInfo *const *r_infos);
+
+/**
+ * Apply an OpenXR haptic output action.
+ */
+int GHOST_XrApplyHapticAction(GHOST_XrContextHandle xr_context,
+ const char *action_set_name,
+ const char *action_name,
+ GHOST_TUns32 count,
+ const char *const *subaction_paths,
+ const GHOST_TInt64 *duration,
+ const float *frequency,
+ const float *amplitude);
+
+/**
+ * Stop a previously applied OpenXR haptic output action.
+ */
+void GHOST_XrStopHapticAction(GHOST_XrContextHandle xr_context,
+ const char *action_set_name,
+ const char *action_name,
+ GHOST_TUns32 count,
+ const char *const *subaction_paths);
#endif
#ifdef __cplusplus
diff --git a/intern/ghost/GHOST_IXrContext.h b/intern/ghost/GHOST_IXrContext.h
index dd266a3b6ae..86fe78814a7 100644
--- a/intern/ghost/GHOST_IXrContext.h
+++ b/intern/ghost/GHOST_IXrContext.h
@@ -22,6 +22,8 @@
#include "GHOST_Types.h"
+class GHOST_XrSession;
+
class GHOST_IXrContext {
public:
virtual ~GHOST_IXrContext() = default;
@@ -31,6 +33,10 @@ class GHOST_IXrContext {
virtual bool isSessionRunning() const = 0;
virtual void drawSessionViews(void *draw_customdata) = 0;
+ /* Needed for the GHOST C api. */
+ virtual GHOST_XrSession *getSession() = 0;
+ virtual const GHOST_XrSession *getSession() const = 0;
+
virtual void dispatchErrorMessage(const class GHOST_XrException *) const = 0;
virtual void setGraphicsContextBindFuncs(GHOST_XrGraphicsContextBindFn bind_fn,
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 5f0516ae121..f7b3004f837 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -618,6 +618,7 @@ typedef enum GHOST_TXrGraphicsBinding {
typedef void (*GHOST_XrErrorHandlerFn)(const struct GHOST_XrError *);
+typedef void (*GHOST_XrSessionCreateFn)(void *customdata);
typedef void (*GHOST_XrSessionExitFn)(void *customdata);
typedef void *(*GHOST_XrGraphicsContextBindFn)(void);
@@ -628,7 +629,7 @@ typedef void (*GHOST_XrDrawViewFn)(const struct GHOST_XrDrawViewInfo *draw_view,
* available candidate will be chosen, so order defines priority. */
typedef const GHOST_TXrGraphicsBinding *GHOST_XrGraphicsBindingCandidates;
-typedef struct {
+typedef struct GHOST_XrPose {
float position[3];
/* Blender convention (w, x, y, z) */
float orientation_quat[4];
@@ -649,6 +650,8 @@ typedef struct {
typedef struct {
GHOST_XrPose base_pose;
+ GHOST_XrSessionCreateFn create_fn;
+ void *create_customdata;
GHOST_XrSessionExitFn exit_fn;
void *exit_customdata;
} GHOST_XrSessionBeginInfo;
@@ -672,7 +675,63 @@ typedef struct GHOST_XrDrawViewInfo {
typedef struct GHOST_XrError {
const char *user_message;
+ /* Whether to destroy the runtime when the error is handled.
+ * Some errors (in particular those related to OpenXR actions)
+ * may not warrant aborting the current context / session. */
+ char destroy_runtime;
+
void *customdata;
} GHOST_XrError;
+typedef struct GHOST_XrActionSetInfo {
+ const char *name;
+ /* Larger values take precedence over smaller values. */
+ GHOST_TUns32 priority;
+} GHOST_XrActionSetInfo;
+
+/* XR action type. Enum values match those in OpenXR's
+ * XrActionType enum for consistency. */
+typedef enum GHOST_XrActionType {
+ GHOST_kXrActionTypeBooleanInput = 1,
+ GHOST_kXrActionTypeFloatInput = 2,
+ GHOST_kXrActionTypeVector2fInput = 3,
+ GHOST_kXrActionTypePoseInput = 4,
+ GHOST_kXrActionTypeVibrationOutput = 100,
+} GHOST_XrActionType;
+
+typedef struct GHOST_XrActionInfo {
+ const char *name;
+ GHOST_XrActionType type;
+ GHOST_TUns32 count_subaction_paths;
+ const char **subaction_paths;
+ /* States for each subaction path. */
+ void *states;
+ /* Previous states, stored to determine XR events. */
+ void *states_prev;
+
+ /* wmOperatorType and wmXrOpFlag, only used by wm. */
+ void *ot;
+ char op_flag;
+} GHOST_XrActionInfo;
+
+typedef struct GHOST_XrActionSpaceInfo {
+ const char *action_name;
+ GHOST_TUns32 count_subaction_paths;
+ const char **subaction_paths;
+ /* Poses for each subaction path. */
+ GHOST_XrPose *poses;
+} GHOST_XrActionSpaceInfo;
+
+typedef struct GHOST_XrActionBinding {
+ const char *action_name;
+ /* Interaction path: User (subaction) path + component path. */
+ const char *interaction_path;
+} GHOST_XrActionBinding;
+
+typedef struct GHOST_XrActionBindingsInfo {
+ const char *interaction_profile_path;
+ GHOST_TUns32 count_bindings;
+ const GHOST_XrActionBinding *bindings;
+} GHOST_XrActionBindingsInfo;
+
#endif
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index e4bb908fec8..f124d5a92ce 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -33,6 +33,7 @@
#include "intern/GHOST_Debug.h"
#ifdef WITH_XR_OPENXR
# include "GHOST_IXrContext.h"
+# include "intern/GHOST_XrSession.h"
#endif
#include "intern/GHOST_CallbackEventConsumer.h"
#include "intern/GHOST_XrException.h"
@@ -968,4 +969,145 @@ int GHOST_XrSessionNeedsUpsideDownDrawing(const GHOST_XrContextHandle xr_context
return 0; /* Only reached if exception is thrown. */
}
+int GHOST_XrCreateActionSet(GHOST_XrContextHandle xr_contexthandle,
+ const GHOST_XrActionSetInfo *info)
+{
+ GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
+ GHOST_XrSession *xr_session = xr_context->getSession();
+ GHOST_XR_CAPI_CALL_RET(xr_session->createActionSet(info), xr_context);
+ return 0;
+}
+
+void GHOST_XrDestroyActionSet(GHOST_XrContextHandle xr_contexthandle, const char *action_set_name)
+{
+ GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
+ GHOST_XrSession *xr_session = xr_context->getSession();
+ GHOST_XR_CAPI_CALL(xr_session->destroyActionSet(action_set_name, true), xr_context);
+}
+
+int GHOST_XrCreateActions(GHOST_XrContextHandle xr_contexthandle,
+ const char *action_set_name,
+ GHOST_TUns32 count,
+ const GHOST_XrActionInfo *infos)
+{
+ GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
+ GHOST_XrS
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list