mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #23097 - Manishearth:transforms, r=asajeffrey
Properly support transforms in WebXR Still need to test this There are also a bunch of fixmes that I should get to in this PR. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23097) <!-- Reviewable:end -->
This commit is contained in:
commit
3c27dc993d
12 changed files with 206 additions and 61 deletions
|
@ -56,7 +56,9 @@ use cssparser::RGBA;
|
||||||
use devtools_traits::{CSSError, TimelineMarkerType, WorkerId};
|
use devtools_traits::{CSSError, TimelineMarkerType, WorkerId};
|
||||||
use encoding_rs::{Decoder, Encoding};
|
use encoding_rs::{Decoder, Encoding};
|
||||||
use euclid::Length as EuclidLength;
|
use euclid::Length as EuclidLength;
|
||||||
use euclid::{Point2D, Rect, Transform2D, Transform3D, TypedScale, TypedSize2D, Vector2D};
|
use euclid::{
|
||||||
|
Point2D, Rect, Rotation3D, Transform2D, Transform3D, TypedScale, TypedSize2D, Vector2D,
|
||||||
|
};
|
||||||
use html5ever::buffer_queue::BufferQueue;
|
use html5ever::buffer_queue::BufferQueue;
|
||||||
use html5ever::{LocalName, Namespace, Prefix, QualName};
|
use html5ever::{LocalName, Namespace, Prefix, QualName};
|
||||||
use http::header::HeaderMap;
|
use http::header::HeaderMap;
|
||||||
|
@ -491,6 +493,8 @@ unsafe_no_jsmanaged_fields!(RenderApiSender);
|
||||||
unsafe_no_jsmanaged_fields!(ResourceFetchTiming);
|
unsafe_no_jsmanaged_fields!(ResourceFetchTiming);
|
||||||
unsafe_no_jsmanaged_fields!(Timespec);
|
unsafe_no_jsmanaged_fields!(Timespec);
|
||||||
unsafe_no_jsmanaged_fields!(HTMLMediaElementFetchContext);
|
unsafe_no_jsmanaged_fields!(HTMLMediaElementFetchContext);
|
||||||
|
unsafe_no_jsmanaged_fields!(Rotation3D<f64>, Transform2D<f32>, Transform3D<f64>);
|
||||||
|
unsafe_no_jsmanaged_fields!(Point2D<f32>, Vector2D<f32>, Rect<Au>, Rect<f32>);
|
||||||
|
|
||||||
unsafe impl<'a> JSTraceable for &'a str {
|
unsafe impl<'a> JSTraceable for &'a str {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -582,27 +586,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl JSTraceable for Transform2D<f32> {
|
|
||||||
#[inline]
|
|
||||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl JSTraceable for Transform3D<f64> {
|
|
||||||
#[inline]
|
|
||||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl JSTraceable for Point2D<f32> {
|
|
||||||
#[inline]
|
|
||||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl<T, U> JSTraceable for TypedScale<f32, T, U> {
|
unsafe impl<T, U> JSTraceable for TypedScale<f32, T, U> {
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||||
|
@ -610,13 +593,6 @@ unsafe impl<T, U> JSTraceable for TypedScale<f32, T, U> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl JSTraceable for Vector2D<f32> {
|
|
||||||
#[inline]
|
|
||||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl<T> JSTraceable for EuclidLength<u64, T> {
|
unsafe impl<T> JSTraceable for EuclidLength<u64, T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||||
|
@ -624,20 +600,6 @@ unsafe impl<T> JSTraceable for EuclidLength<u64, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl JSTraceable for Rect<Au> {
|
|
||||||
#[inline]
|
|
||||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl JSTraceable for Rect<f32> {
|
|
||||||
#[inline]
|
|
||||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl<U> JSTraceable for TypedSize2D<i32, U> {
|
unsafe impl<U> JSTraceable for TypedSize2D<i32, U> {
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||||
|
|
|
@ -173,6 +173,14 @@ impl VRDisplay {
|
||||||
VRDisplayBinding::Wrap,
|
VRDisplayBinding::Wrap,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn left_eye_params_offset(&self) -> [f32; 3] {
|
||||||
|
self.left_eye_params.get().offset_array()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn right_eye_params_offset(&self) -> [f32; 3] {
|
||||||
|
self.right_eye_params.get().offset_array()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for VRDisplay {
|
impl Drop for VRDisplay {
|
||||||
|
|
|
@ -61,6 +61,10 @@ impl VREyeParameters {
|
||||||
|
|
||||||
eye_parameters
|
eye_parameters
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn offset_array(&self) -> [f32; 3] {
|
||||||
|
self.parameters.borrow().offset
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VREyeParametersMethods for VREyeParameters {
|
impl VREyeParametersMethods for VREyeParameters {
|
||||||
|
|
|
@ -10,4 +10,5 @@ interface XRRigidTransform {
|
||||||
readonly attribute DOMPointReadOnly position;
|
readonly attribute DOMPointReadOnly position;
|
||||||
readonly attribute DOMPointReadOnly orientation;
|
readonly attribute DOMPointReadOnly orientation;
|
||||||
// readonly attribute Float32Array matrix;
|
// readonly attribute Float32Array matrix;
|
||||||
|
XRRigidTransform inverse();
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,13 +5,11 @@
|
||||||
use crate::dom::bindings::codegen::Bindings::XRFrameBinding;
|
use crate::dom::bindings::codegen::Bindings::XRFrameBinding;
|
||||||
use crate::dom::bindings::codegen::Bindings::XRFrameBinding::XRFrameMethods;
|
use crate::dom::bindings::codegen::Bindings::XRFrameBinding::XRFrameMethods;
|
||||||
use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye;
|
use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye;
|
||||||
use crate::dom::bindings::inheritance::Castable;
|
|
||||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::xrreferencespace::XRReferenceSpace;
|
use crate::dom::xrreferencespace::XRReferenceSpace;
|
||||||
use crate::dom::xrsession::XRSession;
|
use crate::dom::xrsession::XRSession;
|
||||||
use crate::dom::xrstationaryreferencespace::XRStationaryReferenceSpace;
|
|
||||||
use crate::dom::xrview::XRView;
|
use crate::dom::xrview::XRView;
|
||||||
use crate::dom::xrviewerpose::XRViewerPose;
|
use crate::dom::xrviewerpose::XRViewerPose;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
@ -55,16 +53,21 @@ impl XRFrameMethods for XRFrame {
|
||||||
|
|
||||||
/// https://immersive-web.github.io/webxr/#dom-xrframe-getviewerpose
|
/// https://immersive-web.github.io/webxr/#dom-xrframe-getviewerpose
|
||||||
fn GetViewerPose(&self, reference: &XRReferenceSpace) -> Option<DomRoot<XRViewerPose>> {
|
fn GetViewerPose(&self, reference: &XRReferenceSpace) -> Option<DomRoot<XRViewerPose>> {
|
||||||
if let Some(_) = reference.downcast::<XRStationaryReferenceSpace>() {
|
let pose = reference.get_viewer_pose(&self.data);
|
||||||
// For 3DOF devices all three kinds of reference spaces are identical
|
let left = XRView::new(
|
||||||
// FIXME(#23070, Manishearth) support originOffset
|
&self.global(),
|
||||||
let left = XRView::new(&self.global(), &self.session, XREye::Left, &self.data);
|
&self.session,
|
||||||
let right = XRView::new(&self.global(), &self.session, XREye::Right, &self.data);
|
XREye::Left,
|
||||||
Some(XRViewerPose::new(&self.global(), &left, &right))
|
&pose,
|
||||||
} else {
|
&self.data,
|
||||||
// FIXME(#23070, Manishearth) support identity reference spaces
|
);
|
||||||
// depends on https://github.com/immersive-web/webxr/issues/565
|
let right = XRView::new(
|
||||||
None
|
&self.global(),
|
||||||
}
|
&self.session,
|
||||||
|
XREye::Right,
|
||||||
|
&pose,
|
||||||
|
&self.data,
|
||||||
|
);
|
||||||
|
Some(XRViewerPose::new(&self.global(), &left, &right))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use crate::dom::bindings::codegen::Bindings::XRReferenceSpaceBinding;
|
use crate::dom::bindings::codegen::Bindings::XRReferenceSpaceBinding;
|
||||||
use crate::dom::bindings::codegen::Bindings::XRReferenceSpaceBinding::XRReferenceSpaceMethods;
|
use crate::dom::bindings::codegen::Bindings::XRReferenceSpaceBinding::XRReferenceSpaceMethods;
|
||||||
|
use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::reflector::reflect_dom_object;
|
use crate::dom::bindings::reflector::reflect_dom_object;
|
||||||
use crate::dom::bindings::root::{DomRoot, MutDom};
|
use crate::dom::bindings::root::{DomRoot, MutDom};
|
||||||
use crate::dom::dompointreadonly::DOMPointReadOnly;
|
use crate::dom::dompointreadonly::DOMPointReadOnly;
|
||||||
|
@ -11,7 +12,10 @@ use crate::dom::window::Window;
|
||||||
use crate::dom::xrrigidtransform::XRRigidTransform;
|
use crate::dom::xrrigidtransform::XRRigidTransform;
|
||||||
use crate::dom::xrsession::XRSession;
|
use crate::dom::xrsession::XRSession;
|
||||||
use crate::dom::xrspace::XRSpace;
|
use crate::dom::xrspace::XRSpace;
|
||||||
|
use crate::dom::xrstationaryreferencespace::XRStationaryReferenceSpace;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
use euclid::Transform3D;
|
||||||
|
use webvr_traits::WebVRFrameData;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct XRReferenceSpace {
|
pub struct XRReferenceSpace {
|
||||||
|
@ -64,3 +68,33 @@ impl XRReferenceSpaceMethods for XRReferenceSpace {
|
||||||
self.transform.get()
|
self.transform.get()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl XRReferenceSpace {
|
||||||
|
/// Gets viewer pose represented by this space
|
||||||
|
pub fn get_viewer_pose(&self, base_pose: &WebVRFrameData) -> Transform3D<f64> {
|
||||||
|
let pose = self.get_pose(base_pose);
|
||||||
|
|
||||||
|
// This may change, see https://github.com/immersive-web/webxr/issues/567
|
||||||
|
let offset = self.transform.get().matrix();
|
||||||
|
// XXXManishearth we can directly compute the inverse from the transform parameters
|
||||||
|
// (and perhaps cache it)
|
||||||
|
// XXXManishearth we can also optimize for the unset/identity offset case
|
||||||
|
let inverse = offset
|
||||||
|
.inverse()
|
||||||
|
.expect("rigid transforms are always invertible");
|
||||||
|
inverse.pre_mul(&pose)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets pose represented by this space
|
||||||
|
///
|
||||||
|
/// Does not apply originOffset, use get_viewer_pose instead if you need it
|
||||||
|
pub fn get_pose(&self, base_pose: &WebVRFrameData) -> Transform3D<f64> {
|
||||||
|
if let Some(stationary) = self.downcast::<XRStationaryReferenceSpace>() {
|
||||||
|
stationary.get_pose(base_pose)
|
||||||
|
} else {
|
||||||
|
// non-subclassed XRReferenceSpaces exist, obtained via the "identity"
|
||||||
|
// type. The pose does not depend on the base pose.
|
||||||
|
Transform3D::identity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use crate::dom::bindings::codegen::Bindings::DOMPointBinding::DOMPointInit;
|
use crate::dom::bindings::codegen::Bindings::DOMPointBinding::DOMPointInit;
|
||||||
|
use crate::dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::DOMPointReadOnlyBinding::DOMPointReadOnlyMethods;
|
||||||
use crate::dom::bindings::codegen::Bindings::XRRigidTransformBinding;
|
use crate::dom::bindings::codegen::Bindings::XRRigidTransformBinding;
|
||||||
use crate::dom::bindings::codegen::Bindings::XRRigidTransformBinding::XRRigidTransformMethods;
|
use crate::dom::bindings::codegen::Bindings::XRRigidTransformBinding::XRRigidTransformMethods;
|
||||||
use crate::dom::bindings::error::Fallible;
|
use crate::dom::bindings::error::Fallible;
|
||||||
|
@ -12,12 +13,17 @@ use crate::dom::bindings::root::{Dom, DomRoot};
|
||||||
use crate::dom::dompointreadonly::DOMPointReadOnly;
|
use crate::dom::dompointreadonly::DOMPointReadOnly;
|
||||||
use crate::dom::window::Window;
|
use crate::dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
use euclid::{Rotation3D, Transform3D};
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct XRRigidTransform {
|
pub struct XRRigidTransform {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
position: Dom<DOMPointReadOnly>,
|
position: Dom<DOMPointReadOnly>,
|
||||||
orientation: Dom<DOMPointReadOnly>,
|
orientation: Dom<DOMPointReadOnly>,
|
||||||
|
#[ignore_malloc_size_of = "defined in euclid"]
|
||||||
|
translate: Transform3D<f64>,
|
||||||
|
#[ignore_malloc_size_of = "defined in euclid"]
|
||||||
|
rotate: Rotation3D<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XRRigidTransform {
|
impl XRRigidTransform {
|
||||||
|
@ -25,10 +31,23 @@ impl XRRigidTransform {
|
||||||
position: &DOMPointReadOnly,
|
position: &DOMPointReadOnly,
|
||||||
orientation: &DOMPointReadOnly,
|
orientation: &DOMPointReadOnly,
|
||||||
) -> XRRigidTransform {
|
) -> XRRigidTransform {
|
||||||
|
let translate = Transform3D::create_translation(
|
||||||
|
position.X() as f64,
|
||||||
|
position.Y() as f64,
|
||||||
|
position.Z() as f64,
|
||||||
|
);
|
||||||
|
let rotate = Rotation3D::unit_quaternion(
|
||||||
|
orientation.X() as f64,
|
||||||
|
orientation.Y() as f64,
|
||||||
|
orientation.Z() as f64,
|
||||||
|
orientation.W() as f64,
|
||||||
|
);
|
||||||
XRRigidTransform {
|
XRRigidTransform {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
position: Dom::from_ref(position),
|
position: Dom::from_ref(position),
|
||||||
orientation: Dom::from_ref(orientation),
|
orientation: Dom::from_ref(orientation),
|
||||||
|
translate,
|
||||||
|
rotate,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +84,7 @@ impl XRRigidTransform {
|
||||||
) -> Fallible<DomRoot<Self>> {
|
) -> Fallible<DomRoot<Self>> {
|
||||||
let global = window.global();
|
let global = window.global();
|
||||||
let position = DOMPointReadOnly::new_from_init(&global, &position);
|
let position = DOMPointReadOnly::new_from_init(&global, &position);
|
||||||
|
// XXXManishearth normalize this
|
||||||
let orientation = DOMPointReadOnly::new_from_init(&global, &orientation);
|
let orientation = DOMPointReadOnly::new_from_init(&global, &orientation);
|
||||||
Ok(XRRigidTransform::new(window, &position, &orientation))
|
Ok(XRRigidTransform::new(window, &position, &orientation))
|
||||||
}
|
}
|
||||||
|
@ -79,4 +99,48 @@ impl XRRigidTransformMethods for XRRigidTransform {
|
||||||
fn Orientation(&self) -> DomRoot<DOMPointReadOnly> {
|
fn Orientation(&self) -> DomRoot<DOMPointReadOnly> {
|
||||||
DomRoot::from_ref(&self.orientation)
|
DomRoot::from_ref(&self.orientation)
|
||||||
}
|
}
|
||||||
|
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-inverse
|
||||||
|
fn Inverse(&self) -> DomRoot<XRRigidTransform> {
|
||||||
|
// An XRRigidTransform is a rotation and a translation,
|
||||||
|
// i.e. T * R
|
||||||
|
//
|
||||||
|
// Its inverse is (T * R)^-1
|
||||||
|
// = R^-1 * T^-1
|
||||||
|
// = R^-1 * T^-1 * (R * R^-1)
|
||||||
|
// = (R^-1 * T^-1 * R) * R^-1
|
||||||
|
// = T' * R^-1
|
||||||
|
// = T' * R'
|
||||||
|
//
|
||||||
|
// (R^-1 * T^-1 * R) is a translation matrix, and R^-1 is a
|
||||||
|
// rotation matrix, so we can use these in the new rigid transform
|
||||||
|
let r_1 = self.rotate.inverse();
|
||||||
|
let t_1 = self
|
||||||
|
.translate
|
||||||
|
.inverse()
|
||||||
|
.expect("translation matrices should be invertible");
|
||||||
|
let t_p = r_1
|
||||||
|
.to_transform()
|
||||||
|
.post_mul(&t_1)
|
||||||
|
.post_mul(&self.rotate.to_transform());
|
||||||
|
|
||||||
|
let global = self.global();
|
||||||
|
let position =
|
||||||
|
DOMPointReadOnly::new(&global, t_p.m41.into(), t_p.m42.into(), t_p.m43.into(), 1.);
|
||||||
|
let orientation = DOMPointReadOnly::new(
|
||||||
|
&global,
|
||||||
|
r_1.i.into(),
|
||||||
|
r_1.j.into(),
|
||||||
|
r_1.k.into(),
|
||||||
|
r_1.r.into(),
|
||||||
|
);
|
||||||
|
XRRigidTransform::new(global.as_window(), &position, &orientation)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl XRRigidTransform {
|
||||||
|
pub fn matrix(&self) -> Transform3D<f64> {
|
||||||
|
// Spec says the orientation applies first,
|
||||||
|
// so post-multiply (?)
|
||||||
|
self.translate.post_mul(&self.rotate.to_transform())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,10 @@ impl XRSession {
|
||||||
self.display.xr_present(self, None, Some(p));
|
self.display.xr_present(self, None, Some(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn display(&self) -> &VRDisplay {
|
||||||
|
&self.display
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_layer(&self, layer: &XRLayer) {
|
pub fn set_layer(&self, layer: &XRLayer) {
|
||||||
self.base_layer.set(Some(layer))
|
self.base_layer.set(Some(layer))
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,16 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use crate::dom::bindings::codegen::Bindings::XRSpaceBinding;
|
use crate::dom::bindings::codegen::Bindings::XRSpaceBinding;
|
||||||
|
use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::reflector::reflect_dom_object;
|
use crate::dom::bindings::reflector::reflect_dom_object;
|
||||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||||
use crate::dom::eventtarget::EventTarget;
|
use crate::dom::eventtarget::EventTarget;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
|
use crate::dom::xrreferencespace::XRReferenceSpace;
|
||||||
use crate::dom::xrsession::XRSession;
|
use crate::dom::xrsession::XRSession;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
use euclid::Transform3D;
|
||||||
|
use webvr_traits::WebVRFrameData;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct XRSpace {
|
pub struct XRSpace {
|
||||||
|
@ -33,3 +37,27 @@ impl XRSpace {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl XRSpace {
|
||||||
|
/// Gets viewer pose represented by this space
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn get_viewer_pose(&self, base_pose: &WebVRFrameData) -> Transform3D<f64> {
|
||||||
|
if let Some(reference) = self.downcast::<XRReferenceSpace>() {
|
||||||
|
reference.get_viewer_pose(base_pose)
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets pose represented by this space
|
||||||
|
///
|
||||||
|
/// Does not apply originOffset, use get_viewer_pose instead if you need it
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn get_pose(&self, base_pose: &WebVRFrameData) -> Transform3D<f64> {
|
||||||
|
if let Some(reference) = self.downcast::<XRReferenceSpace>() {
|
||||||
|
reference.get_pose(base_pose)
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ use crate::dom::xrreferencespace::XRReferenceSpace;
|
||||||
use crate::dom::xrrigidtransform::XRRigidTransform;
|
use crate::dom::xrrigidtransform::XRRigidTransform;
|
||||||
use crate::dom::xrsession::XRSession;
|
use crate::dom::xrsession::XRSession;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
use euclid::{Rotation3D, Transform3D};
|
||||||
|
use webvr_traits::WebVRFrameData;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct XRStationaryReferenceSpace {
|
pub struct XRStationaryReferenceSpace {
|
||||||
|
@ -46,3 +48,23 @@ impl XRStationaryReferenceSpace {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl XRStationaryReferenceSpace {
|
||||||
|
/// Gets pose represented by this space
|
||||||
|
///
|
||||||
|
/// Does not apply originOffset, use get_viewer_pose instead
|
||||||
|
pub fn get_pose(&self, base_pose: &WebVRFrameData) -> Transform3D<f64> {
|
||||||
|
// XXXManishearth add floor-level transform for floor-level and disable position in position-disabled
|
||||||
|
let pos = base_pose.pose.position.unwrap_or([0., 0., 0.]);
|
||||||
|
let translation =
|
||||||
|
Transform3D::create_translation(pos[0] as f64, pos[1] as f64, pos[2] as f64);
|
||||||
|
let orient = base_pose.pose.orientation.unwrap_or([0., 0., 0., 0.]);
|
||||||
|
let rotation = Rotation3D::quaternion(
|
||||||
|
orient[0] as f64,
|
||||||
|
orient[1] as f64,
|
||||||
|
orient[2] as f64,
|
||||||
|
orient[3] as f64,
|
||||||
|
);
|
||||||
|
translation.pre_mul(&rotation.to_transform())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::vrframedata::create_typed_array;
|
use crate::dom::vrframedata::create_typed_array;
|
||||||
use crate::dom::xrsession::XRSession;
|
use crate::dom::xrsession::XRSession;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
use euclid::Transform3D;
|
||||||
use js::jsapi::{Heap, JSContext, JSObject};
|
use js::jsapi::{Heap, JSContext, JSObject};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
use webvr_traits::WebVRFrameData;
|
use webvr_traits::WebVRFrameData;
|
||||||
|
@ -39,6 +40,7 @@ impl XRView {
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
session: &XRSession,
|
session: &XRSession,
|
||||||
eye: XREye,
|
eye: XREye,
|
||||||
|
pose: &Transform3D<f64>,
|
||||||
data: &WebVRFrameData,
|
data: &WebVRFrameData,
|
||||||
) -> DomRoot<XRView> {
|
) -> DomRoot<XRView> {
|
||||||
let ret = reflect_dom_object(
|
let ret = reflect_dom_object(
|
||||||
|
@ -47,16 +49,29 @@ impl XRView {
|
||||||
XRViewBinding::Wrap,
|
XRViewBinding::Wrap,
|
||||||
);
|
);
|
||||||
|
|
||||||
let (proj, view) = if eye == XREye::Left {
|
let vr_display = session.display();
|
||||||
(&data.left_projection_matrix, &data.left_view_matrix)
|
|
||||||
|
// XXXManishearth compute and cache projection matrices on the Display
|
||||||
|
let (proj, offset) = if eye == XREye::Left {
|
||||||
|
(
|
||||||
|
&data.left_projection_matrix,
|
||||||
|
vr_display.left_eye_params_offset(),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
(&data.right_projection_matrix, &data.right_view_matrix)
|
(
|
||||||
|
&data.right_projection_matrix,
|
||||||
|
vr_display.right_eye_params_offset(),
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let offset =
|
||||||
|
Transform3D::create_translation(offset[0] as f64, offset[1] as f64, offset[2] as f64);
|
||||||
|
let view = pose.post_mul(&offset).cast().to_column_major_array();
|
||||||
|
|
||||||
let cx = global.get_cx();
|
let cx = global.get_cx();
|
||||||
unsafe {
|
unsafe {
|
||||||
create_typed_array(cx, proj, &ret.proj);
|
create_typed_array(cx, proj, &ret.proj);
|
||||||
create_typed_array(cx, view, &ret.view);
|
create_typed_array(cx, &view, &ret.view);
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl XRViewportMethods for XRViewport {
|
||||||
|
|
||||||
/// https://immersive-web.github.io/webxr/#dom-xrviewport-width
|
/// https://immersive-web.github.io/webxr/#dom-xrviewport-width
|
||||||
fn Width(&self) -> i32 {
|
fn Width(&self) -> i32 {
|
||||||
self.height as i32
|
self.width as i32
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://immersive-web.github.io/webxr/#dom-xrviewport-height
|
/// https://immersive-web.github.io/webxr/#dom-xrviewport-height
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue