mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add XRJointPose
This commit is contained in:
parent
ad6da0591c
commit
c30ad6c422
5 changed files with 94 additions and 0 deletions
|
@ -579,6 +579,7 @@ pub mod xrinputsource;
|
|||
pub mod xrinputsourcearray;
|
||||
pub mod xrinputsourceevent;
|
||||
pub mod xrinputsourceschangeevent;
|
||||
pub mod xrjointpose;
|
||||
pub mod xrjointspace;
|
||||
pub mod xrlayer;
|
||||
pub mod xrmediabinding;
|
||||
|
|
|
@ -10,5 +10,6 @@ interface XRFrame {
|
|||
|
||||
[Throws] XRViewerPose? getViewerPose(XRReferenceSpace referenceSpace);
|
||||
[Throws] XRPose? getPose(XRSpace space, XRSpace relativeTo);
|
||||
[Pref="dom.webxr.hands.enabled", Throws] XRJointPose? getJointPose(XRJointSpace space, XRSpace relativeTo);
|
||||
sequence<XRHitTestResult> getHitTestResults(XRHitTestSource hitTestSource);
|
||||
};
|
||||
|
|
10
components/script/dom/webidls/XRJointPose.webidl
Normal file
10
components/script/dom/webidls/XRJointPose.webidl
Normal 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 XRJointPose: XRPose {
|
||||
readonly attribute float? radius;
|
||||
};
|
|
@ -10,6 +10,8 @@ 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::xrjointpose::XRJointPose;
|
||||
use crate::dom::xrjointspace::XRJointSpace;
|
||||
use crate::dom::xrpose::XRPose;
|
||||
use crate::dom::xrreferencespace::XRReferenceSpace;
|
||||
use crate::dom::xrsession::{ApiPose, XRSession};
|
||||
|
@ -112,6 +114,38 @@ impl XRFrameMethods for XRFrame {
|
|||
Ok(Some(XRPose::new(&self.global(), pose)))
|
||||
}
|
||||
|
||||
/// https://immersive-web.github.io/webxr/#dom-xrframe-getpose
|
||||
fn GetJointPose(
|
||||
&self,
|
||||
space: &XRJointSpace,
|
||||
relative_to: &XRSpace,
|
||||
) -> Result<Option<DomRoot<XRJointPose>>, Error> {
|
||||
if self.session != space.upcast::<XRSpace>().session() ||
|
||||
self.session != relative_to.session()
|
||||
{
|
||||
return Err(Error::InvalidState);
|
||||
}
|
||||
if !self.active.get() {
|
||||
return Err(Error::InvalidState);
|
||||
}
|
||||
let joint_frame = if let Some(frame) = space.frame(&self.data) {
|
||||
frame
|
||||
} else {
|
||||
return Ok(None);
|
||||
};
|
||||
let relative_to = if let Some(r) = self.get_pose(relative_to) {
|
||||
r
|
||||
} else {
|
||||
return Ok(None);
|
||||
};
|
||||
let pose = relative_to.inverse().pre_transform(&joint_frame.pose);
|
||||
Ok(Some(XRJointPose::new(
|
||||
&self.global(),
|
||||
pose.cast_unit(),
|
||||
Some(joint_frame.radius),
|
||||
)))
|
||||
}
|
||||
|
||||
/// https://immersive-web.github.io/hit-test/#dom-xrframe-gethittestresults
|
||||
fn GetHitTestResults(&self, source: &XRHitTestSource) -> Vec<DomRoot<XRHitTestResult>> {
|
||||
self.data
|
||||
|
|
48
components/script/dom/xrjointpose.rs
Normal file
48
components/script/dom/xrjointpose.rs
Normal file
|
@ -0,0 +1,48 @@
|
|||
/* 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::codegen::Bindings::XRJointPoseBinding::XRJointPoseMethods;
|
||||
use crate::dom::bindings::num::Finite;
|
||||
use crate::dom::bindings::reflector::reflect_dom_object;
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::xrpose::XRPose;
|
||||
use crate::dom::xrrigidtransform::XRRigidTransform;
|
||||
use crate::dom::xrsession::ApiRigidTransform;
|
||||
use dom_struct::dom_struct;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct XRJointPose {
|
||||
pose: XRPose,
|
||||
radius: Option<f32>,
|
||||
}
|
||||
|
||||
impl XRJointPose {
|
||||
fn new_inherited(transform: &XRRigidTransform, radius: Option<f32>) -> XRJointPose {
|
||||
XRJointPose {
|
||||
pose: XRPose::new_inherited(transform),
|
||||
radius,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn new(
|
||||
global: &GlobalScope,
|
||||
pose: ApiRigidTransform,
|
||||
radius: Option<f32>,
|
||||
) -> DomRoot<XRJointPose> {
|
||||
let transform = XRRigidTransform::new(global, pose);
|
||||
reflect_dom_object(
|
||||
Box::new(XRJointPose::new_inherited(&transform, radius)),
|
||||
global,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl XRJointPoseMethods for XRJointPose {
|
||||
/// https://immersive-web.github.io/webxr/#dom-XRJointPose-views
|
||||
fn GetRadius(&self) -> Option<Finite<f32>> {
|
||||
self.radius.map(Finite::wrap)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue