- Qt 6.10
- Qt Quick 3D
- QML Types
- QtQuick3D.Xr (Technical Preview)
- XrView
- Qt Quick 3D | Commercial or GPLv3

# XrView QML Type

Sets up the view for an Xr application. More...

Import Statement: | `import QtQuick3D.Xr`
Since: | Qt 6.8
Inherits: | Node
Status: | Technical Preview

- List of all members, including inherited members

## Properties

- depthSubmissionEnabled : bool
- environment : SceneEnvironment
- fixedFoveation : enumeration
- isQuitOnSessionEndEnabled : bool
- multiViewRenderingEnabled : bool
- multiViewRenderingSupported : bool
- passthroughEnabled : bool
- passthroughSupported : bool
- referenceSpace : enumeration
- renderStats : RenderStats
- runtimeInfo : QQuick3DXrRuntimeInfo
- xrOrigin : XrOrigin

## Signals

- initializeFailed(const QString &errorString)
- sessionEnded()

## Methods

- vector3d processTouch(vector3d position, int pointId)
- pickResult rayPick(vector3d origin, vector3d direction)
- List<pickResult> rayPickAll(vector3d origin, vector3d direction)
- setTouchpoint(Item target, point position, int pointId, bool pressed)
- object touchpointState(int pointId)

## Detailed Description

