WebXRInterface
XR interface using WebXR.
WebXRInterface.swift:45class WebXRInterface
WebXR is an open standard that allows creating VR and AR applications that run in the web browser.
As such, this interface is only available when running in Web exports.
WebXR supports a wide range of devices, from the very capable (like Valve Index, HTC Vive, Oculus Rift and Quest) down to the much less capable (like Google Cardboard, Oculus Go, GearVR, or plain smartphones).
Since WebXR is based on JavaScript, it makes extensive use of callbacks, which means that WebXRInterface
is forced to use signals, where other XR interfaces would instead use functions that return a result immediately. This makes WebXRInterface
quite a bit more complicated to initialize than other XR interfaces.
Here’s the minimum code required to start an immersive VR session:
There are a couple ways to handle “controller” input:
Using
XRController3D
nodes and their [signal XRController3D.button_pressed] and [signal XRController3D.button_released] signals. This is how controllers are typically handled in XR apps in Godot, however, this will only work with advanced VR controllers like the Oculus Touch or Index controllers, for example.Using the [signal select], [signal squeeze] and related signals. This method will work for both advanced VR controllers, and non-traditional input sources like a tap on the screen, a spoken voice command or a button press on the device itself.
You can use both methods to allow your game or app to support a wider or narrower set of devices and input methods, or to allow more advanced interactions with more advanced devices.
This object emits the following signals:
Superclasses
class XRInterface
Base class for an XR interface implementation.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
class Signal1
Signal support.
class Signal2
Signal support.
class Signal3
Signal support.
class Signal4
Signal support.
class Signal5
Signal support.
class Signal6
Signal support.
class Signal7
Signal support.
class Signal8
Signal support.
enum TargetRayMode
Type members
Instance members
var displayRefreshRateChanged: SimpleSignal
Emitted after the display’s refresh rate has changed.
var optionalFeatures: String
A comma-seperated list of optional features used by
initialize
when setting up the WebXR session.var referenceSpaceReset: SimpleSignal
Emitted to indicate that the reference space has been reset or reconfigured.
var referenceSpaceType: String
The reference space type (from the list of requested types set in the
requestedReferenceSpaceTypes
property), that was ultimately used byinitialize
when setting up the WebXR session.var requestedReferenceSpaceTypes: String
A comma-seperated list of reference space types used by
initialize
when setting up the WebXR session.var requiredFeatures: String
A comma-seperated list of required features used by
initialize
when setting up the WebXR session.var select: Signal4
Emitted after one of the input sources has finished its “primary action”.
var selectend: Signal5
Emitted when one of the input sources has finished its “primary action”.
var selectstart: Signal3
Emitted when one of the input source has started its “primary action”.
var sessionEnded: SimpleSignal
Emitted when the user ends the WebXR session (which can be done using UI from the browser or device).
var sessionFailed: Signal2
Emitted by
initialize
if the session fails to start.var sessionMode: String
The session mode used by
initialize
when setting up the WebXR session.var sessionStarted: SimpleSignal
Emitted by
initialize
if the session is successfully started.var sessionSupported: Signal1
Emitted by
isSessionSupported(sessionMode:)
to indicate if the givensessionMode
is supported or not.var squeeze: Signal7
Emitted after one of the input sources has finished its “primary squeeze action”.
var squeezeend: Signal8
Emitted when one of the input sources has finished its “primary squeeze action”.
var squeezestart: Signal6
Emitted when one of the input sources has started its “primary squeeze action”.
var visibilityState: String
Indicates if the WebXR session’s imagery is visible to the user.
var visibilityStateChanged: SimpleSignal
Emitted when
visibilityState
has changed.func getAvailableDisplayRefreshRates(
) -> GArray Returns display refresh rates supported by the current HMD. Only returned if this feature is supported by the web browser and after the interface has been initialized.
func getDisplayRefreshRate(
) -> Double Returns the display refresh rate for the current HMD. Not supported on all HMDs and browsers. It may not report an accurate value until after using
setDisplayRefreshRate(_:)
.func getInputSourceTargetRayMode(inputSourceId: Int32
) -> WebXRInterface.TargetRayMode Returns the target ray mode for the given
inputSourceId
.func getInputSourceTracker(inputSourceId: Int32
) -> XRPositionalTracker? Gets an
XRPositionalTracker
for the giveninputSourceId
.func isInputSourceActive(inputSourceId: Int32
) -> Bool Returns
true
if there is an active input source with the giveninputSourceId
.func isSessionSupported(sessionMode: String
) Checks if the given
sessionMode
is supported by the user’s browser.func setDisplayRefreshRate(Double
) Sets the display refresh rate for the current HMD. Not supported on all HMDs and browsers. It won’t take effect right away until after [signal display_refresh_rate_changed] is emitted.