Skip to content

Commit 9c18894

Browse files
committed
Add XRInteractionSpace
1 parent 4451634 commit 9c18894

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

‎ar-module-explainer.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,39 @@ function drawScene() {
6868
}
6969
```
7070

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 <a href="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+
function drawScene() {
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
98+
// see which UI element, if any, was selected
99+
}
100+
}
101+
102+
```
103+
71104
## Appendix B: Proposed IDL
72105

73106
```webidl
@@ -87,7 +120,13 @@ enum XREnvironmentBlendMode {
87120
"alpha-blend",
88121
};
89122
123+
enum XRInteractionSpace {
124+
"screen-space",
125+
"world-space",
126+
};
127+
90128
partial interface XRSession {
91129
readonly attribute XREnvironmentBlendMode environmentBlendMode;
130+
readonly attribute XRInteractionSpace interactionSpace;
92131
}
93132
```

‎index.bs‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ navigator.xr.requestSession("immersive-ar").then((session) => {
165165
</pre>
166166
</div>
167167

168+
168169
XREnvironmentBlendMode {#xrenvironmentblendmode-enum}
169170
----------------------
170171
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
190191

191192
- A blend mode of <dfn enum-value for="XREnvironmentBlendMode">additive</dfn> MUST be reported if the [=XR Compositor=] is using [=additive environment blending=].
192193

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.
200+
201+
<pre class="idl">
202+
enum XRInteractionSpace {
203+
"screen-space",
204+
"world-space",
205+
};
206+
207+
partial interface XRSession {
208+
// Attributes
209+
readonly attribute XRInteractionSpace interactionSpace;
210+
};
211+
</pre>
212+
213+
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+
193221
XR Compositor Behaviors {#xr-compositor-behaviors}
194222
---------------------
195223

0 commit comments

Comments
 (0)