Skip to content

Commit e098cfd

Browse files
committed
wip
1 parent 29b945f commit e098cfd

7 files changed

Lines changed: 164 additions & 0 deletions

main/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2839,6 +2839,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
28392839
GLOBAL_DEF_BASIC("xr/openxr/extensions/hand_tracking_unobstructed_data_source", false); // XR_HAND_TRACKING_DATA_SOURCE_UNOBSTRUCTED_EXT
28402840
GLOBAL_DEF_BASIC("xr/openxr/extensions/hand_tracking_controller_data_source", false); // XR_HAND_TRACKING_DATA_SOURCE_CONTROLLER_EXT
28412841
GLOBAL_DEF_RST_BASIC("xr/openxr/extensions/hand_interaction_profile", false);
2842+
GLOBAL_DEF_RST_BASIC("xr/openxr/extensions/androidxr/mouse_interaction_profile", false);
28422843
GLOBAL_DEF_BASIC("xr/openxr/extensions/spatial_entity/enabled", false);
28432844
GLOBAL_DEF_BASIC("xr/openxr/extensions/spatial_entity/enable_spatial_anchors", false);
28442845
GLOBAL_DEF_BASIC("xr/openxr/extensions/spatial_entity/enable_persistent_anchors", false);

modules/openxr/action_map/openxr_interaction_profile_metadata.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ void OpenXRInteractionProfileMetadata::_register_core_metadata() {
246246
register_top_level_path("Head", "/user/head", "");
247247
register_top_level_path("Gamepad", "/user/gamepad", "");
248248
register_top_level_path("Treadmill", "/user/treadmill", "");
249+
register_top_level_path("Mouse", "/user/mouse", "XR_ANDROID_mouse_interaction");
249250

250251
{ // Fallback Khronos simple controller
251252
const String profile_path = "/interaction_profiles/khr/simple_controller";
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**************************************************************************/
2+
/* openxr_android_mouse_interaction_extension.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+
31+
#include "openxr_android_mouse_interaction_extension.h"
32+
33+
#include "../action_map/openxr_interaction_profile_metadata.h"
34+
#include "core/config/project_settings.h"
35+
36+
#include <openxr/openxr.h>
37+
38+
OpenXRAndroidMouseInteractionExtension *OpenXRAndroidMouseInteractionExtension::singleton = nullptr;
39+
40+
OpenXRAndroidMouseInteractionExtension *OpenXRAndroidMouseInteractionExtension::get_singleton() {
41+
return singleton;
42+
}
43+
44+
OpenXRAndroidMouseInteractionExtension::OpenXRAndroidMouseInteractionExtension() {
45+
singleton = this;
46+
}
47+
48+
OpenXRAndroidMouseInteractionExtension::~OpenXRAndroidMouseInteractionExtension() {
49+
singleton = nullptr;
50+
}
51+
52+
HashMap<String, bool *> OpenXRAndroidMouseInteractionExtension::get_requested_extensions(XrVersion p_version) {
53+
HashMap<String, bool *> request_extensions;
54+
55+
// Only enable this extension when requested.
56+
// We still register our meta data or the action map editor will fail.
57+
if (GLOBAL_GET("xr/openxr/extensions/androidxr/mouse_interaction_profile")) {
58+
request_extensions["XR_ANDROID_mouse_interaction"] = &available;
59+
}
60+
61+
return request_extensions;
62+
}
63+
64+
bool OpenXRAndroidMouseInteractionExtension::is_available() {
65+
return available;
66+
}
67+
68+
void OpenXRAndroidMouseInteractionExtension::on_register_metadata() {
69+
OpenXRInteractionProfileMetadata *openxr_metadata = OpenXRInteractionProfileMetadata::get_singleton();
70+
ERR_FAIL_NULL(openxr_metadata);
71+
72+
// Mouse interaction profile.
73+
const String profile_path = "/interaction_profiles/android/mouse_interaction_android";
74+
const String user_path = "/user/mouse";
75+
openxr_metadata->register_interaction_profile("Android mouse interaction", profile_path, "XR_ANDROID_mouse_interaction");
76+
77+
openxr_metadata->register_io_path(profile_path, "Aim pose", user_path, user_path + "/input/aim/pose", "", OpenXRAction::OPENXR_ACTION_POSE);
78+
79+
openxr_metadata->register_io_path(profile_path, "Select click", user_path, user_path + "/input/select/click", "", OpenXRAction::OPENXR_ACTION_BOOL);
80+
openxr_metadata->register_io_path(profile_path, "Secondary click", user_path, user_path + "/input/secondary_android/click", "", OpenXRAction::OPENXR_ACTION_BOOL);
81+
openxr_metadata->register_io_path(profile_path, "Tertiary click", user_path, user_path + "/input/tertiary_android/click", "", OpenXRAction::OPENXR_ACTION_BOOL);
82+
83+
// openxr_metadata->register_io_path(profile_path, "Scroll", user_path, user_path + "/input/scroll_android/value", "", OpenXRAction::OPENXR_ACTION_FLOAT);
84+
openxr_metadata->register_io_path(profile_path, "Scroll", user_path, user_path + "/input/scroll_android", "", OpenXRAction::OPENXR_ACTION_VECTOR2);
85+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**************************************************************************/
2+
/* openxr_hand_interaction_extension.h */
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+
31+
#pragma once
32+
33+
#include "openxr_extension_wrapper.h"
34+
35+
class OpenXRAndroidMouseInteractionExtension : public OpenXRExtensionWrapper {
36+
GDCLASS(OpenXRAndroidMouseInteractionExtension, OpenXRExtensionWrapper);
37+
38+
protected:
39+
static void _bind_methods() {}
40+
41+
public:
42+
static OpenXRAndroidMouseInteractionExtension *get_singleton();
43+
44+
OpenXRAndroidMouseInteractionExtension();
45+
virtual ~OpenXRAndroidMouseInteractionExtension() override;
46+
47+
virtual HashMap<String, bool *> get_requested_extensions(XrVersion p_version) override;
48+
49+
bool is_available();
50+
51+
virtual void on_register_metadata() override;
52+
53+
private:
54+
static OpenXRAndroidMouseInteractionExtension *singleton;
55+
56+
bool available = false;
57+
};

modules/openxr/openxr_interface.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "openxr_interface.h"
3232

33+
#include "extensions/openxr_android_mouse_interaction_extension.h"
3334
#include "extensions/openxr_eye_gaze_interaction.h"
3435
#include "extensions/openxr_hand_interaction_extension.h"
3536
#include "extensions/openxr_performance_settings_extension.h"
@@ -114,6 +115,7 @@ void OpenXRInterface::_bind_methods() {
114115

115116
ClassDB::bind_method(D_METHOD("is_hand_tracking_supported"), &OpenXRInterface::is_hand_tracking_supported);
116117
ClassDB::bind_method(D_METHOD("is_hand_interaction_supported"), &OpenXRInterface::is_hand_interaction_supported);
118+
ClassDB::bind_method(D_METHOD("is_mouse_interaction_supported"), &OpenXRInterface::is_mouse_interaction_supported);
117119
ClassDB::bind_method(D_METHOD("is_eye_gaze_interaction_supported"), &OpenXRInterface::is_eye_gaze_interaction_supported);
118120

119121
// VRS
@@ -906,6 +908,21 @@ bool OpenXRInterface::is_hand_interaction_supported() const {
906908
}
907909
}
908910

911+
bool OpenXRInterface::is_mouse_interaction_supported() const {
912+
if (openxr_api == nullptr) {
913+
return false;
914+
} else if (!openxr_api->is_initialized()) {
915+
return false;
916+
} else {
917+
OpenXRAndroidMouseInteractionExtension *mouse_interaction_ext = OpenXRAndroidMouseInteractionExtension ::get_singleton();
918+
if (mouse_interaction_ext == nullptr) {
919+
return false;
920+
} else {
921+
return mouse_interaction_ext->is_available();
922+
}
923+
}
924+
}
925+
909926
bool OpenXRInterface::is_eye_gaze_interaction_supported() {
910927
if (openxr_api == nullptr) {
911928
return false;

modules/openxr/openxr_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class OpenXRInterface : public XRInterface {
137137

138138
bool is_hand_tracking_supported();
139139
bool is_hand_interaction_supported() const;
140+
bool is_mouse_interaction_supported() const;
140141
bool is_eye_gaze_interaction_supported();
141142

142143
bool initialize_on_startup() const;

modules/openxr/register_types.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#endif
5858
#include "scene/openxr_visibility_mask.h"
5959

60+
#include "extensions/openxr_android_mouse_interaction_extension.h"
6061
#include "extensions/openxr_android_thread_settings_extension.h"
6162
#include "extensions/openxr_composition_layer_depth_extension.h"
6263
#include "extensions/openxr_composition_layer_extension.h"
@@ -174,6 +175,7 @@ void initialize_openxr_module(ModuleInitializationLevel p_level) {
174175
OpenXRAPI::register_extension_wrapper(memnew(OpenXRMetaControllerExtension));
175176
OpenXRAPI::register_extension_wrapper(memnew(OpenXREyeGazeInteractionExtension));
176177
OpenXRAPI::register_extension_wrapper(memnew(OpenXRHandInteractionExtension));
178+
OpenXRAPI::register_extension_wrapper(memnew(OpenXRAndroidMouseInteractionExtension));
177179
OpenXRAPI::register_extension_wrapper(memnew(OpenXRMxInkExtension));
178180
OpenXRAPI::register_extension_wrapper(memnew(OpenXRVisibilityMaskExtension));
179181
OpenXRAPI::register_extension_wrapper(memnew(OpenXRPerformanceSettingsExtension));

0 commit comments

Comments
 (0)