2021-12-14 01:44:12 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* register_types.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#include "register_types.h"
|
|
|
|
|
|
|
|
#include "action_map/openxr_action.h"
|
|
|
|
#include "action_map/openxr_action_map.h"
|
|
|
|
#include "action_map/openxr_action_set.h"
|
|
|
|
#include "action_map/openxr_interaction_profile.h"
|
2023-08-26 15:39:43 +00:00
|
|
|
#include "action_map/openxr_interaction_profile_metadata.h"
|
2023-06-13 14:56:21 +00:00
|
|
|
#include "openxr_interface.h"
|
2022-12-29 05:34:25 +00:00
|
|
|
|
|
|
|
#include "extensions/openxr_extension_wrapper_extension.h"
|
|
|
|
|
2024-03-25 13:07:28 +00:00
|
|
|
#include "scene/openxr_composition_layer.h"
|
|
|
|
#include "scene/openxr_composition_layer_cylinder.h"
|
|
|
|
#include "scene/openxr_composition_layer_equirect.h"
|
|
|
|
#include "scene/openxr_composition_layer_quad.h"
|
2022-04-17 02:58:09 +00:00
|
|
|
#include "scene/openxr_hand.h"
|
|
|
|
|
2022-12-29 05:34:25 +00:00
|
|
|
#include "extensions/openxr_composition_layer_depth_extension.h"
|
2024-03-25 13:07:28 +00:00
|
|
|
#include "extensions/openxr_composition_layer_extension.h"
|
2023-06-08 02:05:20 +00:00
|
|
|
#include "extensions/openxr_eye_gaze_interaction.h"
|
2022-12-29 05:34:25 +00:00
|
|
|
#include "extensions/openxr_fb_display_refresh_rate_extension.h"
|
|
|
|
#include "extensions/openxr_hand_tracking_extension.h"
|
|
|
|
#include "extensions/openxr_htc_controller_extension.h"
|
|
|
|
#include "extensions/openxr_htc_vive_tracker_extension.h"
|
|
|
|
#include "extensions/openxr_huawei_controller_extension.h"
|
2024-01-15 22:26:55 +00:00
|
|
|
#include "extensions/openxr_local_floor_extension.h"
|
2024-01-09 00:29:56 +00:00
|
|
|
#include "extensions/openxr_meta_controller_extension.h"
|
2023-02-02 11:45:43 +00:00
|
|
|
#include "extensions/openxr_ml2_controller_extension.h"
|
2022-12-29 05:34:25 +00:00
|
|
|
#include "extensions/openxr_palm_pose_extension.h"
|
2022-12-16 20:14:24 +00:00
|
|
|
#include "extensions/openxr_pico_controller_extension.h"
|
2022-12-29 05:34:25 +00:00
|
|
|
#include "extensions/openxr_wmr_controller_extension.h"
|
|
|
|
|
2023-06-13 14:56:21 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
#include "editor/openxr_editor_plugin.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ANDROID_ENABLED
|
2023-12-27 03:49:25 +00:00
|
|
|
#include "extensions/platform/openxr_android_extension.h"
|
2023-06-13 14:56:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "core/config/project_settings.h"
|
|
|
|
#include "main/main.h"
|
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
#include "editor/editor_node.h"
|
|
|
|
#endif
|
|
|
|
|
2022-11-11 14:59:22 +00:00
|
|
|
static OpenXRAPI *openxr_api = nullptr;
|
2023-08-26 15:39:43 +00:00
|
|
|
static OpenXRInteractionProfileMetadata *openxr_interaction_profile_metadata = nullptr;
|
2022-11-11 14:59:22 +00:00
|
|
|
static Ref<OpenXRInterface> openxr_interface;
|
|
|
|
|
2022-03-16 23:24:47 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
static void _editor_init() {
|
|
|
|
if (OpenXRAPI::openxr_is_enabled(false)) {
|
|
|
|
// Only add our OpenXR action map editor if OpenXR is enabled for our project
|
|
|
|
|
2023-08-26 15:39:43 +00:00
|
|
|
if (openxr_interaction_profile_metadata == nullptr) {
|
|
|
|
// If we didn't initialize our actionmap metadata at startup, we initialize it now.
|
|
|
|
openxr_interaction_profile_metadata = memnew(OpenXRInteractionProfileMetadata);
|
|
|
|
ERR_FAIL_NULL(openxr_interaction_profile_metadata);
|
2022-11-11 14:59:22 +00:00
|
|
|
}
|
|
|
|
|
2022-03-16 23:24:47 +00:00
|
|
|
OpenXREditorPlugin *openxr_plugin = memnew(OpenXREditorPlugin());
|
|
|
|
EditorNode::get_singleton()->add_editor_plugin(openxr_plugin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-05-03 09:56:08 +00:00
|
|
|
void initialize_openxr_module(ModuleInitializationLevel p_level) {
|
2022-12-29 05:34:25 +00:00
|
|
|
if (p_level == MODULE_INITIALIZATION_LEVEL_CORE) {
|
|
|
|
GDREGISTER_CLASS(OpenXRExtensionWrapperExtension);
|
|
|
|
GDREGISTER_CLASS(OpenXRAPIExtension);
|
|
|
|
}
|
|
|
|
|
2022-05-03 09:56:08 +00:00
|
|
|
if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) {
|
2022-12-29 05:34:25 +00:00
|
|
|
if (OpenXRAPI::openxr_is_enabled(false)) {
|
2023-01-21 11:25:29 +00:00
|
|
|
// Always register our extension wrappers even if we don't initialize OpenXR.
|
2022-12-29 05:34:25 +00:00
|
|
|
// Some of these wrappers will add functionality to our editor.
|
|
|
|
#ifdef ANDROID_ENABLED
|
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXRAndroidExtension));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// register our other extensions
|
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXRPalmPoseExtension));
|
2024-01-15 22:26:55 +00:00
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXRLocalFloorExtension));
|
2022-12-16 20:14:24 +00:00
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXRPicoControllerExtension));
|
2022-12-29 05:34:25 +00:00
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXRCompositionLayerDepthExtension));
|
2024-03-25 13:07:28 +00:00
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXRCompositionLayerExtension));
|
2022-12-29 05:34:25 +00:00
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXRHTCControllerExtension));
|
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXRHTCViveTrackerExtension));
|
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXRHuaweiControllerExtension));
|
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXRDisplayRefreshRateExtension));
|
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXRWMRControllerExtension));
|
2023-02-02 11:45:43 +00:00
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXRML2ControllerExtension));
|
2024-01-09 00:29:56 +00:00
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXRMetaControllerExtension));
|
2024-02-24 06:32:58 +00:00
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXREyeGazeInteractionExtension));
|
2023-10-03 11:38:43 +00:00
|
|
|
|
|
|
|
// register gated extensions
|
|
|
|
if (GLOBAL_GET("xr/openxr/extensions/hand_tracking")) {
|
|
|
|
OpenXRAPI::register_extension_wrapper(memnew(OpenXRHandTrackingExtension));
|
|
|
|
}
|
2022-12-29 05:34:25 +00:00
|
|
|
}
|
2021-12-14 01:44:12 +00:00
|
|
|
|
2022-05-03 09:56:08 +00:00
|
|
|
if (OpenXRAPI::openxr_is_enabled()) {
|
2023-08-26 15:39:43 +00:00
|
|
|
openxr_interaction_profile_metadata = memnew(OpenXRInteractionProfileMetadata);
|
|
|
|
ERR_FAIL_NULL(openxr_interaction_profile_metadata);
|
2022-05-03 09:56:08 +00:00
|
|
|
openxr_api = memnew(OpenXRAPI);
|
|
|
|
ERR_FAIL_NULL(openxr_api);
|
2022-03-24 11:10:43 +00:00
|
|
|
|
2022-05-03 09:56:08 +00:00
|
|
|
if (!openxr_api->initialize(Main::get_rendering_driver_name())) {
|
2023-02-12 04:10:50 +00:00
|
|
|
const char *init_error_message =
|
|
|
|
"OpenXR was requested but failed to start.\n"
|
|
|
|
"Please check if your HMD is connected.\n"
|
2024-03-28 05:17:54 +00:00
|
|
|
#ifdef WINDOWS_ENABLED
|
|
|
|
"When using Windows Mixed Reality, note that WMR only has DirectX support. Make sure SteamVR is your default OpenXR runtime.\n"
|
|
|
|
#endif
|
2023-02-12 04:10:50 +00:00
|
|
|
"Godot will start in normal mode.\n";
|
|
|
|
|
|
|
|
WARN_PRINT(init_error_message);
|
|
|
|
|
|
|
|
bool init_show_startup_alert = GLOBAL_GET("xr/openxr/startup_alert");
|
|
|
|
if (init_show_startup_alert) {
|
|
|
|
OS::get_singleton()->alert(init_error_message);
|
|
|
|
}
|
|
|
|
|
2022-05-03 09:56:08 +00:00
|
|
|
memdelete(openxr_api);
|
|
|
|
openxr_api = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
2021-12-14 01:44:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-03 09:56:08 +00:00
|
|
|
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
|
|
|
|
GDREGISTER_CLASS(OpenXRInterface);
|
2021-12-14 01:44:12 +00:00
|
|
|
|
2022-05-03 09:56:08 +00:00
|
|
|
GDREGISTER_CLASS(OpenXRAction);
|
|
|
|
GDREGISTER_CLASS(OpenXRActionSet);
|
|
|
|
GDREGISTER_CLASS(OpenXRActionMap);
|
2023-08-26 15:39:43 +00:00
|
|
|
GDREGISTER_CLASS(OpenXRInteractionProfileMetadata);
|
2022-05-03 09:56:08 +00:00
|
|
|
GDREGISTER_CLASS(OpenXRIPBinding);
|
|
|
|
GDREGISTER_CLASS(OpenXRInteractionProfile);
|
2021-12-14 01:44:12 +00:00
|
|
|
|
2024-03-25 13:07:28 +00:00
|
|
|
GDREGISTER_ABSTRACT_CLASS(OpenXRCompositionLayer);
|
|
|
|
GDREGISTER_CLASS(OpenXRCompositionLayerEquirect);
|
|
|
|
GDREGISTER_CLASS(OpenXRCompositionLayerCylinder);
|
|
|
|
GDREGISTER_CLASS(OpenXRCompositionLayerQuad);
|
|
|
|
|
2022-04-17 02:58:09 +00:00
|
|
|
GDREGISTER_CLASS(OpenXRHand);
|
|
|
|
|
2022-05-03 09:56:08 +00:00
|
|
|
XRServer *xr_server = XRServer::get_singleton();
|
|
|
|
if (xr_server) {
|
|
|
|
openxr_interface.instantiate();
|
|
|
|
xr_server->add_interface(openxr_interface);
|
2021-12-14 01:44:12 +00:00
|
|
|
|
2022-05-03 09:56:08 +00:00
|
|
|
if (openxr_interface->initialize_on_startup()) {
|
|
|
|
openxr_interface->initialize();
|
|
|
|
}
|
2021-12-14 01:44:12 +00:00
|
|
|
}
|
2022-03-16 23:24:47 +00:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
2022-05-03 09:56:08 +00:00
|
|
|
EditorNode::add_init_callback(_editor_init);
|
2022-03-16 23:24:47 +00:00
|
|
|
#endif
|
2022-05-03 09:56:08 +00:00
|
|
|
}
|
2021-12-14 01:44:12 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 09:56:08 +00:00
|
|
|
void uninitialize_openxr_module(ModuleInitializationLevel p_level) {
|
|
|
|
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-14 01:44:12 +00:00
|
|
|
if (openxr_interface.is_valid()) {
|
2022-03-24 11:10:43 +00:00
|
|
|
// uninitialize just in case
|
2022-03-05 10:09:21 +00:00
|
|
|
if (openxr_interface->is_initialized()) {
|
|
|
|
openxr_interface->uninitialize();
|
|
|
|
}
|
|
|
|
|
2021-12-14 01:44:12 +00:00
|
|
|
// unregister our interface from the XR server
|
2022-03-05 10:09:21 +00:00
|
|
|
XRServer *xr_server = XRServer::get_singleton();
|
|
|
|
if (xr_server) {
|
|
|
|
if (xr_server->get_primary_interface() == openxr_interface) {
|
|
|
|
xr_server->set_primary_interface(Ref<XRInterface>());
|
|
|
|
}
|
|
|
|
xr_server->remove_interface(openxr_interface);
|
2021-12-14 01:44:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// and release
|
|
|
|
openxr_interface.unref();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (openxr_api) {
|
|
|
|
openxr_api->finish();
|
2022-12-29 05:34:25 +00:00
|
|
|
|
2021-12-14 01:44:12 +00:00
|
|
|
memdelete(openxr_api);
|
2022-03-24 11:10:43 +00:00
|
|
|
openxr_api = nullptr;
|
2021-12-14 01:44:12 +00:00
|
|
|
}
|
2022-11-11 14:59:22 +00:00
|
|
|
|
2023-08-26 15:39:43 +00:00
|
|
|
if (openxr_interaction_profile_metadata) {
|
|
|
|
memdelete(openxr_interaction_profile_metadata);
|
|
|
|
openxr_interaction_profile_metadata = nullptr;
|
2022-11-11 14:59:22 +00:00
|
|
|
}
|
2022-12-29 05:34:25 +00:00
|
|
|
|
|
|
|
// cleanup our extension wrappers
|
|
|
|
OpenXRAPI::cleanup_extension_wrappers();
|
2021-12-14 01:44:12 +00:00
|
|
|
}
|