webxr_interface_js.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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 (!initialized || js_matrix == nullptr) {
  264. transform_for_eye = p_cam_transform;
  265. return transform_for_eye;
  266. }
  267. transform_for_eye = _js_matrix_to_transform(js_matrix);
  268. free(js_matrix);
  269. return p_cam_transform * arvr_server->get_reference_frame() * transform_for_eye;
  270. };
  271. CameraMatrix WebXRInterfaceJS::get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) {
  272. CameraMatrix eye;
  273. float *js_matrix = godot_webxr_get_projection_for_eye(p_eye);
  274. if (!initialized || js_matrix == nullptr) {
  275. return eye;
  276. }
  277. int k = 0;
  278. for (int i = 0; i < 4; i++) {
  279. for (int j = 0; j < 4; j++) {
  280. eye.matrix[i][j] = js_matrix[k++];
  281. }
  282. }
  283. free(js_matrix);
  284. // Copied from godot_oculus_mobile's ovr_mobile_session.cpp
  285. eye.matrix[2][2] = -(p_z_far + p_z_near) / (p_z_far - p_z_near);
  286. eye.matrix[3][2] = -(2.0f * p_z_far * p_z_near) / (p_z_far - p_z_near);
  287. return eye;
  288. }
  289. void WebXRInterfaceJS::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) {
  290. if (!initialized) {
  291. return;
  292. }
  293. RID texture = VSG::storage->render_target_get_texture(p_render_target);
  294. uint32_t texture_id = VSG::storage->texture_get_texid(texture);
  295. godot_webxr_commit_for_eye(p_eye, texture_id);
  296. };
  297. void WebXRInterfaceJS::process() {
  298. if (initialized) {
  299. godot_webxr_sample_controller_data();
  300. int controller_count = godot_webxr_get_controller_count();
  301. if (controller_count == 0) {
  302. return;
  303. }
  304. for (int i = 0; i < controller_count; i++) {
  305. _update_tracker(i);
  306. }
  307. };
  308. };
  309. void WebXRInterfaceJS::_update_tracker(int p_controller_id) {
  310. ARVRServer *arvr_server = ARVRServer::get_singleton();
  311. ERR_FAIL_NULL(arvr_server);
  312. Ref<ARVRPositionalTracker> tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id + 1);
  313. if (godot_webxr_is_controller_connected(p_controller_id)) {
  314. if (tracker.is_null()) {
  315. tracker.instance();
  316. tracker->set_type(ARVRServer::TRACKER_CONTROLLER);
  317. // Controller id's 0 and 1 are always the left and right hands.
  318. if (p_controller_id < 2) {
  319. tracker->set_name(p_controller_id == 0 ? "Left" : "Right");
  320. tracker->set_hand(p_controller_id == 0 ? ARVRPositionalTracker::TRACKER_LEFT_HAND : ARVRPositionalTracker::TRACKER_RIGHT_HAND);
  321. }
  322. // Use the ids we're giving to our "virtual" gamepads.
  323. tracker->set_joy_id(p_controller_id + 100);
  324. arvr_server->add_tracker(tracker);
  325. }
  326. InputDefault *input = (InputDefault *)Input::get_singleton();
  327. int joy_id = p_controller_id + 100;
  328. float *tracker_matrix = godot_webxr_get_controller_transform(p_controller_id);
  329. if (tracker_matrix) {
  330. Transform transform = _js_matrix_to_transform(tracker_matrix);
  331. tracker->set_position(transform.origin);
  332. tracker->set_orientation(transform.basis);
  333. free(tracker_matrix);
  334. }
  335. int *buttons = godot_webxr_get_controller_buttons(p_controller_id, xr_standard_mapping);
  336. if (buttons) {
  337. for (int i = 0; i < buttons[0]; i++) {
  338. input->joy_button(joy_id, i, *((float *)buttons + (i + 1)));
  339. }
  340. free(buttons);
  341. }
  342. int *axes = godot_webxr_get_controller_axes(p_controller_id, xr_standard_mapping);
  343. if (axes) {
  344. WebXRInterface::TargetRayMode target_ray_mode = (WebXRInterface::TargetRayMode)godot_webxr_get_controller_target_ray_mode(p_controller_id);
  345. if (target_ray_mode == WebXRInterface::TARGET_RAY_MODE_SCREEN) {
  346. int touch_index = _get_touch_index(p_controller_id);
  347. if (touch_index < 5 && touching[touch_index]) {
  348. Vector2 joy_vector = _get_joy_vector_from_axes(axes);
  349. Vector2 previous_joy_vector(input->get_joy_axis(joy_id, 0), input->get_joy_axis(joy_id, 1));
  350. if (!joy_vector.is_equal_approx(previous_joy_vector)) {
  351. Vector2 position = _get_screen_position_from_joy_vector(joy_vector);
  352. Vector2 previous_position = _get_screen_position_from_joy_vector(previous_joy_vector);
  353. Ref<InputEventScreenDrag> event;
  354. event.instance();
  355. event->set_index(touch_index);
  356. event->set_position(position);
  357. event->set_relative(position - previous_position);
  358. input->parse_input_event(event);
  359. }
  360. }
  361. }
  362. for (int i = 0; i < axes[0]; i++) {
  363. float value = *((float *)axes + (i + 1));
  364. input->joy_axis(joy_id, i, value);
  365. }
  366. free(axes);
  367. }
  368. } else if (tracker.is_valid()) {
  369. arvr_server->remove_tracker(tracker);
  370. }
  371. }
  372. void WebXRInterfaceJS::_on_controller_changed() {
  373. // Register "virtual" gamepads with Godot for the ones we get from WebXR.
  374. godot_webxr_sample_controller_data();
  375. for (int i = 0; i < 2; i++) {
  376. bool controller_connected = godot_webxr_is_controller_connected(i);
  377. if (controllers_state[i] != controller_connected) {
  378. Input::get_singleton()->joy_connection_changed(i + 100, controller_connected, i == 0 ? "Left" : "Right", "");
  379. controllers_state[i] = controller_connected;
  380. }
  381. }
  382. }
  383. void WebXRInterfaceJS::_on_input_event(int p_event_type, int p_input_source) {
  384. if (p_event_type == WEBXR_INPUT_EVENT_SELECTSTART || p_event_type == WEBXR_INPUT_EVENT_SELECTEND) {
  385. int target_ray_mode = godot_webxr_get_controller_target_ray_mode(p_input_source);
  386. if (target_ray_mode == WebXRInterface::TARGET_RAY_MODE_SCREEN) {
  387. int touch_index = _get_touch_index(p_input_source);
  388. if (touch_index < 5) {
  389. touching[touch_index] = (p_event_type == WEBXR_INPUT_EVENT_SELECTSTART);
  390. }
  391. int *axes = godot_webxr_get_controller_axes(p_input_source, false);
  392. if (axes) {
  393. Vector2 joy_vector = _get_joy_vector_from_axes(axes);
  394. Vector2 position = _get_screen_position_from_joy_vector(joy_vector);
  395. free(axes);
  396. InputDefault *input = (InputDefault *)Input::get_singleton();
  397. int joy_id = p_input_source + 100;
  398. input->set_joy_axis(joy_id, 0, joy_vector.x);
  399. input->set_joy_axis(joy_id, 1, joy_vector.y);
  400. Ref<InputEventScreenTouch> event;
  401. event.instance();
  402. event->set_index(touch_index);
  403. event->set_position(position);
  404. event->set_pressed(p_event_type == WEBXR_INPUT_EVENT_SELECTSTART);
  405. Input::get_singleton()->parse_input_event(event);
  406. }
  407. }
  408. }
  409. int controller_id = p_input_source + 1;
  410. switch (p_event_type) {
  411. case WEBXR_INPUT_EVENT_SELECTSTART:
  412. emit_signal("selectstart", controller_id);
  413. break;
  414. case WEBXR_INPUT_EVENT_SELECTEND:
  415. emit_signal("selectend", controller_id);
  416. break;
  417. case WEBXR_INPUT_EVENT_SELECT:
  418. emit_signal("select", controller_id);
  419. break;
  420. case WEBXR_INPUT_EVENT_SQUEEZESTART:
  421. emit_signal("squeezestart", controller_id);
  422. break;
  423. case WEBXR_INPUT_EVENT_SQUEEZEEND:
  424. emit_signal("squeezeend", controller_id);
  425. break;
  426. case WEBXR_INPUT_EVENT_SQUEEZE:
  427. emit_signal("squeeze", controller_id);
  428. break;
  429. }
  430. }
  431. int WebXRInterfaceJS::_get_touch_index(int p_input_source) {
  432. int index = 0;
  433. for (int i = 0; i < p_input_source; i++) {
  434. if (godot_webxr_get_controller_target_ray_mode(i) == WebXRInterface::TARGET_RAY_MODE_SCREEN) {
  435. index++;
  436. }
  437. }
  438. return index;
  439. }
  440. Vector2 WebXRInterfaceJS::_get_joy_vector_from_axes(int *p_axes) {
  441. float x_axis = 0.0;
  442. float y_axis = 0.0;
  443. if (p_axes[0] >= 2) {
  444. x_axis = *((float *)p_axes + 1);
  445. y_axis = *((float *)p_axes + 2);
  446. }
  447. return Vector2(x_axis, y_axis);
  448. }
  449. Vector2 WebXRInterfaceJS::_get_screen_position_from_joy_vector(const Vector2 &p_joy_vector) {
  450. SceneTree *scene_tree = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
  451. if (!scene_tree) {
  452. return Vector2();
  453. }
  454. Viewport *viewport = scene_tree->get_root();
  455. Vector2 position_percentage((p_joy_vector.x + 1.0f) / 2.0f, ((p_joy_vector.y) + 1.0f) / 2.0f);
  456. Vector2 position = viewport->get_size() * position_percentage;
  457. return position;
  458. }
  459. void WebXRInterfaceJS::notification(int p_what) {
  460. // Nothing to do here.
  461. }
  462. WebXRInterfaceJS::WebXRInterfaceJS() {
  463. initialized = false;
  464. xr_standard_mapping = false;
  465. session_mode = "inline";
  466. requested_reference_space_types = "local";
  467. };
  468. WebXRInterfaceJS::~WebXRInterfaceJS() {
  469. // and make sure we cleanup if we haven't already
  470. if (initialized) {
  471. uninitialize();
  472. };
  473. };
  474. #endif // JAVASCRIPT_ENABLED