WebXRInterface

    AR/VR 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 an HTML5 export.

    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 is forced to use signals, where other AR/VR interfaces would instead use functions that return a result immediately. This makes WebXRInterface quite a bit more complicated to intialize than other AR/VR interfaces.

    Here’s the minimum code required to start an immersive VR session:

    There are several ways to handle “controller” input:

    • Using nodes and their ARVRController.button_pressed and signals. This is how controllers are typically handled in AR/VR apps in Godot, however, this will only work with advanced VR controllers like the Oculus Touch or Index controllers, for example. The buttons codes are defined by Section 3.3 of the WebXR Gamepads Module.
    • Using and InputEventJoypadButton or . This works the same as normal joypads, except the InputEvent.device starts at 100, so the left controller is 100 and the right controller is 101, and the button codes are also defined by .
    • Using the select, and related signals. This method will work for both advanced VR controllers, and non-traditional “controllers” like a tap on the screen, a spoken voice command or a button press on the device itself. The controller_id passed to these signals is the same id as used in ARVRController.controller_id.

    You can use one or all of these methods to allow your game or app to support a wider or narrower set of devices and input methods, or to allow more advanced interations with more advanced devices.

    Tutorials

    Methods

    ARVRPositionalTracker ( int controller_id ) const
    void ( String session_mode )
    • 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 ) or pressed/held a button to recenter their position.

    See WebXR’s XRReferenceSpace reset event for more information.


    Emitted after one of the “controllers” has finished its “primary action”.

    Use to get more information about the controller.


    • selectend ( int controller_id )

    Emitted when one of the “controllers” has finished its “primary action”.

    Use to get more information about the controller.


    • selectstart ( int controller_id )

    Emitted when one of the “controllers” has started its “primary action”.

    Use to get more information about the controller.


    • 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().arvr = false to instruct Godot to resume rendering to the screen.


    • session_failed ( String message )

    message may optionally contain an error message from WebXR, or an empty string if no message is available.


    • session_started ( )

    Emitted by if the session is successfully started.

    At this point, it’s safe to do get_viewport().arvr = true to instruct Godot to start rendering to the AR/VR device.


    • session_supported ( String session_mode, supported )

    Emitted by is_session_supported to indicate if the given is supported or not.


    • squeeze ( controller_id )

    Emitted after one of the “controllers” has finished its “primary squeeze action”.

    Use get_controller to get more information about the controller.


    • squeezeend ( controller_id )

    Emitted when one of the “controllers” has finished its “primary squeeze action”.

    Use get_controller to get more information about the controller.


    • squeezestart ( controller_id )

    Emitted when one of the “controllers” has started its “primary squeeze action”.

    Use get_controller to get more information about the controller.


    • visibility_state_changed ( )

    Emitted when has changed.

    Property Descriptions

    Getterget_bounds_geometry()

    The vertices of a polygon which defines the boundaries of the user’s play area.

    This will only be available if is "bounded-floor" and only on certain browsers and devices that support it.

    The reference_space_reset signal may indicate when this changes.


    • optional_features

    A comma-seperated list of optional features used by ARVRInterface.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.

    Possible values come from . If you want to use a particular reference space type, it must be listed in either required_features or .


    Getterget_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 when setting up the WebXR session.


    • String requested_reference_space_types
    Setterset_requested_reference_space_types(value)
    Getterget_requested_reference_space_types()

    A comma-seperated list of reference space types used by when setting up the WebXR session.

    The reference space types are requested in order, and the first on supported by the users device or browser will be used. The reference_space_type property contains the reference space type that was ultimately used.

    This doesn’t have any effect on the interface when already initialized.

    Possible values come from . If you want to use a particular reference space type, it must be listed in either required_features or .


    A comma-seperated list of required features used by 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.

    Possible values come from . If you want to use a particular reference space type, it must be listed in either required_features or .


    Setterset_session_mode(value)
    Getterget_session_mode()

    The session mode used by 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
    Getterget_visibility_state()

    Indicates if the WebXR session’s imagery is visible to the user.

    Possible values come from WebXR’s XRVisibilityState, including "hidden", , and "visible-blurred".

    • get_controller ( int controller_id ) const

    Gets an for the given controller_id.

    In the context of WebXR, a “controller” 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 controller is used, interpret the position and orientation of the ARVRPositionalTracker as a ray pointing at the object the user wishes to interact with.

    Use this method to get information about the controller that triggered one of these signals:


    • void is_session_supported ( session_mode )

    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 .

    This method returns nothing, instead it emits the signal with the result.