Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some XRSpace improvements #23055

Merged
merged 8 commits into from Mar 21, 2019

Add requestReferenceSpace

  • Loading branch information
Manishearth committed Mar 18, 2019
commit 191fcf66cc59ef91eaf016b38188819d41b67259
@@ -4,16 +4,6 @@

// https://immersive-web.github.io/webxr/#xrreferencespace-interface

enum XRReferenceSpaceType {
"stationary",
"bounded",
"unbounded"
};

dictionary XRReferenceSpaceOptions {
required XRReferenceSpaceType type;
};

[SecureContext, Exposed=Window, Pref="dom.webxr.enabled"]
interface XRReferenceSpace : XRSpace {
attribute XRRigidTransform originOffset;
@@ -24,8 +24,7 @@ interface XRSession : EventTarget {
attribute XRLayer? baseLayer;

// // Methods
// Promise<XRReferenceSpace> requestReferenceSpace(XRReferenceSpaceType type,
// optional XRReferenceSpaceOptions options);
Promise<XRReferenceSpace> requestReferenceSpace(XRReferenceSpaceOptions options);

// FrozenArray<XRInputSource> getInputSources();

@@ -43,3 +42,15 @@ interface XRSession : EventTarget {
// attribute EventHandler onselectstart;
// attribute EventHandler onselectend;
};

enum XRReferenceSpaceType {
"identity",
"stationary",
"bounded",
"unbounded"
};

dictionary XRReferenceSpaceOptions {
required XRReferenceSpaceType type;
XRStationaryReferenceSpaceSubtype subtype;
};
@@ -10,10 +10,6 @@ enum XRStationaryReferenceSpaceSubtype {
"position-disabled"
};

dictionary XRStationaryReferenceSpaceOptions : XRReferenceSpaceOptions {
required XRStationaryReferenceSpaceSubtype subtype;
};

[SecureContext, Exposed=Window, Pref="dom.webxr.enabled"]
interface XRStationaryReferenceSpace: XRReferenceSpace {
// readonly attribute XRStationaryReferenceSpaceSubtype subtype;
@@ -7,17 +7,23 @@ use crate::dom::bindings::codegen::Bindings::XRBinding::XRSessionMode;
use crate::dom::bindings::codegen::Bindings::XRSessionBinding;
use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XREnvironmentBlendMode;
use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XRFrameRequestCallback;
use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XRReferenceSpaceOptions;
use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XRReferenceSpaceType;
use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XRSessionMethods;
use crate::dom::bindings::codegen::Bindings::XRWebGLLayerBinding::XRWebGLLayerMethods;
use crate::dom::bindings::error::Error;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use crate::dom::promise::Promise;
use crate::dom::vrdisplay::VRDisplay;
use crate::dom::xrlayer::XRLayer;
use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrstationaryreferencespace::XRStationaryReferenceSpace;
use crate::dom::xrwebgllayer::XRWebGLLayer;
use dom_struct::dom_struct;
use std::rc::Rc;
@@ -111,4 +117,39 @@ impl XRSessionMethods for XRSession {
fn EnvironmentBlendMode(&self) -> XREnvironmentBlendMode {
self.blend_mode
}

/// https://immersive-web.github.io/webxr/#dom-xrsession-requestreferencespace
fn RequestReferenceSpace(&self, options: &XRReferenceSpaceOptions) -> Rc<Promise> {
let p = Promise::new(&self.global());

// https://immersive-web.github.io/webxr/#create-a-reference-space

match options.type_ {
XRReferenceSpaceType::Identity => {
p.resolve_native(&XRReferenceSpace::identity(
&self.global().as_window(),
self,
));
},
XRReferenceSpaceType::Stationary => {
if let Some(subtype) = options.subtype {
p.resolve_native(&XRStationaryReferenceSpace::new(
&self.global().as_window(),
self,
subtype,
));
} else {
p.reject_error(Error::Type(format!(
"stationary XRReferenceSpaces must specify a subtype"
)))
}
},
XRReferenceSpaceType::Bounded | XRReferenceSpaceType::Unbounded => {
// XXXManishearth eventually support these
p.reject_error(Error::NotSupported)
},
}

p
}
}
@@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::dom::bindings::codegen::Bindings::XRStationaryReferenceSpaceBinding;
use crate::dom::bindings::codegen::Bindings::XRStationaryReferenceSpaceBinding::XRStationaryReferenceSpaceSubtype;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
use crate::dom::window::Window;
@@ -14,24 +15,31 @@ use dom_struct::dom_struct;
#[dom_struct]
pub struct XRStationaryReferenceSpace {
xrreferencespace: XRReferenceSpace,
ty: XRStationaryReferenceSpaceSubtype,
}

#[allow(unused)]
impl XRStationaryReferenceSpace {
pub fn new_inherited(
session: &XRSession,
ty: XRStationaryReferenceSpaceSubtype,
transform: &XRRigidTransform,
) -> XRStationaryReferenceSpace {
XRStationaryReferenceSpace {
xrreferencespace: XRReferenceSpace::new_inherited(session, transform),
ty,
}
}

pub fn new(window: &Window, session: &XRSession) -> DomRoot<XRStationaryReferenceSpace> {
pub fn new(
window: &Window,
session: &XRSession,
ty: XRStationaryReferenceSpaceSubtype,
) -> DomRoot<XRStationaryReferenceSpace> {
let transform = XRRigidTransform::identity(window);
reflect_dom_object(
Box::new(XRStationaryReferenceSpace::new_inherited(
session, &transform,
session, ty, &transform,
)),
window,
XRStationaryReferenceSpaceBinding::Wrap,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.