WebXRInterface

package
v0.0.0-...-7325ca5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package WebXRInterface provides methods for working with WebXRInterface object instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsWebXRInterface() Instance
}

type Instance

type Instance [1]gdclass.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: [codeblock] extends Node3D

var webxr_interface var vr_supported = false

func _ready():

# We assume this node has a button as a child.
# This button is for the user to consent to entering immersive VR mode.
$Button.pressed.connect(self._on_button_pressed)

webxr_interface = XRServer.find_interface("WebXR")
if webxr_interface:
    # WebXR uses a lot of asynchronous callbacks, so we connect to various
    # signals in order to receive them.
    webxr_interface.session_supported.connect(self._webxr_session_supported)
    webxr_interface.session_started.connect(self._webxr_session_started)
    webxr_interface.session_ended.connect(self._webxr_session_ended)
    webxr_interface.session_failed.connect(self._webxr_session_failed)

    # This returns immediately - our _webxr_session_supported() method
    # (which we connected to the "session_supported" signal above) will
    # be called sometime later to let us know if it's supported or not.
    webxr_interface.is_session_supported("immersive-vr")

func _webxr_session_supported(session_mode, supported):

if session_mode == 'immersive-vr':
    vr_supported = supported

func _on_button_pressed():

if not vr_supported:
    OS.alert("Your browser doesn't support VR")
    return

# We want an immersive VR session, as opposed to AR ('immersive-ar') or a
# simple 3DoF viewer ('viewer').
webxr_interface.session_mode = 'immersive-vr'
# 'bounded-floor' is room scale, 'local-floor' is a standing or sitting
# experience (it puts you 1.6m above the ground if you have 3DoF headset),
# whereas as 'local' puts you down at the XROrigin.
# This list means it'll first try to request 'bounded-floor', then
# fallback on 'local-floor' and ultimately 'local', if nothing else is
# supported.
webxr_interface.requested_reference_space_types = 'bounded-floor, local-floor, local'
# In order to use 'local-floor' or 'bounded-floor' we must also
# mark the features as required or optional. By including 'hand-tracking'
# as an optional feature, it will be enabled if supported.
webxr_interface.required_features = 'local-floor'
webxr_interface.optional_features = 'bounded-floor, hand-tracking'

# This will return false if we're unable to even request the session,
# however, it can still fail asynchronously later in the process, so we
# only know if it's really succeeded or failed when our
# _webxr_session_started() or _webxr_session_failed() methods are called.
if not webxr_interface.initialize():
    OS.alert("Failed to initialize")
    return

func _webxr_session_started():

$Button.visible = false
# This tells Godot to start rendering to the headset.
get_viewport().use_xr = true
# This will be the reference space type you ultimately got, out of the
# types that you requested above. This is useful if you want the game to
# work a little differently in 'bounded-floor' versus 'local-floor'.
print("Reference space type: ", webxr_interface.reference_space_type)
# This will be the list of features that were successfully enabled
# (except on browsers that don't support this property).
print("Enabled features: ", webxr_interface.enabled_features)

func _webxr_session_ended():

$Button.visible = true
# If the user exits immersive mode, then we tell Godot to render to the web
# page again.
get_viewport().use_xr = false

func _webxr_session_failed(message):

OS.alert("Failed to initialize: " + message)

[/codeblock] 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.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsWebXRInterface

func (self Instance) AsWebXRInterface() Instance

func (Instance) AsXRInterface

func (self Instance) AsXRInterface() XRInterface.Instance

func (Instance) EnabledFeatures

func (self Instance) EnabledFeatures() string

func (Instance) GetAvailableDisplayRefreshRates

func (self Instance) GetAvailableDisplayRefreshRates() []any

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 (Instance) GetDisplayRefreshRate

func (self Instance) GetDisplayRefreshRate() Float.X

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 [method set_display_refresh_rate].

func (Instance) GetInputSourceTargetRayMode

func (self Instance) GetInputSourceTargetRayMode(input_source_id int) gdclass.WebXRInterfaceTargetRayMode

