You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ar-module-explainer.md
+39Lines changed: 39 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,6 +68,39 @@ function drawScene() {
68
68
}
69
69
```
70
70
71
+
### Drawing UI elements
72
+
73
+
The AR module supports a variety of device form factors, including "handheld" phone AR as well as "headworn" glasses-style AR. If the application wishes to show UI elements to the user, it needs to be done differently based on the form factor. This information is exposed through `XRSession`'s `interactionSpace` attribute.
74
+
75
+
For handheld devices, the UI elements probably should be drawn directly to the screen in screen-space coordinates, without applying any projections. In such a case, `interactionSpace` will report `"screen-space"`.
76
+
77
+
For headworn devices, the UI elements probably should be drawn in the world space, perhaps at some distance from the user's head so that they may easily interact with it. In such a case, `interactionSpace` will report `"world-space"`.
78
+
79
+
The <ahref="https://immersive-web.github.io/dom-overlays/">WebXR DOM Overlays module</a>, if implemented for the device, is able to automatically place UI for both handheld and headworn sessions. However, it is only useful if you wish to do your UI as DOM elements as opposed to
80
+
81
+
```js
82
+
functiondrawScene() {
83
+
// draw the rest of the scene
84
+
85
+
if (xrSession.interactionSpace=="world-space") {
86
+
// Add UI elements to actual scene
87
+
} else {
88
+
// Draw UI elements directly to screen
89
+
}
90
+
}
91
+
92
+
xrSession.onselect=function(e) {
93
+
if (xrSession.interactionSpace=="world-space") {
94
+
// intersect the target ray with the UI elements in world space
95
+
// to determine which UI element, if any, was selected
96
+
} else {
97
+
// determine the screen-space coordinates of the select event and
When drawing XR content, it is often useful to understand how the rendered pixels will be blended by the [=XR Compositor=] with the [=real-world environment=].
@@ -190,6 +191,33 @@ The <dfn attribute for="XRSession">environmentBlendMode</dfn> attribute MUST rep
190
191
191
192
- A blend mode of <dfn enum-value for="XREnvironmentBlendMode">additive</dfn> MUST be reported if the [=XR Compositor=] is using [=additive environment blending=].
192
193
194
+
195
+
196
+
XRInteractionSpace {#xrinteractionspace-enum}
197
+
----------------------
198
+
199
+
Sometimes the application will wish to draw UI that the user may interact with. WebXR allows for a variety of form factors, including both handheld phone AR and head-worn AR. For different form factors, the UIs will belong in different spaces to facilitate smooth interaction, for example the UI for handheld phone AR will likely be drawn directly on the screen without projection, but the UI for headworn AR will likely be drawn a small distance from the head so that users may use their controllers to interact with it.
The <dfn attribute for="XRSession">interactionSpace</dfn> attribute describes the best space (according to the user agent) for the application to draw interactive UI for the current session.
214
+
215
+
- An {{XRSession/interactionSpace}} value of {{XRInteractionSpace/"screen-space"}} indicates that the UI should be drawn directly to the screen without projection. Typically in this scenario, {{select!!event}} events are triggered with {{XRInputSourceEvent/inputSource}}s having an {{XRInputSource/targetRayMode}} of {{XRTargetRayMode/"screen"}}.
216
+
217
+
- An {{XRSession/interactionSpace}} value of {{XRInteractionSpace/"world-space"}} indicates that the UI should be drawn in the world, some distance from the user, so that they may interact with it using controllers. Typically in this scenario, {{select!!event}} events are triggered with {{XRInputSourceEvent/inputSource}}s having an {{XRInputSource/targetRayMode}} of {{XRTargetRayMode/"tracked-pointer"}} or {{XRTargetRayMode/"gaze"}}.
218
+
219
+
Note: The <a href="https://immersive-web.github.io/dom-overlays/">WebXR DOM Overlays module</a>, if supported, can be used in some of these cases instead.
220
+
193
221
XR Compositor Behaviors {#xr-compositor-behaviors}
0 commit comments