openxr_action_map.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /*************************************************************************/
  2. /* openxr_action_map.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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 = p_action_sets;
  52. }
  53. Array OpenXRActionMap::get_action_sets() const {
  54. return action_sets;
  55. }
  56. int OpenXRActionMap::get_action_set_count() const {
  57. return action_sets.size();
  58. }
  59. Ref<OpenXRActionSet> OpenXRActionMap::find_action_set(String p_name) const {
  60. for (int i = 0; i < action_sets.size(); i++) {
  61. Ref<OpenXRActionSet> action_set = action_sets[i];
  62. if (action_set->get_name() == p_name) {
  63. return action_set;
  64. }
  65. }
  66. return Ref<OpenXRActionSet>();
  67. }
  68. Ref<OpenXRActionSet> OpenXRActionMap::get_action_set(int p_idx) const {
  69. ERR_FAIL_INDEX_V(p_idx, action_sets.size(), Ref<OpenXRActionSet>());
  70. return action_sets[p_idx];
  71. }
  72. void OpenXRActionMap::add_action_set(Ref<OpenXRActionSet> p_action_set) {
  73. ERR_FAIL_COND(p_action_set.is_null());
  74. if (action_sets.find(p_action_set) == -1) {
  75. action_sets.push_back(p_action_set);
  76. }
  77. }
  78. void OpenXRActionMap::remove_action_set(Ref<OpenXRActionSet> p_action_set) {
  79. int idx = action_sets.find(p_action_set);
  80. if (idx != -1) {
  81. action_sets.remove_at(idx);
  82. }
  83. }
  84. void OpenXRActionMap::set_interaction_profiles(Array p_interaction_profiles) {
  85. interaction_profiles = p_interaction_profiles;
  86. }
  87. Array OpenXRActionMap::get_interaction_profiles() const {
  88. return interaction_profiles;
  89. }
  90. int OpenXRActionMap::get_interaction_profile_count() const {
  91. return interaction_profiles.size();
  92. }
  93. Ref<OpenXRInteractionProfile> OpenXRActionMap::find_interaction_profile(String p_path) const {
  94. for (int i = 0; i < interaction_profiles.size(); i++) {
  95. Ref<OpenXRInteractionProfile> interaction_profile = interaction_profiles[i];
  96. if (interaction_profile->get_interaction_profile_path() == p_path) {
  97. return interaction_profile;
  98. }
  99. }
  100. return Ref<OpenXRInteractionProfile>();
  101. }
  102. Ref<OpenXRInteractionProfile> OpenXRActionMap::get_interaction_profile(int p_idx) const {
  103. ERR_FAIL_INDEX_V(p_idx, interaction_profiles.size(), Ref<OpenXRInteractionProfile>());
  104. return interaction_profiles[p_idx];
  105. }
  106. void OpenXRActionMap::add_interaction_profile(Ref<OpenXRInteractionProfile> p_interaction_profile) {
  107. ERR_FAIL_COND(p_interaction_profile.is_null());
  108. if (interaction_profiles.find(p_interaction_profile) == -1) {
  109. interaction_profiles.push_back(p_interaction_profile);
  110. }
  111. }
  112. void OpenXRActionMap::remove_interaction_profile(Ref<OpenXRInteractionProfile> p_interaction_profile) {
  113. int idx = interaction_profiles.find(p_interaction_profile);
  114. if (idx != -1) {
  115. interaction_profiles.remove_at(idx);
  116. }
  117. }
  118. void OpenXRActionMap::create_default_action_sets() {
  119. // Note, if you make changes here make sure to delete your default_action_map.tres file of it will load an old version.
  120. // Create our Godot action set
  121. Ref<OpenXRActionSet> action_set = OpenXRActionSet::new_action_set("godot", "Godot action set");
  122. add_action_set(action_set);
  123. // Create our actions
  124. Ref<OpenXRAction> trigger = action_set->add_new_action("trigger", "Trigger", OpenXRAction::OPENXR_ACTION_FLOAT, "/user/hand/left,/user/hand/right");
  125. Ref<OpenXRAction> trigger_click = action_set->add_new_action("trigger_click", "Trigger click", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  126. Ref<OpenXRAction> trigger_touch = action_set->add_new_action("trigger_touch", "Trigger touching", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  127. Ref<OpenXRAction> grip = action_set->add_new_action("grip", "Grip", OpenXRAction::OPENXR_ACTION_FLOAT, "/user/hand/left,/user/hand/right");
  128. Ref<OpenXRAction> grip_click = action_set->add_new_action("grip_click", "Grip click", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  129. Ref<OpenXRAction> grip_touch = action_set->add_new_action("grip_touch", "Grip touching", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  130. Ref<OpenXRAction> primary = action_set->add_new_action("primary", "Primary joystick/thumbstick/trackpad", OpenXRAction::OPENXR_ACTION_VECTOR2, "/user/hand/left,/user/hand/right");
  131. 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");
  132. 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");
  133. Ref<OpenXRAction> secondary = action_set->add_new_action("secondary", "Secondary joystick/thumbstick/trackpad", OpenXRAction::OPENXR_ACTION_VECTOR2, "/user/hand/left,/user/hand/right");
  134. 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");
  135. 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");
  136. Ref<OpenXRAction> menu_button = action_set->add_new_action("menu_button", "Menu button", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  137. Ref<OpenXRAction> select_button = action_set->add_new_action("select_button", "Select button", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  138. Ref<OpenXRAction> ax_button = action_set->add_new_action("ax_button", "A/X button", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  139. Ref<OpenXRAction> ax_touch = action_set->add_new_action("ax_touch", "A/X touching", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  140. Ref<OpenXRAction> by_button = action_set->add_new_action("by_button", "B/Y button", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  141. Ref<OpenXRAction> by_touch = action_set->add_new_action("by_touch", "B/Y touching", OpenXRAction::OPENXR_ACTION_BOOL, "/user/hand/left,/user/hand/right");
  142. Ref<OpenXRAction> default_pose = action_set->add_new_action("default_pose", "Default pose", OpenXRAction::OPENXR_ACTION_POSE, "/user/hand/left,/user/hand/right");
  143. Ref<OpenXRAction> aim_pose = action_set->add_new_action("aim_pose", "Aim pose", OpenXRAction::OPENXR_ACTION_POSE, "/user/hand/left,/user/hand/right");
  144. Ref<OpenXRAction> grip_pose = action_set->add_new_action("grip_pose", "Grip pose", OpenXRAction::OPENXR_ACTION_POSE, "/user/hand/left,/user/hand/right");
  145. Ref<OpenXRAction> haptic = action_set->add_new_action("haptic", "Haptic", OpenXRAction::OPENXR_ACTION_HAPTIC, "/user/hand/left,/user/hand/right");
  146. // Create our interaction profiles
  147. Ref<OpenXRInteractionProfile> profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/khr/simple_controller");
  148. profile->add_new_binding(default_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  149. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  150. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  151. profile->add_new_binding(menu_button, "/user/hand/left/input/menu/click,/user/hand/right/input/menu/click");
  152. profile->add_new_binding(select_button, "/user/hand/left/input/select/click,/user/hand/right/input/select/click");
  153. // generic has no support for triggers, grip, A/B buttons, nor joystick/trackpad inputs
  154. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  155. add_interaction_profile(profile);
  156. // Create our Vive controller profile
  157. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/htc/vive_controller");
  158. profile->add_new_binding(default_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  159. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  160. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  161. profile->add_new_binding(menu_button, "/user/hand/left/input/menu/click,/user/hand/right/input/menu/click");
  162. profile->add_new_binding(select_button, "/user/hand/left/input/system/click,/user/hand/right/input/system/click");
  163. // wmr controller has no a/b/x/y buttons
  164. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  165. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/click,/user/hand/right/input/trigger/click");
  166. profile->add_new_binding(grip, "/user/hand/left/input/squeeze/click,/user/hand/right/input/squeeze/click"); // OpenXR will convert bool to float
  167. profile->add_new_binding(grip_click, "/user/hand/left/input/squeeze/click,/user/hand/right/input/squeeze/click");
  168. // primary on our vive controller is our trackpad
  169. profile->add_new_binding(primary, "/user/hand/left/input/trackpad,/user/hand/right/input/trackpad");
  170. profile->add_new_binding(primary_click, "/user/hand/left/input/trackpad/click,/user/hand/right/input/trackpad/click");
  171. profile->add_new_binding(primary_touch, "/user/hand/left/input/trackpad/touch,/user/hand/right/input/trackpad/touch");
  172. // vive controllers have no secondary input
  173. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  174. add_interaction_profile(profile);
  175. // Create our WMR controller profile
  176. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/microsoft/motion_controller");
  177. profile->add_new_binding(default_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  178. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  179. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  180. // wmr controllers have no select button we can use
  181. profile->add_new_binding(menu_button, "/user/hand/left/input/menu/click,/user/hand/right/input/menu/click");
  182. // wmr controller has no a/b/x/y buttons
  183. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  184. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value"); // OpenXR will convert float to bool
  185. profile->add_new_binding(grip, "/user/hand/left/input/squeeze/click,/user/hand/right/input/squeeze/click"); // OpenXR will convert bool to float
  186. profile->add_new_binding(grip_click, "/user/hand/left/input/squeeze/click,/user/hand/right/input/squeeze/click");
  187. // primary on our wmr controller is our thumbstick, no touch
  188. profile->add_new_binding(primary, "/user/hand/left/input/thumbstick,/user/hand/right/input/thumbstick");
  189. profile->add_new_binding(primary_click, "/user/hand/left/input/thumbstick/click,/user/hand/right/input/thumbstick/click");
  190. // secondary on our wmr controller is our trackpad
  191. profile->add_new_binding(secondary, "/user/hand/left/input/trackpad,/user/hand/right/input/trackpad");
  192. profile->add_new_binding(secondary_click, "/user/hand/left/input/trackpad/click,/user/hand/right/input/trackpad/click");
  193. profile->add_new_binding(secondary_touch, "/user/hand/left/input/trackpad/touch,/user/hand/right/input/trackpad/touch");
  194. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  195. add_interaction_profile(profile);
  196. // Create our HP MR controller profile
  197. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/hp/mixed_reality_controller");
  198. profile->add_new_binding(default_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  199. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  200. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  201. // hpmr controllers have no select button we can use
  202. profile->add_new_binding(menu_button, "/user/hand/left/input/menu/click,/user/hand/right/input/menu/click");
  203. // hpmr controllers only register click, not touch, on our a/b/x/y buttons
  204. 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
  205. 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
  206. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  207. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  208. profile->add_new_binding(grip, "/user/hand/left/input/squeeze/value,/user/hand/right/input/squeeze/value");
  209. profile->add_new_binding(grip_click, "/user/hand/left/input/squeeze/value,/user/hand/right/input/squeeze/value");
  210. // primary on our hpmr controller is our thumbstick
  211. profile->add_new_binding(primary, "/user/hand/left/input/thumbstick,/user/hand/right/input/thumbstick");
  212. profile->add_new_binding(primary_click, "/user/hand/left/input/thumbstick/click,/user/hand/right/input/thumbstick/click");
  213. // No secondary on our hpmr controller
  214. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  215. add_interaction_profile(profile);
  216. // Create our Meta touch controller profile
  217. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/oculus/touch_controller");
  218. profile->add_new_binding(default_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  219. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  220. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  221. // touch controllers have no select button we can use
  222. 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
  223. 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
  224. profile->add_new_binding(ax_touch, "/user/hand/left/input/x/touch,/user/hand/right/input/a/touch");
  225. 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
  226. profile->add_new_binding(by_touch, "/user/hand/left/input/y/touch,/user/hand/right/input/b/touch");
  227. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  228. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value"); // should be converted to boolean
  229. profile->add_new_binding(trigger_touch, "/user/hand/left/input/trigger/touch,/user/hand/right/input/trigger/touch");
  230. profile->add_new_binding(grip, "/user/hand/left/input/squeeze/value,/user/hand/right/input/squeeze/value"); // should be converted to boolean
  231. profile->add_new_binding(grip_click, "/user/hand/left/input/squeeze/value,/user/hand/right/input/squeeze/value");
  232. // primary on our touch controller is our thumbstick
  233. profile->add_new_binding(primary, "/user/hand/left/input/thumbstick,/user/hand/right/input/thumbstick");
  234. profile->add_new_binding(primary_click, "/user/hand/left/input/thumbstick/click,/user/hand/right/input/thumbstick/click");
  235. profile->add_new_binding(primary_touch, "/user/hand/left/input/thumbstick/touch,/user/hand/right/input/thumbstick/touch");
  236. // touch controller has no secondary input
  237. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  238. add_interaction_profile(profile);
  239. // Create our Valve index controller profile
  240. profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/valve/index_controller");
  241. profile->add_new_binding(default_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  242. profile->add_new_binding(aim_pose, "/user/hand/left/input/aim/pose,/user/hand/right/input/aim/pose");
  243. profile->add_new_binding(grip_pose, "/user/hand/left/input/grip/pose,/user/hand/right/input/grip/pose");
  244. // index controllers have no select button we can use
  245. profile->add_new_binding(menu_button, "/user/hand/left/input/system/click,/user/hand/right/input/system/click");
  246. profile->add_new_binding(ax_button, "/user/hand/left/input/a/click,/user/hand/right/input/a/click"); // a on both controllers
  247. profile->add_new_binding(ax_touch, "/user/hand/left/input/a/touch,/user/hand/right/input/a/touch");
  248. profile->add_new_binding(by_button, "/user/hand/left/input/b/click,/user/hand/right/input/b/click"); // b on both controllers
  249. profile->add_new_binding(by_touch, "/user/hand/left/input/b/touch,/user/hand/right/input/b/touch");
  250. profile->add_new_binding(trigger, "/user/hand/left/input/trigger/value,/user/hand/right/input/trigger/value");
  251. profile->add_new_binding(trigger_click, "/user/hand/left/input/trigger/click,/user/hand/right/input/trigger/click");
  252. profile->add_new_binding(trigger_touch, "/user/hand/left/input/trigger/touch,/user/hand/right/input/trigger/touch");
  253. profile->add_new_binding(grip, "/user/hand/left/input/squeeze/value,/user/hand/right/input/squeeze/value");
  254. 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
  255. // primary on our index controller is our thumbstick
  256. profile->add_new_binding(primary, "/user/hand/left/input/thumbstick,/user/hand/right/input/thumbstick");
  257. profile->add_new_binding(primary_click, "/user/hand/left/input/thumbstick/click,/user/hand/right/input/thumbstick/click");
  258. profile->add_new_binding(primary_touch, "/user/hand/left/input/thumbstick/touch,/user/hand/right/input/thumbstick/touch");
  259. // secondary on our index controller is our trackpad
  260. profile->add_new_binding(secondary, "/user/hand/left/input/trackpad,/user/hand/right/input/trackpad");
  261. 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...
  262. profile->add_new_binding(secondary_touch, "/user/hand/left/input/trackpad/touch,/user/hand/right/input/trackpad/touch");
  263. profile->add_new_binding(haptic, "/user/hand/left/output/haptic,/user/hand/right/output/haptic");
  264. add_interaction_profile(profile);
  265. }
  266. void OpenXRActionMap::create_editor_action_sets() {
  267. // TODO implement
  268. }
  269. Ref<OpenXRAction> OpenXRActionMap::get_action(const String p_path) const {
  270. PackedStringArray paths = p_path.split("/", false);
  271. ERR_FAIL_COND_V(paths.size() != 2, Ref<OpenXRAction>());
  272. Ref<OpenXRActionSet> action_set = find_action_set(paths[0]);
  273. if (action_set.is_valid()) {
  274. return action_set->get_action(paths[1]);
  275. }
  276. return Ref<OpenXRAction>();
  277. }
  278. void OpenXRActionMap::remove_action(const String p_path) {
  279. Ref<OpenXRAction> action = get_action(p_path);
  280. if (action.is_valid()) {
  281. OpenXRActionSet *action_set = action->get_action_set();
  282. if (action_set != nullptr) {
  283. // Remove the action from this action set
  284. action_set->remove_action(action);
  285. }
  286. for (int i = 0; i < interaction_profiles.size(); i++) {
  287. Ref<OpenXRInteractionProfile> interaction_profile = interaction_profiles[i];
  288. // Remove any bindings for this action
  289. interaction_profile->remove_binding_for_action(action);
  290. }
  291. }
  292. }
  293. PackedStringArray OpenXRActionMap::get_top_level_paths(Ref<OpenXRAction> p_action) {
  294. PackedStringArray arr;
  295. for (int i = 0; i < interaction_profiles.size(); i++) {
  296. Ref<OpenXRInteractionProfile> ip = interaction_profiles[i];
  297. const OpenXRDefs::InteractionProfile *profile = OpenXRDefs::get_profile(ip->get_interaction_profile_path());
  298. if (profile != nullptr) {
  299. for (int j = 0; j < ip->get_binding_count(); j++) {
  300. Ref<OpenXRIPBinding> binding = ip->get_binding(j);
  301. if (binding->get_action() == p_action) {
  302. PackedStringArray paths = binding->get_paths();
  303. for (int k = 0; k < paths.size(); k++) {
  304. const OpenXRDefs::IOPath *io_path = profile->get_io_path(paths[k]);
  305. if (io_path != nullptr) {
  306. String top_path = String(io_path->top_level_path->openxr_path);
  307. if (!arr.has(top_path)) {
  308. arr.push_back(top_path);
  309. }
  310. }
  311. }
  312. }
  313. }
  314. }
  315. }
  316. print_line("Toplevel paths for", p_action->get_name_with_set(), "are", arr);
  317. return arr;
  318. }
  319. OpenXRActionMap::~OpenXRActionMap() {
  320. action_sets.clear();
  321. interaction_profiles.clear();
  322. }