Auto merge of #24390 - Manishearth:grip-space, r=jdm

Support grip spaces in WebXR

Requires https://github.com/servo/webxr/pull/67

Uses the support added in https://github.com/servo/webxr/pull/67 to expose an optional grip space.

The per-frame click added there can't yet be consumed because we need to hook up gamepads (see https://github.com/servo/servo/issues/24389)

r? @asajeffrey @jdm

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24390)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-10-09 19:29:19 -04:00 committed by GitHub
commit dd1c183a2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 12 deletions

4
Cargo.lock generated
View file

@ -5927,7 +5927,7 @@ dependencies = [
[[package]] [[package]]
name = "webxr" name = "webxr"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/servo/webxr#a7e8cae09a5fc3cd3434e644b6e9e2b7697b438c" source = "git+https://github.com/servo/webxr#ec49fdd1c1a7e45a2dfde2f4a7f07e9581f386ef"
dependencies = [ dependencies = [
"bindgen", "bindgen",
"euclid", "euclid",
@ -5945,7 +5945,7 @@ dependencies = [
[[package]] [[package]]
name = "webxr-api" name = "webxr-api"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/servo/webxr#a7e8cae09a5fc3cd3434e644b6e9e2b7697b438c" source = "git+https://github.com/servo/webxr#ec49fdd1c1a7e45a2dfde2f4a7f07e9581f386ef"
dependencies = [ dependencies = [
"euclid", "euclid",
"gleam 0.6.18", "gleam 0.6.18",

View file

@ -21,6 +21,6 @@ interface XRInputSource {
readonly attribute XRHandedness handedness; readonly attribute XRHandedness handedness;
// [SameObject] readonly attribute XRTargetRayMode targetRayMode; // [SameObject] readonly attribute XRTargetRayMode targetRayMode;
[SameObject] readonly attribute XRSpace targetRaySpace; [SameObject] readonly attribute XRSpace targetRaySpace;
// [SameObject] readonly attribute XRSpace? gripSpace; [SameObject] readonly attribute XRSpace? gripSpace;
// [SameObject] readonly attribute Gamepad? gamepad; // [SameObject] readonly attribute Gamepad? gamepad;
}; };

View file

@ -18,10 +18,12 @@ use webxr_api::{Handedness, InputId, InputSource};
pub struct XRInputSource { pub struct XRInputSource {
reflector: Reflector, reflector: Reflector,
session: Dom<XRSession>, session: Dom<XRSession>,
#[ignore_malloc_size_of = "Defined in rust-webvr"] #[ignore_malloc_size_of = "Defined in rust-webxr"]
info: InputSource, info: InputSource,
#[ignore_malloc_size_of = "Defined in rust-webvr"] #[ignore_malloc_size_of = "Defined in rust-webxr"]
target_ray_space: MutNullableDom<XRSpace>, target_ray_space: MutNullableDom<XRSpace>,
#[ignore_malloc_size_of = "Defined in rust-webxr"]
grip_space: MutNullableDom<XRSpace>,
} }
impl XRInputSource { impl XRInputSource {
@ -31,6 +33,7 @@ impl XRInputSource {
session: Dom::from_ref(session), session: Dom::from_ref(session),
info, info,
target_ray_space: Default::default(), target_ray_space: Default::default(),
grip_space: Default::default(),
} }
} }
@ -65,7 +68,19 @@ impl XRInputSourceMethods for XRInputSource {
fn TargetRaySpace(&self) -> DomRoot<XRSpace> { fn TargetRaySpace(&self) -> DomRoot<XRSpace> {
self.target_ray_space.or_init(|| { self.target_ray_space.or_init(|| {
let global = self.global(); let global = self.global();
XRSpace::new_inputspace(&global, &self.session, &self) XRSpace::new_inputspace(&global, &self.session, &self, false)
}) })
} }
/// https://immersive-web.github.io/webxr/#dom-xrinputsource-gripspace
fn GetGripSpace(&self) -> Option<DomRoot<XRSpace>> {
if self.info.supports_grip {
Some(self.target_ray_space.or_init(|| {
let global = self.global();
XRSpace::new_inputspace(&global, &self.session, &self, true)
}))
} else {
None
}
}
} }

View file

@ -19,6 +19,8 @@ pub struct XRSpace {
eventtarget: EventTarget, eventtarget: EventTarget,
session: Dom<XRSession>, session: Dom<XRSession>,
input_source: MutNullableDom<XRInputSource>, input_source: MutNullableDom<XRInputSource>,
/// If we're an input space, are we an aim space or a grip space?
is_grip_space: bool,
} }
impl XRSpace { impl XRSpace {
@ -27,14 +29,20 @@ impl XRSpace {
eventtarget: EventTarget::new_inherited(), eventtarget: EventTarget::new_inherited(),
session: Dom::from_ref(session), session: Dom::from_ref(session),
input_source: Default::default(), input_source: Default::default(),
is_grip_space: false,
} }
} }
fn new_inputspace_inner(session: &XRSession, input: &XRInputSource) -> XRSpace { fn new_inputspace_inner(
session: &XRSession,
input: &XRInputSource,
is_grip_space: bool,
) -> XRSpace {
XRSpace { XRSpace {
eventtarget: EventTarget::new_inherited(), eventtarget: EventTarget::new_inherited(),
session: Dom::from_ref(session), session: Dom::from_ref(session),
input_source: MutNullableDom::new(Some(input)), input_source: MutNullableDom::new(Some(input)),
is_grip_space,
} }
} }
@ -42,9 +50,10 @@ impl XRSpace {
global: &GlobalScope, global: &GlobalScope,
session: &XRSession, session: &XRSession,
input: &XRInputSource, input: &XRInputSource,
is_grip_space: bool,
) -> DomRoot<XRSpace> { ) -> DomRoot<XRSpace> {
reflect_dom_object( reflect_dom_object(
Box::new(XRSpace::new_inputspace_inner(session, input)), Box::new(XRSpace::new_inputspace_inner(session, input, is_grip_space)),
global, global,
XRSpaceBinding::Wrap, XRSpaceBinding::Wrap,
) )
@ -72,7 +81,11 @@ impl XRSpace {
.iter() .iter()
.find(|i| i.id == id) .find(|i| i.id == id)
.expect("no input found"); .expect("no input found");
frame.target_ray_origin.map(cast_transform) if self.is_grip_space {
frame.grip_origin.map(cast_transform)
} else {
frame.target_ray_origin.map(cast_transform)
}
} else { } else {
unreachable!() unreachable!()
} }

View file

@ -125,9 +125,6 @@
[XRRay interface: existence and properties of interface prototype object] [XRRay interface: existence and properties of interface prototype object]
expected: FAIL expected: FAIL
[XRInputSource interface: attribute gripSpace]
expected: FAIL
[XRReferenceSpaceEvent interface: existence and properties of interface prototype object's "constructor" property] [XRReferenceSpaceEvent interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL expected: FAIL