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;
6use serde::{Deserialize, Serialize};
7
8use crate::{
9    Floor, HitTestId, HitTestResult, InputFrame, Native, SubImages, Viewer, Viewports, Views,
10};
11
12/// The per-frame data that is provided by the device.
13/// <https://www.w3.org/TR/webxr/#xrframe>
14// TODO: other fields?
15#[derive(Clone, Debug, Serialize, 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, Serialize, Deserialize)]
36pub enum FrameUpdateEvent {
37    UpdateFloorTransform(Option<RigidTransform3D<f32, Native, Floor>>),
38    UpdateViewports(Viewports),
39    HitTestSourceAdded(HitTestId),
40}
41
42#[derive(Clone, Debug, Serialize, Deserialize)]
43pub struct ViewerPose {
44    /// The transform from the viewer to native coordinates
45    ///
46    /// This is equivalent to the pose of the viewer in native coordinates.
47    /// This is the inverse of the view matrix.
48    pub transform: RigidTransform3D<f32, Viewer, Native>,
49
50    // The various views
51    pub views: Views,
52}