Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c89dc82
commit 89fac8b
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters