1 /** 2 Base class for an AR/VR interface implementation. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.arvrinterface; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.reference; 24 /** 25 Base class for an AR/VR interface implementation. 26 27 This class needs to be implemented to make an AR or VR platform available to Godot and these should be implemented as C++ modules or GDNative modules (note that for GDNative the subclass ARVRScriptInterface should be used). Part of the interface is exposed to GDScript so you can detect, enable and configure an AR or VR platform. 28 Interfaces should be written in such a way that simply enabling them will give us a working setup. You can query the available interfaces through $(D ARVRServer). 29 */ 30 @GodotBaseClass struct ARVRInterface 31 { 32 package(godot) enum string _GODOT_internal_name = "ARVRInterface"; 33 public: 34 @nogc nothrow: 35 union { /** */ godot_object _godot_object; /** */ Reference _GODOT_base; } 36 alias _GODOT_base this; 37 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 38 package(godot) __gshared bool _classBindingInitialized = false; 39 package(godot) static struct GDNativeClassBinding 40 { 41 __gshared: 42 @GodotName("get_anchor_detection_is_enabled") GodotMethod!(bool) getAnchorDetectionIsEnabled; 43 @GodotName("get_camera_feed_id") GodotMethod!(long) getCameraFeedId; 44 @GodotName("get_capabilities") GodotMethod!(long) getCapabilities; 45 @GodotName("get_name") GodotMethod!(String) getName; 46 @GodotName("get_render_targetsize") GodotMethod!(Vector2) getRenderTargetsize; 47 @GodotName("get_tracking_status") GodotMethod!(ARVRInterface.Tracking_status) getTrackingStatus; 48 @GodotName("initialize") GodotMethod!(bool) initialize; 49 @GodotName("is_initialized") GodotMethod!(bool) isInitialized; 50 @GodotName("is_primary") GodotMethod!(bool) isPrimary; 51 @GodotName("is_stereo") GodotMethod!(bool) isStereo; 52 @GodotName("set_anchor_detection_is_enabled") GodotMethod!(void, bool) setAnchorDetectionIsEnabled; 53 @GodotName("set_is_initialized") GodotMethod!(void, bool) setIsInitialized; 54 @GodotName("set_is_primary") GodotMethod!(void, bool) setIsPrimary; 55 @GodotName("uninitialize") GodotMethod!(void) uninitialize; 56 } 57 /// 58 pragma(inline, true) bool opEquals(in ARVRInterface other) const 59 { return _godot_object.ptr is other._godot_object.ptr; } 60 /// 61 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 62 { _godot_object.ptr = n; return null; } 63 /// 64 pragma(inline, true) bool opEquals(typeof(null) n) const 65 { return _godot_object.ptr is n; } 66 /// 67 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 68 mixin baseCasts; 69 /// Construct a new instance of ARVRInterface. 70 /// Note: use `memnew!ARVRInterface` instead. 71 static ARVRInterface _new() 72 { 73 static godot_class_constructor constructor; 74 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("ARVRInterface"); 75 if(constructor is null) return typeof(this).init; 76 return cast(ARVRInterface)(constructor()); 77 } 78 @disable new(size_t s); 79 /// 80 enum Tracking_status : int 81 { 82 /** 83 Tracking is behaving as expected. 84 */ 85 arvrNormalTracking = 0, 86 /** 87 Tracking is hindered by excessive motion (the player is moving faster than tracking can keep up). 88 */ 89 arvrExcessiveMotion = 1, 90 /** 91 Tracking is hindered by insufficient features, it's too dark (for camera-based tracking), player is blocked, etc. 92 */ 93 arvrInsufficientFeatures = 2, 94 /** 95 We don't know the status of the tracking or this interface does not provide feedback. 96 */ 97 arvrUnknownTracking = 3, 98 /** 99 Tracking is not functional (camera not plugged in or obscured, lighthouses turned off, etc.). 100 */ 101 arvrNotTracking = 4, 102 } 103 /// 104 enum Eyes : int 105 { 106 /** 107 Mono output, this is mostly used internally when retrieving positioning information for our camera node or when stereo scopic rendering is not supported. 108 */ 109 eyeMono = 0, 110 /** 111 Left eye output, this is mostly used internally when rendering the image for the left eye and obtaining positioning and projection information. 112 */ 113 eyeLeft = 1, 114 /** 115 Right eye output, this is mostly used internally when rendering the image for the right eye and obtaining positioning and projection information. 116 */ 117 eyeRight = 2, 118 } 119 /// 120 enum Capabilities : int 121 { 122 /** 123 No ARVR capabilities. 124 */ 125 arvrNone = 0, 126 /** 127 This interface can work with normal rendering output (non-HMD based AR). 128 */ 129 arvrMono = 1, 130 /** 131 This interface supports stereoscopic rendering. 132 */ 133 arvrStereo = 2, 134 /** 135 This interface supports AR (video background and real world tracking). 136 */ 137 arvrAr = 4, 138 /** 139 This interface outputs to an external device. If the main viewport is used, the on screen output is an unmodified buffer of either the left or right eye (stretched if the viewport size is not changed to the same aspect ratio of $(D getRenderTargetsize)). Using a separate viewport node frees up the main viewport for other purposes. 140 */ 141 arvrExternal = 8, 142 } 143 /// 144 enum Constants : int 145 { 146 eyeMono = 0, 147 arvrNone = 0, 148 arvrNormalTracking = 0, 149 eyeLeft = 1, 150 arvrMono = 1, 151 arvrExcessiveMotion = 1, 152 arvrInsufficientFeatures = 2, 153 eyeRight = 2, 154 arvrStereo = 2, 155 arvrUnknownTracking = 3, 156 arvrAr = 4, 157 arvrNotTracking = 4, 158 arvrExternal = 8, 159 } 160 /** 161 162 */ 163 bool getAnchorDetectionIsEnabled() const 164 { 165 checkClassBinding!(typeof(this))(); 166 return ptrcall!(bool)(GDNativeClassBinding.getAnchorDetectionIsEnabled, _godot_object); 167 } 168 /** 169 If this is an AR interface that requires displaying a camera feed as the background, this method returns the feed ID in the $(D CameraServer) for this interface. 170 */ 171 long getCameraFeedId() 172 { 173 checkClassBinding!(typeof(this))(); 174 return ptrcall!(long)(GDNativeClassBinding.getCameraFeedId, _godot_object); 175 } 176 /** 177 Returns a combination of $(D capabilities) flags providing information about the capabilities of this interface. 178 */ 179 long getCapabilities() const 180 { 181 checkClassBinding!(typeof(this))(); 182 return ptrcall!(long)(GDNativeClassBinding.getCapabilities, _godot_object); 183 } 184 /** 185 Returns the name of this interface (OpenVR, OpenHMD, ARKit, etc). 186 */ 187 String getName() const 188 { 189 checkClassBinding!(typeof(this))(); 190 return ptrcall!(String)(GDNativeClassBinding.getName, _godot_object); 191 } 192 /** 193 Returns the resolution at which we should render our intermediate results before things like lens distortion are applied by the VR platform. 194 */ 195 Vector2 getRenderTargetsize() 196 { 197 checkClassBinding!(typeof(this))(); 198 return ptrcall!(Vector2)(GDNativeClassBinding.getRenderTargetsize, _godot_object); 199 } 200 /** 201 If supported, returns the status of our tracking. This will allow you to provide feedback to the user whether there are issues with positional tracking. 202 */ 203 ARVRInterface.Tracking_status getTrackingStatus() const 204 { 205 checkClassBinding!(typeof(this))(); 206 return ptrcall!(ARVRInterface.Tracking_status)(GDNativeClassBinding.getTrackingStatus, _godot_object); 207 } 208 /** 209 Call this to initialize this interface. The first interface that is initialized is identified as the primary interface and it will be used for rendering output. 210 After initializing the interface you want to use you then need to enable the AR/VR mode of a viewport and rendering should commence. 211 $(B Note:) You must enable the AR/VR mode on the main viewport for any device that uses the main output of Godot, such as for mobile VR. 212 If you do this for a platform that handles its own output (such as OpenVR) Godot will show just one eye without distortion on screen. Alternatively, you can add a separate viewport node to your scene and enable AR/VR on that viewport. It will be used to output to the HMD, leaving you free to do anything you like in the main window, such as using a separate camera as a spectator camera or rendering something completely different. 213 While currently not used, you can activate additional interfaces. You may wish to do this if you want to track controllers from other platforms. However, at this point in time only one interface can render to an HMD. 214 */ 215 bool initialize() 216 { 217 checkClassBinding!(typeof(this))(); 218 return ptrcall!(bool)(GDNativeClassBinding.initialize, _godot_object); 219 } 220 /** 221 222 */ 223 bool isInitialized() const 224 { 225 checkClassBinding!(typeof(this))(); 226 return ptrcall!(bool)(GDNativeClassBinding.isInitialized, _godot_object); 227 } 228 /** 229 230 */ 231 bool isPrimary() 232 { 233 checkClassBinding!(typeof(this))(); 234 return ptrcall!(bool)(GDNativeClassBinding.isPrimary, _godot_object); 235 } 236 /** 237 Returns `true` if the current output of this interface is in stereo. 238 */ 239 bool isStereo() 240 { 241 checkClassBinding!(typeof(this))(); 242 return ptrcall!(bool)(GDNativeClassBinding.isStereo, _godot_object); 243 } 244 /** 245 246 */ 247 void setAnchorDetectionIsEnabled(in bool enable) 248 { 249 checkClassBinding!(typeof(this))(); 250 ptrcall!(void)(GDNativeClassBinding.setAnchorDetectionIsEnabled, _godot_object, enable); 251 } 252 /** 253 254 */ 255 void setIsInitialized(in bool initialized) 256 { 257 checkClassBinding!(typeof(this))(); 258 ptrcall!(void)(GDNativeClassBinding.setIsInitialized, _godot_object, initialized); 259 } 260 /** 261 262 */ 263 void setIsPrimary(in bool enable) 264 { 265 checkClassBinding!(typeof(this))(); 266 ptrcall!(void)(GDNativeClassBinding.setIsPrimary, _godot_object, enable); 267 } 268 /** 269 Turns the interface off. 270 */ 271 void uninitialize() 272 { 273 checkClassBinding!(typeof(this))(); 274 ptrcall!(void)(GDNativeClassBinding.uninitialize, _godot_object); 275 } 276 /** 277 On an AR interface, `true` if anchor detection is enabled. 278 */ 279 @property bool arIsAnchorDetectionEnabled() 280 { 281 return getAnchorDetectionIsEnabled(); 282 } 283 /// ditto 284 @property void arIsAnchorDetectionEnabled(bool v) 285 { 286 setAnchorDetectionIsEnabled(v); 287 } 288 /** 289 `true` if this interface been initialized. 290 */ 291 @property bool interfaceIsInitialized() 292 { 293 return isInitialized(); 294 } 295 /// ditto 296 @property void interfaceIsInitialized(bool v) 297 { 298 setIsInitialized(v); 299 } 300 /** 301 `true` if this is the primary interface. 302 */ 303 @property bool interfaceIsPrimary() 304 { 305 return isPrimary(); 306 } 307 /// ditto 308 @property void interfaceIsPrimary(bool v) 309 { 310 setIsPrimary(v); 311 } 312 }