Skip to content

Commit

Permalink
Change to new PICO interaction profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiaanOlij committed Aug 30, 2023
1 parent d2f76e8 commit 3a89bb3
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 53 deletions.
6 changes: 3 additions & 3 deletions modules/openxr/action_map/openxr_action_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,14 @@ void OpenXRActionMap::create_default_action_sets() {
profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
add_interaction_profile(profile);

// Create our Pico 4 / Neo 3 controller profile
profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/pico/neo3_controller");
// Create our Pico 4 controller profile.
profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/bytedance/pico4_controller");
profile->add_new_binding(default_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
profile->add_new_binding(palm_pose, "/user/hand/left/input/palm_ext/pose,/user/hand/right/input/palm_ext/pose");
profile->add_new_binding(select_button, "/user/hand/left/input/system/click,/user/hand/right/input/system/click"); // system click may not be available
profile->add_new_binding(menu_button, "/user/hand/left/input/back/click,/user/hand/right/input/back/click"); // right hand back click may not be available
profile->add_new_binding(menu_button, "/user/hand/left/input/menu/click");
profile->add_new_binding(ax_button, "/user/hand/left/input/x/click,/user/hand/right/input/a/click"); // x on left hand, a on right hand
profile->add_new_binding(ax_touch, "/user/hand/left/input/x/touch,/user/hand/right/input/a/touch");
profile->add_new_binding(by_button, "/user/hand/left/input/y/click,/user/hand/right/input/b/click"); // y on left hand, b on right hand
Expand Down
5 changes: 4 additions & 1 deletion modules/openxr/action_map/openxr_interaction_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ Ref<OpenXRInteractionProfile> OpenXRInteractionProfile::new_profile(const char *
}

void OpenXRInteractionProfile::set_interaction_profile_path(const String p_input_profile_path) {
interaction_profile_path = p_input_profile_path;
OpenXRInteractionProfileMetadata *pmd = OpenXRInteractionProfileMetadata::get_singleton();
ERR_FAIL_NULL(pmd);

interaction_profile_path = pmd->check_profile_name(p_input_profile_path);
emit_changed();
}

Expand Down
15 changes: 15 additions & 0 deletions modules/openxr/action_map/openxr_interaction_profile_metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,26 @@ OpenXRInteractionProfileMetadata::~OpenXRInteractionProfileMetadata() {
}

void OpenXRInteractionProfileMetadata::_bind_methods() {
ClassDB::bind_method(D_METHOD("register_profile_rename", "old_name", "new_name"), &OpenXRInteractionProfileMetadata::register_profile_rename);
ClassDB::bind_method(D_METHOD("register_top_level_path", "display_name", "openxr_path", "openxr_extension_name"), &OpenXRInteractionProfileMetadata::register_top_level_path);
ClassDB::bind_method(D_METHOD("register_interaction_profile", "display_name", "openxr_path", "openxr_extension_name"), &OpenXRInteractionProfileMetadata::register_interaction_profile);
ClassDB::bind_method(D_METHOD("register_io_path", "interaction_profile", "display_name", "toplevel_path", "openxr_path", "openxr_extension_name", "action_type"), &OpenXRInteractionProfileMetadata::register_io_path);
}

void OpenXRInteractionProfileMetadata::register_profile_rename(const String &p_old_name, const String &p_new_name) {
ERR_FAIL_COND(profile_renames.has(p_old_name));

profile_renames[p_old_name] = p_new_name;
}

String OpenXRInteractionProfileMetadata::check_profile_name(const String &p_name) const {
if (profile_renames.has(p_name)) {
return profile_renames[p_name];
}

return p_name;
}

void OpenXRInteractionProfileMetadata::register_top_level_path(const String &p_display_name, const String &p_openxr_path, const String &p_openxr_extension_name) {
ERR_FAIL_COND_MSG(has_top_level_path(p_openxr_path), p_openxr_path + " had already been registered");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "openxr_action.h"

#include "core/object/object.h"
#include "core/templates/hash_map.h"

#define XR_PATH_UNSUPPORTED_NAME "unsupported"

Expand Down Expand Up @@ -88,6 +89,7 @@ class OpenXRInteractionProfileMetadata : public Object {
private:
static OpenXRInteractionProfileMetadata *singleton;

HashMap<String, String> profile_renames;
Vector<TopLevelPath> top_level_paths;
Vector<InteractionProfile> interaction_profiles;

Expand All @@ -102,6 +104,9 @@ class OpenXRInteractionProfileMetadata : public Object {
OpenXRInteractionProfileMetadata();
~OpenXRInteractionProfileMetadata();

void register_profile_rename(const String &p_old_name, const String &p_new_name);
String check_profile_name(const String &p_name) const;

void register_top_level_path(const String &p_display_name, const String &p_openxr_path, const String &p_openxr_extension_name);
bool has_top_level_path(const String p_openxr_path) const;
String get_top_level_name(const String p_openxr_path) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
Registers an input/output path for the given [param interaction_profile]. The profile should previously have been registered using [method register_interaction_profile]. [param display_name] is the description shown to the user. [param toplevel_path] specifies the bind path this input/output can be bound to (e.g. [code]/user/hand/left[/code] or [code]/user/hand/right[/code]). [param openxr_path] is the action input/output being registered (e.g. [code]/user/hand/left/input/aim/pose[/code]). [param openxr_extension_name] restricts this input/output to an enabled/available extension, this doesn't need to repeat the extension on the profile but relates to overlapping extension (e.g. [code]XR_EXT_palm_pose[/code] that introduces [code]…/input/palm_ext/pose[/code] input paths). [param action_type] defines the type of input or output provided by OpenXR.
</description>
</method>
<method name="register_profile_rename">
<return type="void" />
<param index="0" name="old_name" type="String" />
<param index="1" name="new_name" type="String" />
<description>
Allows for renaming old interaction profile paths to new paths to maintain backwards compatibility with older action maps.
</description>
</method>
<method name="register_top_level_path">
<return type="void" />
<param index="0" name="display_name" type="String" />
Expand Down
Loading

0 comments on commit 3a89bb3

Please sign in to comment.