1 /** 2 Base class for ARVR 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.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.reference; 23 /** 24 Base class for ARVR interface implementation. 25 26 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. 27 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 ARVRServer. 28 */ 29 @GodotBaseClass struct ARVRInterface 30 { 31 enum string _GODOT_internal_name = "ARVRInterface"; 32 public: 33 @nogc nothrow: 34 union { godot_object _godot_object; Reference _GODOT_base; } 35 alias _GODOT_base this; 36 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 37 package(godot) __gshared bool _classBindingInitialized = false; 38 package(godot) static struct _classBinding 39 { 40 __gshared: 41 @GodotName("get_name") GodotMethod!(String) getName; 42 @GodotName("get_capabilities") GodotMethod!(long) getCapabilities; 43 @GodotName("is_primary") GodotMethod!(bool) isPrimary; 44 @GodotName("set_is_primary") GodotMethod!(void, bool) setIsPrimary; 45 @GodotName("is_initialized") GodotMethod!(bool) isInitialized; 46 @GodotName("set_is_initialized") GodotMethod!(void, bool) setIsInitialized; 47 @GodotName("initialize") GodotMethod!(bool) initialize; 48 @GodotName("uninitialize") GodotMethod!(void) uninitialize; 49 @GodotName("get_tracking_status") GodotMethod!(ARVRInterface.Tracking_status) getTrackingStatus; 50 @GodotName("get_render_targetsize") GodotMethod!(Vector2) getRenderTargetsize; 51 @GodotName("is_stereo") GodotMethod!(bool) isStereo; 52 @GodotName("get_anchor_detection_is_enabled") GodotMethod!(bool) getAnchorDetectionIsEnabled; 53 @GodotName("set_anchor_detection_is_enabled") GodotMethod!(void, bool) setAnchorDetectionIsEnabled; 54 } 55 bool opEquals(in ARVRInterface other) const { return _godot_object.ptr is other._godot_object.ptr; } 56 ARVRInterface opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 57 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 58 mixin baseCasts; 59 static ARVRInterface _new() 60 { 61 static godot_class_constructor constructor; 62 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("ARVRInterface"); 63 if(constructor is null) return typeof(this).init; 64 return cast(ARVRInterface)(constructor()); 65 } 66 @disable new(size_t s); 67 /// 68 enum Tracking_status : int 69 { 70 /** 71 Tracking is behaving as expected. 72 */ 73 arvrNormalTracking = 0, 74 /** 75 Tracking is hindered by excessive motion, player is moving faster then tracking can keep up. 76 */ 77 arvrExcessiveMotion = 1, 78 /** 79 Tracking is hindered by insufficient features, it's too dark (for camera based tracking), player is blocked, etc. 80 */ 81 arvrInsufficientFeatures = 2, 82 /** 83 We don't know the status of the tracking or this interface does not provide feedback. 84 */ 85 arvrUnknownTracking = 3, 86 /** 87 Tracking is not functional (camera not plugged in or obscured, lighthouses turned off, etc.) 88 */ 89 arvrNotTracking = 4, 90 } 91 /// 92 enum Eyes : int 93 { 94 /** 95 Mono output, this is mostly used internally when retrieving positioning information for our camera node or when stereo scopic rendering is not supported. 96 */ 97 eyeMono = 0, 98 /** 99 Left eye output, this is mostly used internally when rendering the image for the left eye and obtaining positioning and projection information. 100 */ 101 eyeLeft = 1, 102 /** 103 Right eye output, this is mostly used internally when rendering the image for the right eye and obtaining positioning and projection information. 104 */ 105 eyeRight = 2, 106 } 107 /// 108 enum Capabilities : int 109 { 110 /** 111 No ARVR capabilities. 112 */ 113 arvrNone = 0, 114 /** 115 This interface can work with normal rendering output (non-HMD based AR). 116 */ 117 arvrMono = 1, 118 /** 119 This interface supports stereoscopic rendering. 120 */ 121 arvrStereo = 2, 122 /** 123 This interface support AR (video background and real world tracking). 124 */ 125 arvrAr = 4, 126 /** 127 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 get_render_targetsize. Using a separate viewport node frees up the main viewport for other purposes. 128 */ 129 arvrExternal = 8, 130 } 131 /// 132 enum Constants : int 133 { 134 eyeMono = 0, 135 arvrNone = 0, 136 arvrNormalTracking = 0, 137 eyeLeft = 1, 138 arvrMono = 1, 139 arvrExcessiveMotion = 1, 140 arvrInsufficientFeatures = 2, 141 eyeRight = 2, 142 arvrStereo = 2, 143 arvrUnknownTracking = 3, 144 arvrAr = 4, 145 arvrNotTracking = 4, 146 arvrExternal = 8, 147 } 148 /** 149 Returns the name of this interface (OpenVR, OpenHMD, ARKit, etc). 150 */ 151 String getName() const 152 { 153 checkClassBinding!(typeof(this))(); 154 return ptrcall!(String)(_classBinding.getName, _godot_object); 155 } 156 /** 157 Returns a combination of flags providing information about the capabilities of this interface. 158 */ 159 long getCapabilities() const 160 { 161 checkClassBinding!(typeof(this))(); 162 return ptrcall!(long)(_classBinding.getCapabilities, _godot_object); 163 } 164 /** 165 166 */ 167 bool isPrimary() 168 { 169 checkClassBinding!(typeof(this))(); 170 return ptrcall!(bool)(_classBinding.isPrimary, _godot_object); 171 } 172 /** 173 174 */ 175 void setIsPrimary(in bool enable) 176 { 177 checkClassBinding!(typeof(this))(); 178 ptrcall!(void)(_classBinding.setIsPrimary, _godot_object, enable); 179 } 180 /** 181 182 */ 183 bool isInitialized() const 184 { 185 checkClassBinding!(typeof(this))(); 186 return ptrcall!(bool)(_classBinding.isInitialized, _godot_object); 187 } 188 /** 189 190 */ 191 void setIsInitialized(in bool initialized) 192 { 193 checkClassBinding!(typeof(this))(); 194 ptrcall!(void)(_classBinding.setIsInitialized, _godot_object, initialized); 195 } 196 /** 197 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. 198 After initializing the interface you want to use you then need to enable the AR/VR mode of a viewport and rendering should commence. 199 Note that 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. 200 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 and 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 render out something completely different. 201 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. 202 */ 203 bool initialize() 204 { 205 checkClassBinding!(typeof(this))(); 206 return ptrcall!(bool)(_classBinding.initialize, _godot_object); 207 } 208 /** 209 Turns the interface off. 210 */ 211 void uninitialize() 212 { 213 checkClassBinding!(typeof(this))(); 214 ptrcall!(void)(_classBinding.uninitialize, _godot_object); 215 } 216 /** 217 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. 218 */ 219 ARVRInterface.Tracking_status getTrackingStatus() const 220 { 221 checkClassBinding!(typeof(this))(); 222 return ptrcall!(ARVRInterface.Tracking_status)(_classBinding.getTrackingStatus, _godot_object); 223 } 224 /** 225 Returns the resolution at which we should render our intermediate results before things like lens distortion are applied by the VR platform. 226 */ 227 Vector2 getRenderTargetsize() 228 { 229 checkClassBinding!(typeof(this))(); 230 return ptrcall!(Vector2)(_classBinding.getRenderTargetsize, _godot_object); 231 } 232 /** 233 Returns true if the current output of this interface is in stereo. 234 */ 235 bool isStereo() 236 { 237 checkClassBinding!(typeof(this))(); 238 return ptrcall!(bool)(_classBinding.isStereo, _godot_object); 239 } 240 /** 241 242 */ 243 bool getAnchorDetectionIsEnabled() const 244 { 245 checkClassBinding!(typeof(this))(); 246 return ptrcall!(bool)(_classBinding.getAnchorDetectionIsEnabled, _godot_object); 247 } 248 /** 249 250 */ 251 void setAnchorDetectionIsEnabled(in bool enable) 252 { 253 checkClassBinding!(typeof(this))(); 254 ptrcall!(void)(_classBinding.setAnchorDetectionIsEnabled, _godot_object, enable); 255 } 256 /** 257 Is this our primary interface? 258 */ 259 @property bool interfaceIsPrimary() 260 { 261 return isPrimary(); 262 } 263 /// ditto 264 @property void interfaceIsPrimary(bool v) 265 { 266 setIsPrimary(v); 267 } 268 /** 269 Has this interface been initialized? 270 */ 271 @property bool interfaceIsInitialized() 272 { 273 return isInitialized(); 274 } 275 /// ditto 276 @property void interfaceIsInitialized(bool v) 277 { 278 setIsInitialized(v); 279 } 280 /** 281 On an AR interface, is our anchor detection enabled? 282 */ 283 @property bool arIsAnchorDetectionEnabled() 284 { 285 return getAnchorDetectionIsEnabled(); 286 } 287 /// ditto 288 @property void arIsAnchorDetectionEnabled(bool v) 289 { 290 setAnchorDetectionIsEnabled(v); 291 } 292 }