mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Add XRJointSpace
This commit is contained in:
parent
c89dc821ba
commit
89fac8be5c
5 changed files with 75 additions and 0 deletions
|
@ -554,6 +554,7 @@ unsafe_no_jsmanaged_fields!(
|
||||||
webxr_api::Frame,
|
webxr_api::Frame,
|
||||||
webxr_api::InputSource,
|
webxr_api::InputSource,
|
||||||
webxr_api::InputId,
|
webxr_api::InputId,
|
||||||
|
webxr_api::Joint,
|
||||||
webxr_api::HitTestId,
|
webxr_api::HitTestId,
|
||||||
webxr_api::HitTestResult
|
webxr_api::HitTestResult
|
||||||
);
|
);
|
||||||
|
|
|
@ -579,6 +579,7 @@ pub mod xrinputsource;
|
||||||
pub mod xrinputsourcearray;
|
pub mod xrinputsourcearray;
|
||||||
pub mod xrinputsourceevent;
|
pub mod xrinputsourceevent;
|
||||||
pub mod xrinputsourceschangeevent;
|
pub mod xrinputsourceschangeevent;
|
||||||
|
pub mod xrjointspace;
|
||||||
pub mod xrlayer;
|
pub mod xrlayer;
|
||||||
pub mod xrmediabinding;
|
pub mod xrmediabinding;
|
||||||
pub mod xrpose;
|
pub mod xrpose;
|
||||||
|
|
8
components/script/dom/webidls/XRJointSpace.webidl
Normal file
8
components/script/dom/webidls/XRJointSpace.webidl
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
/* 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 XRJointSpace: XRSpace {};
|
60
components/script/dom/xrjointspace.rs
Normal file
60
components/script/dom/xrjointspace.rs
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/* 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;
|
||||||
|
use crate::dom::bindings::root::DomRoot;
|
||||||
|
use crate::dom::globalscope::GlobalScope;
|
||||||
|
use crate::dom::xrsession::{ApiPose, XRSession};
|
||||||
|
use crate::dom::xrspace::XRSpace;
|
||||||
|
use dom_struct::dom_struct;
|
||||||
|
use euclid::RigidTransform3D;
|
||||||
|
use webxr_api::{BaseSpace, Frame, InputId, Joint, JointFrame, Space};
|
||||||
|
|
||||||
|
#[dom_struct]
|
||||||
|
pub struct XRJointSpace {
|
||||||
|
xrspace: XRSpace,
|
||||||
|
#[ignore_malloc_size_of = "defined in rust-webxr"]
|
||||||
|
input: InputId,
|
||||||
|
#[ignore_malloc_size_of = "defined in rust-webxr"]
|
||||||
|
joint: Joint,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl XRJointSpace {
|
||||||
|
pub fn new_inherited(session: &XRSession, input: InputId, joint: Joint) -> XRJointSpace {
|
||||||
|
XRJointSpace {
|
||||||
|
xrspace: XRSpace::new_inherited(session),
|
||||||
|
input,
|
||||||
|
joint,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn new(
|
||||||
|
global: &GlobalScope,
|
||||||
|
session: &XRSession,
|
||||||
|
input: InputId,
|
||||||
|
joint: Joint,
|
||||||
|
) -> DomRoot<XRJointSpace> {
|
||||||
|
reflect_dom_object(Box::new(Self::new_inherited(session, input, joint)), global)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn space(&self) -> Space {
|
||||||
|
let base = BaseSpace::Joint(self.input, self.joint);
|
||||||
|
let offset = RigidTransform3D::identity();
|
||||||
|
Space { base, offset }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn frame<'a>(&self, frame: &'a Frame) -> Option<&'a JointFrame> {
|
||||||
|
frame
|
||||||
|
.inputs
|
||||||
|
.iter()
|
||||||
|
.find(|i| i.id == self.input)
|
||||||
|
.and_then(|i| i.hand.as_ref())
|
||||||
|
.and_then(|h| h.get(self.joint))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_pose(&self, frame: &Frame) -> Option<ApiPose> {
|
||||||
|
self.frame(frame).map(|f| f.pose).map(|t| t.cast_unit())
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
|
||||||
use crate::dom::eventtarget::EventTarget;
|
use crate::dom::eventtarget::EventTarget;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::xrinputsource::XRInputSource;
|
use crate::dom::xrinputsource::XRInputSource;
|
||||||
|
use crate::dom::xrjointspace::XRJointSpace;
|
||||||
use crate::dom::xrreferencespace::XRReferenceSpace;
|
use crate::dom::xrreferencespace::XRReferenceSpace;
|
||||||
use crate::dom::xrsession::{cast_transform, ApiPose, XRSession};
|
use crate::dom::xrsession::{cast_transform, ApiPose, XRSession};
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
@ -61,6 +62,8 @@ impl XRSpace {
|
||||||
pub fn space(&self) -> Space {
|
pub fn space(&self) -> Space {
|
||||||
if let Some(rs) = self.downcast::<XRReferenceSpace>() {
|
if let Some(rs) = self.downcast::<XRReferenceSpace>() {
|
||||||
rs.space()
|
rs.space()
|
||||||
|
} else if let Some(j) = self.downcast::<XRJointSpace>() {
|
||||||
|
j.space()
|
||||||
} else if let Some(source) = self.input_source.get() {
|
} else if let Some(source) = self.input_source.get() {
|
||||||
let base = if self.is_grip_space {
|
let base = if self.is_grip_space {
|
||||||
BaseSpace::Grip(source.id())
|
BaseSpace::Grip(source.id())
|
||||||
|
@ -86,6 +89,8 @@ impl XRSpace {
|
||||||
pub fn get_pose(&self, base_pose: &Frame) -> Option<ApiPose> {
|
pub fn get_pose(&self, base_pose: &Frame) -> Option<ApiPose> {
|
||||||
if let Some(reference) = self.downcast::<XRReferenceSpace>() {
|
if let Some(reference) = self.downcast::<XRReferenceSpace>() {
|
||||||
reference.get_pose(base_pose)
|
reference.get_pose(base_pose)
|
||||||
|
} else if let Some(joint) = self.downcast::<XRJointSpace>() {
|
||||||
|
joint.get_pose(base_pose)
|
||||||
} else if let Some(source) = self.input_source.get() {
|
} else if let Some(source) = self.input_source.get() {
|
||||||
// XXXManishearth we should be able to request frame information
|
// XXXManishearth we should be able to request frame information
|
||||||
// for inputs when necessary instead of always loading it
|
// for inputs when necessary instead of always loading it
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue