diff --git a/xr_api/Cargo.toml b/xr_api/Cargo.toml index 504e789..435029c 100644 --- a/xr_api/Cargo.toml +++ b/xr_api/Cargo.toml @@ -9,6 +9,7 @@ linked = ["openxr/linked"] [dependencies] futures = "0.3.29" +glam = "0.25.0" thiserror = "1.0.51" wgpu = "0.18" diff --git a/xr_api/src/api.rs b/xr_api/src/api.rs index 394e0fb..e83ca54 100644 --- a/xr_api/src/api.rs +++ b/xr_api/src/api.rs @@ -7,8 +7,12 @@ use crate::prelude::*; pub struct Entry(Rc); impl Entry { + /// Constructs a new Xr entry pub fn new() -> Self { - todo!() + #[cfg(target_family = "wasm")] + return crate::backend::webxr::WebXrEntry::new().into(); + #[cfg(not(target_family = "wasm"))] + return crate::backend::oxr::OXrEntry::new().into(); } } @@ -18,6 +22,9 @@ pub struct Instance(Rc); #[derive(Clone)] pub struct Session(Rc); +#[derive(Clone)] +pub struct View(Rc); + #[derive(Clone)] pub struct Input(Rc); @@ -48,6 +55,14 @@ impl Deref for Session { } } +impl Deref for View { + type Target = dyn ViewTrait; + + fn deref(&self) -> &Self::Target { + &*self.0 + } +} + impl Deref for Input { type Target = dyn InputTrait; @@ -86,6 +101,12 @@ impl From for Session { } } +impl From for View { + fn from(value: T) -> Self { + Self(Rc::new(value)) + } +} + impl From for Input { fn from(value: T) -> Self { Self(Rc::new(value)) diff --git a/xr_api/src/api_traits.rs b/xr_api/src/api_traits.rs index 14e964b..1c6ba47 100644 --- a/xr_api/src/api_traits.rs +++ b/xr_api/src/api_traits.rs @@ -32,6 +32,15 @@ pub trait SessionTrait { fn end_frame(&self) -> Result<()>; } +pub trait ViewTrait { + /// Returns the [TextureView] used to render this view. + fn texture_view(&self) -> TextureView; + /// Returns the [Pose] representing the current position of this view. + fn pose(&self) -> Pose; + /// Returns the projection matrix for the current view. + fn projection_matrix(&self) -> glam::Mat4; +} + pub trait InputTrait { /// Get the haptic action at the specified path. fn get_haptics(&self, path: ActionId) -> Result>; diff --git a/xr_api/src/backend/webxr.rs b/xr_api/src/backend/webxr.rs index a57bf88..2ca069f 100644 --- a/xr_api/src/backend/webxr.rs +++ b/xr_api/src/backend/webxr.rs @@ -16,6 +16,17 @@ use utils::*; #[derive(Clone)] pub struct WebXrEntry(web_sys::XrSystem); +impl WebXrEntry { + pub fn new() -> Self { + Self( + web_sys::window() + .expect("No window available in current environment") + .navigator() + .xr(), + ) + } +} + impl EntryTrait for WebXrEntry { fn available_extensions(&self) -> Result { Ok(ExtensionSet::default()) @@ -45,7 +56,7 @@ impl InstanceTrait for WebXrInstance { self.exts } - fn create_session(&self, info: SessionCreateInfo) -> Result { + fn create_session(&self, _info: SessionCreateInfo) -> Result { Ok(WebXrSession { instance: self.clone().into(), session: self @@ -170,15 +181,15 @@ impl InputTrait for WebXrInput { Ok(WebXrHaptics(haptics, path).into()) } - fn get_pose(&self, path: ActionId) -> Result> { + fn get_pose(&self, _path: ActionId) -> Result> { todo!() } - fn get_float(&self, path: ActionId) -> Result> { + fn get_float(&self, _path: ActionId) -> Result> { todo!() } - fn get_bool(&self, path: ActionId) -> Result> { + fn get_bool(&self, _path: ActionId) -> Result> { todo!() } } diff --git a/xr_api/src/error.rs b/xr_api/src/error.rs index 9626a69..dc87e98 100644 --- a/xr_api/src/error.rs +++ b/xr_api/src/error.rs @@ -10,7 +10,7 @@ pub enum XrError { } impl Display for XrError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { todo!() } }