Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/xr/xr_interface.cpp
10277 views
1
/**************************************************************************/
2
/* xr_interface.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "xr_interface.h"
32
33
void XRInterface::_bind_methods() {
34
ADD_SIGNAL(MethodInfo("play_area_changed", PropertyInfo(Variant::INT, "mode")));
35
36
ClassDB::bind_method(D_METHOD("get_name"), &XRInterface::get_name);
37
ClassDB::bind_method(D_METHOD("get_capabilities"), &XRInterface::get_capabilities);
38
39
ClassDB::bind_method(D_METHOD("is_primary"), &XRInterface::is_primary);
40
ClassDB::bind_method(D_METHOD("set_primary", "primary"), &XRInterface::set_primary);
41
42
ClassDB::bind_method(D_METHOD("is_initialized"), &XRInterface::is_initialized);
43
ClassDB::bind_method(D_METHOD("initialize"), &XRInterface::initialize);
44
ClassDB::bind_method(D_METHOD("uninitialize"), &XRInterface::uninitialize);
45
ClassDB::bind_method(D_METHOD("get_system_info"), &XRInterface::get_system_info);
46
47
ClassDB::bind_method(D_METHOD("get_tracking_status"), &XRInterface::get_tracking_status);
48
49
ClassDB::bind_method(D_METHOD("get_render_target_size"), &XRInterface::get_render_target_size);
50
ClassDB::bind_method(D_METHOD("get_view_count"), &XRInterface::get_view_count);
51
52
ClassDB::bind_method(D_METHOD("trigger_haptic_pulse", "action_name", "tracker_name", "frequency", "amplitude", "duration_sec", "delay_sec"), &XRInterface::trigger_haptic_pulse);
53
54
ADD_GROUP("Interface", "interface_");
55
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interface_is_primary"), "set_primary", "is_primary");
56
57
// methods and properties specific to VR...
58
ClassDB::bind_method(D_METHOD("supports_play_area_mode", "mode"), &XRInterface::supports_play_area_mode);
59
ClassDB::bind_method(D_METHOD("get_play_area_mode"), &XRInterface::get_play_area_mode);
60
ClassDB::bind_method(D_METHOD("set_play_area_mode", "mode"), &XRInterface::set_play_area_mode);
61
ClassDB::bind_method(D_METHOD("get_play_area"), &XRInterface::get_play_area);
62
63
ADD_GROUP("XR", "xr_");
64
ADD_PROPERTY(PropertyInfo(Variant::INT, "xr_play_area_mode", PROPERTY_HINT_ENUM, "Unknown,3DOF,Sitting,Roomscale,Stage"), "set_play_area_mode", "get_play_area_mode");
65
66
// methods and properties specific to AR....
67
ClassDB::bind_method(D_METHOD("get_anchor_detection_is_enabled"), &XRInterface::get_anchor_detection_is_enabled);
68
ClassDB::bind_method(D_METHOD("set_anchor_detection_is_enabled", "enable"), &XRInterface::set_anchor_detection_is_enabled);
69
ClassDB::bind_method(D_METHOD("get_camera_feed_id"), &XRInterface::get_camera_feed_id);
70
71
ClassDB::bind_method(D_METHOD("is_passthrough_supported"), &XRInterface::is_passthrough_supported);
72
ClassDB::bind_method(D_METHOD("is_passthrough_enabled"), &XRInterface::is_passthrough_enabled);
73
ClassDB::bind_method(D_METHOD("start_passthrough"), &XRInterface::start_passthrough);
74
ClassDB::bind_method(D_METHOD("stop_passthrough"), &XRInterface::stop_passthrough);
75
ClassDB::bind_method(D_METHOD("get_transform_for_view", "view", "cam_transform"), &XRInterface::get_transform_for_view);
76
ClassDB::bind_method(D_METHOD("get_projection_for_view", "view", "aspect", "near", "far"), &XRInterface::get_projection_for_view);
77
78
/** environment blend mode. */
79
ClassDB::bind_method(D_METHOD("get_supported_environment_blend_modes"), &XRInterface::get_supported_environment_blend_modes);
80
ClassDB::bind_method(D_METHOD("set_environment_blend_mode", "mode"), &XRInterface::set_environment_blend_mode);
81
ClassDB::bind_method(D_METHOD("get_environment_blend_mode"), &XRInterface::get_environment_blend_mode);
82
ADD_PROPERTY(PropertyInfo(Variant::INT, "environment_blend_mode"), "set_environment_blend_mode", "get_environment_blend_mode");
83
84
ADD_GROUP("AR", "ar_");
85
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ar_is_anchor_detection_enabled"), "set_anchor_detection_is_enabled", "get_anchor_detection_is_enabled");
86
87
BIND_ENUM_CONSTANT(XR_NONE);
88
BIND_ENUM_CONSTANT(XR_MONO);
89
BIND_ENUM_CONSTANT(XR_STEREO);
90
BIND_ENUM_CONSTANT(XR_QUAD);
91
BIND_ENUM_CONSTANT(XR_VR);
92
BIND_ENUM_CONSTANT(XR_AR);
93
BIND_ENUM_CONSTANT(XR_EXTERNAL);
94
95
BIND_ENUM_CONSTANT(XR_NORMAL_TRACKING);
96
BIND_ENUM_CONSTANT(XR_EXCESSIVE_MOTION);
97
BIND_ENUM_CONSTANT(XR_INSUFFICIENT_FEATURES);
98
BIND_ENUM_CONSTANT(XR_UNKNOWN_TRACKING);
99
BIND_ENUM_CONSTANT(XR_NOT_TRACKING);
100
101
BIND_ENUM_CONSTANT(XR_PLAY_AREA_UNKNOWN);
102
BIND_ENUM_CONSTANT(XR_PLAY_AREA_3DOF);
103
BIND_ENUM_CONSTANT(XR_PLAY_AREA_SITTING);
104
BIND_ENUM_CONSTANT(XR_PLAY_AREA_ROOMSCALE);
105
BIND_ENUM_CONSTANT(XR_PLAY_AREA_STAGE);
106
BIND_ENUM_CONSTANT(XR_PLAY_AREA_CUSTOM);
107
108
BIND_ENUM_CONSTANT(XR_ENV_BLEND_MODE_OPAQUE);
109
BIND_ENUM_CONSTANT(XR_ENV_BLEND_MODE_ADDITIVE);
110
BIND_ENUM_CONSTANT(XR_ENV_BLEND_MODE_ALPHA_BLEND);
111
112
BIND_ENUM_CONSTANT(XR_VRS_TEXTURE_FORMAT_UNIFIED);
113
BIND_ENUM_CONSTANT(XR_VRS_TEXTURE_FORMAT_FRAGMENT_SHADING_RATE);
114
BIND_ENUM_CONSTANT(XR_VRS_TEXTURE_FORMAT_FRAGMENT_DENSITY_MAP);
115
}
116
117
bool XRInterface::is_primary() {
118
XRServer *xr_server = XRServer::get_singleton();
119
ERR_FAIL_NULL_V(xr_server, false);
120
121
return xr_server->get_primary_interface() == this;
122
}
123
124
void XRInterface::set_primary(bool p_primary) {
125
XRServer *xr_server = XRServer::get_singleton();
126
ERR_FAIL_NULL(xr_server);
127
128
if (p_primary) {
129
ERR_FAIL_COND(!is_initialized());
130
131
xr_server->set_primary_interface(this);
132
} else if (xr_server->get_primary_interface() == this) {
133
xr_server->set_primary_interface(nullptr);
134
}
135
}
136
137
XRInterface::XRInterface() {}
138
139
XRInterface::~XRInterface() {}
140
141
// query if this interface supports this play area mode
142
bool XRInterface::supports_play_area_mode(XRInterface::PlayAreaMode p_mode) {
143
return p_mode == XR_PLAY_AREA_UNKNOWN;
144
}
145
146
// get the current play area mode
147
XRInterface::PlayAreaMode XRInterface::get_play_area_mode() const {
148
return XR_PLAY_AREA_UNKNOWN;
149
}
150
151
// change the play area mode, note that this should return false if the mode is not available
152
bool XRInterface::set_play_area_mode(XRInterface::PlayAreaMode p_mode) {
153
return p_mode == XR_PLAY_AREA_UNKNOWN;
154
}
155
156
// if available, returns an array of vectors denoting the play area the player can move around in
157
PackedVector3Array XRInterface::get_play_area() const {
158
// Return an empty array by default.
159
// Note implementation is responsible for applying our reference frame and world scale to the raw data.
160
// `play_area_changed` should be emitted if play area data is available and either the reference frame or world scale changes.
161
return PackedVector3Array();
162
}
163
164
/** these will only be implemented on AR interfaces, so we want dummies for VR **/
165
bool XRInterface::get_anchor_detection_is_enabled() const {
166
return false;
167
}
168
169
void XRInterface::set_anchor_detection_is_enabled(bool p_enable) {
170
}
171
172
int XRInterface::get_camera_feed_id() {
173
return 0;
174
}
175
176
RID XRInterface::get_vrs_texture() {
177
return RID();
178
}
179
180
/** these are optional, so we want dummies **/
181
182
RID XRInterface::get_color_texture() {
183
return RID();
184
}
185
186
RID XRInterface::get_depth_texture() {
187
return RID();
188
}
189
190
RID XRInterface::get_velocity_texture() {
191
return RID();
192
}
193
194
RID XRInterface::get_velocity_depth_texture() {
195
return RID();
196
}
197
198
Size2i XRInterface::get_velocity_target_size() {
199
return Size2i();
200
}
201
202
Rect2i XRInterface::get_render_region() {
203
return Rect2i();
204
}
205
206
PackedStringArray XRInterface::get_suggested_tracker_names() const {
207
PackedStringArray arr;
208
209
return arr;
210
}
211
212
PackedStringArray XRInterface::get_suggested_pose_names(const StringName &p_tracker_name) const {
213
PackedStringArray arr;
214
215
return arr;
216
}
217
218
XRInterface::TrackingStatus XRInterface::get_tracking_status() const {
219
return XR_UNKNOWN_TRACKING;
220
}
221
222
void XRInterface::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) {
223
}
224
225
Array XRInterface::get_supported_environment_blend_modes() {
226
Array default_blend_modes = { XR_ENV_BLEND_MODE_OPAQUE };
227
return default_blend_modes;
228
}
229
230