webxr_interface_js.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /**************************************************************************/
  2. /* webxr_interface_js.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. #ifdef JAVASCRIPT_ENABLED
  31. #include "webxr_interface_js.h"
  32. #include "core/os/input.h"
  33. #include "core/os/os.h"
  34. #include "emscripten.h"
  35. #include "godot_webxr.h"
  36. #include "main/input_default.h"
  37. #include "servers/visual/visual_server_globals.h"
  38. #include <stdlib.h>
  39. void _emwebxr_on_session_supported(char *p_session_mode, int p_supported) {
  40. ARVRServer *arvr_server = ARVRServer::get_singleton();
  41. ERR_FAIL_NULL(arvr_server);
  42. Ref<ARVRInterface> interface = arvr_server->find_interface("WebXR");
  43. ERR_FAIL_COND(interface.is_null());
  44. String session_mode = String(p_session_mode);
  45. interface->emit_signal("session_supported", session_mode, p_supported ? true : false);
  46. }
  47. void _emwebxr_on_session_started(char *p_reference_space_type) {
  48. ARVRServer *arvr_server = ARVRServer::get_singleton();
  49. ERR_FAIL_NULL(arvr_server);
  50. Ref<ARVRInterface> interface = arvr_server->find_interface("WebXR");
  51. ERR_FAIL_COND(interface.is_null());
  52. String reference_space_type = String(p_reference_space_type);
  53. ((WebXRInterfaceJS *)interface.ptr())->_set_reference_space_type(reference_space_type);
  54. interface->emit_signal("session_started");
  55. }
  56. void _emwebxr_on_session_ended() {
  57. ARVRServer *arvr_server = ARVRServer::get_singleton();
  58. ERR_FAIL_NULL(arvr_server);
  59. Ref<ARVRInterface> interface = arvr_server->find_interface("WebXR");
  60. ERR_FAIL_COND(interface.is_null());
  61. interface->uninitialize();
  62. interface->emit_signal("session_ended");
  63. }
  64. void _emwebxr_on_session_failed(char *p_message) {
  65. ARVRServer *arvr_server = ARVRServer::get_singleton();
  66. ERR_FAIL_NULL(arvr_server);
  67. Ref<ARVRInterface> interface = arvr_server->find_interface("WebXR");
  68. ERR_FAIL_COND(interface.is_null());
  69. interface->uninitialize();
  70. String message = String(p_message);
  71. interface->emit_signal("session_failed", message);
  72. }
  73. void _emwebxr_on_controller_changed() {
  74. ARVRServer *arvr_server = ARVRServer::get_singleton();
  75. ERR_FAIL_NULL(arvr_server);
  76. Ref<ARVRInterface> interface = arvr_server->find_interface("WebXR");
  77. ERR_FAIL_COND(interface.is_null());
  78. ((WebXRInterfaceJS *)interface.ptr())->_on_controller_changed();
  79. }
  80. extern "C" EMSCRIPTEN_KEEPALIVE void _emwebxr_on_input_event(int p_event_type, int p_input_source) {
  81. ARVRServer *arvr_server = ARVRServer::get_singleton();
  82. ERR_FAIL_NULL(arvr_server);
  83. Ref<ARVRInterface> interface = arvr_server->find_interface("WebXR");
  84. ERR_FAIL_COND(interface.is_null());
  85. ((WebXRInterfaceJS *)interface.ptr())->_on_input_event(p_event_type, p_input_source);
  86. }
  87. extern "C" EMSCRIPTEN_KEEPALIVE void _emwebxr_on_simple_event(char *p_signal_name) {
  88. ARVRServer *arvr_server = ARVRServer::get_singleton();
  89. ERR_FAIL_NULL(arvr_server);
  90. Ref<ARVRInterface> interface = arvr_server->find_interface("WebXR");
  91. ERR_FAIL_COND(interface.is_null());
  92. StringName signal_name = StringName(p_signal_name);
  93. interface->emit_signal(signal_name);
  94. }
  95. void WebXRInterfaceJS::is_session_supported(const String &p_session_mode) {
  96. godot_webxr_is_session_supported(p_session_mode.utf8().get_data(), &_emwebxr_on_session_supported);
  97. }
  98. void WebXRInterfaceJS::set_session_mode(String p_session_mode) {
  99. session_mode = p_session_mode;
  100. }
  101. String WebXRInterfaceJS::get_session_mode() const {
  102. return session_mode;
  103. }
  104. void WebXRInterfaceJS::set_required_features(String p_required_features) {
  105. required_features = p_required_features;
  106. }
  107. String WebXRInterfaceJS::get_required_features() const {
  108. return required_features;
  109. }
  110. void WebXRInterfaceJS::set_optional_features(String p_optional_features) {
  111. optional_features = p_optional_features;
  112. }
  113. String WebXRInterfaceJS::get_optional_features() const {
  114. return optional_features;
  115. }
  116. void WebXRInterfaceJS::set_requested_reference_space_types(String p_requested_reference_space_types) {
  117. requested_reference_space_types = p_requested_reference_space_types;
  118. }
  119. String WebXRInterfaceJS::get_requested_reference_space_types() const {
  120. return requested_reference_space_types;
  121. }
  122. void WebXRInterfaceJS::_set_reference_space_type(String p_reference_space_type) {
  123. reference_space_type = p_reference_space_type;
  124. }
  125. String WebXRInterfaceJS::get_reference_space_type() const {
  126. return reference_space_type;
  127. }
  128. Ref<ARVRPositionalTracker> WebXRInterfaceJS::get_controller(int p_controller_id) const {
  129. ARVRServer *arvr_server = ARVRServer::get_singleton();
  130. ERR_FAIL_NULL_V(arvr_server, nullptr);
  131. return arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id);
  132. }
  133. WebXRInterface::TargetRayMode WebXRInterfaceJS::get_controller_target_ray_mode(int p_controller_id) const {
  134. ERR_FAIL_COND_V(p_controller_id <= 0, WebXRInterface::TARGET_RAY_MODE_UNKNOWN);
  135. ARVRServer *arvr_server = ARVRServer::get_singleton();
  136. ERR_FAIL_NULL_V(arvr_server, WebXRInterface::TARGET_RAY_MODE_UNKNOWN);
  137. return (WebXRInterface::TargetRayMode)godot_webxr_get_controller_target_ray_mode(p_controller_id - 1);
  138. }
  139. String WebXRInterfaceJS::get_visibility_state() const {
  140. char *c_str = godot_webxr_get_visibility_state();
  141. if (c_str) {
  142. String visibility_state = String(c_str);
  143. free(c_str);
  144. return visibility_state;
  145. }
  146. return String();
  147. }
  148. PoolVector3Array WebXRInterfaceJS::get_bounds_geometry() const {
  149. PoolVector3Array ret;
  150. int *js_bounds = godot_webxr_get_bounds_geometry();
  151. if (js_bounds) {
  152. ret.resize(js_bounds[0]);
  153. for (int i = 0; i < js_bounds[0]; i++) {
  154. float *js_vector3 = ((float *)js_bounds) + (i * 3) + 1;
  155. ret.set(i, Vector3(js_vector3[0], js_vector3[1], js_vector3[2]));
  156. }
  157. free(js_bounds);
  158. }
  159. return ret;
  160. }
  161. void WebXRInterfaceJS::set_xr_standard_mapping(bool p_xr_standard_mapping) {
  162. xr_standard_mapping = p_xr_standard_mapping;
  163. }
  164. bool WebXRInterfaceJS::get_xr_standard_mapping() const {
  165. return xr_standard_mapping;
  166. }
  167. StringName WebXRInterfaceJS::get_name() const {
  168. return "WebXR";
  169. };
  170. int WebXRInterfaceJS::get_capabilities() const {
  171. return ARVRInterface::ARVR_STEREO | ARVRInterface::ARVR_MONO;
  172. };
  173. bool WebXRInterfaceJS::is_stereo() {
  174. return godot_webxr_get_view_count() == 2;
  175. };
  176. bool WebXRInterfaceJS::is_initialized() const {
  177. return (initialized);
  178. };
  179. bool WebXRInterfaceJS::initialize() {
  180. ARVRServer *arvr_server = ARVRServer::get_singleton();
  181. ERR_FAIL_NULL_V(arvr_server, false);
  182. if (!initialized) {
  183. if (!godot_webxr_is_supported()) {
  184. return false;
  185. }
  186. if (requested_reference_space_types.size() == 0) {
  187. return false;
  188. }
  189. // make this our primary interface
  190. arvr_server->set_primary_interface(this);
  191. // Clear state variables.
  192. memset(controllers_state, 0, sizeof controllers_state);
  193. memset(touching, 0, sizeof touching);
  194. // Clear render_targetsize to make sure it gets reset to the new size.
  195. // Clearing in uninitialize() doesn't work because a frame can still be
  196. // rendered after it's called, which will fill render_targetsize again.
  197. render_targetsize.width = 0;
  198. render_targetsize.height = 0;
  199. initialized = true;
  200. godot_webxr_initialize(
  201. session_mode.utf8().get_data(),
  202. required_features.utf8().get_data(),
  203. optional_features.utf8().get_data(),
  204. requested_reference_space_types.utf8().get_data(),
  205. &_emwebxr_on_session_started,
  206. &_emwebxr_on_session_ended,
  207. &_emwebxr_on_session_failed,
  208. &_emwebxr_on_controller_changed,
  209. &_emwebxr_on_input_event,
  210. &_emwebxr_on_simple_event);
  211. };
  212. return true;
  213. };
  214. void WebXRInterfaceJS::uninitialize() {
  215. if (initialized) {
  216. ARVRServer *arvr_server = ARVRServer::get_singleton();
  217. if (arvr_server != NULL) {
  218. // no longer our primary interface
  219. arvr_server->clear_primary_interface_if(this);
  220. }
  221. godot_webxr_uninitialize();
  222. reference_space_type = "";
  223. initialized = false;
  224. };
  225. };
  226. Transform WebXRInterfaceJS::_js_matrix_to_transform(float *p_js_matrix) {
  227. Transform transform;
  228. transform.basis.elements[0].x = p_js_matrix[0];
  229. transform.basis.elements[1].x = p_js_matrix[1];
  230. transform.basis.elements[2].x = p_js_matrix[2];
  231. transform.basis.elements[0].y = p_js_matrix[4];
  232. transform.basis.elements[1].y = p_js_matrix[5];
  233. transform.basis.elements[2].y = p_js_matrix[6];
  234. transform.basis.elements[0].z = p_js_matrix[8];
  235. transform.basis.elements[1].z = p_js_matrix[9];
  236. transform.basis.elements[2].z = p_js_matrix[10];
  237. transform.origin.x = p_js_matrix[12];
  238. transform.origin.y = p_js_matrix[13];
  239. transform.origin.z = p_js_matrix[14];
  240. return transform;
  241. }
  242. Size2 WebXRInterfaceJS::get_render_targetsize() {
  243. if (render_targetsize.width != 0 && render_targetsize.height != 0) {
  244. return render_targetsize;
  245. }
  246. int *js_size = godot_webxr_get_render_targetsize();
  247. if (!initialized || js_size == nullptr) {
  248. // As a temporary default (until WebXR is fully initialized), use half the window size.
  249. Size2 temp = OS::get_singleton()->get_window_size();
  250. temp.width /= 2.0;
  251. return temp;
  252. }
  253. render_targetsize.width = js_size[0];
  254. render_targetsize.height = js_size[1];
  255. free(js_size);
  256. return render_targetsize;
  257. };
  258. Transform WebXRInterfaceJS::get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform) {
  259. Transform transform_for_eye;
  260. ARVRServer *arvr_server = ARVRServer::get_singleton();
  261. ERR_FAIL_NULL_V(arvr_server, transform_for_eye);
  262. float *js_matrix = godot_webxr_get_transform_for_eye(p_eye);
  263. if (js_matrix != nullptr) {
  264. transform_for_eye = _js_matrix_to_transform(js_matrix);
  265. free(js_matrix);
  266. transform_for_eye.origin *= arvr_server->get_world_scale();
  267. }
  268. return p_cam_transform * arvr_server->get_reference_frame() * transform_for_eye;
  269. };
  270. CameraMatrix WebXRInterfaceJS::get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) {
  271. CameraMatrix eye;
  272. float *js_matrix = godot_webxr_get_projection_for_eye(p_eye);
  273. if (!initialized || js_matrix == nullptr) {
  274. return eye;
  275. }
  276. int k = 0;
  277. for (int i = 0; i < 4; i++) {
  278. for (int j = 0; j < 4; j++) {
  279. eye.matrix[i][j] = js_matrix[k++];
  280. }
  281. }
  282. free(js_matrix);
  283. // Copied from godot_oculus_mobile's ovr_mobile_session.cpp
  284. eye.matrix[2][2] = -(p_z_far + p_z_near) / (p_z_far - p_z_near);
  285. eye.matrix[3][2] = -(2.0f * p_z_far * p_z_near) / (p_z_far - p_z_near);
  286. return eye;
  287. }
  288. void WebXRInterfaceJS::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) {
  289. if (!initialized) {
  290. return;
  291. }
  292. RID texture = VSG::storage->render_target_get_texture(p_render_target);
  293. uint32_t texture_id = VSG::storage->texture_get_texid(texture);
  294. godot_webxr_commit_for_eye(p_eye, texture_id);
  295. };
  296. void WebXRInterfaceJS::process() {
  297. if (initialized) {
  298. godot_webxr_sample_controller_data();
  299. int controller_count = godot_webxr_get_controller_count();
  300. if (controller_count == 0) {
  301. return;
  302. }
  303. for (int i = 0; i < controller_count; i++) {
  304. _update_tracker(i);
  305. }
  306. };
  307. };
  308. void WebXRInterfaceJS::_update_tracker(int p_controller_id) {
  309. ARVRServer *arvr_server = ARVRServer::get_singleton();
  310. ERR_FAIL_NULL(arvr_server);
  311. Ref<ARVRPositionalTracker> tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id + 1);
  312. if (godot_webxr_is_controller_connected(p_controller_id)) {
  313. if (tracker.is_null()) {
  314. tracker.instance();
  315. tracker->set_type(ARVRServer::TRACKER_CONTROLLER);
  316. // Controller id's 0 and 1 are always the left and right hands.
  317. if (p_controller_id < 2) {
  318. tracker->set_name(p_controller_id == 0 ? "Left" : "Right");
  319. tracker->set_hand(p_controller_id == 0 ? ARVRPositionalTracker::TRACKER_LEFT_HAND : ARVRPositionalTracker::TRACKER_RIGHT_HAND);
  320. }
  321. // Use the ids we're giving to our "virtual" gamepads.
  322. tracker->set_joy_id(p_controller_id + 100);
  323. arvr_server->add_tracker(tracker);
  324. }
  325. InputDefault *input = (InputDefault *)Input::get_singleton();
  326. int joy_id = p_controller_id + 100;
  327. float *tracker_matrix = godot_webxr_get_controller_transform(p_controller_id);
  328. if (tracker_matrix) {
  329. Transform transform = _js_matrix_to_transform(tracker_matrix);
  330. tracker->set_rw_position(transform.origin);
  331. tracker->set_orientation(transform.basis);
  332. free(tracker_matrix);
  333. }
  334. int *buttons = godot_webxr_get_controller_buttons(p_controller_id, xr_standard_mapping);
  335. if (buttons) {
  336. for (int i = 0; i < buttons[0]; i++) {
  337. input->joy_button(joy_id, i, *((float *)buttons + (i + 1)));
  338. }
  339. free(buttons);
  340. }
  341. int *axes = godot_webxr_get_controller_axes(p_controller_id, xr_standard_mapping);
  342. if (axes) {
  343. WebXRInterface::TargetRayMode target_ray_mode = (WebXRInterface::TargetRayMode)godot_webxr_get_controller_target_ray_mode(p_controller_id);
  344. if (target_ray_mode == WebXRInterface::TARGET_RAY_MODE_SCREEN) {
  345. int touch_index = _get_touch_index(p_controller_id);
  346. if (touch_index < 5 && touching[touch_index]) {
  347. Vector2 joy_vector = _get_joy_vector_from_axes(axes);
  348. Vector2 previous_joy_vector(input->get_joy_axis(joy_id, 0), input->get_joy_axis(joy_id, 1));
  349. if (!joy_vector.is_equal_approx(previous_joy_vector)) {
  350. Vector2 position = _get_screen_position_from_joy_vector(joy_vector);
  351. Vector2 previous_position = _get_screen_position_from_joy_vector(previous_joy_vector);
  352. Ref<InputEventScreenDrag> event;
  353. event.instance();
  354. event->set_index(touch_index);
  355. event->set_position(position);
  356. event->set_relative(position - previous_position);
  357. input->parse_input_event(event);
  358. }
  359. }
  360. }
  361. for (int i = 0; i < axes[0]; i++) {
  362. float value = *((float *)axes + (i + 1));
  363. input->joy_axis(joy_id, i, value);
  364. }
  365. free(axes);
  366. }
  367. } else if (tracker.is_valid()) {
  368. arvr_server->remove_tracker(tracker);
  369. }
  370. }
  371. void WebXRInterfaceJS::_on_controller_changed() {
  372. // Register "virtual" gamepads with Godot for the ones we get from WebXR.
  373. godot_webxr_sample_controller_data();
  374. for (int i = 0; i < 2; i++) {
  375. bool controller_connected = godot_webxr_is_controller_connected(i);
  376. if (controllers_state[i] != controller_connected) {
  377. Input::get_singleton()->joy_connection_changed(i + 100, controller_connected, i == 0 ? "Left" : "Right", "");
  378. controllers_state[i] = controller_connected;
  379. }
  380. }
  381. }
  382. void WebXRInterfaceJS::_on_input_event(int p_event_type, int p_input_source) {
  383. if (p_event_type == WEBXR_INPUT_EVENT_SELECTSTART || p_event_type == WEBXR_INPUT_EVENT_SELECTEND) {
  384. int target_ray_mode = godot_webxr_get_controller_target_ray_mode(p_input_source);
  385. if (target_ray_mode == WebXRInterface::TARGET_RAY_MODE_SCREEN) {
  386. int touch_index = _get_touch_index(p_input_source);
  387. if (touch_index < 5) {
  388. touching[touch_index] = (p_event_type == WEBXR_INPUT_EVENT_SELECTSTART);
  389. }
  390. int *axes = godot_webxr_get_controller_axes(p_input_source, false);
  391. if (axes) {
  392. Vector2 joy_vector = _get_joy_vector_from_axes(axes);
  393. Vector2 position = _get_screen_position_from_joy_vector(joy_vector);
  394. free(axes);
  395. InputDefault *input = (InputDefault *)Input::get_singleton();
  396. int joy_id = p_input_source + 100;
  397. input->set_joy_axis(joy_id, 0, joy_vector.x);
  398. input->set_joy_axis(joy_id, 1, joy_vector.y);
  399. Ref<InputEventScreenTouch> event;
  400. event.instance();
  401. event->set_index(touch_index);
  402. event->set_position(position);
  403. event->set_pressed(p_event_type == WEBXR_INPUT_EVENT_SELECTSTART);
  404. Input::get_singleton()->parse_input_event(event);
  405. }
  406. }
  407. }
  408. int controller_id = p_input_source + 1;
  409. switch (p_event_type) {
  410. case WEBXR_INPUT_EVENT_SELECTSTART:
  411. emit_signal("selectstart", controller_id);
  412. break;
  413. case WEBXR_INPUT_EVENT_SELECTEND:
  414. emit_signal("selectend", controller_id);
  415. break;
  416. case WEBXR_INPUT_EVENT_SELECT:
  417. emit_signal("select", controller_id);
  418. break;
  419. case WEBXR_INPUT_EVENT_SQUEEZESTART:
  420. emit_signal("squeezestart", controller_id);
  421. break;
  422. case WEBXR_INPUT_EVENT_SQUEEZEEND:
  423. emit_signal("squeezeend", controller_id);
  424. break;
  425. case WEBXR_INPUT_EVENT_SQUEEZE:
  426. emit_signal("squeeze", controller_id);
  427. break;
  428. }
  429. }
  430. int WebXRInterfaceJS::_get_touch_index(int p_input_source) {
  431. int index = 0;
  432. for (int i = 0; i < p_input_source; i++) {
  433. if (godot_webxr_get_controller_target_ray_mode(i) == WebXRInterface::TARGET_RAY_MODE_SCREEN) {
  434. index++;
  435. }
  436. }
  437. return index;
  438. }
  439. Vector2 WebXRInterfaceJS::_get_joy_vector_from_axes(int *p_axes) {
  440. float x_axis = 0.0;
  441. float y_axis = 0.0;
  442. if (p_axes[0] >= 2) {
  443. x_axis = *((float *)p_axes + 1);
  444. y_axis = *((float *)p_axes + 2);
  445. }
  446. return Vector2(x_axis, y_axis);
  447. }
  448. Vector2 WebXRInterfaceJS::_get_screen_position_from_joy_vector(const Vector2 &p_joy_vector) {
  449. SceneTree *scene_tree = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
  450. if (!scene_tree) {
  451. return Vector2();
  452. }
  453. Viewport *viewport = scene_tree->get_root();
  454. Vector2 position_percentage((p_joy_vector.x + 1.0f) / 2.0f, ((p_joy_vector.y) + 1.0f) / 2.0f);
  455. Vector2 position = viewport->get_size() * position_percentage;
  456. return position;
  457. }
  458. void WebXRInterfaceJS::notification(int p_what) {
  459. // Nothing to do here.
  460. }
  461. WebXRInterfaceJS::WebXRInterfaceJS() {
  462. initialized = false;
  463. xr_standard_mapping = false;
  464. session_mode = "inline";
  465. requested_reference_space_types = "local";
  466. };
  467. WebXRInterfaceJS::~WebXRInterfaceJS() {
  468. // and make sure we cleanup if we haven't already
  469. if (initialized) {
  470. uninitialize();
  471. };
  472. };
  473. #endif // JAVASCRIPT_ENABLED