openxr_action_map.cpp 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /**************************************************************************/
  2. /* openxr_action_map.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "openxr_action_map.h"
  31. void OpenXRActionMap::_bind_methods() {
  32. ClassDB::bind_method(D_METHOD("set_action_sets", "action_sets"), &OpenXRActionMap::set_action_sets);
  33. ClassDB::bind_method(D_METHOD("get_action_sets"), &OpenXRActionMap::get_action_sets);
  34. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "action_sets", PROPERTY_HINT_RESOURCE_TYPE, "OpenXRActionSet", PROPERTY_USAGE_NO_EDITOR), "set_action_sets", "get_action_sets");
  35. ClassDB::bind_method(D_METHOD("get_action_set_count"), &OpenXRActionMap::get_action_set_count);
  36. ClassDB::bind_method(D_METHOD("find_action_set", "name"), &OpenXRActionMap::find_action_set);
  37. ClassDB::bind_method(D_METHOD("get_action_set", "idx"), &OpenXRActionMap::get_action_set);
  38. ClassDB::bind_method(D_METHOD("add_action_set", "action_set"), &OpenXRActionMap::add_action_set);
  39. ClassDB::bind_method(D_METHOD("remove_action_set", "action_set"), &OpenXRActionMap::remove_action_set);
  40. ClassDB::bind_method(D_METHOD("set_interaction_profiles", "interaction_profiles"), &OpenXRActionMap::set_interaction_profiles);
  41. ClassDB::bind_method(D_METHOD("get_interaction_profiles"), &OpenXRActionMap::get_interaction_profiles);
  42. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "interaction_profiles", PROPERTY_HINT_RESOURCE_TYPE, "OpenXRInteractionProfile", PROPERTY_USAGE_NO_EDITOR), "set_interaction_profiles", "get_interaction_profiles");
  43. ClassDB::bind_method(D_METHOD("get_interaction_profile_count"), &OpenXRActionMap::get_interaction_profile_count);
  44. ClassDB::bind_method(D_METHOD("find_interaction_profile", "name"), &OpenXRActionMap::find_interaction_profile);
  45. ClassDB::bind_method(D_METHOD("get_interaction_profile", "idx"), &OpenXRActionMap::get_interaction_profile);
  46. ClassDB::bind_method(D_METHOD("add_interaction_profile", "interaction_profile"), &OpenXRActionMap::add_interaction_profile);
  47. ClassDB::bind_method(D_METHOD("remove_interaction_profile", "interaction_profile"), &OpenXRActionMap::remove_interaction_profile);
  48. ClassDB::bind_method(D_METHOD("create_default_action_sets"), &OpenXRActionMap::create_default_action_sets);
  49. }
  50. void OpenXRActionMap::set_action_sets(Array p_action_sets) {
  51. action_sets.clear();
  52. for (int i = 0; i < p_action_sets.size(); i++) {
  53. Ref<OpenXRActionSet> action_set = p_action_sets[i];
  54. if (action_set.is_valid() && !action_sets.has(action_set)) {
  55. action_sets.push_back(action_set);
  56. }
  57. }
  58. }
  59. Array OpenXRActionMap::get_action_sets() const {
  60. return action_sets;
  61. }
  62. int OpenXRActionMap::get_action_set_count() const {
  63. return action_sets.size();
  64. }
  65. Ref<OpenXRActionSet> OpenXRActionMap::find_action_set(String p_name) const {
  66. for (int i = 0; i < action_sets.size(); i++) {
  67. Ref<OpenXRActionSet> action_set = action_sets[i];
  68. if (action_set->get_name() == p_name) {
  69. return action_set;
  70. }
  71. }
  72. return Ref<OpenXRActionSet>();
  73. }
  74. Ref<OpenXRActionSet> OpenXRActionMap::get_action_set(int p_idx) const {
  75. ERR_FAIL_INDEX_V(p_idx, action_sets.size(), Ref<OpenXRActionSet>());
  76. return action_sets[p_idx];
  77. }
  78. void OpenXRActionMap::add_action_set(Ref<OpenXRActionSet> p_action_set) {
  79. ERR_FAIL_COND(p_action_set.is_null());
  80. if (!action_sets.has(p_action_set)) {
  81. action_sets.push_back(p_action_set);
  82. emit_changed();
  83. }
  84. }
  85. void OpenXRActionMap::remove_action_set(Ref<OpenXRActionSet> p_action_set) {
  86. int idx = action_sets.find(p_action_set);
  87. if (idx != -1) {
  88. action_sets.remove_at(idx);
  89. emit_changed();
  90. }
  91. }
  92. void OpenXRActionMap::clear_interaction_profiles() {
  93. if (interaction_profiles.is_empty()) {
  94. return;
  95. }
  96. // Interaction profiles held within our action map set should be released and destroyed but just in case they are still used some where else.
  97. for (Ref<OpenXRInteractionProfile> interaction_profile : interaction_profiles) {
  98. interaction_profile->action_map = nullptr;
  99. }
  100. interaction_profiles.clear();
  101. emit_changed();
  102. }
  103. void OpenXRActionMap::set_interaction_profiles(Array p_interaction_profiles) {
  104. clear_interaction_profiles();
  105. for (const Variant &interaction_profile : p_interaction_profiles) {
  106. // Add them anew so we verify our interaction profile pointer.
  107. add_interaction_profile(interaction_profile);
  108. }
  109. }
  110. Array OpenXRActionMap::get_interaction_profiles() const {
  111. return interaction_profiles;
  112. }
  113. int OpenXRActionMap::get_interaction_profile_count() const {
  114. return interaction_profiles.size();
  115. }
  116. Ref<OpenXRInteractionProfile> OpenXRActionMap::find_interaction_profile(String p_path) const {
  117. for (Ref<OpenXRInteractionProfile> interaction_profile : interaction_profiles) {
  118. if (interaction_profile->get_interaction_profile_path() == p_path) {
  119. return interaction_profile;
  120. }
  121. }
  122. return Ref<OpenXRInteractionProfile>();
  123. }
  124. Ref<OpenXRInteractionProfile> OpenXRActionMap::get_interaction_profile(int p_idx) const {
  125. ERR_FAIL_INDEX_V(p_idx, interaction_profiles.size(), Ref<OpenXRInteractionProfile>());
  126. return interaction_profiles[p_idx];
  127. }
  128. void OpenXRActionMap::add_interaction_profile(Ref<OpenXRInteractionProfile> p_interaction_profile) {
  129. ERR_FAIL_COND(p_interaction_profile.is_null());
  130. if (!interaction_profiles.has(p_interaction_profile)) {
  131. if (p_interaction_profile->action_map && p_interaction_profile->action_map != this) {
  132. // Interaction profiles should only relate to our action map.
  133. p_interaction_profile->action_map->remove_interaction_profile(p_interaction_profile);
  134. }
  135. p_interaction_profile->action_map = this;
  136. interaction_profiles.push_back(p_interaction_profile);
  137. emit_changed();
  138. }
  139. }
  140. void OpenXRActionMap::remove_interaction_profile(Ref<OpenXRInteractionProfile> p_interaction_profile) {
  141. int idx = interaction_profiles.find(p_interaction_profile);
  142. if (idx != -1) {
  143. interaction_profiles.remove_at(idx);
  144. ERR_FAIL_COND_MSG(p_interaction_profile->action_map != this, "Removing interaction profile that belongs to this action map but had incorrect action map pointer."); // This should never happen!
  145. p_interaction_profile->action_map = nullptr;
  146. emit_changed();
  147. }
  148. }
  149. void OpenXRActionMap::create_default_action_sets() {
  150. // Note:
  151. // - if you make changes here make sure to delete your default_action_map.tres file of it will load an old version.
  152. // - our palm pose is only available if the relevant extension is supported,
  153. // we still want it to be part of our action map as we may deploy the same game to platforms that do and don't support it.
  154. // - the same applies for interaction profiles that are only supported if the relevant extension is supported.
  155. // Create our Godot action set.
  156. Ref<OpenXRActionSet> action_set = OpenXRActionSet::new_action_set("godot", "Godot action set");
  157. add_action_set(action_set);
  158. // Create our actions.
  159. Ref<OpenXRAction> trigger = action_set->add_new_action("trigger", "Trigger", OpenXRAction::OPENXR_ACTION_FLOAT, "/user/hand/left,/user/hand/right");
  160. Ref<OpenXRAction> trigger_click = action_set->add_new_action("trigger_click", "Trigger click", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  161. Ref<OpenXRAction> trigger_touch = action_set->add_new_action("trigger_touch", "Trigger touching", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  162. Ref<OpenXRAction> grip = action_set->add_new_action("grip", "Grip", OpenXRAction::OPENXR_ACTION_FLOAT, "/user/hand/left,/user/hand/right");
  163. Ref<OpenXRAction> grip_click = action_set->add_new_action("grip_click", "Grip click", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  164. Ref<OpenXRAction> grip_force = action_set->add_new_action("grip_force", "Grip force", OpenXRAction::OPENXR_ACTION_FLOAT, "/user/hand/left,/user/hand/right");
  165. Ref<OpenXRAction> primary = action_set->add_new_action("primary", "Primary joystick/thumbstick/trackpad", OpenXRAction::OPENXR_ACTION_VECTOR2, "/user/hand/left,/user/hand/right");
  166. Ref<OpenXRAction> primary_click = action_set->add_new_action("primary_click", "Primary joystick/thumbstick/trackpad click", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  167. Ref<OpenXRAction> primary_touch = action_set->add_new_action("primary_touch", "Primary joystick/thumbstick/trackpad touching", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  168. Ref<OpenXRAction> secondary = action_set->add_new_action("secondary", "Secondary joystick/thumbstick/trackpad", OpenXRAction::OPENXR_ACTION_VECTOR2, "/user/hand/left,/user/hand/right");
  169. Ref<OpenXRAction> secondary_click = action_set->add_new_action("secondary_click", "Secondary joystick/thumbstick/trackpad click", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  170. Ref<OpenXRAction> secondary_touch = action_set->add_new_action("secondary_touch", "Secondary joystick/thumbstick/trackpad touching", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  171. Ref<OpenXRAction> menu_button = action_set->add_new_action("menu_button", "Menu button", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  172. Ref<OpenXRAction> select_button = action_set->add_new_action("select_button", "Select button", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  173. Ref<OpenXRAction> ax_button = action_set->add_new_action("ax_button", "A/X button", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  174. Ref<OpenXRAction> ax_touch = action_set->add_new_action("ax_touch", "A/X touching", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  175. Ref<OpenXRAction> by_button = action_set->add_new_action("by_button", "B/Y button", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  176. Ref<OpenXRAction> by_touch = action_set->add_new_action("by_touch", "B/Y touching", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  177. Ref<OpenXRAction> default_pose = action_set->add_new_action("default_pose", "Default pose", OpenXRAction::OPENXR_ACTION_POSE,
  178. "/user/hand/left,"
  179. "/user/hand/right,"
  180. // "/user/vive_tracker_htcx/role/handheld_object," <-- getting errors on this one.
  181. "/user/vive_tracker_htcx/role/left_foot,"
  182. "/user/vive_tracker_htcx/role/right_foot,"
  183. "/user/vive_tracker_htcx/role/left_shoulder,"
  184. "/user/vive_tracker_htcx/role/right_shoulder,"
  185. "/user/vive_tracker_htcx/role/left_elbow,"
  186. "/user/vive_tracker_htcx/role/right_elbow,"
  187. "/user/vive_tracker_htcx/role/left_knee,"
  188. "/user/vive_tracker_htcx/role/right_knee,"
  189. "/user/vive_tracker_htcx/role/waist,"
  190. "/user/vive_tracker_htcx/role/chest,"
  191. "/user/vive_tracker_htcx/role/camera,"
  192. "/user/vive_tracker_htcx/role/keyboard,"
  193. "/user/vive_tracker_htcx/role/left_wrist,"
  194. "/user/vive_tracker_htcx/role/right_wrist,"
  195. "/user/vive_tracker_htcx/role/left_ankle,"
  196. "/user/vive_tracker_htcx/role/right_ankle,"
  197. "/user/eyes_ext");
  198. Ref<OpenXRAction> aim_pose = action_set->add_new_action("aim_pose", "Aim pose", OpenXRAction::OPENXR_ACTION_POSE, "/user/hand/left,/user/hand/right");
  199. Ref<OpenXRAction> grip_pose = action_set->add_new_action("grip_pose", "Grip pose", OpenXRAction::OPENXR_ACTION_POSE, "/user/hand/left,/user/hand/right");
  200. Ref<OpenXRAction> palm_pose = action_set->add_new_action("palm_pose", "Palm pose", OpenXRAction::OPENXR_ACTION_POSE, "/user/hand/left,/user/hand/right");
  201. Ref<OpenXRAction> haptic = action_set->add_new_action("haptic", "Haptic", OpenXRAction::OPENXR_ACTION_HAPTIC,
  202. "/user/hand/left,"
  203. "/user/hand/right,"
  204. // "/user/vive_tracker_htcx/role/handheld_object," <-- getting errors on this one.
  205. "/user/vive_tracker_htcx/role/left_foot,"
  206. "/user/vive_tracker_htcx/role/right_foot,"
  207. "/user/vive_tracker_htcx/role/left_shoulder,"
  208. "/user/vive_tracker_htcx/role/right_shoulder,"
  209. "/user/vive_tracker_htcx/role/left_elbow,"
  210. "/user/vive_tracker_htcx/role/right_elbow,"
  211. "/user/vive_tracker_htcx/role/left_knee,"
  212. "/user/vive_tracker_htcx/role/right_knee,"
  213. "/user/vive_tracker_htcx/role/waist,"
  214. "/user/vive_tracker_htcx/role/chest,"
  215. "/user/vive_tracker_htcx/role/camera,"
  216. "/user/vive_tracker_htcx/role/keyboard,"
  217. "/user/vive_tracker_htcx/role/left_wrist,"
  218. "/user/vive_tracker_htcx/role/right_wrist,"
  219. "/user/vive_tracker_htcx/role/left_ankle,"
  220. "/user/vive_tracker_htcx/role/right_ankle");
  221. // Create our interaction profiles.
  222. Ref<OpenXRInteractionProfile> profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/khr/simple_controller");
  223. profile->add_new_binding(default_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  224. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  225. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  226. profile->add_new_binding(palm_pose, "/user/hand/left/input/palm_ext/pose,/user/hand/right/input/palm_ext/pose");
  227. profile->add_new_binding(menu_button, "/user/hand/left/input/menu/click,/user/hand/right/input/menu/click");
  228. profile->add_new_binding(select_button, "/user/hand/left/input/select/click,/user/hand/right/input/select/click");
  229. // generic has no support for triggers, grip, A/B buttons, nor joystick/trackpad inputs.
  230. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  231. add_interaction_profile(profile);
  232. // Create our Vive controller profile.
  233. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/htc/vive_controller");
  234. profile->add_new_binding(default_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  235. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  236. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  237. profile->add_new_binding(palm_pose, "/user/hand/left/input/palm_ext/pose,/user/hand/right/input/palm_ext/pose");
  238. profile->add_new_binding(menu_button, "/user/hand/left/input/menu/click,/user/hand/right/input/menu/click");
  239. profile->add_new_binding(select_button, "/user/hand/left/input/system/click,/user/hand/right/input/system/click");
  240. // wmr controller has no a/b/x/y buttons.
  241. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  242. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/click,/user/hand/right/input/trigger/click");
  243. profile->add_new_binding(grip, "/user/hand/left/input/squeeze/click,/user/hand/right/input/squeeze/click"); // OpenXR will convert bool to float.
  244. profile->add_new_binding(grip_click, "/user/hand/left/input/squeeze/click,/user/hand/right/input/squeeze/click");
  245. // primary on our vive controller is our trackpad.
  246. profile->add_new_binding(primary, "/user/hand/left/input/trackpad,/user/hand/right/input/trackpad");
  247. profile->add_new_binding(primary_click, "/user/hand/left/input/trackpad/click,/user/hand/right/input/trackpad/click");
  248. profile->add_new_binding(primary_touch, "/user/hand/left/input/trackpad/touch,/user/hand/right/input/trackpad/touch");
  249. // vive controllers have no secondary input.
  250. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  251. add_interaction_profile(profile);
  252. // Create our WMR controller profile.
  253. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/microsoft/motion_controller");
  254. profile->add_new_binding(default_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  255. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  256. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  257. profile->add_new_binding(palm_pose, "/user/hand/left/input/palm_ext/pose,/user/hand/right/input/palm_ext/pose");
  258. // wmr controllers have no select button we can use.
  259. profile->add_new_binding(menu_button, "/user/hand/left/input/menu/click,/user/hand/right/input/menu/click");
  260. // wmr controller has no a/b/x/y buttons.
  261. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  262. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value"); // OpenXR will convert float to bool.
  263. profile->add_new_binding(grip, "/user/hand/left/input/squeeze/click,/user/hand/right/input/squeeze/click"); // OpenXR will convert bool to float.
  264. profile->add_new_binding(grip_click, "/user/hand/left/input/squeeze/click,/user/hand/right/input/squeeze/click");
  265. // primary on our wmr controller is our thumbstick, no touch.
  266. profile->add_new_binding(primary, "/user/hand/left/input/thumbstick,/user/hand/right/input/thumbstick");
  267. profile->add_new_binding(primary_click, "/user/hand/left/input/thumbstick/click,/user/hand/right/input/thumbstick/click");
  268. // secondary on our wmr controller is our trackpad.
  269. profile->add_new_binding(secondary, "/user/hand/left/input/trackpad,/user/hand/right/input/trackpad");
  270. profile->add_new_binding(secondary_click, "/user/hand/left/input/trackpad/click,/user/hand/right/input/trackpad/click");
  271. profile->add_new_binding(secondary_touch, "/user/hand/left/input/trackpad/touch,/user/hand/right/input/trackpad/touch");
  272. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  273. add_interaction_profile(profile);
  274. // Create our Meta touch controller profile.
  275. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/oculus/touch_controller");
  276. profile->add_new_binding(default_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  277. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  278. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  279. profile->add_new_binding(palm_pose, "/user/hand/left/input/palm_ext/pose,/user/hand/right/input/palm_ext/pose");
  280. // touch controllers have no select button we can use.
  281. profile->add_new_binding(menu_button, "/user/hand/left/input/menu/click,/user/hand/right/input/system/click"); // right hand system click may not be available.
  282. 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.
  283. profile->add_new_binding(ax_touch, "/user/hand/left/input/x/touch,/user/hand/right/input/a/touch");
  284. 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.
  285. profile->add_new_binding(by_touch, "/user/hand/left/input/y/touch,/user/hand/right/input/b/touch");
  286. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  287. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value"); // should be converted to boolean.
  288. profile->add_new_binding(trigger_touch, "/user/hand/left/input/trigger/touch,/user/hand/right/input/trigger/touch");
  289. profile->add_new_binding(grip, "/user/hand/left/input/squeeze/value,/user/hand/right/input/squeeze/value"); // should be converted to boolean.
  290. profile->add_new_binding(grip_click, "/user/hand/left/input/squeeze/value,/user/hand/right/input/squeeze/value");
  291. // primary on our touch controller is our thumbstick.
  292. profile->add_new_binding(primary, "/user/hand/left/input/thumbstick,/user/hand/right/input/thumbstick");
  293. profile->add_new_binding(primary_click, "/user/hand/left/input/thumbstick/click,/user/hand/right/input/thumbstick/click");
  294. profile->add_new_binding(primary_touch, "/user/hand/left/input/thumbstick/touch,/user/hand/right/input/thumbstick/touch");
  295. // touch controller has no secondary input.
  296. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  297. add_interaction_profile(profile);
  298. // Create our Pico 4 controller profile.
  299. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/bytedance/pico4_controller");
  300. profile->add_new_binding(default_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  301. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  302. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  303. profile->add_new_binding(palm_pose, "/user/hand/left/input/palm_ext/pose,/user/hand/right/input/palm_ext/pose");
  304. profile->add_new_binding(select_button, "/user/hand/left/input/system/click,/user/hand/right/input/system/click"); // system click may not be available.
  305. profile->add_new_binding(menu_button, "/user/hand/left/input/menu/click");
  306. 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.
  307. profile->add_new_binding(ax_touch, "/user/hand/left/input/x/touch,/user/hand/right/input/a/touch");
  308. 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.
  309. profile->add_new_binding(by_touch, "/user/hand/left/input/y/touch,/user/hand/right/input/b/touch");
  310. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  311. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value"); // should be converted to boolean.
  312. profile->add_new_binding(trigger_touch, "/user/hand/left/input/trigger/touch,/user/hand/right/input/trigger/touch");
  313. profile->add_new_binding(grip, "/user/hand/left/input/squeeze/value,/user/hand/right/input/squeeze/value"); // should be converted to boolean.
  314. profile->add_new_binding(grip_click, "/user/hand/left/input/squeeze/value,/user/hand/right/input/squeeze/value");
  315. // primary on our pico controller is our thumbstick.
  316. profile->add_new_binding(primary, "/user/hand/left/input/thumbstick,/user/hand/right/input/thumbstick");
  317. profile->add_new_binding(primary_click, "/user/hand/left/input/thumbstick/click,/user/hand/right/input/thumbstick/click");
  318. profile->add_new_binding(primary_touch, "/user/hand/left/input/thumbstick/touch,/user/hand/right/input/thumbstick/touch");
  319. // pico controller has no secondary input.
  320. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  321. add_interaction_profile(profile);
  322. // Create our Valve index controller profile.
  323. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/valve/index_controller");
  324. profile->add_new_binding(default_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  325. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  326. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  327. profile->add_new_binding(palm_pose, "/user/hand/left/input/palm_ext/pose,/user/hand/right/input/palm_ext/pose");
  328. // index controllers have no select button we can use.
  329. profile->add_new_binding(menu_button, "/user/hand/left/input/system/click,/user/hand/right/input/system/click");
  330. profile->add_new_binding(ax_button, "/user/hand/left/input/a/click,/user/hand/right/input/a/click"); // a on both controllers.
  331. profile->add_new_binding(ax_touch, "/user/hand/left/input/a/touch,/user/hand/right/input/a/touch");
  332. profile->add_new_binding(by_button, "/user/hand/left/input/b/click,/user/hand/right/input/b/click"); // b on both controllers.
  333. profile->add_new_binding(by_touch, "/user/hand/left/input/b/touch,/user/hand/right/input/b/touch");
  334. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  335. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/click,/user/hand/right/input/trigger/click");
  336. profile->add_new_binding(trigger_touch, "/user/hand/left/input/trigger/touch,/user/hand/right/input/trigger/touch");
  337. profile->add_new_binding(grip, "/user/hand/left/input/squeeze/value,/user/hand/right/input/squeeze/value");
  338. profile->add_new_binding(grip_click, "/user/hand/left/input/squeeze/value,/user/hand/right/input/squeeze/value"); // this should do a float to bool conversion.
  339. profile->add_new_binding(grip_force, "/user/hand/left/input/squeeze/force,/user/hand/right/input/squeeze/force"); // grip force seems to be unique to the Valve Index.
  340. // primary on our index controller is our thumbstick.
  341. profile->add_new_binding(primary, "/user/hand/left/input/thumbstick,/user/hand/right/input/thumbstick");
  342. profile->add_new_binding(primary_click, "/user/hand/left/input/thumbstick/click,/user/hand/right/input/thumbstick/click");
  343. profile->add_new_binding(primary_touch, "/user/hand/left/input/thumbstick/touch,/user/hand/right/input/thumbstick/touch");
  344. // secondary on our index controller is our trackpad.
  345. profile->add_new_binding(secondary, "/user/hand/left/input/trackpad,/user/hand/right/input/trackpad");
  346. profile->add_new_binding(secondary_click, "/user/hand/left/input/trackpad/force,/user/hand/right/input/trackpad/force"); // not sure if this will work but doesn't seem to support click...
  347. profile->add_new_binding(secondary_touch, "/user/hand/left/input/trackpad/touch,/user/hand/right/input/trackpad/touch");
  348. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  349. add_interaction_profile(profile);
  350. // Create our HP MR controller profile.
  351. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/hp/mixed_reality_controller");
  352. profile->add_new_binding(default_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  353. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  354. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  355. profile->add_new_binding(palm_pose, "/user/hand/left/input/palm_ext/pose,/user/hand/right/input/palm_ext/pose");
  356. // hpmr controllers have no select button we can use.
  357. profile->add_new_binding(menu_button, "/user/hand/left/input/menu/click,/user/hand/right/input/menu/click");
  358. // hpmr controllers only register click, not touch, on our a/b/x/y buttons.
  359. 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.
  360. 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.
  361. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  362. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  363. profile->add_new_binding(grip, "/user/hand/left/input/squeeze/value,/user/hand/right/input/squeeze/value");
  364. profile->add_new_binding(grip_click, "/user/hand/left/input/squeeze/value,/user/hand/right/input/squeeze/value");
  365. // primary on our hpmr controller is our thumbstick.
  366. profile->add_new_binding(primary, "/user/hand/left/input/thumbstick,/user/hand/right/input/thumbstick");
  367. profile->add_new_binding(primary_click, "/user/hand/left/input/thumbstick/click,/user/hand/right/input/thumbstick/click");
  368. // No secondary on our hpmr controller.
  369. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  370. add_interaction_profile(profile);
  371. // Create our Samsung Odyssey controller profile,
  372. // Note that this controller is only identified specifically on WMR, on SteamVR this is identified as a normal WMR controller.
  373. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/samsung/odyssey_controller");
  374. profile->add_new_binding(default_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  375. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  376. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  377. profile->add_new_binding(palm_pose, "/user/hand/left/input/palm_ext/pose,/user/hand/right/input/palm_ext/pose");
  378. // Odyssey controllers have no select button we can use.
  379. profile->add_new_binding(menu_button, "/user/hand/left/input/menu/click,/user/hand/right/input/menu/click");
  380. // Odyssey controller has no a/b/x/y buttons.
  381. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  382. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  383. profile->add_new_binding(grip, "/user/hand/left/input/squeeze/click,/user/hand/right/input/squeeze/click");
  384. profile->add_new_binding(grip_click, "/user/hand/left/input/squeeze/click,/user/hand/right/input/squeeze/click");
  385. // primary on our Odyssey controller is our thumbstick, no touch.
  386. profile->add_new_binding(primary, "/user/hand/left/input/thumbstick,/user/hand/right/input/thumbstick");
  387. profile->add_new_binding(primary_click, "/user/hand/left/input/thumbstick/click,/user/hand/right/input/thumbstick/click");
  388. // secondary on our Odyssey controller is our trackpad.
  389. profile->add_new_binding(secondary, "/user/hand/left/input/trackpad,/user/hand/right/input/trackpad");
  390. profile->add_new_binding(secondary_click, "/user/hand/left/input/trackpad/click,/user/hand/right/input/trackpad/click");
  391. profile->add_new_binding(secondary_touch, "/user/hand/left/input/trackpad/touch,/user/hand/right/input/trackpad/touch");
  392. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  393. add_interaction_profile(profile);
  394. // Create our Vive Cosmos controller.
  395. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/htc/vive_cosmos_controller");
  396. profile->add_new_binding(default_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  397. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  398. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  399. profile->add_new_binding(palm_pose, "/user/hand/left/input/palm_ext/pose,/user/hand/right/input/palm_ext/pose");
  400. profile->add_new_binding(menu_button, "/user/hand/left/input/menu/click");
  401. profile->add_new_binding(select_button, "/user/hand/right/input/system/click"); // we'll map system to select.
  402. 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.
  403. 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.
  404. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  405. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/click,/user/hand/right/input/trigger/click");
  406. profile->add_new_binding(grip, "/user/hand/left/input/squeeze/click,/user/hand/right/input/squeeze/click");
  407. profile->add_new_binding(grip_click, "/user/hand/left/input/squeeze/click,/user/hand/right/input/squeeze/click");
  408. // primary on our Cosmos controller is our thumbstick.
  409. profile->add_new_binding(primary, "/user/hand/left/input/thumbstick,/user/hand/right/input/thumbstick");
  410. profile->add_new_binding(primary_click, "/user/hand/left/input/thumbstick/click,/user/hand/right/input/thumbstick/click");
  411. profile->add_new_binding(primary_touch, "/user/hand/left/input/thumbstick/touch,/user/hand/right/input/thumbstick/touch");
  412. // No secondary on our cosmos controller.
  413. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  414. add_interaction_profile(profile);
  415. // Create our Vive Focus 3 controller.
  416. // Note, Vive Focus 3 currently is not yet supported as a stand alone device
  417. // however HTC currently has a beta OpenXR runtime in testing we may support in the near future.
  418. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/htc/vive_focus3_controller");
  419. profile->add_new_binding(default_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  420. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  421. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  422. profile->add_new_binding(palm_pose, "/user/hand/left/input/palm_ext/pose,/user/hand/right/input/palm_ext/pose");
  423. profile->add_new_binding(menu_button, "/user/hand/left/input/menu/click");
  424. profile->add_new_binding(select_button, "/user/hand/right/input/system/click"); // we'll map system to select.
  425. 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.
  426. 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.
  427. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  428. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/click,/user/hand/right/input/trigger/click");
  429. profile->add_new_binding(trigger_touch, "/user/hand/left/input/trigger/touch,/user/hand/right/input/trigger/touch");
  430. profile->add_new_binding(grip, "/user/hand/left/input/squeeze/click,/user/hand/right/input/squeeze/click");
  431. profile->add_new_binding(grip_click, "/user/hand/left/input/squeeze/click,/user/hand/right/input/squeeze/click");
  432. // primary on our Focus 3 controller is our thumbstick.
  433. profile->add_new_binding(primary, "/user/hand/left/input/thumbstick,/user/hand/right/input/thumbstick");
  434. profile->add_new_binding(primary_click, "/user/hand/left/input/thumbstick/click,/user/hand/right/input/thumbstick/click");
  435. profile->add_new_binding(primary_touch, "/user/hand/left/input/thumbstick/touch,/user/hand/right/input/thumbstick/touch");
  436. // We only have a thumb rest.
  437. profile->add_new_binding(secondary_touch, "/user/hand/left/input/thumbrest/touch,/user/hand/right/input/thumbrest/touch");
  438. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  439. add_interaction_profile(profile);
  440. // Create our Huawei controller.
  441. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/huawei/controller");
  442. profile->add_new_binding(default_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  443. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  444. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  445. profile->add_new_binding(palm_pose, "/user/hand/left/input/palm_ext/pose,/user/hand/right/input/palm_ext/pose");
  446. profile->add_new_binding(menu_button, "/user/hand/left/input/home/click,/user/hand/right/input/home/click");
  447. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  448. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/click,/user/hand/right/input/trigger/click");
  449. // primary on our Huawei controller is our trackpad.
  450. profile->add_new_binding(primary, "/user/hand/left/input/trackpad,/user/hand/right/input/trackpad");
  451. profile->add_new_binding(primary_click, "/user/hand/left/input/trackpad/click,/user/hand/right/input/trackpad/click");
  452. profile->add_new_binding(primary_touch, "/user/hand/left/input/trackpad/touch,/user/hand/right/input/trackpad/touch");
  453. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  454. add_interaction_profile(profile);
  455. // Create our HTC Vive tracker profile.
  456. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/htc/vive_tracker_htcx");
  457. profile->add_new_binding(default_pose,
  458. // "/user/vive_tracker_htcx/role/handheld_object/input/grip/pose," <-- getting errors on this one.
  459. "/user/vive_tracker_htcx/role/left_foot/input/grip/pose,"
  460. "/user/vive_tracker_htcx/role/right_foot/input/grip/pose,"
  461. "/user/vive_tracker_htcx/role/left_shoulder/input/grip/pose,"
  462. "/user/vive_tracker_htcx/role/right_shoulder/input/grip/pose,"
  463. "/user/vive_tracker_htcx/role/left_elbow/input/grip/pose,"
  464. "/user/vive_tracker_htcx/role/right_elbow/input/grip/pose,"
  465. "/user/vive_tracker_htcx/role/left_knee/input/grip/pose,"
  466. "/user/vive_tracker_htcx/role/right_knee/input/grip/pose,"
  467. "/user/vive_tracker_htcx/role/waist/input/grip/pose,"
  468. "/user/vive_tracker_htcx/role/chest/input/grip/pose,"
  469. "/user/vive_tracker_htcx/role/camera/input/grip/pose,"
  470. "/user/vive_tracker_htcx/role/keyboard/input/grip/pose,"
  471. "/user/vive_tracker_htcx/role/left_wrist/input/grip/pose,"
  472. "/user/vive_tracker_htcx/role/right_wrist/input/grip/pose,"
  473. "/user/vive_tracker_htcx/role/left_ankle/input/grip/pose,"
  474. "/user/vive_tracker_htcx/role/right_ankle/input/grip/pose");
  475. profile->add_new_binding(haptic,
  476. // "/user/vive_tracker_htcx/role/handheld_object/output/haptic," <-- getting errors on this one.
  477. "/user/vive_tracker_htcx/role/left_foot/output/haptic,"
  478. "/user/vive_tracker_htcx/role/right_foot/output/haptic,"
  479. "/user/vive_tracker_htcx/role/left_shoulder/output/haptic,"
  480. "/user/vive_tracker_htcx/role/right_shoulder/output/haptic,"
  481. "/user/vive_tracker_htcx/role/left_elbow/output/haptic,"
  482. "/user/vive_tracker_htcx/role/right_elbow/output/haptic,"
  483. "/user/vive_tracker_htcx/role/left_knee/output/haptic,"
  484. "/user/vive_tracker_htcx/role/right_knee/output/haptic,"
  485. "/user/vive_tracker_htcx/role/waist/output/haptic,"
  486. "/user/vive_tracker_htcx/role/chest/output/haptic,"
  487. "/user/vive_tracker_htcx/role/camera/output/haptic,"
  488. "/user/vive_tracker_htcx/role/keyboard/output/haptic,"
  489. "/user/vive_tracker_htcx/role/left_wrist/output/haptic,"
  490. "/user/vive_tracker_htcx/role/right_wrist/output/haptic,"
  491. "/user/vive_tracker_htcx/role/left_ankle/output/haptic,"
  492. "/user/vive_tracker_htcx/role/right_ankle/output/haptic");
  493. add_interaction_profile(profile);
  494. // Create our eye gaze interaction profile.
  495. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/ext/eye_gaze_interaction");
  496. profile->add_new_binding(default_pose, "/user/eyes_ext/input/gaze_ext/pose");
  497. add_interaction_profile(profile);
  498. // Create our hand interaction profile.
  499. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/ext/hand_interaction_ext");
  500. profile->add_new_binding(default_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  501. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  502. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  503. profile->add_new_binding(palm_pose, "/user/hand/left/input/palm_ext/pose,/user/hand/right/input/palm_ext/pose");
  504. // Use pinch as primary.
  505. profile->add_new_binding(primary, "/user/hand/left/input/pinch_ext/value,/user/hand/right/input/pinch_ext/value");
  506. profile->add_new_binding(primary_click, "/user/hand/left/input/pinch_ext/ready_ext,/user/hand/right/input/pinch_ext/ready_ext");
  507. // Use activation as secondary.
  508. profile->add_new_binding(secondary, "/user/hand/left/input/aim_activate_ext/value,/user/hand/right/input/aim_activate_ext/value");
  509. profile->add_new_binding(secondary_click, "/user/hand/left/input/aim_activate_ext/ready_ext,/user/hand/right/input/aim_activate_ext/ready_ext");
  510. // We link grasp to our grip.
  511. profile->add_new_binding(grip, "/user/hand/left/input/grasp_ext/value,/user/hand/right/input/grasp_ext/value");
  512. profile->add_new_binding(grip_click, "/user/hand/left/input/grasp_ext/ready_ext,/user/hand/right/input/grasp_ext/ready_ext");
  513. add_interaction_profile(profile);
  514. }
  515. void OpenXRActionMap::create_editor_action_sets() {
  516. // TODO implement
  517. }
  518. Ref<OpenXRAction> OpenXRActionMap::get_action(const String p_path) const {
  519. PackedStringArray paths = p_path.split("/", false);
  520. ERR_FAIL_COND_V(paths.size() != 2, Ref<OpenXRAction>());
  521. Ref<OpenXRActionSet> action_set = find_action_set(paths[0]);
  522. if (action_set.is_valid()) {
  523. return action_set->get_action(paths[1]);
  524. }
  525. return Ref<OpenXRAction>();
  526. }
  527. void OpenXRActionMap::remove_action(const String p_path, bool p_remove_interaction_profiles) {
  528. Ref<OpenXRAction> action = get_action(p_path);
  529. if (action.is_valid()) {
  530. for (Ref<OpenXRInteractionProfile> interaction_profile : interaction_profiles) {
  531. if (p_remove_interaction_profiles) {
  532. // Remove any bindings for this action
  533. interaction_profile->remove_binding_for_action(action);
  534. } else {
  535. ERR_FAIL_COND(interaction_profile->has_binding_for_action(action));
  536. }
  537. }
  538. OpenXRActionSet *action_set = action->get_action_set();
  539. if (action_set != nullptr) {
  540. // Remove the action from this action set
  541. action_set->remove_action(action);
  542. }
  543. }
  544. }
  545. PackedStringArray OpenXRActionMap::get_top_level_paths(const Ref<OpenXRAction> p_action) {
  546. PackedStringArray arr;
  547. for (Ref<OpenXRInteractionProfile> ip : interaction_profiles) {
  548. const OpenXRInteractionProfileMetadata::InteractionProfile *profile = OpenXRInteractionProfileMetadata::get_singleton()->get_profile(ip->get_interaction_profile_path());
  549. if (profile != nullptr) {
  550. Vector<Ref<OpenXRIPBinding>> bindings = ip->get_bindings_for_action(p_action);
  551. for (const Ref<OpenXRIPBinding> &binding : bindings) {
  552. String binding_path = binding->get_binding_path();
  553. const OpenXRInteractionProfileMetadata::IOPath *io_path = profile->get_io_path(binding_path);
  554. if (io_path != nullptr) {
  555. String top_path = io_path->top_level_path;
  556. if (!arr.has(top_path)) {
  557. arr.push_back(top_path);
  558. }
  559. }
  560. }
  561. }
  562. }
  563. // print_line("Toplevel paths for", p_action->get_name_with_set(), "are", arr);
  564. return arr;
  565. }
  566. OpenXRActionMap::~OpenXRActionMap() {
  567. action_sets.clear();
  568. clear_interaction_profiles();
  569. }