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

Commit

Permalink
Update bounded space handling, add support in mock (#244)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Adams <msub2official@gmail.com>
  • Loading branch information
msub2 authored Aug 31, 2024
1 parent 7656508 commit 1a2186a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
5 changes: 2 additions & 3 deletions webxr-api/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ use crate::SessionInit;
use crate::SessionMode;
use crate::Viewports;

use euclid::Box2D;
use euclid::RigidTransform3D;
use euclid::{Point2D, RigidTransform3D};

/// A trait for discovering XR devices
pub trait DiscoveryAPI<GL>: 'static {
Expand Down Expand Up @@ -94,7 +93,7 @@ pub trait DeviceAPI: 'static {
Vec::new()
}

fn reference_space_bounds(&self) -> Option<Box2D<f32, Floor>> {
fn reference_space_bounds(&self) -> Option<Vec<Point2D<f32, Floor>>> {
None
}
}
Expand Down
3 changes: 2 additions & 1 deletion webxr-api/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::Viewer;
use crate::Viewport;
use crate::Visibility;

use euclid::{Rect, RigidTransform3D, Transform3D};
use euclid::{Point2D, Rect, RigidTransform3D, Transform3D};

#[cfg(feature = "ipc")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -80,6 +80,7 @@ pub enum MockDeviceMsg {
SetWorld(MockWorld),
ClearWorld,
Disconnect(Sender<()>),
SetBoundsGeometry(Vec<Point2D<f32, Floor>>),
}

#[derive(Clone, Debug)]
Expand Down
16 changes: 10 additions & 6 deletions webxr-api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::Sender;
use crate::Viewport;
use crate::Viewports;

use euclid::Box2D;
use euclid::Point2D;
use euclid::Rect;
use euclid::RigidTransform3D;
use euclid::Size2D;
Expand Down Expand Up @@ -120,6 +120,7 @@ enum SessionMsg {
CancelHitTest(HitTestId),
UpdateFrameRate(f32, Sender<f32>),
Quit,
GetBoundsGeometry(Sender<Option<Vec<Point2D<f32, Floor>>>>),
}

#[cfg_attr(feature = "ipc", derive(Serialize, Deserialize))]
Expand Down Expand Up @@ -147,7 +148,6 @@ 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 @@ -163,8 +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 reference_space_bounds(&self) -> Option<Vec<Point2D<f32, Floor>>> {
let (sender, receiver) = channel().ok()?;
let _ = self.sender.send(SessionMsg::GetBoundsGeometry(sender));
receiver.recv().ok()?
}

pub fn initial_inputs(&self) -> &[InputSource] {
Expand Down Expand Up @@ -320,7 +322,6 @@ 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 @@ -330,7 +331,6 @@ where
granted_features,
id: self.id,
supported_frame_rates,
reference_space_bounds,
}
}

Expand Down Expand Up @@ -421,6 +421,10 @@ where
self.render_state = RenderState::PendingQuit;
}
}
SessionMsg::GetBoundsGeometry(sender) => {
let bounds = self.device.reference_space_bounds();
let _ = sender.send(bounds);
}
}
true
}
Expand Down
12 changes: 11 additions & 1 deletion webxr/headless/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use crate::SurfmanGL;
use crate::SurfmanLayerManager;
use euclid::RigidTransform3D;
use euclid::{Point2D, RigidTransform3D};
use std::sync::{Arc, Mutex};
use std::thread;
use surfman::chains::SwapChains;
Expand Down Expand Up @@ -64,6 +64,7 @@ struct HeadlessDeviceData {
disconnected: bool,
world: Option<MockWorld>,
next_id: u32,
bounds_geometry: Vec<Point2D<f32, Floor>>,
}

impl MockDiscoveryAPI<SurfmanGL> for HeadlessMockDiscovery {
Expand All @@ -86,6 +87,7 @@ impl MockDiscoveryAPI<SurfmanGL> for HeadlessMockDiscovery {
disconnected: false,
world: init.world,
next_id: 0,
bounds_geometry: vec![],
};
let data = Arc::new(Mutex::new(data));
let data_ = data.clone();
Expand Down Expand Up @@ -305,6 +307,11 @@ impl DeviceAPI for HeadlessDevice {
fn cancel_hit_test(&mut self, id: HitTestId) {
self.hit_tests.cancel_hit_test(id)
}

fn reference_space_bounds(&self) -> Option<Vec<Point2D<f32, Floor>>> {
let bounds = self.data.lock().unwrap().bounds_geometry.clone();
Some(bounds)
}
}

impl HeadlessMockDiscovery {
Expand Down Expand Up @@ -495,6 +502,9 @@ impl HeadlessDeviceData {
let _ = s.send(());
return false;
}
MockDeviceMsg::SetBoundsGeometry(g) => {
self.bounds_geometry = g;
}
}
true
}
Expand Down
4 changes: 2 additions & 2 deletions webxr/openxr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ impl DeviceAPI for OpenXrDevice {
}
}

fn reference_space_bounds(&self) -> Option<Box2D<f32, Floor>> {
fn reference_space_bounds(&self) -> Option<Vec<Point2D<f32, Floor>>> {
match self
.session
.reference_space_bounds_rect(ReferenceSpaceType::STAGE)
Expand All @@ -1534,7 +1534,7 @@ impl DeviceAPI for OpenXrDevice {
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]))
Some(vec![point1, point2, point3, point4])
} else {
None
}
Expand Down

0 comments on commit 1a2186a

Please sign in to comment.