Returns the target ray mode for the given [param input_source_id]. This can help interpret the input coming from that input source. See [url=https://developer.mozilla.org/en-US/docs/Web/API/XRInputSource/targetRayMode]XRInputSource.targetRayMode[/url] for more information.

func (Instance) GetInputSourceTracker

func (self Instance) GetInputSourceTracker(input_source_id int) [1]gdclass.XRControllerTracker

Gets an [XRControllerTracker] for the given [param 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: - [signal selectstart] - [signal select] - [signal selectend] - [signal squeezestart] - [signal squeeze] - [signal squeezestart]

func (Instance) IsInputSourceActive

func (self Instance) IsInputSourceActive(input_source_id int) bool

Returns [code]true[/code] if there is an active input source with the given [param input_source_id].

func (Instance) IsSessionSupported

func (self Instance) IsSessionSupported(session_mode string)

Checks if the given [param session_mode] is supported by the user's browser. Possible values come from [url=https://developer.mozilla.org/en-US/docs/Web/API/XRSessionMode]WebXR's XRSessionMode[/url], including: [code]"immersive-vr"[/code], [code]"immersive-ar"[/code], and [code]"inline"[/code]. This method returns nothing, instead it emits the [signal session_supported] signal with the result.

func (Instance) OnDisplayRefreshRateChanged

func (self Instance) OnDisplayRefreshRateChanged(cb func())

func (Instance) OnReferenceSpaceReset

func (self Instance) OnReferenceSpaceReset(cb func())

func (Instance) OnSelect

func (self Instance) OnSelect(cb func(input_source_id int))

func (Instance) OnSelectend

func (self Instance) OnSelectend(cb func(input_source_id int))

func (Instance) OnSelectstart

func (self Instance) OnSelectstart(cb func(input_source_id int))

func (Instance) OnSessionEnded

func (self Instance) OnSessionEnded(cb func())

func (Instance) OnSessionFailed

func (self Instance) OnSessionFailed(cb func(message string))

func (Instance) OnSessionStarted

func (self Instance) OnSessionStarted(cb func())

func (Instance) OnSessionSupported

func (self Instance) OnSessionSupported(cb func(session_mode string, supported bool))

func (Instance) OnSqueeze

func (self Instance) OnSqueeze(cb func(input_source_id int))

func (Instance) OnSqueezeend

func (self Instance) OnSqueezeend(cb func(input_source_id int))

func (Instance) OnSqueezestart

func (self Instance) OnSqueezestart(cb func(input_source_id int))

func (Instance) OnVisibilityStateChanged

func (self Instance) OnVisibilityStateChanged(cb func())

func (Instance) OptionalFeatures

func (self Instance) OptionalFeatures() string

func (Instance) ReferenceSpaceType

func (self Instance) ReferenceSpaceType() string

func (Instance) RequestedReferenceSpaceTypes

func (self Instance) RequestedReferenceSpaceTypes() string

func (Instance) RequiredFeatures

func (self Instance) RequiredFeatures() string

func (Instance) SessionMode

func (self Instance) SessionMode() string

func (Instance) SetDisplayRefreshRate

func (self Instance) SetDisplayRefreshRate(refresh_rate Float.X)

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.

func (Instance) SetOptionalFeatures

func (self Instance) SetOptionalFeatures(value string)

func (Instance) SetRequestedReferenceSpaceTypes

func (self Instance) SetRequestedReferenceSpaceTypes(value string)

func (Instance) SetRequiredFeatures

func (self Instance) SetRequiredFeatures(value string)

func (Instance) SetSessionMode

func (self Instance) SetSessionMode(value string)

func (*Instance) UnsafePointer

func (self *Instance) UnsafePointer() unsafe.Pointer

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

func (Instance) VisibilityState

func (self Instance) VisibilityState() string

type TargetRayMode

type TargetRayMode = gdclass.WebXRInterfaceTargetRayMode //gd:WebXRInterface.TargetRayMode
const (
	/*We don't know the the target ray mode.*/
	TargetRayModeUnknown TargetRayMode = 0
	/*Target ray originates at the viewer's eyes and points in the direction they are looking.*/
	TargetRayModeGaze TargetRayMode = 1
	/*Target ray from a handheld pointer, most likely a VR touch controller.*/
	TargetRayModeTrackedPointer TargetRayMode = 2
	/*Target ray from touch screen, mouse or other tactile input device.*/
	TargetRayModeScreen TargetRayMode = 3
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL