Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenXR: Add support for binding modifiers #97140

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3114,6 +3114,12 @@
<member name="threading/worker_pool/max_threads" type="int" setter="" getter="" default="-1">
Maximum number of threads to be used by [WorkerThreadPool]. Value of [code]-1[/code] means no limit.
</member>
<member name="xr/openxr/binding_modifiers/analog_threshold" type="bool" setter="" getter="" default="false">
If [code]true[/code], enables the analog threshold binding modifier if supported by the XR runtime.
</member>
<member name="xr/openxr/binding_modifiers/dpad_binding" type="bool" setter="" getter="" default="false">
If [code]true[/code], enables the D-pad binding modifier if supported by the XR runtime.
</member>
<member name="xr/openxr/default_action_map" type="String" setter="" getter="" default="&quot;res://openxr_action_map.tres&quot;">
Action map configuration to load by default.
</member>
Expand Down
1 change: 1 addition & 0 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4459,6 +4459,7 @@ void EditorInspector::_notification(int p_what) {
} break;

case NOTIFICATION_READY: {
ERR_FAIL_NULL(EditorFeatureProfileManager::get_singleton());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that CI testing runs through this, and we're not fully setting up the editor, we need to exit here as the EditorFeatureProfileManager singleton does not get constructed.

EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &EditorInspector::_feature_profile_changed));
set_process(is_visible_in_tree());
add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));
Expand Down
1 change: 1 addition & 0 deletions editor/icons/Modifiers.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2630,7 +2630,11 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
GLOBAL_DEF_BASIC("xr/openxr/extensions/hand_tracking_unobstructed_data_source", false); // XR_HAND_TRACKING_DATA_SOURCE_UNOBSTRUCTED_EXT
GLOBAL_DEF_BASIC("xr/openxr/extensions/hand_tracking_controller_data_source", false); // XR_HAND_TRACKING_DATA_SOURCE_CONTROLLER_EXT
GLOBAL_DEF_RST_BASIC("xr/openxr/extensions/hand_interaction_profile", false);
GLOBAL_DEF_BASIC("xr/openxr/extensions/eye_gaze_interaction", false);
GLOBAL_DEF_RST_BASIC("xr/openxr/extensions/eye_gaze_interaction", false);

// OpenXR Binding modifier settings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// OpenXR Binding modifier settings
// OpenXR Binding modifier settings.

GLOBAL_DEF_BASIC("xr/openxr/binding_modifiers/analog_threshold", false);
GLOBAL_DEF_RST_BASIC("xr/openxr/binding_modifiers/dpad_binding", false);

#ifdef TOOLS_ENABLED
// Disabled for now, using XR inside of the editor we'll be working on during the coming months.
Expand Down
46 changes: 32 additions & 14 deletions modules/openxr/action_map/openxr_action_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,25 @@ void OpenXRActionMap::remove_action_set(Ref<OpenXRActionSet> p_action_set) {
}
}

