2017-04-23 12:10:41 +00:00
|
|
|
/**************************************************************************/
|
2020-04-08 14:47:36 +00:00
|
|
|
/* xr_nodes.h */
|
2017-04-23 12:10:41 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* 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. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
#ifndef XR_NODES_H
|
|
|
|
#define XR_NODES_H
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
#include "scene/3d/camera_3d.h"
|
2020-04-08 14:47:36 +00:00
|
|
|
#include "servers/xr/xr_positional_tracker.h"
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
/*
|
2020-04-08 14:47:36 +00:00
|
|
|
XRCamera is a subclass of camera which will register itself with its parent XROrigin and as a result is automatically positioned
|
2017-04-23 12:10:41 +00:00
|
|
|
*/
|
2022-01-04 19:26:22 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
class XRCamera3D : public Camera3D {
|
|
|
|
GDCLASS(XRCamera3D, Camera3D);
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
protected:
|
2021-08-29 06:05:11 +00:00
|
|
|
// The name and pose for our HMD tracker is currently the only hardcoded bit.
|
|
|
|
// If we ever are able to support multiple HMDs we may need to make this settable.
|
|
|
|
StringName tracker_name = "head";
|
|
|
|
StringName pose_name = "default";
|
|
|
|
Ref<XRPositionalTracker> tracker;
|
|
|
|
|
2022-07-29 04:18:05 +00:00
|
|
|
void _bind_tracker();
|
|
|
|
void _unbind_tracker();
|
2021-08-01 19:47:20 +00:00
|
|
|
void _changed_tracker(const StringName &p_tracker_name, int p_tracker_type);
|
|
|
|
void _removed_tracker(const StringName &p_tracker_name, int p_tracker_type);
|
2021-08-29 06:05:11 +00:00
|
|
|
void _pose_changed(const Ref<XRPose> &p_pose);
|
|
|
|
|
2017-04-23 12:10:41 +00:00
|
|
|
public:
|
2024-02-17 18:03:21 +00:00
|
|
|
PackedStringArray get_configuration_warnings() const override;
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual Vector3 project_local_ray_normal(const Point2 &p_pos) const override;
|
|
|
|
virtual Point2 unproject_position(const Vector3 &p_pos) const override;
|
2021-01-30 00:55:54 +00:00
|
|
|
virtual Vector3 project_position(const Point2 &p_point, real_t p_z_depth) const override;
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual Vector<Plane> get_frustum() const override;
|
2017-09-29 11:36:27 +00:00
|
|
|
|
2021-08-29 06:05:11 +00:00
|
|
|
XRCamera3D();
|
|
|
|
~XRCamera3D();
|
2017-04-23 12:10:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2021-08-29 06:05:11 +00:00
|
|
|
XRNode3D is a helper node that implements binding to a tracker.
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
It must be a child node of our XROrigin node
|
2017-04-23 12:10:41 +00:00
|
|
|
*/
|
|
|
|
|
2021-08-29 06:05:11 +00:00
|
|
|
class XRNode3D : public Node3D {
|
|
|
|
GDCLASS(XRNode3D, Node3D);
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
private:
|
2021-08-29 06:05:11 +00:00
|
|
|
StringName tracker_name;
|
|
|
|
StringName pose_name = "default";
|
2023-09-01 23:13:54 +00:00
|
|
|
bool has_tracking_data = false;
|
2024-04-13 21:26:46 +00:00
|
|
|
bool show_when_tracked = false;
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
protected:
|
2021-08-29 06:05:11 +00:00
|
|
|
Ref<XRPositionalTracker> tracker;
|
|
|
|
|
2017-04-23 12:10:41 +00:00
|
|
|
static void _bind_methods();
|
|
|
|
|
2021-08-29 06:05:11 +00:00
|
|
|
virtual void _bind_tracker();
|
|
|
|
virtual void _unbind_tracker();
|
2021-08-01 19:47:20 +00:00
|
|
|
void _changed_tracker(const StringName &p_tracker_name, int p_tracker_type);
|
|
|
|
void _removed_tracker(const StringName &p_tracker_name, int p_tracker_type);
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2021-08-29 06:05:11 +00:00
|
|
|
void _pose_changed(const Ref<XRPose> &p_pose);
|
2023-09-01 23:13:54 +00:00
|
|
|
void _pose_lost_tracking(const Ref<XRPose> &p_pose);
|
|
|
|
void _set_has_tracking_data(bool p_has_tracking_data);
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2024-08-05 05:39:27 +00:00
|
|
|
void _update_visibility();
|
|
|
|
|
2021-08-29 06:05:11 +00:00
|
|
|
public:
|
2022-08-12 20:57:11 +00:00
|
|
|
void _validate_property(PropertyInfo &p_property) const;
|
2021-08-01 19:47:20 +00:00
|
|
|
void set_tracker(const StringName &p_tracker_name);
|
2021-08-29 06:05:11 +00:00
|
|
|
StringName get_tracker() const;
|
|
|
|
|
2021-08-01 19:47:20 +00:00
|
|
|
void set_pose_name(const StringName &p_pose);
|
2021-08-29 06:05:11 +00:00
|
|
|
StringName get_pose_name() const;
|
2017-11-01 10:46:37 +00:00
|
|
|
|
2017-04-23 12:10:41 +00:00
|
|
|
bool get_is_active() const;
|
2021-08-29 06:05:11 +00:00
|
|
|
bool get_has_tracking_data() const;
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2024-04-13 21:26:46 +00:00
|
|
|
void set_show_when_tracked(bool p_show);
|
|
|
|
bool get_show_when_tracked() const;
|
|
|
|
|
2021-08-29 06:05:11 +00:00
|
|
|
void trigger_haptic_pulse(const String &p_action_name, double p_frequency, double p_amplitude, double p_duration_sec, double p_delay_sec = 0);
|
|
|
|
|
|
|
|
Ref<XRPose> get_pose();
|
2019-02-05 10:02:13 +00:00
|
|
|
|
2024-02-17 18:03:21 +00:00
|
|
|
PackedStringArray get_configuration_warnings() const override;
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2021-08-29 06:05:11 +00:00
|
|
|
XRNode3D();
|
|
|
|
~XRNode3D();
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
XRController3D is a helper node that automatically updates its position based on tracker data.
|
|
|
|
|
|
|
|
It must be a child node of our XROrigin node
|
|
|
|
*/
|
|
|
|
|
|
|
|
class XRController3D : public XRNode3D {
|
|
|
|
GDCLASS(XRController3D, XRNode3D);
|
|
|
|
|
|
|
|
private:
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
virtual void _bind_tracker() override;
|
|
|
|
virtual void _unbind_tracker() override;
|
|
|
|
|
|
|
|
void _button_pressed(const String &p_name);
|
|
|
|
void _button_released(const String &p_name);
|
2023-01-22 02:17:20 +00:00
|
|
|
void _input_float_changed(const String &p_name, float p_value);
|
|
|
|
void _input_vector2_changed(const String &p_name, Vector2 p_value);
|
2024-03-06 14:43:19 +00:00
|
|
|
void _profile_changed(const String &p_role);
|
2021-08-29 06:05:11 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
bool is_button_pressed(const StringName &p_name) const;
|
2023-01-22 02:17:20 +00:00
|
|
|
Variant get_input(const StringName &p_name) const;
|
|
|
|
float get_float(const StringName &p_name) const;
|
|
|
|
Vector2 get_vector2(const StringName &p_name) const;
|
2021-08-29 06:05:11 +00:00
|
|
|
|
|
|
|
XRPositionalTracker::TrackerHand get_tracker_hand() const;
|
|
|
|
|
2020-05-19 09:24:58 +00:00
|
|
|
XRController3D() {}
|
|
|
|
~XRController3D() {}
|
2017-04-23 12:10:41 +00:00
|
|
|
};
|
|
|
|
|
2017-08-03 08:58:05 +00:00
|
|
|
/*
|
2020-04-08 14:47:36 +00:00
|
|
|
XRAnchor3D is a helper node that automatically updates its position based on anchor data, it represents a real world location.
|
|
|
|
It must be a child node of our XROrigin3D node
|
2017-08-03 08:58:05 +00:00
|
|
|
*/
|
|
|
|
|
2021-08-29 06:05:11 +00:00
|
|
|
class XRAnchor3D : public XRNode3D {
|
|
|
|
GDCLASS(XRAnchor3D, XRNode3D);
|
2017-08-03 08:58:05 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Vector3 size;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
Vector3 get_size() const;
|
2017-09-29 11:36:27 +00:00
|
|
|
Plane get_plane() const;
|
|
|
|
|
2020-05-19 09:24:58 +00:00
|
|
|
XRAnchor3D() {}
|
|
|
|
~XRAnchor3D() {}
|
2017-08-03 08:58:05 +00:00
|
|
|
};
|
|
|
|
|
2017-04-23 12:10:41 +00:00
|
|
|
/*
|
2020-04-08 14:47:36 +00:00
|
|
|
XROrigin3D is special spatial node that acts as our origin point mapping our real world center of our tracking volume into our virtual world.
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
It is this point that you will move around the world as the player 'moves while standing still', i.e. the player moves through teleporting or controller inputs as opposed to physically moving.
|
|
|
|
|
|
|
|
Our camera and controllers will always be child nodes and thus place relative to this origin point.
|
2020-04-08 14:47:36 +00:00
|
|
|
This node will automatically locate any camera child nodes and update its position while our XRController3D node will handle tracked controllers.
|
2017-04-23 12:10:41 +00:00
|
|
|
*/
|
2022-01-04 19:26:22 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
class XROrigin3D : public Node3D {
|
|
|
|
GDCLASS(XROrigin3D, Node3D);
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
private:
|
2022-07-29 04:18:05 +00:00
|
|
|
bool current = false;
|
|
|
|
static Vector<XROrigin3D *> origin_nodes; // all origin nodes in tree
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2022-12-03 10:42:05 +00:00
|
|
|
void _set_current(bool p_enabled, bool p_update_others);
|
|
|
|
|
2017-04-23 12:10:41 +00:00
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2024-02-17 18:03:21 +00:00
|
|
|
PackedStringArray get_configuration_warnings() const override;
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2021-01-30 00:55:54 +00:00
|
|
|
real_t get_world_scale() const;
|
|
|
|
void set_world_scale(real_t p_world_scale);
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2022-07-29 04:18:05 +00:00
|
|
|
void set_current(bool p_enabled);
|
|
|
|
bool is_current() const;
|
|
|
|
|
2020-05-19 09:24:58 +00:00
|
|
|
XROrigin3D() {}
|
|
|
|
~XROrigin3D() {}
|
2017-04-23 12:10:41 +00:00
|
|
|
};
|
|
|
|
|
2022-01-04 19:26:22 +00:00
|
|
|
#endif // XR_NODES_H
|