Add XRHand interface

This commit is contained in:
Manish Goregaokar 2020-04-24 09:12:58 -07:00
parent 6ad3e0c047
commit c89dc821ba
7 changed files with 116 additions and 3 deletions

View file

@ -157,8 +157,8 @@ use webgpu::{
WebGPUPipelineLayout, WebGPUQueue, WebGPUShaderModule,
};
use webrender_api::{DocumentId, ImageKey};
use webxr_api::Ray;
use webxr_api::SwapChainId as WebXRSwapChainId;
use webxr_api::{Finger, Hand, Ray};
unsafe_no_jsmanaged_fields!(Tm);
@ -881,6 +881,58 @@ where
}
}
unsafe impl<J> JSTraceable for Hand<J>
where
J: JSTraceable,
{
#[inline]
unsafe fn trace(&self, trc: *mut JSTracer) {
// exhaustive match so we don't miss new fields
let Hand {
ref wrist,
ref thumb_metacarpal,
ref thumb_phalanx_proximal,
ref thumb_phalanx_distal,
ref thumb_phalanx_tip,
ref index,
ref middle,
ref ring,
ref little,
} = *self;
wrist.trace(trc);
thumb_metacarpal.trace(trc);
thumb_phalanx_proximal.trace(trc);
thumb_phalanx_distal.trace(trc);
thumb_phalanx_tip.trace(trc);
index.trace(trc);
middle.trace(trc);
ring.trace(trc);
little.trace(trc);
}
}
unsafe impl<J> JSTraceable for Finger<J>
where
J: JSTraceable,
{
#[inline]
unsafe fn trace(&self, trc: *mut JSTracer) {
// exhaustive match so we don't miss new fields
let Finger {
ref metacarpal,
ref phalanx_proximal,
ref phalanx_intermediate,
ref phalanx_distal,
ref phalanx_tip,
} = *self;
metacarpal.trace(trc);
phalanx_proximal.trace(trc);
phalanx_intermediate.trace(trc);
phalanx_distal.trace(trc);
phalanx_tip.trace(trc);
}
}
/// Holds a set of JSTraceables that need to be rooted
struct RootedTraceableSet {
set: Vec<*const dyn JSTraceable>,

View file

@ -572,6 +572,7 @@ pub mod xmlhttprequesteventtarget;
pub mod xmlhttprequestupload;
pub mod xmlserializer;
pub mod xrframe;
pub mod xrhand;
pub mod xrhittestresult;
pub mod xrhittestsource;
pub mod xrinputsource;

View file

@ -0,0 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://github.com/immersive-web/webxr-hands-input/blob/master/explainer.md
[SecureContext, Exposed=Window, Pref="dom.webxr.hands.enabled"]
interface XRHand {
// getter XRJoint(unsigned short jointIndex);
};

View file

@ -24,4 +24,7 @@ interface XRInputSource {
[SameObject] readonly attribute XRSpace? gripSpace;
// [SameObject] readonly attribute Gamepad? gamepad;
/* [SameObject] */ readonly attribute /* FrozenArray<DOMString> */ any profiles;
[Pref="dom.webxr.hands.enabled"]
readonly attribute XRHand? hand;
};

View file

@ -0,0 +1,33 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope;
use crate::dom::xrinputsource::XRInputSource;
use dom_struct::dom_struct;
use webxr_api::Hand;
#[dom_struct]
pub struct XRHand {
reflector_: Reflector,
#[ignore_malloc_size_of = "defined in webxr"]
source: Dom<XRInputSource>,
#[ignore_malloc_size_of = "partially defind in webxr"]
support: Hand<()>,
}
impl XRHand {
fn new_inherited(source: &XRInputSource, support: Hand<()>) -> XRHand {
XRHand {
reflector_: Reflector::new(),
source: Dom::from_ref(source),
support,
}
}
pub fn new(global: &GlobalScope, source: &XRInputSource, support: Hand<()>) -> DomRoot<XRHand> {
reflect_dom_object(Box::new(XRHand::new_inherited(source, support)), global)
}
}

View file

@ -8,6 +8,7 @@ use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding::{
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
use crate::dom::globalscope::GlobalScope;
use crate::dom::xrhand::XRHand;
use crate::dom::xrsession::XRSession;
use crate::dom::xrspace::XRSpace;
use crate::realms::enter_realm;
@ -24,10 +25,9 @@ pub struct XRInputSource {
session: Dom<XRSession>,
#[ignore_malloc_size_of = "Defined in rust-webxr"]
info: InputSource,
#[ignore_malloc_size_of = "Defined in rust-webxr"]
target_ray_space: MutNullableDom<XRSpace>,
#[ignore_malloc_size_of = "Defined in rust-webxr"]
grip_space: MutNullableDom<XRSpace>,
hand: MutNullableDom<XRHand>,
#[ignore_malloc_size_of = "mozjs"]
profiles: Heap<JSVal>,
}
@ -40,6 +40,7 @@ impl XRInputSource {
info,
target_ray_space: Default::default(),
grip_space: Default::default(),
hand: Default::default(),
profiles: Heap::default(),
}
}
@ -112,4 +113,16 @@ impl XRInputSourceMethods for XRInputSource {
fn Profiles(&self, _cx: JSContext) -> JSVal {
self.profiles.get()
}
// https://github.com/immersive-web/webxr-hands-input/blob/master/explainer.md
fn GetHand(&self) -> Option<DomRoot<XRHand>> {
if let Some(ref hand) = self.info.hand_support {
Some(
self.hand
.or_init(|| XRHand::new(&self.global(), &self, hand.clone())),
)
} else {
None
}
}
}

View file

@ -102,6 +102,7 @@ WEBIDL_STANDARDS = [
b"//webaudio.github.io",
b"//immersive-web.github.io/",
b"//github.com/immersive-web/webxr-test-api/",
b"//github.com/immersive-web/webxr-hands-input/",
b"//gpuweb.github.io",
# Not a URL
b"// This interface is entirely internal to Servo, and should not be" +