diff options
author | David Snopek <dsnopek@gmail.com> | 2022-11-18 20:43:11 -0600 |
---|---|---|
committer | David Snopek <dsnopek@gmail.com> | 2022-12-01 21:46:30 -0600 |
commit | 310bf39cd3f8c0e9ac6602e37fa9d65ca0d1c2e1 (patch) | |
tree | 0bca28bf11f672052a182e9cbe8c26c1ad23e44d /modules/webxr/doc_classes | |
parent | 84c404f6bcce9ba112118d77afd6bd70a92774d1 (diff) |
Get WebXR fully working in Godot 4!
Diffstat (limited to 'modules/webxr/doc_classes')
-rw-r--r-- | modules/webxr/doc_classes/WebXRInterface.xml | 105 |
1 files changed, 64 insertions, 41 deletions
diff --git a/modules/webxr/doc_classes/WebXRInterface.xml b/modules/webxr/doc_classes/WebXRInterface.xml index 49dd9f7318..f5964eb4d1 100644 --- a/modules/webxr/doc_classes/WebXRInterface.xml +++ b/modules/webxr/doc_classes/WebXRInterface.xml @@ -1,13 +1,13 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="WebXRInterface" inherits="XRInterface" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd"> <brief_description> - AR/VR interface using WebXR. + XR interface using WebXR. </brief_description> <description> 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 AR/VR interfaces would instead use functions that return a result immediately. This makes [WebXRInterface] quite a bit more complicated to initialize than other AR/VR interfaces. + 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 @@ -69,7 +69,7 @@ func _webxr_session_started(): $Button.visible = false # This tells Godot to start rendering to the headset. - get_viewport().xr = true + 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'. @@ -79,28 +79,35 @@ $Button.visible = true # If the user exits immersive mode, then we tell Godot to render to the web # page again. - get_viewport().xr = false + get_viewport().use_xr = false func _webxr_session_failed(message): OS.alert("Failed to initialize: " + message) [/codeblock] - There are several 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 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 [url=https://immersive-web.github.io/webxr-gamepads-module/#xr-standard-gamepad-mapping]Section 3.3 of the WebXR Gamepads Module[/url]. - - Using [method Node._unhandled_input] and [InputEventJoypadButton] or [InputEventJoypadMotion]. This works the same as normal joypads, except the [member 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 [url=https://immersive-web.github.io/webxr-gamepads-module/#xr-standard-gamepad-mapping]Section 3.3 of the WebXR Gamepads Module[/url]. - - Using the [signal select], [signal squeeze] 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. - 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 interactions with more advanced devices. + 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. </description> <tutorials> <link title="How to make a VR game for WebXR with Godot">https://www.snopekgames.com/blog/2020/how-make-vr-game-webxr-godot</link> </tutorials> <methods> - <method name="get_controller" qualifiers="const"> + <method name="get_input_source_target_ray_mode" qualifiers="const"> + <return type="int" enum="WebXRInterface.TargetRayMode" /> + <param index="0" name="input_source_id" type="int" /> + <description> + Returns the target ray mode for the given [code]input_source_id[/code]. + 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. + </description> + </method> + <method name="get_input_source_tracker" qualifiers="const"> <return type="XRPositionalTracker" /> - <param index="0" name="controller_id" type="int" /> + <param index="0" name="input_source_id" type="int" /> <description> - Gets an [XRPositionalTracker] for the given [code]controller_id[/code]. - 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 [XRPositionalTracker] 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: + Gets an [XRPositionalTracker] for the given [code]input_source_id[/code]. + 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] @@ -109,6 +116,13 @@ - [signal squeezestart] </description> </method> + <method name="is_input_source_active" qualifiers="const"> + <return type="bool" /> + <param index="0" name="input_source_id" type="int" /> + <description> + Returns [code]true[/code] if there is an active input source with the given [code]input_source_id[/code]. + </description> + </method> <method name="is_session_supported"> <return type="void" /> <param index="0" name="session_mode" type="String" /> @@ -120,11 +134,6 @@ </method> </methods> <members> - <member name="bounds_geometry" type="PackedVector3Array" setter="" getter="get_bounds_geometry"> - The vertices of a polygon which defines the boundaries of the user's play area. - This will only be available if [member reference_space_type] is [code]"bounded-floor"[/code] and only on certain browsers and devices that support it. - The [signal reference_space_reset] signal may indicate when this changes. - </member> <member name="optional_features" type="String" setter="set_optional_features" getter="get_optional_features"> A comma-seperated list of optional features used by [method 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. @@ -137,7 +146,7 @@ </member> <member name="requested_reference_space_types" type="String" setter="set_requested_reference_space_types" getter="get_requested_reference_space_types"> A comma-seperated list of reference space types used by [method XRInterface.initialize] 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 [member reference_space_type] property contains the reference space type that was ultimately used. + The reference space types are requested in order, and the first one supported by the users device or browser will be used. The [member 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 [url=https://developer.mozilla.org/en-US/docs/Web/API/XRReferenceSpaceType]WebXR's XRReferenceSpaceType[/url]. If you want to use a particular reference space type, it must be listed in either [member required_features] or [member optional_features]. </member> @@ -161,35 +170,35 @@ <signal name="reference_space_reset"> <description> 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 [member bounds_geometry]) or pressed/held a button to recenter their position. + 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 [method XRInterface.get_play_area]) or pressed/held a button to recenter their position. See [url=https://developer.mozilla.org/en-US/docs/Web/API/XRReferenceSpace/reset_event]WebXR's XRReferenceSpace reset event[/url] for more information. </description> </signal> <signal name="select"> - <param index="0" name="controller_id" type="int" /> + <param index="0" name="input_source_id" type="int" /> <description> - Emitted after one of the "controllers" has finished its "primary action". - Use [method get_controller] to get more information about the controller. + Emitted after one of the input sources has finished its "primary action". + Use [method get_input_source_tracker] and [method get_input_source_target_ray_mode] to get more information about the input source. </description> </signal> <signal name="selectend"> - <param index="0" name="controller_id" type="int" /> + <param index="0" name="input_source_id" type="int" /> <description> - Emitted when one of the "controllers" has finished its "primary action". - Use [method get_controller] to get more information about the controller. + Emitted when one of the input sources has finished its "primary action". + Use [method get_input_source_tracker] and [method get_input_source_target_ray_mode] to get more information about the input source. </description> </signal> <signal name="selectstart"> - <param index="0" name="controller_id" type="int" /> + <param index="0" name="input_source_id" type="int" /> <description> - Emitted when one of the "controllers" has started its "primary action". - Use [method get_controller] to get more information about the controller. + Emitted when one of the input source has started its "primary action". + Use [method get_input_source_tracker] and [method get_input_source_target_ray_mode] to get more information about the input source. </description> </signal> <signal name="session_ended"> <description> 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 [code]get_viewport().xr = false[/code] to instruct Godot to resume rendering to the screen. + At this point, you should do [code]get_viewport().use_xr = false[/code] to instruct Godot to resume rendering to the screen. </description> </signal> <signal name="session_failed"> @@ -202,7 +211,7 @@ <signal name="session_started"> <description> Emitted by [method XRInterface.initialize] if the session is successfully started. - At this point, it's safe to do [code]get_viewport().xr = true[/code] to instruct Godot to start rendering to the AR/VR device. + At this point, it's safe to do [code]get_viewport().use_xr = true[/code] to instruct Godot to start rendering to the XR device. </description> </signal> <signal name="session_supported"> @@ -213,24 +222,24 @@ </description> </signal> <signal name="squeeze"> - <param index="0" name="controller_id" type="int" /> + <param index="0" name="input_source_id" type="int" /> <description> - Emitted after one of the "controllers" has finished its "primary squeeze action". - Use [method get_controller] to get more information about the controller. + Emitted after one of the input sources has finished its "primary squeeze action". + Use [method get_input_source_tracker] and [method get_input_source_target_ray_mode] to get more information about the input source. </description> </signal> <signal name="squeezeend"> - <param index="0" name="controller_id" type="int" /> + <param index="0" name="input_source_id" type="int" /> <description> - Emitted when one of the "controllers" has finished its "primary squeeze action". - Use [method get_controller] to get more information about the controller. + Emitted when one of the input sources has finished its "primary squeeze action". + Use [method get_input_source_tracker] and [method get_input_source_target_ray_mode] to get more information about the input source. </description> </signal> <signal name="squeezestart"> - <param index="0" name="controller_id" type="int" /> + <param index="0" name="input_source_id" type="int" /> <description> - Emitted when one of the "controllers" has started its "primary squeeze action". - Use [method get_controller] to get more information about the controller. + Emitted when one of the input sources has started its "primary squeeze action". + Use [method get_input_source_tracker] and [method get_input_source_target_ray_mode] to get more information about the input source. </description> </signal> <signal name="visibility_state_changed"> @@ -239,4 +248,18 @@ </description> </signal> </signals> + <constants> + <constant name="TARGET_RAY_MODE_UNKNOWN" value="0" enum="TargetRayMode"> + We don't know the the target ray mode. + </constant> + <constant name="TARGET_RAY_MODE_GAZE" value="1" enum="TargetRayMode"> + Target ray originates at the viewer's eyes and points in the direction they are looking. + </constant> + <constant name="TARGET_RAY_MODE_TRACKED_POINTER" value="2" enum="TargetRayMode"> + Target ray from a handheld pointer, most likely a VR touch controller. + </constant> + <constant name="TARGET_RAY_MODE_SCREEN" value="3" enum="TargetRayMode"> + Target ray from touch screen, mouse or other tactile input device. + </constant> + </constants> </class> |