Skip to content
This repository has been archived by the owner on Feb 16, 2025. It is now read-only.

Commit

Permalink
Expose reference space bounds
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Adams <msub2official@gmail.com>
  • Loading branch information
msub2 committed Aug 24, 2024
1 parent 13a0b24 commit f1b0f8c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions webxr-api/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::SessionInit;
use crate::SessionMode;
use crate::Viewports;

use euclid::Box2D;
use euclid::RigidTransform3D;

/// A trait for discovering XR devices
Expand Down Expand Up @@ -92,6 +93,10 @@ pub trait DeviceAPI: 'static {
fn supported_frame_rates(&self) -> Vec<f32> {
Vec::new()
}

fn reference_space_bounds(&self) -> Option<Box2D<f32, Floor>> {
None
}
}

impl<GL: 'static> DiscoveryAPI<GL> for Box<dyn DiscoveryAPI<GL>> {
Expand Down
8 changes: 8 additions & 0 deletions webxr-api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::Sender;
use crate::Viewport;
use crate::Viewports;

use euclid::Box2D;
use euclid::Rect;
use euclid::RigidTransform3D;
use euclid::Size2D;
Expand Down Expand Up @@ -146,6 +147,7 @@ pub struct Session {
granted_features: Vec<String>,
id: SessionId,
supported_frame_rates: Vec<f32>,
reference_space_bounds: Option<Box2D<f32, Floor>>,
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
Expand All @@ -161,6 +163,10 @@ impl Session {
self.floor_transform.clone()
}

pub fn reference_space_bounds(&self) -> Option<Box2D<f32, Floor>> {
self.reference_space_bounds.clone()
}

pub fn initial_inputs(&self) -> &[InputSource] {
&self.initial_inputs
}
Expand Down Expand Up @@ -314,6 +320,7 @@ where
let environment_blend_mode = self.device.environment_blend_mode();
let granted_features = self.device.granted_features().into();
let supported_frame_rates = self.device.supported_frame_rates();
let reference_space_bounds = self.device.reference_space_bounds();
Session {
floor_transform,
viewports,
Expand All @@ -323,6 +330,7 @@ where
granted_features,
id: self.id,
supported_frame_rates,
reference_space_bounds,
}
}

Expand Down
1 change: 1 addition & 0 deletions webxr-api/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub enum BaseSpace {
Local,
Floor,
Viewer,
BoundedFloor,
TargetRay(InputId),
Grip(InputId),
Joint(InputId, Joint),
Expand Down
1 change: 1 addition & 0 deletions webxr/headless/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ impl HeadlessDeviceData {
BaseSpace::Local => RigidTransform3D::identity(),
BaseSpace::Floor => self.floor_transform?.inverse().cast_unit(),
BaseSpace::Viewer => self.viewer_origin?.cast_unit(),
BaseSpace::BoundedFloor => self.floor_transform?.inverse().cast_unit(),
BaseSpace::TargetRay(id) => self
.inputs
.iter()
Expand Down
23 changes: 22 additions & 1 deletion webxr/openxr/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::gl_utils::GlClearer;
use crate::SurfmanGL;

use euclid::Box2D;
use euclid::Point2D;
use euclid::Rect;
use euclid::RigidTransform3D;
Expand Down Expand Up @@ -388,7 +389,7 @@ impl DiscoveryAPI<SurfmanGL> for OpenXrDiscovery {
)
.map_err(|e| Error::BackendSpecific(e))?;

let mut supported_features = vec!["local-floor".into()];
let mut supported_features = vec!["local-floor".into(), "bounded-floor".into()];
if instance.supports_hands {
supported_features.push("hand-tracking".into());
}
Expand Down Expand Up @@ -1620,6 +1621,26 @@ impl DeviceAPI for OpenXrDevice {
vec![]
}
}

fn reference_space_bounds(&self) -> Option<Box2D<f32, Floor>> {
match self
.session
.reference_space_bounds_rect(ReferenceSpaceType::STAGE)
{
Ok(bounds) => {
if let Some(bounds) = bounds {
let point1 = Point2D::new(-bounds.width / 2., -bounds.height / 2.);
let point2 = Point2D::new(-bounds.width / 2., bounds.height / 2.);
let point3 = Point2D::new(bounds.width / 2., bounds.height / 2.);
let point4 = Point2D::new(bounds.width / 2., -bounds.height / 2.);
Some(Box2D::from_points([point1, point2, point3, point4]))
} else {
None
}
}
Err(_) => None,
}
}
}

fn transform<Src, Dst>(pose: &Posef) -> RigidTransform3D<f32, Src, Dst> {
Expand Down

0 comments on commit f1b0f8c

Please sign in to comment.