Skip to content
Permalink
Browse files

Add XRSession.viewerSpace

  • Loading branch information...
Manishearth committed Apr 5, 2019
1 parent 7e4b651 commit 813613628db87f09014330a9c508b079454198e6
@@ -20,6 +20,7 @@ interface XRSession : EventTarget {
readonly attribute XREnvironmentBlendMode environmentBlendMode;

readonly attribute XRRenderState renderState;
readonly attribute XRSpace viewerSpace;

// // Methods
Promise<XRReferenceSpace> requestReferenceSpace(XRReferenceSpaceOptions options);
@@ -21,6 +21,7 @@ use crate::dom::vrdisplay::VRDisplay;
use crate::dom::xrlayer::XRLayer;
use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrrenderstate::XRRenderState;
use crate::dom::xrspace::XRSpace;
use crate::dom::xrstationaryreferencespace::XRStationaryReferenceSpace;
use dom_struct::dom_struct;
use std::rc::Rc;
@@ -82,6 +83,11 @@ impl XRSessionMethods for XRSession {
)
}

// https://immersive-web.github.io/webxr/#dom-xrsession-viewerspace
fn ViewerSpace(&self) -> DomRoot<XRSpace> {
XRSpace::new_viewerspace(&self.global(), &self)
}

/// https://immersive-web.github.io/webxr/#dom-xrsession-requestanimationframe
fn UpdateRenderState(&self, init: &XRRenderStateInit) -> Rc<Promise> {
let p = Promise::new(&self.global());
@@ -18,20 +18,29 @@ use webvr_traits::WebVRFrameData;
pub struct XRSpace {
eventtarget: EventTarget,
session: Dom<XRSession>,
is_viewerspace: bool,
}

impl XRSpace {
pub fn new_inherited(session: &XRSession) -> XRSpace {
XRSpace {
eventtarget: EventTarget::new_inherited(),
session: Dom::from_ref(session),
is_viewerspace: false,
}
}

#[allow(unused)]
pub fn new(global: &GlobalScope, session: &XRSession) -> DomRoot<XRSpace> {
fn new_viewerspace_inner(session: &XRSession) -> XRSpace {
XRSpace {
eventtarget: EventTarget::new_inherited(),
session: Dom::from_ref(session),
is_viewerspace: true,
}
}

pub fn new_viewerspace(global: &GlobalScope, session: &XRSession) -> DomRoot<XRSpace> {
reflect_dom_object(
Box::new(XRSpace::new_inherited(session)),
Box::new(XRSpace::new_viewerspace_inner(session)),
global,
XRSpaceBinding::Wrap,
)
@@ -47,6 +56,8 @@ impl XRSpace {
pub fn get_pose(&self, base_pose: &WebVRFrameData) -> RigidTransform3D<f64> {
if let Some(reference) = self.downcast::<XRReferenceSpace>() {
reference.get_pose(base_pose)
} else if self.is_viewerspace {
XRSpace::viewer_pose_from_frame_data(base_pose)
} else {
unreachable!()
}

0 comments on commit 8136136

Please sign in to comment.
You can’t perform that action at this time.