1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Rework XR Trackers to have a common ancestor. Allow creation of XRNode3D to drive node positions and visibility.

This commit is contained in:
Malcolm Nixon
2024-04-13 17:26:46 -04:00
parent 3b1806182a
commit 823ae7b3fa
49 changed files with 769 additions and 636 deletions

View File

@@ -31,23 +31,13 @@
#include "xr_positional_tracker.h"
#include "core/input/input.h"
#include "xr_controller_tracker.h"
void XRPositionalTracker::_bind_methods() {
BIND_ENUM_CONSTANT(TRACKER_HAND_UNKNOWN);
BIND_ENUM_CONSTANT(TRACKER_HAND_LEFT);
BIND_ENUM_CONSTANT(TRACKER_HAND_RIGHT);
ClassDB::bind_method(D_METHOD("get_tracker_type"), &XRPositionalTracker::get_tracker_type);
ClassDB::bind_method(D_METHOD("set_tracker_type", "type"), &XRPositionalTracker::set_tracker_type);
ADD_PROPERTY(PropertyInfo(Variant::INT, "type"), "set_tracker_type", "get_tracker_type");
ClassDB::bind_method(D_METHOD("get_tracker_name"), &XRPositionalTracker::get_tracker_name);
ClassDB::bind_method(D_METHOD("set_tracker_name", "name"), &XRPositionalTracker::set_tracker_name);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "name"), "set_tracker_name", "get_tracker_name");
ClassDB::bind_method(D_METHOD("get_tracker_desc"), &XRPositionalTracker::get_tracker_desc);
ClassDB::bind_method(D_METHOD("set_tracker_desc", "description"), &XRPositionalTracker::set_tracker_desc);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "description"), "set_tracker_desc", "get_tracker_desc");
BIND_ENUM_CONSTANT(TRACKER_HAND_MAX);
ClassDB::bind_method(D_METHOD("get_tracker_profile"), &XRPositionalTracker::get_tracker_profile);
ClassDB::bind_method(D_METHOD("set_tracker_profile", "profile"), &XRPositionalTracker::set_tracker_profile);
@@ -73,34 +63,6 @@ void XRPositionalTracker::_bind_methods() {
ADD_SIGNAL(MethodInfo("profile_changed", PropertyInfo(Variant::STRING, "role")));
};
void XRPositionalTracker::set_tracker_type(XRServer::TrackerType p_type) {
if (type != p_type) {
type = p_type;
hand = XRPositionalTracker::TRACKER_HAND_UNKNOWN;
};
};
XRServer::TrackerType XRPositionalTracker::get_tracker_type() const {
return type;
};
void XRPositionalTracker::set_tracker_name(const StringName &p_name) {
// Note: this should not be changed after the tracker is registered with the XRServer!
name = p_name;
};
StringName XRPositionalTracker::get_tracker_name() const {
return name;
};
void XRPositionalTracker::set_tracker_desc(const String &p_desc) {
description = p_desc;
}
String XRPositionalTracker::get_tracker_desc() const {
return description;
}
void XRPositionalTracker::set_tracker_profile(const String &p_profile) {
if (profile != p_profile) {
profile = p_profile;
@@ -114,19 +76,12 @@ String XRPositionalTracker::get_tracker_profile() const {
}
XRPositionalTracker::TrackerHand XRPositionalTracker::get_tracker_hand() const {
return hand;
return tracker_hand;
};
void XRPositionalTracker::set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand) {
XRServer *xr_server = XRServer::get_singleton();
ERR_FAIL_NULL(xr_server);
if (hand != p_hand) {
// we can only set this if we've previously set this to be a controller!!
ERR_FAIL_COND((type != XRServer::TRACKER_CONTROLLER) && (p_hand != XRPositionalTracker::TRACKER_HAND_UNKNOWN));
hand = p_hand;
};
ERR_FAIL_INDEX(p_hand, TRACKER_HAND_MAX);
tracker_hand = p_hand;
};
bool XRPositionalTracker::has_pose(const StringName &p_action_name) const {
@@ -177,6 +132,11 @@ void XRPositionalTracker::set_pose(const StringName &p_action_name, const Transf
}
Variant XRPositionalTracker::get_input(const StringName &p_action_name) const {
// Complain if this method is called on a XRPositionalTracker instance.
if (!dynamic_cast<const XRControllerTracker *>(this)) {
WARN_DEPRECATED_MSG(R"*(The "get_input()" method is deprecated, use "XRControllerTracker" instead.)*");
}
if (inputs.has(p_action_name)) {
return inputs[p_action_name];
} else {
@@ -185,10 +145,13 @@ Variant XRPositionalTracker::get_input(const StringName &p_action_name) const {
}
void XRPositionalTracker::set_input(const StringName &p_action_name, const Variant &p_value) {
bool changed = false;
// Complain if this method is called on a XRPositionalTracker instance.
if (!dynamic_cast<XRControllerTracker *>(this)) {
WARN_DEPRECATED_MSG(R"*(The "set_input()" method is deprecated, use "XRControllerTracker" instead.)*");
}
// XR inputs
bool changed;
if (inputs.has(p_action_name)) {
changed = inputs[p_action_name] != p_value;
} else {
@@ -227,9 +190,3 @@ void XRPositionalTracker::set_input(const StringName &p_action_name, const Varia
}
}
}
XRPositionalTracker::XRPositionalTracker() {
type = XRServer::TRACKER_UNKNOWN;
name = "Unknown";
hand = TRACKER_HAND_UNKNOWN;
};