2023-01-05 12:25:55 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* openxr_interface.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. */
|
|
|
|
/**************************************************************************/
|
2021-12-14 01:44:12 +00:00
|
|
|
|
|
|
|
#ifndef OPENXR_INTERFACE_H
|
|
|
|
#define OPENXR_INTERFACE_H
|
|
|
|
|
|
|
|
#include "action_map/openxr_action_map.h"
|
2023-06-13 14:56:21 +00:00
|
|
|
#include "extensions/openxr_fb_passthrough_extension_wrapper.h"
|
2023-10-03 11:38:43 +00:00
|
|
|
#include "extensions/openxr_hand_tracking_extension.h"
|
2021-12-14 01:44:12 +00:00
|
|
|
#include "openxr_api.h"
|
|
|
|
|
2023-06-13 14:56:21 +00:00
|
|
|
#include "servers/xr/xr_interface.h"
|
|
|
|
#include "servers/xr/xr_positional_tracker.h"
|
2022-09-26 07:04:12 +00:00
|
|
|
|
2022-03-05 10:09:21 +00:00
|
|
|
// declare some default strings
|
|
|
|
#define INTERACTION_PROFILE_NONE "/interaction_profiles/none"
|
|
|
|
|
2021-12-14 01:44:12 +00:00
|
|
|
class OpenXRInterface : public XRInterface {
|
|
|
|
GDCLASS(OpenXRInterface, XRInterface);
|
|
|
|
|
|
|
|
private:
|
|
|
|
OpenXRAPI *openxr_api = nullptr;
|
|
|
|
bool initialized = false;
|
|
|
|
XRInterface::TrackingStatus tracking_state;
|
2022-09-26 07:04:12 +00:00
|
|
|
OpenXRFbPassthroughExtensionWrapper *passthrough_wrapper = nullptr;
|
2021-12-14 01:44:12 +00:00
|
|
|
|
|
|
|
// At a minimum we need a tracker for our head
|
|
|
|
Ref<XRPositionalTracker> head;
|
|
|
|
Transform3D head_transform;
|
|
|
|
Vector3 head_linear_velocity;
|
|
|
|
Vector3 head_angular_velocity;
|
2023-10-03 11:38:43 +00:00
|
|
|
XRPose::TrackingConfidence head_confidence;
|
2021-12-14 01:44:12 +00:00
|
|
|
Transform3D transform_for_view[2]; // We currently assume 2, but could be 4 for VARJO which we do not support yet
|
|
|
|
|
|
|
|
void _load_action_map();
|
|
|
|
|
2022-03-05 10:09:21 +00:00
|
|
|
struct Action { // An action we've registered with OpenXR
|
|
|
|
String action_name; // Name of our action as presented to Godot (can be altered from the action map)
|
|
|
|
OpenXRAction::ActionType action_type; // The action type of this action
|
|
|
|
RID action_rid; // RID of the action registered with our OpenXR API
|
2021-12-14 01:44:12 +00:00
|
|
|
};
|
2022-03-05 10:09:21 +00:00
|
|
|
struct ActionSet { // An action set we've registered with OpenXR
|
|
|
|
String action_set_name; // Name of our action set
|
|
|
|
bool is_active; // If true this action set is active and we will sync it
|
|
|
|
Vector<Action *> actions; // List of actions in this action set
|
|
|
|
RID action_set_rid; // RID of the action registered with our OpenXR API
|
2021-12-14 01:44:12 +00:00
|
|
|
};
|
2022-03-05 10:09:21 +00:00
|
|
|
struct Tracker { // A tracker we've registered with OpenXR
|
|
|
|
String tracker_name; // Name of our tracker (can be altered from the action map)
|
|
|
|
Vector<Action *> actions; // Actions related to this tracker
|
|
|
|
Ref<XRPositionalTracker> positional_tracker; // Our positional tracker object that holds our tracker state
|
|
|
|
RID tracker_rid; // RID of the tracker registered with our OpenXR API
|
|
|
|
RID interaction_profile; // RID of the interaction profile bound to this tracker (can be null)
|
2021-12-14 01:44:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector<ActionSet *> action_sets;
|
2022-03-05 10:09:21 +00:00
|
|
|
Vector<RID> interaction_profiles;
|
2021-12-14 01:44:12 +00:00
|
|
|
Vector<Tracker *> trackers;
|
|
|
|
|
|
|
|
ActionSet *create_action_set(const String &p_action_set_name, const String &p_localized_name, const int p_priority);
|
|
|
|
void free_action_sets();
|
|
|
|
|
2022-03-05 10:09:21 +00:00
|
|
|
Action *create_action(ActionSet *p_action_set, const String &p_action_name, const String &p_localized_name, OpenXRAction::ActionType p_action_type, const Vector<Tracker *> p_trackers);
|
2021-12-14 01:44:12 +00:00
|
|
|
Action *find_action(const String &p_action_name);
|
|
|
|
void free_actions(ActionSet *p_action_set);
|
|
|
|
|
2022-03-05 10:09:21 +00:00
|
|
|
Tracker *find_tracker(const String &p_tracker_name, bool p_create = false);
|
2021-12-14 01:44:12 +00:00
|
|
|
void handle_tracker(Tracker *p_tracker);
|
|
|
|
void free_trackers();
|
|
|
|
|
2022-03-05 10:09:21 +00:00
|
|
|
void free_interaction_profiles();
|
|
|
|
|
2021-12-14 01:44:12 +00:00
|
|
|
void _set_default_pos(Transform3D &p_transform, double p_world_scale, uint64_t p_eye);
|
|
|
|
|
2023-10-03 11:38:43 +00:00
|
|
|
void handle_hand_tracking(const String &p_path, OpenXRHandTrackingExtension::HandTrackedHands p_hand);
|
|
|
|
|
2021-12-14 01:44:12 +00:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual StringName get_name() const override;
|
|
|
|
virtual uint32_t get_capabilities() const override;
|
|
|
|
|
2022-03-05 10:09:21 +00:00
|
|
|
virtual PackedStringArray get_suggested_tracker_names() const override;
|
2021-12-14 01:44:12 +00:00
|
|
|
virtual TrackingStatus get_tracking_status() const override;
|
|
|
|
|
2023-06-08 02:05:20 +00:00
|
|
|
bool is_eye_gaze_interaction_supported();
|
|
|
|
|
2022-03-24 11:10:43 +00:00
|
|
|
bool initialize_on_startup() const;
|
2021-12-14 01:44:12 +00:00
|
|
|
virtual bool is_initialized() const override;
|
|
|
|
virtual bool initialize() override;
|
|
|
|
virtual void uninitialize() override;
|
2023-03-13 01:26:10 +00:00
|
|
|
virtual Dictionary get_system_info() override;
|
2021-12-14 01:44:12 +00:00
|
|
|
|
|
|
|
virtual void trigger_haptic_pulse(const String &p_action_name, const StringName &p_tracker_name, double p_frequency, double p_amplitude, double p_duration_sec, double p_delay_sec = 0) override;
|
|
|
|
|
|
|
|
virtual bool supports_play_area_mode(XRInterface::PlayAreaMode p_mode) override;
|
|
|
|
virtual XRInterface::PlayAreaMode get_play_area_mode() const override;
|
|
|
|
virtual bool set_play_area_mode(XRInterface::PlayAreaMode p_mode) override;
|
|
|
|
|
2022-10-10 07:51:53 +00:00
|
|
|
float get_display_refresh_rate() const;
|
|
|
|
void set_display_refresh_rate(float p_refresh_rate);
|
|
|
|
Array get_available_display_refresh_rates() const;
|
|
|
|
|
2023-01-30 23:20:19 +00:00
|
|
|
bool is_action_set_active(const String &p_action_set) const;
|
|
|
|
void set_action_set_active(const String &p_action_set, bool p_active);
|
|
|
|
Array get_action_sets() const;
|
|
|
|
|
2023-02-18 15:50:55 +00:00
|
|
|
double get_render_target_size_multiplier() const;
|
|
|
|
void set_render_target_size_multiplier(double multiplier);
|
|
|
|
|
2023-08-21 07:45:28 +00:00
|
|
|
bool is_foveation_supported() const;
|
|
|
|
|
|
|
|
int get_foveation_level() const;
|
|
|
|
void set_foveation_level(int p_foveation_level);
|
|
|
|
|
|
|
|
bool get_foveation_dynamic() const;
|
|
|
|
void set_foveation_dynamic(bool p_foveation_dynamic);
|
|
|
|
|
2021-12-14 01:44:12 +00:00
|
|
|
virtual Size2 get_render_target_size() override;
|
|
|
|
virtual uint32_t get_view_count() override;
|
|
|
|
virtual Transform3D get_camera_transform() override;
|
|
|
|
virtual Transform3D get_transform_for_view(uint32_t p_view, const Transform3D &p_cam_transform) override;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-19 23:11:13 +00:00
|
|
|
virtual Projection get_projection_for_view(uint32_t p_view, double p_aspect, double p_z_near, double p_z_far) override;
|
2021-12-14 01:44:12 +00:00
|
|
|
|
2022-09-01 08:10:53 +00:00
|
|
|
virtual RID get_color_texture() override;
|
|
|
|
virtual RID get_depth_texture() override;
|
|
|
|
|
2021-12-14 01:44:12 +00:00
|
|
|
virtual void process() override;
|
|
|
|
virtual void pre_render() override;
|
|
|
|
bool pre_draw_viewport(RID p_render_target) override;
|
|
|
|
virtual Vector<BlitToScreen> post_draw_viewport(RID p_render_target, const Rect2 &p_screen_rect) override;
|
|
|
|
virtual void end_frame() override;
|
|
|
|
|
2022-09-26 07:04:12 +00:00
|
|
|
virtual bool is_passthrough_supported() override;
|
|
|
|
virtual bool is_passthrough_enabled() override;
|
|
|
|
virtual bool start_passthrough() override;
|
|
|
|
virtual void stop_passthrough() override;
|
|
|
|
|
2023-02-02 14:14:16 +00:00
|
|
|
/** environment blend mode. */
|
|
|
|
virtual Array get_supported_environment_blend_modes() override;
|
2023-09-12 02:39:48 +00:00
|
|
|
virtual XRInterface::EnvironmentBlendMode get_environment_blend_mode() const override;
|
2023-02-02 14:14:16 +00:00
|
|
|
virtual bool set_environment_blend_mode(XRInterface::EnvironmentBlendMode mode) override;
|
|
|
|
|
2022-03-05 10:09:21 +00:00
|
|
|
void on_state_ready();
|
|
|
|
void on_state_visible();
|
|
|
|
void on_state_focused();
|
|
|
|
void on_state_stopping();
|
|
|
|
void on_pose_recentered();
|
|
|
|
void tracker_profile_changed(RID p_tracker, RID p_interaction_profile);
|
|
|
|
|
2023-06-09 04:19:53 +00:00
|
|
|
/** Hand tracking. */
|
|
|
|
enum Hand {
|
|
|
|
HAND_LEFT,
|
|
|
|
HAND_RIGHT,
|
|
|
|
HAND_MAX,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum HandMotionRange {
|
|
|
|
HAND_MOTION_RANGE_UNOBSTRUCTED,
|
|
|
|
HAND_MOTION_RANGE_CONFORM_TO_CONTROLLER,
|
|
|
|
HAND_MOTION_RANGE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
void set_motion_range(const Hand p_hand, const HandMotionRange p_motion_range);
|
|
|
|
HandMotionRange get_motion_range(const Hand p_hand) const;
|
|
|
|
|
|
|
|
enum HandJoints {
|
|
|
|
HAND_JOINT_PALM = 0,
|
|
|
|
HAND_JOINT_WRIST = 1,
|
|
|
|
HAND_JOINT_THUMB_METACARPAL = 2,
|
|
|
|
HAND_JOINT_THUMB_PROXIMAL = 3,
|
|
|
|
HAND_JOINT_THUMB_DISTAL = 4,
|
|
|
|
HAND_JOINT_THUMB_TIP = 5,
|
|
|
|
HAND_JOINT_INDEX_METACARPAL = 6,
|
|
|
|
HAND_JOINT_INDEX_PROXIMAL = 7,
|
|
|
|
HAND_JOINT_INDEX_INTERMEDIATE = 8,
|
|
|
|
HAND_JOINT_INDEX_DISTAL = 9,
|
|
|
|
HAND_JOINT_INDEX_TIP = 10,
|
|
|
|
HAND_JOINT_MIDDLE_METACARPAL = 11,
|
|
|
|
HAND_JOINT_MIDDLE_PROXIMAL = 12,
|
|
|
|
HAND_JOINT_MIDDLE_INTERMEDIATE = 13,
|
|
|
|
HAND_JOINT_MIDDLE_DISTAL = 14,
|
|
|
|
HAND_JOINT_MIDDLE_TIP = 15,
|
|
|
|
HAND_JOINT_RING_METACARPAL = 16,
|
|
|
|
HAND_JOINT_RING_PROXIMAL = 17,
|
|
|
|
HAND_JOINT_RING_INTERMEDIATE = 18,
|
|
|
|
HAND_JOINT_RING_DISTAL = 19,
|
|
|
|
HAND_JOINT_RING_TIP = 20,
|
|
|
|
HAND_JOINT_LITTLE_METACARPAL = 21,
|
|
|
|
HAND_JOINT_LITTLE_PROXIMAL = 22,
|
|
|
|
HAND_JOINT_LITTLE_INTERMEDIATE = 23,
|
|
|
|
HAND_JOINT_LITTLE_DISTAL = 24,
|
|
|
|
HAND_JOINT_LITTLE_TIP = 25,
|
|
|
|
HAND_JOINT_MAX = 26,
|
|
|
|
};
|
|
|
|
|
|
|
|
Quaternion get_hand_joint_rotation(Hand p_hand, HandJoints p_joint) const;
|
|
|
|
Vector3 get_hand_joint_position(Hand p_hand, HandJoints p_joint) const;
|
|
|
|
float get_hand_joint_radius(Hand p_hand, HandJoints p_joint) const;
|
|
|
|
|
|
|
|
Vector3 get_hand_joint_linear_velocity(Hand p_hand, HandJoints p_joint) const;
|
|
|
|
Vector3 get_hand_joint_angular_velocity(Hand p_hand, HandJoints p_joint) const;
|
|
|
|
|
2021-12-14 01:44:12 +00:00
|
|
|
OpenXRInterface();
|
|
|
|
~OpenXRInterface();
|
|
|
|
};
|
|
|
|
|
2023-06-09 04:19:53 +00:00
|
|
|
VARIANT_ENUM_CAST(OpenXRInterface::Hand)
|
|
|
|
VARIANT_ENUM_CAST(OpenXRInterface::HandMotionRange)
|
|
|
|
VARIANT_ENUM_CAST(OpenXRInterface::HandJoints)
|
|
|
|
|
2022-07-23 21:41:51 +00:00
|
|
|
#endif // OPENXR_INTERFACE_H
|