WebXRInterface
Inherits: XRInterface < RefCounted < Object
Description
Section titled “Description”XR interface using WebXR.
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
XRController3D.button_pressedandXRController3D.button_releasedsignals. This is how controllers are typically handled in XR apps in Orblit, however, this will only work with advanced VR controllers like the Oculus Touch or Index controllers, for example. -
Using the
select,squeezeand 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.
Properties
Section titled “Properties”Methods
Section titled “Methods”| Returns | Method |
|---|---|
| Array | get_available_display_refresh_rates() const |
| float | get_display_refresh_rate() const |
| TargetRayMode | get_input_source_target_ray_mode(input_source_id: int) const |
| XRControllerTracker | get_input_source_tracker(input_source_id: int) const |
| bool | is_input_source_active(input_source_id: int) const |
| void | is_session_supported(session_mode: String) |
| void | set_display_refresh_rate(refresh_rate: float) |
Signals
Section titled “Signals”display_refresh_rate_changed
display_refresh_rate_changed()
Emitted after the display’s refresh rate has changed.
reference_space_reset
reference_space_reset()
Emitted to indicate that the reference space has been reset or reconfigured.
When (or whether) this is emitted depends on the user’s browser or device, but may include when the user has changed the dimensions of their play space (which you may be able to access via XRInterface.get_play_area()) or pressed/held a button to recenter their position.
See WebXR’s XRReferenceSpace reset event for more information.
select
select(input_source_id: int)
Emitted after one of the input sources has finished its “primary action”.
Use get_input_source_tracker() and get_input_source_target_ray_mode() to get more information about the input source.
selectend
selectend(input_source_id: int)
Emitted when one of the input sources has finished its “primary action”.
Use get_input_source_tracker() and get_input_source_target_ray_mode() to get more information about the input source.
selectstart
selectstart(input_source_id: int)
Emitted when one of the input source has started its “primary action”.
Use get_input_source_tracker() and get_input_source_target_ray_mode() to get more information about the input source.
session_ended
session_ended()
Emitted when the user ends the WebXR session (which can be done using UI from the browser or device).
At this point, you should do get_viewport().use_xr = false to instruct Orblit to resume rendering to the screen.
session_failed
session_failed(message: String)
Emitted by XRInterface.initialize() if the session fails to start.
message may optionally contain an error message from WebXR, or an empty string if no message is available.
session_started
session_started()
Emitted by XRInterface.initialize() if the session is successfully started.
At this point, it’s safe to do get_viewport().use_xr = true to instruct Orblit to start rendering to the XR device.
session_supported
session_supported(session_mode: String, supported: bool)
Emitted by is_session_supported() to indicate if the given session_mode is supported or not.
squeeze
squeeze(input_source_id: int)
Emitted after one of the input sources has finished its “primary squeeze action”.
Use get_input_source_tracker() and get_input_source_target_ray_mode() to get more information about the input source.
squeezeend
squeezeend(input_source_id: int)
Emitted when one of the input sources has finished its “primary squeeze action”.
Use get_input_source_tracker() and get_input_source_target_ray_mode() to get more information about the input source.
squeezestart
squeezestart(input_source_id: int)
Emitted when one of the input sources has started its “primary squeeze action”.
Use get_input_source_tracker() and get_input_source_target_ray_mode() to get more information about the input source.
visibility_state_changed
visibility_state_changed()
Emitted when visibility_state has changed.
Enumerations
Section titled “Enumerations”TargetRayMode
enum TargetRayMode
TARGET_RAY_MODE_UNKNOWN = 0
We don’t know the target ray mode.
TARGET_RAY_MODE_GAZE = 1
Target ray originates at the viewer’s eyes and points in the direction they are looking.
TARGET_RAY_MODE_TRACKED_POINTER = 2
Target ray from a handheld pointer, most likely a VR touch controller.
TARGET_RAY_MODE_SCREEN = 3
Target ray from touch screen, mouse or other tactile input device.
Property descriptions
Section titled “Property descriptions”disable_webxr_layers
bool disable_webxr_layers
If true, the WebXR Layers API won’t be used even when the browser supports it.
Orblit falls back to this mode automatically when the browser doesn’t support WebXR Layers and the polyfill isn’t in use.
This doesn’t have any effect on the interface when already initialized.
enabled_features
String enabled_features
A comma-separated list of features that were successfully enabled by XRInterface.initialize() when setting up the WebXR session.
This may include features requested by setting required_features and optional_features, and will only be available after session_started has been emitted.
Note: This may not be support by all web browsers, in which case it will be an empty string.
optional_features
String optional_features
A comma-seperated list of optional features used by XRInterface.initialize() when setting up the WebXR session.
If a user’s browser or device doesn’t support one of the given features, initialization will continue, but you won’t be able to use the requested feature.
This doesn’t have any effect on the interface when already initialized.
See the MDN documentation on WebXR’s session features for a list of possible values.
reference_space_type
String reference_space_type
The reference space type (from the list of requested types set in the requested_reference_space_types property), that was ultimately used by XRInterface.initialize() when setting up the WebXR session.
Possible values come from WebXR’s XRReferenceSpaceType. If you want to use a particular reference space type, it must be listed in either required_features or optional_features.
requested_reference_space_types
String requested_reference_space_types
A comma-seperated list of reference space types used by XRInterface.initialize() when setting up the WebXR session.
The reference space types are requested in order, and the first one supported by the user’s device or browser will be used. The reference_space_type property contains the reference space type that was ultimately selected.
This doesn’t have any effect on the interface when already initialized.
Possible values come from WebXR’s XRReferenceSpaceType. If you want to use a particular reference space type, it must be listed in either required_features or optional_features.
required_features
String required_features
A comma-seperated list of required features used by XRInterface.initialize() when setting up the WebXR session.
If a user’s browser or device doesn’t support one of the given features, initialization will fail and session_failed will be emitted.
This doesn’t have any effect on the interface when already initialized.
See the MDN documentation on WebXR’s session features for a list of possible values.
session_mode
String session_mode
The session mode used by XRInterface.initialize() when setting up the WebXR session.
This doesn’t have any effect on the interface when already initialized.
Possible values come from WebXR’s XRSessionMode, including: "immersive-vr", "immersive-ar", and "inline".
visibility_state
String visibility_state
Indicates if the WebXR session’s imagery is visible to the user.
Possible values come from WebXR’s XRVisibilityState, including "hidden", "visible", and "visible-blurred".
Method descriptions
Section titled “Method descriptions”get_available_display_refresh_rates
Array get_available_display_refresh_rates() const
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.
get_display_refresh_rate
float get_display_refresh_rate() const
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 set_display_refresh_rate().
get_input_source_target_ray_mode
TargetRayMode get_input_source_target_ray_mode(input_source_id: int) const
Returns the target ray mode for the given input_source_id.
This can help interpret the input coming from that input source. See XRInputSource.targetRayMode for more information.
get_input_source_tracker
XRControllerTracker get_input_source_tracker(input_source_id: int) const
Gets an XRControllerTracker for the given input_source_id.
In the context of WebXR, an input source can be an advanced VR controller like the Oculus Touch or Index controllers, or even a tap on the screen, a spoken voice command or a button press on the device itself. When a non-traditional input source is used, interpret the position and orientation of the XRPositionalTracker as a ray pointing at the object the user wishes to interact with.
Use this method to get information about the input source that triggered one of these signals:
is_input_source_active
bool is_input_source_active(input_source_id: int) const
Returns true if there is an active input source with the given input_source_id.
is_session_supported
void is_session_supported(session_mode: String)
Checks if the given session_mode is supported by the user’s browser.
Possible values come from WebXR’s XRSessionMode, including: "immersive-vr", "immersive-ar", and "inline".
This method returns nothing, instead it emits the session_supported signal with the result.
set_display_refresh_rate
void set_display_refresh_rate(refresh_rate: float)
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 display_refresh_rate_changed is emitted.