void OpenXRActionMap::set_interaction_profiles(Array p_interaction_profiles) {
void OpenXRActionMap::clear_interaction_profiles() {
if (interaction_profiles.is_empty()) {
return;
}

// Interaction profiles held within our action map set should be released and destroyed but just in case they are still used some where else.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Interaction profiles held within our action map set should be released and destroyed but just in case they are still used some where else.
// Interaction profiles held within our action map set should be released and destroyed but just in case they are still used somewhere else.

for (Ref<OpenXRInteractionProfile> interaction_profile : interaction_profiles) {
interaction_profile->action_map = nullptr;
}
interaction_profiles.clear();
emit_changed();
}

for (int i = 0; i < p_interaction_profiles.size(); i++) {
Ref<OpenXRInteractionProfile> interaction_profile = p_interaction_profiles[i];
if (interaction_profile.is_valid() && !interaction_profiles.has(interaction_profile)) {
interaction_profiles.push_back(interaction_profile);
}
void OpenXRActionMap::set_interaction_profiles(Array p_interaction_profiles) {
clear_interaction_profiles();

for (const Variant &interaction_profile : p_interaction_profiles) {
// Add them anew so we verify our interaction profile pointer.
add_interaction_profile(interaction_profile);
}
}

Expand All @@ -127,8 +138,7 @@ int OpenXRActionMap::get_interaction_profile_count() const {
}

Ref<OpenXRInteractionProfile> OpenXRActionMap::find_interaction_profile(String p_path) const {
for (int i = 0; i < interaction_profiles.size(); i++) {
Ref<OpenXRInteractionProfile> interaction_profile = interaction_profiles[i];
for (Ref<OpenXRInteractionProfile> interaction_profile : interaction_profiles) {
if (interaction_profile->get_interaction_profile_path() == p_path) {
return interaction_profile;
}
Expand All @@ -147,6 +157,13 @@ void OpenXRActionMap::add_interaction_profile(Ref<OpenXRInteractionProfile> p_in
ERR_FAIL_COND(p_interaction_profile.is_null());

if (!interaction_profiles.has(p_interaction_profile)) {
if (p_interaction_profile->action_map && p_interaction_profile->action_map != this) {
// Interaction profiles should only relate to our action map.
p_interaction_profile->action_map->remove_interaction_profile(p_interaction_profile);
}

p_interaction_profile->action_map = this;

interaction_profiles.push_back(p_interaction_profile);
emit_changed();
}
Expand All @@ -156,6 +173,10 @@ void OpenXRActionMap::remove_interaction_profile(Ref<OpenXRInteractionProfile> p
int idx = interaction_profiles.find(p_interaction_profile);
if (idx != -1) {
interaction_profiles.remove_at(idx);

ERR_FAIL_COND_MSG(p_interaction_profile->action_map != this, "Removing interaction profile that belongs to this action map but had incorrect action map pointer."); // This should never happen!
p_interaction_profile->action_map = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to call p_interaction_profile->action_map->remove_interaction_profile(p_interaction_profile) before you reset the action_map?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the design is that an interaction profile always belongs to a single action map. The action_map member is only null momentarily in 2 conditions:

  1. when we're creating a new interaction profile right before it's added to an action map
  2. when we're destructing an interaction profile where it's remove from the action map just before.

The check to see if the actionmap pointer is different is just to catch errors in usage, someone who later on adds code that would attempt to add an interaction profile to multiple action maps, and these checks just erroring out.


emit_changed();
}
}
Expand Down Expand Up @@ -549,9 +570,7 @@ Ref<OpenXRAction> OpenXRActionMap::get_action(const String p_path) const {
void OpenXRActionMap::remove_action(const String p_path, bool p_remove_interaction_profiles) {
Ref<OpenXRAction> action = get_action(p_path);
if (action.is_valid()) {
for (int i = 0; i < interaction_profiles.size(); i++) {
Ref<OpenXRInteractionProfile> interaction_profile = interaction_profiles[i];

for (Ref<OpenXRInteractionProfile> interaction_profile : interaction_profiles) {
if (p_remove_interaction_profiles) {
// Remove any bindings for this action
interaction_profile->remove_binding_for_action(action);
Expand All @@ -571,8 +590,7 @@ void OpenXRActionMap::remove_action(const String p_path, bool p_remove_interacti
PackedStringArray OpenXRActionMap::get_top_level_paths(const Ref<OpenXRAction> p_action) {
PackedStringArray arr;

for (int i = 0; i < interaction_profiles.size(); i++) {
Ref<OpenXRInteractionProfile> ip = interaction_profiles[i];
for (Ref<OpenXRInteractionProfile> ip : interaction_profiles) {
const OpenXRInteractionProfileMetadata::InteractionProfile *profile = OpenXRInteractionProfileMetadata::get_singleton()->get_profile(ip->get_interaction_profile_path());

if (profile != nullptr) {
Expand All @@ -598,5 +616,5 @@ PackedStringArray OpenXRActionMap::get_top_level_paths(const Ref<OpenXRAction> p

OpenXRActionMap::~OpenXRActionMap() {
action_sets.clear();
interaction_profiles.clear();
clear_interaction_profiles();
}
1 change: 1 addition & 0 deletions modules/openxr/action_map/openxr_action_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class OpenXRActionMap : public Resource {
void add_action_set(Ref<OpenXRActionSet> p_action_set); // Add an action set to our action map
void remove_action_set(Ref<OpenXRActionSet> p_action_set); // Remove an action set from our action map

void clear_interaction_profiles(); // Remove all our interaction profiles
void set_interaction_profiles(Array p_interaction_profiles); // Set our interaction profiles by providing an array (for loading from resource)
Array get_interaction_profiles() const; // Get our interaction profiles as an array (for saving to resource)

Expand Down
2 changes: 1 addition & 1 deletion modules/openxr/action_map/openxr_action_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void OpenXRActionSet::remove_action(Ref<OpenXRAction> p_action) {
if (idx != -1) {
actions.remove_at(idx);

ERR_FAIL_COND_MSG(p_action->action_set != this, "Removing action that belongs to this action set but had incorrect action set pointer."); // this should never happen!
ERR_FAIL_COND_MSG(p_action->action_set != this, "Removing action that belongs to this action set but had incorrect action set pointer."); // This should never happen!
p_action->action_set = nullptr;

emit_changed();
Expand Down
52 changes: 52 additions & 0 deletions modules/openxr/action_map/openxr_binding_modifier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**************************************************************************/
/* openxr_binding_modifier.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 "openxr_binding_modifier.h"

void OpenXRBindingModifier::_bind_methods() {
GDVIRTUAL_BIND(_get_description);
GDVIRTUAL_BIND(_get_ip_modification);
}

String OpenXRBindingModifier::get_description() const {
String desc;
if (GDVIRTUAL_CALL(_get_description, desc)) {
return desc;
}
return "";
}

PackedByteArray OpenXRBindingModifier::get_ip_modification() {
PackedByteArray data;
if (GDVIRTUAL_CALL(_get_ip_modification, data)) {
return data;
}
return PackedByteArray();
}
81 changes: 81 additions & 0 deletions modules/openxr/action_map/openxr_binding_modifier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**************************************************************************/
/* openxr_binding_modifier.h */
/**************************************************************************/
/* 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. */
/**************************************************************************/

#ifndef OPENXR_BINDING_MODIFIER_H
#define OPENXR_BINDING_MODIFIER_H

#include "../action_map/openxr_action.h"
#include "core/io/resource.h"

// Part of implementation for:
// https://registry.khronos.org/OpenXR/specs/1.1/html/xrspec.html#XR_KHR_binding_modification

class OpenXRInteractionProfile;
class OpenXRIPBinding;

class OpenXRBindingModifier : public Resource {
GDCLASS(OpenXRBindingModifier, Resource);

protected:
static void _bind_methods();

GDVIRTUAL0RC_REQUIRED(String, _get_description)
GDVIRTUAL0R_REQUIRED(PackedByteArray, _get_ip_modification)

public:
virtual String get_description() const; // Returns the description shown in the editor
virtual PackedByteArray get_ip_modification(); // Return the XrBindingModificationsKHR binding modifier struct data used when calling xrSuggestInteractionProfileBindings
};

class OpenXRIPBindingModifier : public OpenXRBindingModifier {
GDCLASS(OpenXRIPBindingModifier, OpenXRBindingModifier);

protected:
friend class OpenXRInteractionProfile;

OpenXRInteractionProfile *interaction_profile = nullptr; // action belongs to this interaction profile

public:
OpenXRInteractionProfile *get_interaction_profile() const { return interaction_profile; }
};

class OpenXRActionBindingModifier : public OpenXRBindingModifier {
GDCLASS(OpenXRActionBindingModifier, OpenXRBindingModifier);

protected:
friend class OpenXRIPBinding;

OpenXRIPBinding *ip_binding = nullptr; // action belongs to this binding

public:
OpenXRIPBinding *get_ip_binding() const { return ip_binding; }
};

#endif // OPENXR_BINDING_MODIFIER_H
93 changes: 93 additions & 0 deletions modules/openxr/action_map/openxr_haptic_feedback.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**************************************************************************/
/* openxr_haptic_feedback.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 "openxr_haptic_feedback.h"

////////////////////////////////////////////////////////////////////////////
// OpenXRHapticBase

void OpenXRHapticBase::_bind_methods() {
}

////////////////////////////////////////////////////////////////////////////
// OpenXRHapticVibration

void OpenXRHapticVibration::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_duration", "duration"), &OpenXRHapticVibration::set_duration);
ClassDB::bind_method(D_METHOD("get_duration"), &OpenXRHapticVibration::get_duration);
ADD_PROPERTY(PropertyInfo(Variant::INT, "duration"), "set_duration", "get_duration");

ClassDB::bind_method(D_METHOD("set_frequency", "frequency"), &OpenXRHapticVibration::set_frequency);
ClassDB::bind_method(D_METHOD("get_frequency"), &OpenXRHapticVibration::get_frequency);
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "frequency"), "set_frequency", "get_frequency");

ClassDB::bind_method(D_METHOD("set_amplitude", "amplitude"), &OpenXRHapticVibration::set_amplitude);
ClassDB::bind_method(D_METHOD("get_amplitude"), &OpenXRHapticVibration::get_amplitude);
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "amplitude", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_amplitude", "get_amplitude");
}

void OpenXRHapticVibration::set_duration(int64_t p_duration) {
haptic_vibration.duration = p_duration;
emit_changed();
}

int64_t OpenXRHapticVibration::get_duration() const {
return haptic_vibration.duration;
}

void OpenXRHapticVibration::set_frequency(float p_frequency) {
haptic_vibration.frequency = p_frequency;
emit_changed();
}

float OpenXRHapticVibration::get_frequency() const {
return haptic_vibration.frequency;
}

void OpenXRHapticVibration::set_amplitude(float p_amplitude) {
haptic_vibration.amplitude = p_amplitude;
emit_changed();
}

float OpenXRHapticVibration::get_amplitude() const {
return haptic_vibration.amplitude;
}

const XrHapticBaseHeader *OpenXRHapticVibration::get_xr_structure() {
return (XrHapticBaseHeader *)&haptic_vibration;
}

OpenXRHapticVibration::OpenXRHapticVibration() {
haptic_vibration.type = XR_TYPE_HAPTIC_VIBRATION;
haptic_vibration.next = nullptr;
haptic_vibration.duration = -1;
haptic_vibration.frequency = 0.0;
haptic_vibration.amplitude = 1.0;
}
Loading