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 malloc_size_of_derive::MallocSizeOf;
7use serde::{Deserialize, Serialize};
8
9use crate::{
10 Floor, HitTestId, HitTestResult, InputFrame, Native, SubImages, Viewer, Viewports, Views,
11};
12
13/// The per-frame data that is provided by the device.
14/// <https://www.w3.org/TR/webxr/#xrframe>
15// TODO: other fields?
16#[derive(Clone, Debug, Serialize, Deserialize, MallocSizeOf)]
17pub struct Frame {
18 /// The pose information of the viewer
19 pub pose: Option<ViewerPose>,
20 /// Frame information for each connected input source
21 pub inputs: Vec<InputFrame>,
22
23 /// Events that occur with the frame.
24 pub events: Vec<FrameUpdateEvent>,
25
26 /// The subimages to render to
27 pub sub_images: Vec<SubImages>,
28
29 /// The hit test results for this frame, if any
30 pub hit_test_results: Vec<HitTestResult>,
31
32 /// The average point in time this XRFrame is expected to be displayed on the devices' display
33 pub predicted_display_time: f64,
34}
35
36#[derive(Clone, Debug, Serialize, Deserialize, MallocSizeOf)]
37pub enum FrameUpdateEvent {
38 UpdateFloorTransform(Option<RigidTransform3D<f32, Native, Floor>>),
39 UpdateViewports(Viewports),
40 HitTestSourceAdded(HitTestId),
41}
42
43#[derive(Clone, Debug, Serialize, Deserialize, MallocSizeOf)]
44pub struct ViewerPose {
45 /// The transform from the viewer to native coordinates
46 ///
47 /// This is equivalent to the pose of the viewer in native coordinates.
48 /// This is the inverse of the view matrix.
49 pub transform: RigidTransform3D<f32, Viewer, Native>,
50
51 // The various views
52 pub views: Views,
53}