Skip to content

Commit 2b29650

Browse files
kevthecoderKev Kirkland
and
Kev Kirkland
authored
Webxrdevice (#2000)
* crates/web-sys/webidls/enabled/WebXRDevice.webidl * Add WebXR Web IDL. * Add WebXr example. * Workaround in WebXR for FrozenArray and XRWebGLLayer constructor. * Remove commented code. * Attempt to improve WebXr example. * Add WebXr as unstable WebIDL. * Fixes for XRWebGLLayer. * Tidy up WebXR example code. * Update WebXr example docs. Co-authored-by: Kev Kirkland <[email protected]>
1 parent 3c85ae1 commit 2b29650

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3109
-0
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ members = [
8282
"examples/webaudio",
8383
"examples/webgl",
8484
"examples/websockets",
85+
"examples/webxr",
8586
"examples/without-a-bundler",
8687
"examples/without-a-bundler-no-modules",
8788
"tests/no-std",

crates/web-sys/Cargo.toml

+32
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,38 @@ XmlHttpRequestEventTarget = ["EventTarget"]
12951295
XmlHttpRequestResponseType = []
12961296
XmlHttpRequestUpload = ["EventTarget", "XmlHttpRequestEventTarget"]
12971297
XmlSerializer = []
1298+
Xr = ["EventTarget"]
1299+
XrBoundedReferenceSpace = ["EventTarget", "XrReferenceSpace", "XrSpace"]
1300+
XrEye = []
1301+
XrFrame = []
1302+
XrHandedness = []
1303+
XrInputSource = []
1304+
XrInputSourceArray = []
1305+
XrInputSourceEvent = ["Event"]
1306+
XrInputSourceEventInit = []
1307+
XrInputSourcesChangeEvent = ["Event"]
1308+
XrInputSourcesChangeEventInit = []
1309+
XrPose = []
1310+
XrReferenceSpace = ["EventTarget", "XrSpace"]
1311+
XrReferenceSpaceEvent = ["Event"]
1312+
XrReferenceSpaceEventInit = []
1313+
XrReferenceSpaceType = []
1314+
XrRenderState = []
1315+
XrRenderStateInit = []
1316+
XrRigidTransform = []
1317+
XrSession = ["EventTarget"]
1318+
XrSessionEvent = ["Event"]
1319+
XrSessionEventInit = []
1320+
XrSessionInit = []
1321+
XrSessionMode = []
1322+
XrSpace = ["EventTarget"]
1323+
XrTargetRayMode = []
1324+
XrView = []
1325+
XrViewerPose = ["XrPose"]
1326+
XrViewport = []
1327+
XrVisibilityState = []
1328+
XrWebGlLayer = []
1329+
XrWebGlLayerInit = []
12981330
XsltProcessor = []
12991331
console = []
13001332
css = []

crates/web-sys/src/features/gen_Navigator.rs

+12
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ extern "C" {
105105
#[doc = "*This API requires the following crate features to be activated: `CredentialsContainer`, `Navigator`*"]
106106
pub fn credentials(this: &Navigator) -> CredentialsContainer;
107107
#[cfg(web_sys_unstable_apis)]
108+
#[cfg(feature = "Xr")]
109+
# [ wasm_bindgen ( structural , method , getter , js_class = "Navigator" , js_name = xr ) ]
110+
#[doc = "Getter for the `xr` field of this object."]
111+
#[doc = ""]
112+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/xr)"]
113+
#[doc = ""]
114+
#[doc = "*This API requires the following crate features to be activated: `Navigator`, `Xr`*"]
115+
#[doc = ""]
116+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
117+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
118+
pub fn xr(this: &Navigator) -> Xr;
119+
#[cfg(web_sys_unstable_apis)]
108120
#[cfg(feature = "Gpu")]
109121
# [ wasm_bindgen ( structural , method , getter , js_class = "Navigator" , js_name = gpu ) ]
110122
#[doc = "Getter for the `gpu` field of this object."]

crates/web-sys/src/features/gen_WebGl2RenderingContext.rs

+7
Original file line numberDiff line numberDiff line change
@@ -5844,6 +5844,13 @@ extern "C" {
58445844
#[doc = ""]
58455845
#[doc = "*This API requires the following crate features to be activated: `WebGl2RenderingContext`, `WebGlProgram`*"]
58465846
pub fn link_program(this: &WebGl2RenderingContext, program: &WebGlProgram);
5847+
# [ wasm_bindgen ( method , structural , js_class = "WebGL2RenderingContext" , js_name = makeXRCompatible ) ]
5848+
#[doc = "The `makeXRCompatible()` method."]
5849+
#[doc = ""]
5850+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/makeXRCompatible)"]
5851+
#[doc = ""]
5852+
#[doc = "*This API requires the following crate features to be activated: `WebGl2RenderingContext`*"]
5853+
pub fn make_xr_compatible(this: &WebGl2RenderingContext) -> ::js_sys::Promise;
58475854
# [ wasm_bindgen ( method , structural , js_class = "WebGL2RenderingContext" , js_name = pixelStorei ) ]
58485855
#[doc = "The `pixelStorei()` method."]
58495856
#[doc = ""]

crates/web-sys/src/features/gen_WebGlContextAttributes.rs

+17
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,21 @@ impl WebGlContextAttributes {
148148
let _ = r;
149149
self
150150
}
151+
#[doc = "Change the `xrCompatible` field of this object."]
152+
#[doc = ""]
153+
#[doc = "*This API requires the following crate features to be activated: `WebGlContextAttributes`*"]
154+
pub fn xr_compatible(&mut self, val: bool) -> &mut Self {
155+
use wasm_bindgen::JsValue;
156+
let r = ::js_sys::Reflect::set(
157+
self.as_ref(),
158+
&JsValue::from("xrCompatible"),
159+
&JsValue::from(val),
160+
);
161+
debug_assert!(
162+
r.is_ok(),
163+
"setting properties should never fail on our dictionary objects"
164+
);
165+
let _ = r;
166+
self
167+
}
151168
}

crates/web-sys/src/features/gen_WebGlRenderingContext.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,13 @@ extern "C" {
15581558
#[doc = ""]
15591559
#[doc = "*This API requires the following crate features to be activated: `WebGlProgram`, `WebGlRenderingContext`*"]
15601560
pub fn link_program(this: &WebGlRenderingContext, program: &WebGlProgram);
1561+
# [ wasm_bindgen ( method , structural , js_class = "WebGLRenderingContext" , js_name = makeXRCompatible ) ]
1562+
#[doc = "The `makeXRCompatible()` method."]
1563+
#[doc = ""]
1564+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/makeXRCompatible)"]
1565+
#[doc = ""]
1566+
#[doc = "*This API requires the following crate features to be activated: `WebGlRenderingContext`*"]
1567+
pub fn make_xr_compatible(this: &WebGlRenderingContext) -> ::js_sys::Promise;
15611568
# [ wasm_bindgen ( method , structural , js_class = "WebGLRenderingContext" , js_name = pixelStorei ) ]
15621569
#[doc = "The `pixelStorei()` method."]
15631570
#[doc = ""]

crates/web-sys/src/features/gen_Xr.rs

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#![allow(unused_imports)]
2+
use super::*;
3+
use wasm_bindgen::prelude::*;
4+
#[cfg(web_sys_unstable_apis)]
5+
#[wasm_bindgen]
6+
extern "C" {
7+
# [ wasm_bindgen ( extends = EventTarget , extends = :: js_sys :: Object , js_name = XR , typescript_type = "XR" ) ]
8+
#[derive(Debug, Clone, PartialEq, Eq)]
9+
#[doc = "The `Xr` class."]
10+
#[doc = ""]
11+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XR)"]
12+
#[doc = ""]
13+
#[doc = "*This API requires the following crate features to be activated: `Xr`*"]
14+
#[doc = ""]
15+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
16+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
17+
pub type Xr;
18+
#[cfg(web_sys_unstable_apis)]
19+
# [ wasm_bindgen ( structural , method , getter , js_class = "XR" , js_name = ondevicechange ) ]
20+
#[doc = "Getter for the `ondevicechange` field of this object."]
21+
#[doc = ""]
22+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XR/ondevicechange)"]
23+
#[doc = ""]
24+
#[doc = "*This API requires the following crate features to be activated: `Xr`*"]
25+
#[doc = ""]
26+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
27+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
28+
pub fn ondevicechange(this: &Xr) -> Option<::js_sys::Function>;
29+
#[cfg(web_sys_unstable_apis)]
30+
# [ wasm_bindgen ( structural , method , setter , js_class = "XR" , js_name = ondevicechange ) ]
31+
#[doc = "Setter for the `ondevicechange` field of this object."]
32+
#[doc = ""]
33+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XR/ondevicechange)"]
34+
#[doc = ""]
35+
#[doc = "*This API requires the following crate features to be activated: `Xr`*"]
36+
#[doc = ""]
37+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
38+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
39+
pub fn set_ondevicechange(this: &Xr, value: Option<&::js_sys::Function>);
40+
#[cfg(web_sys_unstable_apis)]
41+
#[cfg(feature = "XrSessionMode")]
42+
# [ wasm_bindgen ( method , structural , js_class = "XR" , js_name = isSessionSupported ) ]
43+
#[doc = "The `isSessionSupported()` method."]
44+
#[doc = ""]
45+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XR/isSessionSupported)"]
46+
#[doc = ""]
47+
#[doc = "*This API requires the following crate features to be activated: `Xr`, `XrSessionMode`*"]
48+
#[doc = ""]
49+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
50+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
51+
pub fn is_session_supported(this: &Xr, mode: XrSessionMode) -> ::js_sys::Promise;
52+
#[cfg(web_sys_unstable_apis)]
53+
#[cfg(feature = "XrSessionMode")]
54+
# [ wasm_bindgen ( method , structural , js_class = "XR" , js_name = requestSession ) ]
55+
#[doc = "The `requestSession()` method."]
56+
#[doc = ""]
57+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XR/requestSession)"]
58+
#[doc = ""]
59+
#[doc = "*This API requires the following crate features to be activated: `Xr`, `XrSessionMode`*"]
60+
#[doc = ""]
61+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
62+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
63+
pub fn request_session(this: &Xr, mode: XrSessionMode) -> ::js_sys::Promise;
64+
#[cfg(web_sys_unstable_apis)]
65+
#[cfg(all(feature = "XrSessionInit", feature = "XrSessionMode",))]
66+
# [ wasm_bindgen ( method , structural , js_class = "XR" , js_name = requestSession ) ]
67+
#[doc = "The `requestSession()` method."]
68+
#[doc = ""]
69+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XR/requestSession)"]
70+
#[doc = ""]
71+
#[doc = "*This API requires the following crate features to be activated: `Xr`, `XrSessionInit`, `XrSessionMode`*"]
72+
#[doc = ""]
73+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
74+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
75+
pub fn request_session_with_options(
76+
this: &Xr,
77+
mode: XrSessionMode,
78+
options: &XrSessionInit,
79+
) -> ::js_sys::Promise;
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![allow(unused_imports)]
2+
use super::*;
3+
use wasm_bindgen::prelude::*;
4+
#[cfg(web_sys_unstable_apis)]
5+
#[wasm_bindgen]
6+
extern "C" {
7+
# [ wasm_bindgen ( extends = XrReferenceSpace , extends = XrSpace , extends = EventTarget , extends = :: js_sys :: Object , js_name = XRBoundedReferenceSpace , typescript_type = "XRBoundedReferenceSpace" ) ]
8+
#[derive(Debug, Clone, PartialEq, Eq)]
9+
#[doc = "The `XrBoundedReferenceSpace` class."]
10+
#[doc = ""]
11+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRBoundedReferenceSpace)"]
12+
#[doc = ""]
13+
#[doc = "*This API requires the following crate features to be activated: `XrBoundedReferenceSpace`*"]
14+
#[doc = ""]
15+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
16+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
17+
pub type XrBoundedReferenceSpace;
18+
#[cfg(web_sys_unstable_apis)]
19+
# [ wasm_bindgen ( structural , method , getter , js_class = "XRBoundedReferenceSpace" , js_name = boundsGeometry ) ]
20+
#[doc = "Getter for the `boundsGeometry` field of this object."]
21+
#[doc = ""]
22+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRBoundedReferenceSpace/boundsGeometry)"]
23+
#[doc = ""]
24+
#[doc = "*This API requires the following crate features to be activated: `XrBoundedReferenceSpace`*"]
25+
#[doc = ""]
26+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
27+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
28+
pub fn bounds_geometry(this: &XrBoundedReferenceSpace) -> ::js_sys::Array;
29+
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![allow(unused_imports)]
2+
use wasm_bindgen::prelude::*;
3+
#[cfg(web_sys_unstable_apis)]
4+
#[wasm_bindgen]
5+
#[doc = "The `XrEye` enum."]
6+
#[doc = ""]
7+
#[doc = "*This API requires the following crate features to be activated: `XrEye`*"]
8+
#[doc = ""]
9+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
10+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
11+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12+
pub enum XrEye {
13+
None = "none",
14+
Left = "left",
15+
Right = "right",
16+
}
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#![allow(unused_imports)]
2+
use super::*;
3+
use wasm_bindgen::prelude::*;
4+
#[cfg(web_sys_unstable_apis)]
5+
#[wasm_bindgen]
6+
extern "C" {
7+
# [ wasm_bindgen ( extends = :: js_sys :: Object , js_name = XRFrame , typescript_type = "XRFrame" ) ]
8+
#[derive(Debug, Clone, PartialEq, Eq)]
9+
#[doc = "The `XrFrame` class."]
10+
#[doc = ""]
11+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRFrame)"]
12+
#[doc = ""]
13+
#[doc = "*This API requires the following crate features to be activated: `XrFrame`*"]
14+
#[doc = ""]
15+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
16+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
17+
pub type XrFrame;
18+
#[cfg(web_sys_unstable_apis)]
19+
#[cfg(feature = "XrSession")]
20+
# [ wasm_bindgen ( structural , method , getter , js_class = "XRFrame" , js_name = session ) ]
21+
#[doc = "Getter for the `session` field of this object."]
22+
#[doc = ""]
23+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRFrame/session)"]
24+
#[doc = ""]
25+
#[doc = "*This API requires the following crate features to be activated: `XrFrame`, `XrSession`*"]
26+
#[doc = ""]
27+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
28+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
29+
pub fn session(this: &XrFrame) -> XrSession;
30+
#[cfg(web_sys_unstable_apis)]
31+
#[cfg(all(feature = "XrPose", feature = "XrSpace",))]
32+
# [ wasm_bindgen ( method , structural , js_class = "XRFrame" , js_name = getPose ) ]
33+
#[doc = "The `getPose()` method."]
34+
#[doc = ""]
35+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRFrame/getPose)"]
36+
#[doc = ""]
37+
#[doc = "*This API requires the following crate features to be activated: `XrFrame`, `XrPose`, `XrSpace`*"]
38+
#[doc = ""]
39+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
40+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
41+
pub fn get_pose(this: &XrFrame, space: &XrSpace, base_space: &XrSpace) -> Option<XrPose>;
42+
#[cfg(web_sys_unstable_apis)]
43+
#[cfg(all(feature = "XrReferenceSpace", feature = "XrViewerPose",))]
44+
# [ wasm_bindgen ( method , structural , js_class = "XRFrame" , js_name = getViewerPose ) ]
45+
#[doc = "The `getViewerPose()` method."]
46+
#[doc = ""]
47+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRFrame/getViewerPose)"]
48+
#[doc = ""]
49+
#[doc = "*This API requires the following crate features to be activated: `XrFrame`, `XrReferenceSpace`, `XrViewerPose`*"]
50+
#[doc = ""]
51+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
52+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
53+
pub fn get_viewer_pose(
54+
this: &XrFrame,
55+
reference_space: &XrReferenceSpace,
56+
) -> Option<XrViewerPose>;
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![allow(unused_imports)]
2+
use wasm_bindgen::prelude::*;
3+
#[cfg(web_sys_unstable_apis)]
4+
#[wasm_bindgen]
5+
#[doc = "The `XrHandedness` enum."]
6+
#[doc = ""]
7+
#[doc = "*This API requires the following crate features to be activated: `XrHandedness`*"]
8+
#[doc = ""]
9+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
10+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
11+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12+
pub enum XrHandedness {
13+
None = "none",
14+
Left = "left",
15+
Right = "right",
16+
}

0 commit comments

Comments
 (0)