[Bf-blender-cvs] [517dc644f12] xr-dev: XR: Customizable Actions
Peter Kim
noreply at git.blender.org
Sun Feb 20 07:59:17 CET 2022
Commit: 517dc644f1204e58ea80331edf1d4fe79033a039
Author: Peter Kim
Date: Sun Feb 20 15:00:10 2022 +0900
Branches: xr-dev
https://developer.blender.org/rB517dc644f1204e58ea80331edf1d4fe79033a039
XR: Customizable Actions
https://developer.blender.org/D13420
===================================================================
M source/blender/editors/include/UI_interface.h
M source/blender/editors/interface/CMakeLists.txt
M source/blender/editors/interface/interface_templates.c
M source/blender/makesdna/DNA_xr_types.h
M source/blender/makesrna/intern/rna_ui_api.c
M source/blender/makesrna/intern/rna_xr.c
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/intern/wm.c
M source/blender/windowmanager/intern/wm_files.c
M source/blender/windowmanager/xr/intern/wm_xr.c
M source/blender/windowmanager/xr/intern/wm_xr_actionmap.c
M source/blender/windowmanager/xr/intern/wm_xr_intern.h
===================================================================
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 7bbc8249a97..0bdce504946 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2365,6 +2365,7 @@ void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C);
void uiTemplateReportsBanner(uiLayout *layout, struct bContext *C);
void uiTemplateInputStatus(uiLayout *layout, struct bContext *C);
void uiTemplateKeymapItemProperties(uiLayout *layout, struct PointerRNA *ptr);
+void uiTemplateXrActionmapItemProperties(uiLayout *layout, struct PointerRNA *ptr);
bool uiTemplateEventFromKeymapItem(struct uiLayout *layout,
const char *text,
diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index 6033aaf9105..3e10d808058 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -102,5 +102,8 @@ if(WIN32 OR APPLE)
endif()
endif()
+if(WITH_XR_OPENXR)
+ add_definitions(-DWITH_XR_OPENXR)
+endif()
blender_add_lib(bf_editor_interface "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index f8fbc2d01a6..e3396d14779 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -6151,6 +6151,44 @@ void uiTemplateKeymapItemProperties(uiLayout *layout, PointerRNA *ptr)
/** \} */
+/* -------------------------------------------------------------------- */
+/** \name XR Actionmap Template
+ * \{ */
+
+#ifdef WITH_XR_OPENXR
+static void xr_actionmap_item_modified(bContext *UNUSED(C),
+ void *UNUSED(ami_p),
+ void *UNUSED(unused))
+{
+}
+#endif
+
+void uiTemplateXrActionmapItemProperties(uiLayout *layout, PointerRNA *ptr)
+{
+#ifdef WITH_XR_OPENXR
+ PointerRNA propptr = RNA_pointer_get(ptr, "op_properties");
+
+ if (propptr.data) {
+ uiBut *but = uiLayoutGetBlock(layout)->buttons.last;
+
+ WM_operator_properties_sanitize(&propptr, false);
+ /* Use same template as keymap item properties. */
+ template_keymap_item_properties(layout, NULL, &propptr);
+
+ for (; but; but = but->next) {
+ if (but->rnaprop) {
+ UI_but_func_set(but, xr_actionmap_item_modified, ptr->data, NULL);
+ UI_but_flag_enable(but, UI_BUT_UPDATE_DELAY);
+ }
+ }
+ }
+#else
+ UNUSED_VARS(layout, ptr);
+#endif
+}
+
+/** \} */
+
/* -------------------------------------------------------------------- */
/** \name Event Icon Template
* \{ */
diff --git a/source/blender/makesdna/DNA_xr_types.h b/source/blender/makesdna/DNA_xr_types.h
index 09eab0d7bf7..92f5ff3ccc3 100644
--- a/source/blender/makesdna/DNA_xr_types.h
+++ b/source/blender/makesdna/DNA_xr_types.h
@@ -36,6 +36,11 @@ typedef struct XrSessionSettings {
float clip_start, clip_end;
int flag;
+
+ ListBase actionmaps; /* XrActionMap */
+ short actactionmap;
+ short selactionmap;
+ char _pad3[4];
} XrSessionSettings;
typedef enum eXrSessionFlag {
@@ -137,7 +142,8 @@ typedef struct XrActionMapBinding {
/** Input threshold/region. */
float float_threshold;
short axis_flag; /* eXrAxisFlag */
- char _pad[2];
+
+ short sel_component_path;
/** Pose action properties. */
float pose_location[3];
@@ -183,8 +189,8 @@ typedef struct XrActionMapItem {
float haptic_frequency;
float haptic_amplitude;
- short selbinding;
- char _pad3[2];
+ short sel_user_path;
+ short sel_binding;
ListBase bindings; /* XrActionMapBinding */
} XrActionMapItem;
@@ -197,7 +203,7 @@ typedef struct XrActionMap {
char name[64]; /* MAX_NAME */
ListBase items; /* XrActionMapItem */
- short selitem;
+ short sel_item;
char _pad[6];
} XrActionMap;
diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c
index c4396719bb9..8f12e3fa581 100644
--- a/source/blender/makesrna/intern/rna_ui_api.c
+++ b/source/blender/makesrna/intern/rna_ui_api.c
@@ -1789,6 +1789,11 @@ void RNA_api_ui_layout(StructRNA *srna)
parm = RNA_def_pointer(func, "item", "KeyMapItem", "", "");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+ func = RNA_def_function(
+ srna, "template_xr_actionmap_item_properties", "uiTemplateXrActionmapItemProperties");
+ parm = RNA_def_pointer(func, "item", "XrActionMapItem", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+
func = RNA_def_function(srna, "template_component_menu", "uiTemplateComponentMenu");
RNA_def_function_ui_description(func, "Item. Display expanded property in a popup menu");
parm = RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property");
diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index 9fe3153eb1e..83eb92e6533 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -66,6 +66,12 @@ static void rna_XrComponentPath_remove(XrActionMapBinding *amb, PointerRNA *comp
int idx = BLI_findindex(&amb->component_paths, component_path);
if (idx != -1) {
BLI_freelinkN(&amb->component_paths, component_path);
+
+ if (idx <= amb->sel_component_path) {
+ if (--amb->sel_component_path < 0) {
+ amb->sel_component_path = 0;
+ }
+ }
}
RNA_POINTER_INVALIDATE(component_path_ptr);
# else
@@ -216,12 +222,11 @@ static void rna_XrActionMapBinding_name_update(Main *bmain, Scene *UNUSED(scene)
{
# ifdef WITH_XR_OPENXR
wmWindowManager *wm = bmain->wm.first;
- if (wm && wm->xr.runtime) {
- ListBase *actionmaps = WM_xr_actionmaps_get(wm->xr.runtime);
- short idx = WM_xr_actionmap_selected_index_get(wm->xr.runtime);
- XrActionMap *actionmap = BLI_findlink(actionmaps, idx);
+ if (wm) {
+ XrActionMap *actionmap = BLI_findlink(&wm->xr.session_settings.actionmaps,
+ wm->xr.session_settings.selactionmap);
if (actionmap) {
- XrActionMapItem *ami = BLI_findlink(&actionmap->items, actionmap->selitem);
+ XrActionMapItem *ami = BLI_findlink(&actionmap->items, actionmap->sel_item);
if (ami) {
XrActionMapBinding *amb = ptr->data;
WM_xr_actionmap_binding_ensure_unique(ami, amb);
@@ -253,6 +258,12 @@ static void rna_XrUserPath_remove(XrActionMapItem *ami, PointerRNA *user_path_pt
int idx = BLI_findindex(&ami->user_paths, user_path);
if (idx != -1) {
BLI_freelinkN(&ami->user_paths, user_path);
+
+ if (idx <= ami->sel_user_path) {
+ if (--ami->sel_user_path < 0) {
+ ami->sel_user_path = 0;
+ }
+ }
}
RNA_POINTER_INVALIDATE(user_path_ptr);
# else
@@ -537,10 +548,9 @@ static void rna_XrActionMapItem_name_update(Main *bmain, Scene *UNUSED(scene), P
{
# ifdef WITH_XR_OPENXR
wmWindowManager *wm = bmain->wm.first;
- if (wm && wm->xr.runtime) {
- ListBase *actionmaps = WM_xr_actionmaps_get(wm->xr.runtime);
- short idx = WM_xr_actionmap_selected_index_get(wm->xr.runtime);
- XrActionMap *actionmap = BLI_findlink(actionmaps, idx);
+ if (wm) {
+ XrActionMap *actionmap = BLI_findlink(&wm->xr.session_settings.actionmaps,
+ wm->xr.session_settings.selactionmap);
if (actionmap) {
XrActionMapItem *ami = ptr->data;
WM_xr_actionmap_item_ensure_unique(actionmap, ami);
@@ -561,50 +571,51 @@ static void rna_XrActionMapItem_update(Main *UNUSED(bmain), Scene *UNUSED(scene)
# endif
}
-static XrActionMap *rna_XrActionMap_new(PointerRNA *ptr, const char *name, bool replace_existing)
+static XrActionMap *rna_XrActionMap_new(XrSessionSettings *settings,
+ const char *name,
+ bool replace_existing)
{
# ifdef WITH_XR_OPENXR
- wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
- return WM_xr_actionmap_new(xr->runtime, name, replace_existing);
+ return WM_xr_actionmap_new(settings, name, replace_existing);
# else
- UNUSED_VARS(ptr, name, replace_existing);
+ UNUSED_VARS(settings, name, replace_existing);
return NULL;
# endif
}
-static XrActionMap *rna_XrActionMap_new_from_actionmap(PointerRNA *ptr, XrActionMap *am_src)
+static XrActionMap *rna_XrActionMap_new_from_actionmap(XrSessionSettings *settings,
+ XrActionMap *am_src)
{
# ifdef WITH_XR_OPENXR
- wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
- return WM_xr_actionmap_add_copy(xr->runtime, am_src);
+ return WM_xr_actionmap_add_copy(settings, am_src);
# else
- UNUSED_VARS(ptr, am_src);
+ UNUSED_VARS(settings, am_src);
return NULL;
# endif
}
-static void rna_XrActionMap_remove(ReportList *reports, PointerRNA *ptr, PointerRNA *actionmap_ptr)
+static void rna_XrActionMap_remove(XrSessionSettings *settings,
+ ReportList *reports,
+ PointerRNA *actionmap_ptr)
{
# ifdef WITH_XR_OPENXR
- wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
XrActionMap *actionmap = actionmap_ptr->data;
- if (WM_xr_actionmap_remove(xr->runtime, actionmap) == false) {
+ if (WM_xr_actionmap_remove(settings, actionmap) == false) {
BKE_reportf(reports, RPT_ERROR, "ActionMap '%s' cannot be removed", actionmap->name);
return;
}
RNA_POINTER_INVALIDATE(actionmap_ptr);
# else
- UNUSED_VARS(ptr, reports, actionmap_ptr);
+ UNUSED_VARS(settings, reports, actionmap_ptr);
# endif
}
-static XrActionMap *rna_XrActionMap_find(PointerRNA *ptr, const char *name)
+static XrActionMap *rna_XrActionMap_find(XrSessionSettings *settings, const char *name)
{
# ifdef WITH_XR_OPENXR
- wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
- return WM_xr_actionmap_find(xr->runtime, name);
+ return WM_xr_actionmap_find(settings, name);
# else
- UNUSED_VARS(ptr, name);
+ UNUSED_VARS(settings, name);
return NULL;
# endif
}
@@ -634,9 +645,9
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list