An XrView sets up the view for an XR application. The following snippet is from the Qt Quick 3D Xr Simple Example and shows how to use the type.

     // Copyright (C) 2023 The Qt Company Ltd.
     // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

     import QtQuick
     import QtQuick.Layouts
     import QtQuick3D.Helpers
     //! [XrView]
     import QtQuick3D
     import QtQuick3D.Xr

     XrView {
         id: xrView
         XrErrorDialog { id: err }
         onInitializeFailed: (errorString) => err.run("XRView", errorString)
         referenceSpace: XrView.ReferenceSpaceLocalFloor
     //! [XrView]

         environment: SceneEnvironment {
             clearColor: "black"
             backgroundMode: SceneEnvironment.Color
         }

## Platform notes

### Meta Quest Devices

To enable passthrough you need to add the following permisson your app's `AndroidManifest.xml` file:

     <uses-feature android:name="com.oculus.feature.PASSTHROUGH" android:required="false"/>

## Property Documentation

depthSubmissionEnabled : bool `[default: false]`

Controls whether submitting the depth buffer to the XR compositor is enabled.

By default, the depth buffer used by the 3D scene in the XrView is not exposed to the XR compositor. However, in some platforms, depth submission is implicit and cannot be disabled or controlled by the application. An example of this is VisionOS. Changing this property has no effect on those platforms. Elsewhere, with OpenXR in particular, support depends on the OpenXR implementation used at run time.

It is always safe to set depthSubmissionEnabled to `true`. It will just have no effect when not supported by the underlying stack. To be sure, you can inspect the debug output to see if depth submission is in use. Submitting the depth buffer may improve reprojections that the XR compositor may perform. Reprojection could happen, for example, when the system cannot maintain the target frame rate and thus has to resort to predicting frame contents to improve and stabilize the user's perception of the scene and reduce possible motion sickness. However, the application and Qt have no control over data usage. It could also happen that submitting depth data has no practical effects and is ignored by the underlying XR runtime and compositor.

In practice, submitting the depth buffer implies rendering into a depth texture provided by the XR runtime instead of the intermediate texture/render buffer created and managed by Qt. Rendering into a depth texture has certain lower-level consequences that can have a performance impact:

When using multisample antialiasing (MSAA), enabling depth submission implies rendering into a multisample depth texture and resolving the samples into the non-multisample depth texture provided by the XR runtime. Without depth submission, the resolve step would not be necessary. In addition, some 3D APIs do not support resolving multisample depth-stencil data (see the QRhi::ResolveDepthStencil flag for details). Without this support, attempts to enable depth submission in combination with MSAA are gracefully ignored.

Even when MSAA is not used, enabling depth submission triggers writing out depth data with 3D APIs that have control over this. The store operation for depth/stencil data is typically indicated by Qt as unnecessary, which can have positive performance impacts on tiled GPU architectures. This is not done with depth submission because depth data must always be written out from Qt's perspective.

Note: We recommended that developers test their applications with depth submission enabled, evaluate the advantages and disadvantages, and make a conscious choice based on their testing if they wish to enable it or not.

environment : SceneEnvironment

Holds

Holds the SceneEnvironment for the XR view.

fixedFoveation : enumeration `[default: XrView.HighFoveation]`

Controls the level of fixed foveated rendering for the XrView.

Foveated rendering reduces GPU load by reducing image quality (resolution) in areas where the difference is less perceptible to the eye. With fixed foveated rendering, the areas with reduced visual fidelity are fixed and do not change. On some platforms, there is no concept of fixed foveated rendering or control over it. For example, VisionOS-based devices perform dynamic, eye-tracked foveation; thus, the value of this property is ignored in practice. Other devices, such as the Meta Quest 3, only support fixed foveation, which makes this property relevant.

The value can be one of:

Constant | Description
--- | ---
`XrView.NoFoveation` | 0, no foveation.
`XrView.LowFoveation` | 1, low foveation.
`XrView.MediumFoveation` | 2, medium foveation.
`XrView.HighFoveation` | 3, high foveation.

Where supported, the default is `HighFoveation`. Therefore, changing this value in applications should be rarely needed in practice.

isQuitOnSessionEndEnabled : bool

Holds whether the application should quit when the XR session ends.

multiViewRenderingEnabled : bool `[default: true]`

This is a read-only property that reports if Multiview Rendering is enabled for the XR view.

This property tells you if multiview rendering is actually in use at run time. When not supported, the value will flip back to `false`.

Enabling multiview rendering is recommended. It can improve performance and reduce CPU and GPU power usage. It defaults to disabled to ensure maximum compatibility. Developers are encouraged to verify that their application renders as expected with multiViewRenderingEnabled set to `true` and then leave it set afterward.

Note: Certain Qt Quick and Quick 3D features that involve shader code that is provided by the application may need this code to be modified to be multiview compatible. Examples of these are custom 2D and 3D materials and postprocessing effects. The Multiview Rendering documentation provides more information on this and how to disable multiview rendering.

See also multiViewRenderingSupported and Multiview Rendering.

multiViewRenderingSupported : bool

This read-only property reports the availability of Multiview Rendering.

See also multiViewRenderingEnabled.

passthroughEnabled : bool

Holds

Holds whether passthrough is enabled for the XR view.

passthroughSupported : bool

Indicates

Indicates whether passthrough is supported for the XR view.

referenceSpace : enumeration `[default: XrView.ReferenceSpaceLocal]`

Gets or sets the reference space for the XR view.

It can be one of:

Constant | Description
--- | ---
`XrView.ReferenceSpaceUnknown` |
`XrView.ReferenceSpaceLocal` | Origin is at the default view position (typically defined by a "reset view" operation).
`XrView.ReferenceSpaceStage` | Origin is at floor height in the center of the user's defined area.
`XrView.ReferenceSpaceLocalFloor` | Origin is at floor height, below the default view position.

`ReferenceSpaceLocal` is mainly useful for seated applications where the content is not positioned relative to the floor, for example floating menus. The content will move when the user resets the view.

`ReferenceSpaceStage` is mainly useful for room-scale applications where the user will move freely within the playing area. The content will not move when the user resets the view.

`ReferenceSpaceLocalFloor` is mainly useful for stationary applications (seated or standing) where the content is positioned relative to the floor. The content will move when the user resets the view.

renderStats : RenderStats

Holds

Holds rendering statistics for the XR view.

runtimeInfo : QQuick3DXrRuntimeInfo

Provides

Provides information about the XR runtime for the XR view.

xrOrigin : XrOrigin

Holds the active XR origin.

The XR origin is the point in the scene that is considered the origin of the XR coordinate system. The XR origin is used to position tracked objects like the camera and controllers in the scene. An application can have multiple XrOrigins but only one can be active at a time.

Note: This property must be set for the scene to be rendered in XR.

See also XrOrigin.

## Signal Documentation

initializeFailed(const QString &errorString)

Emitted when initialization fails, and there is a new errorString describing the failure.

Note: The corresponding handler is `onInitializeFailed`.

sessionEnded()

Emitted when the session ends.

Note: The corresponding handler is `onSessionEnded`.

## Method Documentation

vector3d processTouch(vector3d position, int pointId)

This method will search for an XrItem near position and send a virtual touch event with touch point ID pointId if position maps to a point on the surface.

The return value is the offset between position and the touched point on the surface. This can be used to prevent a hand model from passing through an XrItem.

See also XrHandModel.

pickResult rayPick(vector3d origin, vector3d direction)

This method will shoot a ray into the scene starting at origin and in direction and return information about the nearest intersection with an object in the scene.

For example, pass the position and forward vector of any object in a scene to see what object is in front of an item. This makes it possible to do picking from any point in the scene.

List<pickResult> rayPickAll(vector3d origin, vector3d direction)

This method will shoot a ray into the scene starting at origin and in direction and return a list of information about the nearest intersections with objects in the scene. The list is presorted by distance from the origin along the direction vector with the nearest intersections appearing first and the furthest appearing last.

This can, for instance, be called with the position and forward vector of any object in a scene to see what objects are in front of an item. This makes it possible to do picking from any point in the scene.

setTouchpoint(Item target, point position, int pointId, bool pressed)

Sends a synthetic touch event to target, moving the touch point with ID pointId to position, with pressed determining if the point is pressed. Also sends the appropriate touch release event if pointId was previously active on a different item.

object touchpointState(int pointId)

This method returns the state of the touch point with ID pointId. The state is represented by a map from property names to values:

Key | Type | Description
--- | --- | ---
`grabbed` | `bool` | Is the point grabbed by an item? If `false`, all other values are `undefined`.
`target` | XrItem | The item that is grabbing the touch point.
`pressed` | `bool` | Is the touch point pressed?
`cursorPos` | `point` | The 2D position of the touch point within `target`
`touchDistance` | `real` | The distance from the plane to the touch point. It will be `0` if `pressed` is `true`.