Add XRFrame::getHitTestResults()

This commit is contained in:
Manish Goregaokar 2020-04-10 20:14:50 -07:00
parent 87bce8cde9
commit f1d6a89150
3 changed files with 17 additions and 1 deletions

View file

@ -10,5 +10,5 @@ interface XRFrame {
[Throws] XRViewerPose? getViewerPose(XRReferenceSpace referenceSpace);
[Throws] XRPose? getPose(XRSpace space, XRSpace relativeTo);
// XRInputPose? getInputPose(XRInputSource inputSource, optional XRReferenceSpace referenceSpace);
sequence<XRHitTestResult> getHitTestResults(XRHitTestSource hitTestSource);
};

View file

@ -8,6 +8,8 @@ use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope;
use crate::dom::xrhittestresult::XRHitTestResult;
use crate::dom::xrhittestsource::XRHitTestSource;
use crate::dom::xrpose::XRPose;
use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrsession::{ApiPose, XRSession};
@ -109,4 +111,14 @@ impl XRFrameMethods for XRFrame {
let pose = relative_to.inverse().pre_transform(&space);
Ok(Some(XRPose::new(&self.global(), pose)))
}
/// https://immersive-web.github.io/hit-test/#dom-xrframe-gethittestresults
fn GetHitTestResults(&self, source: &XRHitTestSource) -> Vec<DomRoot<XRHitTestResult>> {
self.data
.hit_test_results
.iter()
.filter(|r| r.id == source.id())
.map(|r| XRHitTestResult::new(&self.global(), *r, self))
.collect()
}
}

View file

@ -37,6 +37,10 @@ impl XRHitTestSource {
global,
)
}
pub fn id(&self) -> HitTestId {
self.id
}
}
impl XRHitTestSourceMethods for XRHitTestSource {