webxr_api/
frame.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use euclid::RigidTransform3D;
6
7use crate::{
8    Floor, HitTestId, HitTestResult, InputFrame, Native, SubImages, Viewer, Viewports, Views,
9};
10
11/// The per-frame data that is provided by the device.
12/// <https://www.w3.org/TR/webxr/#xrframe>
13// TODO: other fields?
14#[derive(Clone, Debug)]
15#[cfg_attr(feature = "ipc", derive(serde::Serialize, serde::Deserialize))]
16pub struct Frame {
17    /// The pose information of the viewer
18    pub pose: Option<ViewerPose>,
19    /// Frame information for each connected input source
20    pub inputs: Vec<InputFrame>,
21
22    /// Events that occur with the frame.
23    pub events: Vec<FrameUpdateEvent>,
24
25    /// The subimages to render to
26    pub sub_images: Vec<SubImages>,
27
28    /// The hit test results for this frame, if any
29    pub hit_test_results: Vec<HitTestResult>,
30
31    /// The average point in time this XRFrame is expected to be displayed on the devices' display
32    pub predicted_display_time: f64,
33}
34
35#[derive(Clone, Debug)]
36#[cfg_attr(feature = "ipc", derive(serde::Serialize, serde::Deserialize))]
37pub enum FrameUpdateEvent {
38    UpdateFloorTransform(Option<RigidTransform3D<f32, Native, Floor>>),
39    UpdateViewports(Viewports),
40    HitTestSourceAdded(HitTestId),
41}
42
43#[derive(Clone, Debug)]
44#[cfg_attr(feature = "ipc", derive(serde::Serialize, serde::Deserialize))]
45pub struct ViewerPose {
46    /// The transform from the viewer to native coordinates
47    ///
48    /// This is equivalent to the pose of the viewer in native coordinates.
49    /// This is the inverse of the view matrix.
50    pub transform: RigidTransform3D<f32, Viewer, Native>,
51
52    // The various views
53    pub views: Views,
54}