From e00e5c03866be37bfe77ff66948d59a7a08bb0d2 Mon Sep 17 00:00:00 2001 From: Malcolm Nixon Date: Wed, 24 Apr 2024 19:57:57 -0400 Subject: [PATCH] Remove the Hand enum from XRHandTracker to fix name-collision with the hand property of the base class. Co-Authored-By: David Snopek <191561+dsnopek@users.noreply.github.com> --- doc/classes/XRHandTracker.xml | 23 +------- .../openxr_hand_tracking_extension.cpp | 2 +- modules/webxr/webxr_interface_js.cpp | 2 +- servers/xr/xr_hand_tracker.cpp | 52 ++----------------- servers/xr/xr_hand_tracker.h | 11 ---- 5 files changed, 6 insertions(+), 84 deletions(-) diff --git a/doc/classes/XRHandTracker.xml b/doc/classes/XRHandTracker.xml index 69390df696b8..636af6625bde 100644 --- a/doc/classes/XRHandTracker.xml +++ b/doc/classes/XRHandTracker.xml @@ -11,12 +11,6 @@ $DOCS_URL/tutorials/xr/index.html - - - - Returns the type of hand. - - @@ -52,13 +46,6 @@ Returns the transform for the given hand joint. - - - - - Sets the type of hand. - - @@ -101,6 +88,7 @@ + The source of the hand tracking data. @@ -110,15 +98,6 @@ - - A left hand. - - - A right hand. - - - Represents the size of the [enum Hand] enum. - The source of hand tracking data is unknown. diff --git a/modules/openxr/extensions/openxr_hand_tracking_extension.cpp b/modules/openxr/extensions/openxr_hand_tracking_extension.cpp index f8cc3d1d8cf7..12fa3bed7e88 100644 --- a/modules/openxr/extensions/openxr_hand_tracking_extension.cpp +++ b/modules/openxr/extensions/openxr_hand_tracking_extension.cpp @@ -195,7 +195,7 @@ void OpenXRHandTrackingExtension::on_process() { Ref godot_tracker; godot_tracker.instantiate(); - godot_tracker->set_hand(i == 0 ? XRHandTracker::HAND_LEFT : XRHandTracker::HAND_RIGHT); + godot_tracker->set_tracker_hand(i == 0 ? XRPositionalTracker::TRACKER_HAND_LEFT : XRPositionalTracker::TRACKER_HAND_RIGHT); godot_tracker->set_tracker_name(i == 0 ? "/user/hand_tracker/left" : "/user/hand_tracker/right"); XRServer::get_singleton()->add_tracker(godot_tracker); hand_trackers[i].godot_tracker = godot_tracker; diff --git a/modules/webxr/webxr_interface_js.cpp b/modules/webxr/webxr_interface_js.cpp index 535d464d6fc6..45c1d8ec0678 100644 --- a/modules/webxr/webxr_interface_js.cpp +++ b/modules/webxr/webxr_interface_js.cpp @@ -713,7 +713,7 @@ void WebXRInterfaceJS::_update_input_source(int p_input_source_id) { if (unlikely(hand_tracker.is_null())) { hand_tracker.instantiate(); - hand_tracker->set_hand(p_input_source_id == 0 ? XRHandTracker::HAND_LEFT : XRHandTracker::HAND_RIGHT); + hand_tracker->set_tracker_hand(p_input_source_id == 0 ? XRPositionalTracker::TRACKER_HAND_LEFT : XRPositionalTracker::TRACKER_HAND_RIGHT); hand_tracker->set_tracker_name(p_input_source_id == 0 ? "/user/hand_tracker/left" : "/user/hand_tracker/right"); // These flags always apply, since WebXR doesn't give us enough insight to be more fine grained. diff --git a/servers/xr/xr_hand_tracker.cpp b/servers/xr/xr_hand_tracker.cpp index cb0fbfb35f01..abfe2e986755 100644 --- a/servers/xr/xr_hand_tracker.cpp +++ b/servers/xr/xr_hand_tracker.cpp @@ -33,9 +33,6 @@ #include "xr_body_tracker.h" void XRHandTracker::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_hand", "hand"), &XRHandTracker::set_hand); - ClassDB::bind_method(D_METHOD("get_hand"), &XRHandTracker::get_hand); - ClassDB::bind_method(D_METHOD("set_has_tracking_data", "has_data"), &XRHandTracker::set_has_tracking_data); ClassDB::bind_method(D_METHOD("get_has_tracking_data"), &XRHandTracker::get_has_tracking_data); @@ -60,10 +57,6 @@ void XRHandTracker::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "has_tracking_data", PROPERTY_HINT_NONE), "set_has_tracking_data", "get_has_tracking_data"); ADD_PROPERTY(PropertyInfo(Variant::INT, "hand_tracking_source", PROPERTY_HINT_ENUM, "Unknown,Unobstructed,Controller"), "set_hand_tracking_source", "get_hand_tracking_source"); - BIND_ENUM_CONSTANT(HAND_LEFT); - BIND_ENUM_CONSTANT(HAND_RIGHT); - BIND_ENUM_CONSTANT(HAND_MAX); - BIND_ENUM_CONSTANT(HAND_TRACKING_SOURCE_UNKNOWN); BIND_ENUM_CONSTANT(HAND_TRACKING_SOURCE_UNOBSTRUCTED); BIND_ENUM_CONSTANT(HAND_TRACKING_SOURCE_CONTROLLER); @@ -110,48 +103,8 @@ void XRHandTracker::set_tracker_type(XRServer::TrackerType p_type) { } void XRHandTracker::set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand) { - ERR_FAIL_INDEX(p_hand, TRACKER_HAND_MAX); - - switch (p_hand) { - case TRACKER_HAND_LEFT: - tracker_hand = TRACKER_HAND_LEFT; - hand = HAND_LEFT; - break; - - case TRACKER_HAND_RIGHT: - tracker_hand = TRACKER_HAND_RIGHT; - hand = HAND_RIGHT; - break; - - case TRACKER_HAND_UNKNOWN: - default: - ERR_FAIL_MSG("XRHandTracker must specify hand"); - break; - } -} - -void XRHandTracker::set_hand(XRHandTracker::Hand p_hand) { - ERR_FAIL_INDEX(p_hand, HAND_MAX); - - switch (p_hand) { - case HAND_LEFT: - tracker_hand = TRACKER_HAND_LEFT; - hand = HAND_LEFT; - break; - - case HAND_RIGHT: - tracker_hand = TRACKER_HAND_RIGHT; - hand = HAND_RIGHT; - break; - - default: - ERR_FAIL_MSG("XRHandTracker must specify hand"); - break; - } -} - -XRHandTracker::Hand XRHandTracker::get_hand() const { - return hand; + ERR_FAIL_COND_MSG(p_hand != TRACKER_HAND_LEFT && p_hand != TRACKER_HAND_RIGHT, "XRHandTracker must specify hand."); + tracker_hand = p_hand; } void XRHandTracker::set_has_tracking_data(bool p_has_tracking_data) { @@ -222,4 +175,5 @@ Vector3 XRHandTracker::get_hand_joint_angular_velocity(XRHandTracker::HandJoint XRHandTracker::XRHandTracker() { type = XRServer::TRACKER_HAND; + tracker_hand = TRACKER_HAND_LEFT; } diff --git a/servers/xr/xr_hand_tracker.h b/servers/xr/xr_hand_tracker.h index 8ef3c229c312..c7c18a31f8a1 100644 --- a/servers/xr/xr_hand_tracker.h +++ b/servers/xr/xr_hand_tracker.h @@ -38,12 +38,6 @@ class XRHandTracker : public XRPositionalTracker { _THREAD_SAFE_CLASS_ public: - enum Hand { - HAND_LEFT, - HAND_RIGHT, - HAND_MAX, - }; - enum HandTrackingSource { HAND_TRACKING_SOURCE_UNKNOWN, HAND_TRACKING_SOURCE_UNOBSTRUCTED, @@ -93,9 +87,6 @@ class XRHandTracker : public XRPositionalTracker { void set_tracker_type(XRServer::TrackerType p_type) override; void set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand) override; - void set_hand(Hand p_hand); - Hand get_hand() const; - void set_has_tracking_data(bool p_has_tracking_data); bool get_has_tracking_data() const; @@ -123,7 +114,6 @@ class XRHandTracker : public XRPositionalTracker { static void _bind_methods(); private: - Hand hand = HAND_LEFT; bool has_tracking_data = false; HandTrackingSource hand_tracking_source = HAND_TRACKING_SOURCE_UNKNOWN; @@ -134,7 +124,6 @@ class XRHandTracker : public XRPositionalTracker { Vector3 hand_joint_angular_velocities[HAND_JOINT_MAX]; }; -VARIANT_ENUM_CAST(XRHandTracker::Hand) VARIANT_ENUM_CAST(XRHandTracker::HandTrackingSource) VARIANT_ENUM_CAST(XRHandTracker::HandJoint) VARIANT_BITFIELD_CAST(XRHandTracker::HandJointFlags)