Skip to content

Commit

Permalink
Webxrdevice (#2000)
Browse files Browse the repository at this point in the history
* 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 <kev.kirkland@elucidata.co.uk>
  • Loading branch information
kevthecoder and Kev Kirkland authored Mar 17, 2020
1 parent 3c85ae1 commit 2b29650
Show file tree
Hide file tree
Showing 49 changed files with 3,109 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ members = [
"examples/webaudio",
"examples/webgl",
"examples/websockets",
"examples/webxr",
"examples/without-a-bundler",
"examples/without-a-bundler-no-modules",
"tests/no-std",
Expand Down
32 changes: 32 additions & 0 deletions crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,38 @@ XmlHttpRequestEventTarget = ["EventTarget"]
XmlHttpRequestResponseType = []
XmlHttpRequestUpload = ["EventTarget", "XmlHttpRequestEventTarget"]
XmlSerializer = []
Xr = ["EventTarget"]
XrBoundedReferenceSpace = ["EventTarget", "XrReferenceSpace", "XrSpace"]
XrEye = []
XrFrame = []
XrHandedness = []
XrInputSource = []
XrInputSourceArray = []
XrInputSourceEvent = ["Event"]
XrInputSourceEventInit = []
XrInputSourcesChangeEvent = ["Event"]
XrInputSourcesChangeEventInit = []
XrPose = []
XrReferenceSpace = ["EventTarget", "XrSpace"]
XrReferenceSpaceEvent = ["Event"]
XrReferenceSpaceEventInit = []
XrReferenceSpaceType = []
XrRenderState = []
XrRenderStateInit = []
XrRigidTransform = []
XrSession = ["EventTarget"]
XrSessionEvent = ["Event"]
XrSessionEventInit = []
XrSessionInit = []
XrSessionMode = []
XrSpace = ["EventTarget"]
XrTargetRayMode = []
XrView = []
XrViewerPose = ["XrPose"]
XrViewport = []
XrVisibilityState = []
XrWebGlLayer = []
XrWebGlLayerInit = []
XsltProcessor = []
console = []
css = []
12 changes: 12 additions & 0 deletions crates/web-sys/src/features/gen_Navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ extern "C" {
#[doc = "*This API requires the following crate features to be activated: `CredentialsContainer`, `Navigator`*"]
pub fn credentials(this: &Navigator) -> CredentialsContainer;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "Xr")]
# [ wasm_bindgen ( structural , method , getter , js_class = "Navigator" , js_name = xr ) ]
#[doc = "Getter for the `xr` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/xr)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Navigator`, `Xr`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn xr(this: &Navigator) -> Xr;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "Gpu")]
# [ wasm_bindgen ( structural , method , getter , js_class = "Navigator" , js_name = gpu ) ]
#[doc = "Getter for the `gpu` field of this object."]
Expand Down
7 changes: 7 additions & 0 deletions crates/web-sys/src/features/gen_WebGl2RenderingContext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5844,6 +5844,13 @@ extern "C" {
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebGl2RenderingContext`, `WebGlProgram`*"]
pub fn link_program(this: &WebGl2RenderingContext, program: &WebGlProgram);
# [ wasm_bindgen ( method , structural , js_class = "WebGL2RenderingContext" , js_name = makeXRCompatible ) ]
#[doc = "The `makeXRCompatible()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/makeXRCompatible)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebGl2RenderingContext`*"]
pub fn make_xr_compatible(this: &WebGl2RenderingContext) -> ::js_sys::Promise;
# [ wasm_bindgen ( method , structural , js_class = "WebGL2RenderingContext" , js_name = pixelStorei ) ]
#[doc = "The `pixelStorei()` method."]
#[doc = ""]
Expand Down
17 changes: 17 additions & 0 deletions crates/web-sys/src/features/gen_WebGlContextAttributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,21 @@ impl WebGlContextAttributes {
let _ = r;
self
}
#[doc = "Change the `xrCompatible` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebGlContextAttributes`*"]
pub fn xr_compatible(&mut self, val: bool) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(
self.as_ref(),
&JsValue::from("xrCompatible"),
&JsValue::from(val),
);
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
}
7 changes: 7 additions & 0 deletions crates/web-sys/src/features/gen_WebGlRenderingContext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,13 @@ extern "C" {
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebGlProgram`, `WebGlRenderingContext`*"]
pub fn link_program(this: &WebGlRenderingContext, program: &WebGlProgram);
# [ wasm_bindgen ( method , structural , js_class = "WebGLRenderingContext" , js_name = makeXRCompatible ) ]
#[doc = "The `makeXRCompatible()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/makeXRCompatible)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `WebGlRenderingContext`*"]
pub fn make_xr_compatible(this: &WebGlRenderingContext) -> ::js_sys::Promise;
# [ wasm_bindgen ( method , structural , js_class = "WebGLRenderingContext" , js_name = pixelStorei ) ]
#[doc = "The `pixelStorei()` method."]
#[doc = ""]
Expand Down
80 changes: 80 additions & 0 deletions crates/web-sys/src/features/gen_Xr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [ wasm_bindgen ( extends = EventTarget , extends = :: js_sys :: Object , js_name = XR , typescript_type = "XR" ) ]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `Xr` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XR)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Xr`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type Xr;
#[cfg(web_sys_unstable_apis)]
# [ wasm_bindgen ( structural , method , getter , js_class = "XR" , js_name = ondevicechange ) ]
#[doc = "Getter for the `ondevicechange` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XR/ondevicechange)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Xr`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn ondevicechange(this: &Xr) -> Option<::js_sys::Function>;
#[cfg(web_sys_unstable_apis)]
# [ wasm_bindgen ( structural , method , setter , js_class = "XR" , js_name = ondevicechange ) ]
#[doc = "Setter for the `ondevicechange` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XR/ondevicechange)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Xr`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn set_ondevicechange(this: &Xr, value: Option<&::js_sys::Function>);
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "XrSessionMode")]
# [ wasm_bindgen ( method , structural , js_class = "XR" , js_name = isSessionSupported ) ]
#[doc = "The `isSessionSupported()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XR/isSessionSupported)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Xr`, `XrSessionMode`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn is_session_supported(this: &Xr, mode: XrSessionMode) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "XrSessionMode")]
# [ wasm_bindgen ( method , structural , js_class = "XR" , js_name = requestSession ) ]
#[doc = "The `requestSession()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XR/requestSession)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Xr`, `XrSessionMode`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn request_session(this: &Xr, mode: XrSessionMode) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
#[cfg(all(feature = "XrSessionInit", feature = "XrSessionMode",))]
# [ wasm_bindgen ( method , structural , js_class = "XR" , js_name = requestSession ) ]
#[doc = "The `requestSession()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XR/requestSession)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Xr`, `XrSessionInit`, `XrSessionMode`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn request_session_with_options(
this: &Xr,
mode: XrSessionMode,
options: &XrSessionInit,
) -> ::js_sys::Promise;
}
29 changes: 29 additions & 0 deletions crates/web-sys/src/features/gen_XrBoundedReferenceSpace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [ wasm_bindgen ( extends = XrReferenceSpace , extends = XrSpace , extends = EventTarget , extends = :: js_sys :: Object , js_name = XRBoundedReferenceSpace , typescript_type = "XRBoundedReferenceSpace" ) ]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `XrBoundedReferenceSpace` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRBoundedReferenceSpace)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `XrBoundedReferenceSpace`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type XrBoundedReferenceSpace;
#[cfg(web_sys_unstable_apis)]
# [ wasm_bindgen ( structural , method , getter , js_class = "XRBoundedReferenceSpace" , js_name = boundsGeometry ) ]
#[doc = "Getter for the `boundsGeometry` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRBoundedReferenceSpace/boundsGeometry)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `XrBoundedReferenceSpace`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn bounds_geometry(this: &XrBoundedReferenceSpace) -> ::js_sys::Array;
}
16 changes: 16 additions & 0 deletions crates/web-sys/src/features/gen_XrEye.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![allow(unused_imports)]
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
#[doc = "The `XrEye` enum."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `XrEye`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum XrEye {
None = "none",
Left = "left",
Right = "right",
}
57 changes: 57 additions & 0 deletions crates/web-sys/src/features/gen_XrFrame.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [ wasm_bindgen ( extends = :: js_sys :: Object , js_name = XRFrame , typescript_type = "XRFrame" ) ]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `XrFrame` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRFrame)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `XrFrame`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type XrFrame;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "XrSession")]
# [ wasm_bindgen ( structural , method , getter , js_class = "XRFrame" , js_name = session ) ]
#[doc = "Getter for the `session` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRFrame/session)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `XrFrame`, `XrSession`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn session(this: &XrFrame) -> XrSession;
#[cfg(web_sys_unstable_apis)]
#[cfg(all(feature = "XrPose", feature = "XrSpace",))]
# [ wasm_bindgen ( method , structural , js_class = "XRFrame" , js_name = getPose ) ]
#[doc = "The `getPose()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRFrame/getPose)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `XrFrame`, `XrPose`, `XrSpace`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn get_pose(this: &XrFrame, space: &XrSpace, base_space: &XrSpace) -> Option<XrPose>;
#[cfg(web_sys_unstable_apis)]
#[cfg(all(feature = "XrReferenceSpace", feature = "XrViewerPose",))]
# [ wasm_bindgen ( method , structural , js_class = "XRFrame" , js_name = getViewerPose ) ]
#[doc = "The `getViewerPose()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRFrame/getViewerPose)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `XrFrame`, `XrReferenceSpace`, `XrViewerPose`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn get_viewer_pose(
this: &XrFrame,
reference_space: &XrReferenceSpace,
) -> Option<XrViewerPose>;
}
16 changes: 16 additions & 0 deletions crates/web-sys/src/features/gen_XrHandedness.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![allow(unused_imports)]
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
#[doc = "The `XrHandedness` enum."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `XrHandedness`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum XrHandedness {
None = "none",
Left = "left",
Right = "right",
}
Loading

0 comments on commit 2b29650

Please sign in to comment.