summaryrefslogtreecommitdiffstats
path: root/servers/xr
diff options
context:
space:
mode:
authorMalcolm Nixon <Malcolm.nixon@gmail.com>2024-04-13 17:26:46 -0400
committerMalcolm Nixon <Malcolm.nixon@gmail.com>2024-04-18 20:04:01 -0400
commit823ae7b3fa25832d1cd9d7613c650bfc712d1f49 (patch)
tree36a0c75dd36faf7c15cf81a78267f71c62b3009e /servers/xr
parent3b1806182a3564736ad64793b203c2c13c251f56 (diff)
downloadredot-engine-823ae7b3fa25832d1cd9d7613c650bfc712d1f49.tar.gz
Rework XR Trackers to have a common ancestor. Allow creation of XRNode3D to drive node positions and visibility.
Diffstat (limited to 'servers/xr')
-rw-r--r--servers/xr/xr_body_tracker.cpp12
-rw-r--r--servers/xr/xr_body_tracker.h11
-rw-r--r--servers/xr/xr_controller_tracker.cpp39
-rw-r--r--servers/xr/xr_controller_tracker.h52
-rw-r--r--servers/xr/xr_face_tracker.cpp8
-rw-r--r--servers/xr/xr_face_tracker.h10
-rw-r--r--servers/xr/xr_hand_tracker.cpp50
-rw-r--r--servers/xr/xr_hand_tracker.h11
-rw-r--r--servers/xr/xr_positional_tracker.cpp73
-rw-r--r--servers/xr/xr_positional_tracker.h28
-rw-r--r--servers/xr/xr_tracker.cpp70
-rw-r--r--servers/xr/xr_tracker.h61
12 files changed, 337 insertions, 88 deletions
diff --git a/servers/xr/xr_body_tracker.cpp b/servers/xr/xr_body_tracker.cpp
index cd58c14348..9c82b80911 100644
--- a/servers/xr/xr_body_tracker.cpp
+++ b/servers/xr/xr_body_tracker.cpp
@@ -134,6 +134,14 @@ void XRBodyTracker::_bind_methods() {
BIND_BITFIELD_FLAG(JOINT_FLAG_POSITION_TRACKED);
}
+void XRBodyTracker::set_tracker_type(XRServer::TrackerType p_type) {
+ ERR_FAIL_COND_MSG(p_type != XRServer::TRACKER_BODY, "XRBodyTracker must be of type TRACKER_BODY.");
+}
+
+void XRBodyTracker::set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand) {
+ ERR_FAIL_COND_MSG(p_hand != XRPositionalTracker::TRACKER_HAND_UNKNOWN, "XRBodyTracker cannot specify hand.");
+}
+
void XRBodyTracker::set_has_tracking_data(bool p_has_tracking_data) {
has_tracking_data = p_has_tracking_data;
}
@@ -169,3 +177,7 @@ Transform3D XRBodyTracker::get_joint_transform(Joint p_joint) const {
ERR_FAIL_INDEX_V(p_joint, JOINT_MAX, Transform3D());
return joint_transforms[p_joint];
}
+
+XRBodyTracker::XRBodyTracker() {
+ type = XRServer::TRACKER_BODY;
+}
diff --git a/servers/xr/xr_body_tracker.h b/servers/xr/xr_body_tracker.h
index 659aa39df1..544de8ca8b 100644
--- a/servers/xr/xr_body_tracker.h
+++ b/servers/xr/xr_body_tracker.h
@@ -31,10 +31,10 @@
#ifndef XR_BODY_TRACKER_H
#define XR_BODY_TRACKER_H
-#include "core/object/ref_counted.h"
+#include "servers/xr/xr_positional_tracker.h"
-class XRBodyTracker : public RefCounted {
- GDCLASS(XRBodyTracker, RefCounted);
+class XRBodyTracker : public XRPositionalTracker {
+ GDCLASS(XRBodyTracker, XRPositionalTracker);
_THREAD_SAFE_CLASS_
public:
@@ -140,6 +140,9 @@ public:
JOINT_FLAG_POSITION_TRACKED = 8,
};
+ void set_tracker_type(XRServer::TrackerType p_type) override;
+ void set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand) override;
+
void set_has_tracking_data(bool p_has_tracking_data);
bool get_has_tracking_data() const;
@@ -152,6 +155,8 @@ public:
void set_joint_transform(Joint p_joint, const Transform3D &p_transform);
Transform3D get_joint_transform(Joint p_joint) const;
+ XRBodyTracker();
+
protected:
static void _bind_methods();
diff --git a/servers/xr/xr_controller_tracker.cpp b/servers/xr/xr_controller_tracker.cpp
new file mode 100644
index 0000000000..df85e86b7e
--- /dev/null
+++ b/servers/xr/xr_controller_tracker.cpp
@@ -0,0 +1,39 @@
+/**************************************************************************/
+/* xr_controller_tracker.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 "xr_controller_tracker.h"
+
+#include "core/input/input.h"
+
+void XRControllerTracker::_bind_methods(){};
+
+XRControllerTracker::XRControllerTracker() {
+ type = XRServer::TRACKER_CONTROLLER;
+}
diff --git a/servers/xr/xr_controller_tracker.h b/servers/xr/xr_controller_tracker.h
new file mode 100644
index 0000000000..a443cc1fd8
--- /dev/null
+++ b/servers/xr/xr_controller_tracker.h
@@ -0,0 +1,52 @@
+/**************************************************************************/
+/* xr_controller_tracker.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 XR_CONTROLLER_TRACKER_H
+#define XR_CONTROLLER_TRACKER_H
+
+#include "core/os/thread_safe.h"
+#include "servers/xr/xr_positional_tracker.h"
+
+/**
+ The controller tracker object as an object that represents the position and orientation of a controller.
+*/
+
+class XRControllerTracker : public XRPositionalTracker {
+ GDCLASS(XRControllerTracker, XRPositionalTracker);
+ _THREAD_SAFE_CLASS_
+
+protected:
+ static void _bind_methods();
+
+public:
+ XRControllerTracker();
+};
+
+#endif // XR_CONTROLLER_TRACKER_H
diff --git a/servers/xr/xr_face_tracker.cpp b/servers/xr/xr_face_tracker.cpp
index a38ccfd527..7015cd0805 100644
--- a/servers/xr/xr_face_tracker.cpp
+++ b/servers/xr/xr_face_tracker.cpp
@@ -187,6 +187,10 @@ void XRFaceTracker::_bind_methods() {
ADD_PROPERTY_DEFAULT("blend_shapes", PackedFloat32Array()); // To prevent ludicrously large default values.
}
+void XRFaceTracker::set_tracker_type(XRServer::TrackerType p_type) {
+ ERR_FAIL_COND_MSG(p_type != XRServer::TRACKER_FACE, "XRFaceTracker must be of type TRACKER_FACE.");
+}
+
float XRFaceTracker::get_blend_shape(BlendShapeEntry p_blend_shape) const {
// Fail if the blend shape index is out of range.
ERR_FAIL_INDEX_V(p_blend_shape, FT_MAX, 0.0f);
@@ -220,3 +224,7 @@ void XRFaceTracker::set_blend_shapes(const PackedFloat32Array &p_blend_shapes) {
// Copy the blend shape values into the blend shape array.
memcpy(blend_shape_values, p_blend_shapes.ptr(), sizeof(blend_shape_values));
}
+
+XRFaceTracker::XRFaceTracker() {
+ type = XRServer::TRACKER_FACE;
+}
diff --git a/servers/xr/xr_face_tracker.h b/servers/xr/xr_face_tracker.h
index b9f553cba6..a753a7abdc 100644
--- a/servers/xr/xr_face_tracker.h
+++ b/servers/xr/xr_face_tracker.h
@@ -31,7 +31,7 @@
#ifndef XR_FACE_TRACKER_H
#define XR_FACE_TRACKER_H
-#include "core/object/ref_counted.h"
+#include "servers/xr/xr_tracker.h"
/**
The XRFaceTracker class provides face blend shape weights.
@@ -41,8 +41,8 @@
and Meta Movement standards.
*/
-class XRFaceTracker : public RefCounted {
- GDCLASS(XRFaceTracker, RefCounted);
+class XRFaceTracker : public XRTracker {
+ GDCLASS(XRFaceTracker, XRTracker);
_THREAD_SAFE_CLASS_
public:
@@ -195,12 +195,16 @@ public:
FT_MAX // Maximum blend shape.
};
+ void set_tracker_type(XRServer::TrackerType p_type) override;
+
float get_blend_shape(BlendShapeEntry p_blend_shape) const;
void set_blend_shape(BlendShapeEntry p_blend_shape, float p_value);
PackedFloat32Array get_blend_shapes() const;
void set_blend_shapes(const PackedFloat32Array &p_blend_shapes);
+ XRFaceTracker();
+
protected:
static void _bind_methods();
diff --git a/servers/xr/xr_hand_tracker.cpp b/servers/xr/xr_hand_tracker.cpp
index 8cc2d5f7d2..cb0fbfb35f 100644
--- a/servers/xr/xr_hand_tracker.cpp
+++ b/servers/xr/xr_hand_tracker.cpp
@@ -30,6 +30,8 @@
#include "xr_hand_tracker.h"
+#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);
@@ -55,7 +57,6 @@ void XRHandTracker::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_hand_joint_angular_velocity", "joint", "angular_velocity"), &XRHandTracker::set_hand_joint_angular_velocity);
ClassDB::bind_method(D_METHOD("get_hand_joint_angular_velocity", "joint"), &XRHandTracker::get_hand_joint_angular_velocity);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "hand", PROPERTY_HINT_ENUM, "Left,Right"), "set_hand", "get_hand");
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");
@@ -104,8 +105,49 @@ void XRHandTracker::_bind_methods() {
BIND_BITFIELD_FLAG(HAND_JOINT_FLAG_ANGULAR_VELOCITY_VALID);
}
+void XRHandTracker::set_tracker_type(XRServer::TrackerType p_type) {
+ ERR_FAIL_COND_MSG(p_type != XRServer::TRACKER_HAND, "XRHandTracker must be of type TRACKER_HAND.");
+}
+
+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) {
- 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 {
@@ -177,3 +219,7 @@ Vector3 XRHandTracker::get_hand_joint_angular_velocity(XRHandTracker::HandJoint
ERR_FAIL_INDEX_V(p_joint, HAND_JOINT_MAX, Vector3());
return hand_joint_angular_velocities[p_joint];
}
+
+XRHandTracker::XRHandTracker() {
+ type = XRServer::TRACKER_HAND;
+}
diff --git a/servers/xr/xr_hand_tracker.h b/servers/xr/xr_hand_tracker.h
index 648f02d1f8..8ef3c229c3 100644
--- a/servers/xr/xr_hand_tracker.h
+++ b/servers/xr/xr_hand_tracker.h
@@ -31,10 +31,10 @@
#ifndef XR_HAND_TRACKER_H
#define XR_HAND_TRACKER_H
-#include "core/object/ref_counted.h"
+#include "servers/xr/xr_positional_tracker.h"
-class XRHandTracker : public RefCounted {
- GDCLASS(XRHandTracker, RefCounted);
+class XRHandTracker : public XRPositionalTracker {
+ GDCLASS(XRHandTracker, XRPositionalTracker);
_THREAD_SAFE_CLASS_
public:
@@ -90,6 +90,9 @@ public:
HAND_JOINT_FLAG_ANGULAR_VELOCITY_VALID = 32,
};
+ 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;
@@ -114,6 +117,8 @@ public:
void set_hand_joint_angular_velocity(HandJoint p_joint, const Vector3 &p_velocity);
Vector3 get_hand_joint_angular_velocity(HandJoint p_joint) const;
+ XRHandTracker();
+
protected:
static void _bind_methods();
diff --git a/servers/xr/xr_positional_tracker.cpp b/servers/xr/xr_positional_tracker.cpp
index 6c15e4c1b0..b479237730 100644
--- a/servers/xr/xr_positional_tracker.cpp
+++ b/servers/xr/xr_positional_tracker.cpp
@@ -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;
-};
diff --git a/servers/xr/xr_positional_tracker.h b/servers/xr/xr_positional_tracker.h
index d8939b4582..9e4e4d1cc3 100644
--- a/servers/xr/xr_positional_tracker.h
+++ b/servers/xr/xr_positional_tracker.h
@@ -34,6 +34,7 @@
#include "core/os/thread_safe.h"
#include "scene/resources/mesh.h"
#include "servers/xr/xr_pose.h"
+#include "servers/xr/xr_tracker.h"
#include "servers/xr_server.h"
/**
@@ -42,41 +43,33 @@
This is where potentially additional AR/VR interfaces may be active as there are AR/VR SDKs that solely deal with positional tracking.
*/
-class XRPositionalTracker : public RefCounted {
- GDCLASS(XRPositionalTracker, RefCounted);
+class XRPositionalTracker : public XRTracker {
+ GDCLASS(XRPositionalTracker, XRTracker);
_THREAD_SAFE_CLASS_
public:
enum TrackerHand {
TRACKER_HAND_UNKNOWN, /* unknown or not applicable */
TRACKER_HAND_LEFT, /* controller is the left hand controller */
- TRACKER_HAND_RIGHT /* controller is the right hand controller */
+ TRACKER_HAND_RIGHT, /* controller is the right hand controller */
+ TRACKER_HAND_MAX
};
-private:
- XRServer::TrackerType type; // type of tracker
- StringName name; // (unique) name of the tracker
- String description; // description of the tracker
+protected:
String profile; // this is interface dependent, for OpenXR this will be the interaction profile bound for to the tracker
- TrackerHand hand; // if known, the hand this tracker is held in
+ TrackerHand tracker_hand = TRACKER_HAND_UNKNOWN; // if known, the hand this tracker is held in
HashMap<StringName, Ref<XRPose>> poses;
HashMap<StringName, Variant> inputs;
-protected:
static void _bind_methods();
public:
- void set_tracker_type(XRServer::TrackerType p_type);
- XRServer::TrackerType get_tracker_type() const;
- void set_tracker_name(const StringName &p_name);
- StringName get_tracker_name() const;
- void set_tracker_desc(const String &p_desc);
- String get_tracker_desc() const;
void set_tracker_profile(const String &p_profile);
String get_tracker_profile() const;
+
XRPositionalTracker::TrackerHand get_tracker_hand() const;
- void set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand);
+ virtual void set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand);
bool has_pose(const StringName &p_action_name) const;
Ref<XRPose> get_pose(const StringName &p_action_name) const;
@@ -85,9 +78,6 @@ public:
Variant get_input(const StringName &p_action_name) const;
void set_input(const StringName &p_action_name, const Variant &p_value);
-
- XRPositionalTracker();
- ~XRPositionalTracker() {}
};
VARIANT_ENUM_CAST(XRPositionalTracker::TrackerHand);
diff --git a/servers/xr/xr_tracker.cpp b/servers/xr/xr_tracker.cpp
new file mode 100644
index 0000000000..0b917a5dc3
--- /dev/null
+++ b/servers/xr/xr_tracker.cpp
@@ -0,0 +1,70 @@
+/**************************************************************************/
+/* xr_tracker.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 "xr_tracker.h"
+
+void XRTracker::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("get_tracker_type"), &XRTracker::get_tracker_type);
+ ClassDB::bind_method(D_METHOD("set_tracker_type", "type"), &XRTracker::set_tracker_type);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "type"), "set_tracker_type", "get_tracker_type");
+
+ ClassDB::bind_method(D_METHOD("get_tracker_name"), &XRTracker::get_tracker_name);
+ ClassDB::bind_method(D_METHOD("set_tracker_name", "name"), &XRTracker::set_tracker_name);
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "name"), "set_tracker_name", "get_tracker_name");
+
+ ClassDB::bind_method(D_METHOD("get_tracker_desc"), &XRTracker::get_tracker_desc);
+ ClassDB::bind_method(D_METHOD("set_tracker_desc", "description"), &XRTracker::set_tracker_desc);
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "description"), "set_tracker_desc", "get_tracker_desc");
+};
+
+void XRTracker::set_tracker_type(XRServer::TrackerType p_type) {
+ type = p_type;
+};
+
+XRServer::TrackerType XRTracker::get_tracker_type() const {
+ return type;
+};
+
+void XRTracker::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 XRTracker::get_tracker_name() const {
+ return name;
+};
+
+void XRTracker::set_tracker_desc(const String &p_desc) {
+ description = p_desc;
+}
+
+String XRTracker::get_tracker_desc() const {
+ return description;
+}
diff --git a/servers/xr/xr_tracker.h b/servers/xr/xr_tracker.h
new file mode 100644
index 0000000000..3348e164d8
--- /dev/null
+++ b/servers/xr/xr_tracker.h
@@ -0,0 +1,61 @@
+/**************************************************************************/
+/* xr_tracker.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 XR_TRACKER_H
+#define XR_TRACKER_H
+
+#include "core/os/thread_safe.h"
+#include "servers/xr_server.h"
+
+/**
+ The XR tracker object is a common base for all different types of XR trackers.
+*/
+
+class XRTracker : public RefCounted {
+ GDCLASS(XRTracker, RefCounted);
+ _THREAD_SAFE_CLASS_
+
+protected:
+ XRServer::TrackerType type = XRServer::TRACKER_UNKNOWN; // type of tracker
+ StringName name = "Unknown"; // (unique) name of the tracker
+ String description; // description of the tracker
+
+ static void _bind_methods();
+
+public:
+ virtual void set_tracker_type(XRServer::TrackerType p_type);
+ XRServer::TrackerType get_tracker_type() const;
+ void set_tracker_name(const StringName &p_name);
+ StringName get_tracker_name() const;
+ void set_tracker_desc(const String &p_desc);
+ String get_tracker_desc() const;
+};
+
+#endif // XR_TRACKER_H