Skip to content

Commit 113d1b1

Browse files
committed
OpenXR support
1 parent 1076a8f commit 113d1b1

20 files changed

+2476
-0
lines changed

Cargo.toml

+42
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ default = [
3636
"hdr",
3737
"mp3",
3838
"x11",
39+
"bevy_openxr", # todo: remove
3940
]
4041

42+
4143
# Force dynamic linking, which improves iterative compile times
4244
dynamic = ["bevy_dylib"]
4345

@@ -50,13 +52,16 @@ render = [
5052
"bevy_internal/bevy_ui",
5153
]
5254

55+
xr = ["bevy_internal/bevy_xr"]
56+
5357
# Optional bevy crates
5458
bevy_audio = ["bevy_internal/bevy_audio"]
5559
bevy_dynamic_plugin = ["bevy_internal/bevy_dynamic_plugin"]
5660
bevy_gilrs = ["bevy_internal/bevy_gilrs"]
5761
bevy_gltf = ["bevy_internal/bevy_gltf"]
5862
bevy_wgpu = ["bevy_internal/bevy_wgpu"]
5963
bevy_winit = ["bevy_internal/bevy_winit"]
64+
bevy_openxr = ["bevy_internal/bevy_xr", "bevy_internal/bevy_openxr"]
6065

6166
bevy_core_pipeline = ["bevy_internal/bevy_core_pipeline"]
6267
bevy_render2 = ["bevy_internal/bevy_render2"]
@@ -551,6 +556,18 @@ name = "winit_wasm"
551556
path = "examples/wasm/winit_wasm.rs"
552557
required-features = ["bevy_winit"]
553558

559+
# XR
560+
[[example]]
561+
name = "vr_cubes"
562+
path = "examples/xr/vr_cubes.rs"
563+
required-features = ["bevy_openxr"]
564+
565+
[[example]]
566+
name = "vr_cubes_android"
567+
path = "examples/xr/vr_cubes.rs"
568+
required-features = ["bevy_openxr"]
569+
crate-type = ["cdylib"]
570+
554571
# Android
555572
[[example]]
556573
crate-type = ["cdylib"]
@@ -563,5 +580,30 @@ assets = "assets"
563580
res = "assets/android-res"
564581
icon = "@mipmap/ic_launcher"
565582
build_targets = ["aarch64-linux-android", "armv7-linux-androideabi"]
583+
runtime_libs = "libs"
584+
585+
[package.metadata.android.sdk]
566586
min_sdk_version = 16
567587
target_sdk_version = 29
588+
589+
[package.metadata.android.application]
590+
icon = "@mipmap/ic_launcher"
591+
592+
[[package.metadata.android.application.meta_data]]
593+
name = "com.samsung.android.vr.application.mode"
594+
value = "vr_only"
595+
596+
[package.metadata.android.application.activity]
597+
theme = "@android:style/Theme.Black.NoTitleBar.Fullscreen"
598+
config_changes = "density|keyboard|keyboardHidden|navigation|orientation|screenLayout|screenSize|uiMode"
599+
launch_mode = "singleTask"
600+
orientation = "landscape"
601+
resizeable_activity = "false"
602+
603+
[[package.metadata.android.application.activity.intent_filter]]
604+
actions = ["android.intent.action.MAIN"]
605+
categories = [
606+
"com.oculus.intent.category.VR",
607+
"android.intent.category.LAUNCHER",
608+
"android.intent.category.INFO",
609+
]

crates/bevy_internal/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ bevy_ui = { path = "../bevy_ui", optional = true, version = "0.5.0" }
8181
bevy_wgpu = { path = "../bevy_wgpu", optional = true, version = "0.5.0" }
8282
bevy_winit = { path = "../bevy_winit", optional = true, version = "0.5.0" }
8383
bevy_gilrs = { path = "../bevy_gilrs", optional = true, version = "0.5.0" }
84+
bevy_xr = { path = "../bevy_xr", optional = true, version = "0.5.0" }
85+
bevy_openxr = { path = "../bevy_openxr", optional = true, version = "0.5.0" }
8486

8587

8688
[target.'cfg(target_os = "android")'.dependencies]

crates/bevy_internal/src/default_plugins.rs

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use bevy_gilrs::GilrsPlugin;
1212
use bevy_gltf::GltfPlugin;
1313
use bevy_input::InputPlugin;
1414
use bevy_log::LogPlugin;
15+
#[cfg(feature = "bevy_openxr")]
16+
use bevy_openxr::OpenXrPlugin;
1517
#[cfg(feature = "bevy_pbr")]
1618
use bevy_pbr::PbrPlugin;
1719
#[cfg(feature = "bevy_render")]
@@ -29,6 +31,8 @@ use bevy_wgpu::WgpuPlugin;
2931
use bevy_window::WindowPlugin;
3032
#[cfg(feature = "bevy_winit")]
3133
use bevy_winit::WinitPlugin;
34+
#[cfg(feature = "bevy_xr")]
35+
use bevy_xr::XrPlugin;
3236

3337
/// This plugin group will add all the default plugins:
3438
/// * [`LogPlugin`]
@@ -48,6 +52,8 @@ use bevy_winit::WinitPlugin;
4852
/// * [`GilrsPlugin`] - with feature `bevy_gilrs`
4953
/// * [`GltfPlugin`] - with feature `bevy_gltf`
5054
/// * [`WinitPlugin`] - with feature `bevy_winit`
55+
/// * [`XrPlugin`] - with feature `bevy_xr`
56+
/// * [`OpenXrPlugin`] - with feature `bevy_openxr`
5157
/// * [`WgpuPlugin`] - with feature `bevy_wgpu`
5258
pub struct DefaultPlugins;
5359

@@ -89,6 +95,13 @@ impl PluginGroup for DefaultPlugins {
8995
#[cfg(feature = "bevy_winit")]
9096
group.add(WinitPlugin::default());
9197

98+
#[cfg(feature = "bevy_xr")]
99+
group.add(XrPlugin::default());
100+
101+
// OpenXrPlugin must be initialized before WgpuPlugin
102+
#[cfg(feature = "bevy_openxr")]
103+
group.add(OpenXrPlugin::default());
104+
92105
#[cfg(feature = "bevy_wgpu")]
93106
group.add(WgpuPlugin::default());
94107
}

crates/bevy_internal/src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ pub mod wgpu {
164164
pub use bevy_wgpu::*;
165165
}
166166

167+
#[cfg(feature = "bevy_xr")]
168+
pub mod xr {
169+
//! Common interface for XR backends
170+
pub use bevy_xr::*;
171+
}
172+
173+
#[cfg(feature = "bevy_openxr")]
174+
pub mod openxr {
175+
//! OpenXR backend
176+
pub use bevy_openxr::*;
177+
}
178+
167179
#[cfg(feature = "bevy_dynamic_plugin")]
168180
pub mod dynamic_plugin {
169181
pub use bevy_dynamic_plugin::*;

crates/bevy_openxr/Cargo.toml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[package]
2+
name = "bevy_openxr"
3+
version = "0.5.0"
4+
edition = "2018"
5+
authors = [
6+
"Bevy Contributors <bevyengine@gmail.com>",
7+
"Carter Anderson <mcanders1@gmail.com>",
8+
]
9+
description = "OpenXR presentation and input backend for Bevy Engine"
10+
homepage = "https://bevyengine.org"
11+
repository = "https://github.com/bevyengine/bevy"
12+
license = "MIT"
13+
keywords = ["bevy"]
14+
15+
[dependencies]
16+
# bevy
17+
bevy_app = { path = "../bevy_app", version = "0.5.0" }
18+
bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" }
19+
bevy_log = { path = "../bevy_log", version = "0.5.0" }
20+
bevy_math = { path = "../bevy_math", version = "0.5.0" }
21+
bevy_utils = { path = "../bevy_utils", version = "0.5.0" }
22+
bevy_xr = { path = "../bevy_xr", version = "0.5.0" }
23+
24+
# other
25+
openxr = { git = "https://github.com/Ralith/openxrs" }
26+
serde = "1"
27+
ash = "0.33"
28+
wgpu = "0.10"
29+
wgpu-hal = { version = "0.10", features = ["vulkan"] }
30+
thiserror = "1.0"
31+
parking_lot = "0.11"
32+
33+
[target.'cfg(target_os = "android")'.dependencies]
34+
ndk-glue = "0.4.0"
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Lifecycle
2+
3+
## Android
4+
5+
```mermaid
6+
graph
7+
start(( )) -- Startup --> Idle -- Resume --> Running -- Pause --> Idle -- Exit --> start
8+
```
9+
10+
## OpenXR
11+
12+
```mermaid
13+
graph
14+
start(( )) -- Startup --> WaitingForDevice -- SessionCreated --> Idle
15+
Idle -- Resume --> running["Running (Hidden/Visible/Focused)"] -- Pause --> Idle
16+
Idle -- SessionEnd --> WaitingForDevice -- Exit --> start
17+
```

crates/bevy_openxr/src/conversion.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use bevy_math::{Quat, Vec3};
2+
use bevy_utils::Duration;
3+
use openxr as xr;
4+
5+
pub fn from_duration(duration: Duration) -> xr::Duration {
6+
xr::Duration::from_nanos(duration.as_nanos() as _)
7+
}
8+
9+
pub fn to_vec3(v: xr::Vector3f) -> Vec3 {
10+
Vec3::new(v.x, v.y, v.z)
11+
}
12+
13+
pub fn to_quat(q: xr::Quaternionf) -> Quat {
14+
Quat::from_xyzw(q.x, q.y, q.z, q.w)
15+
}

0 commit comments

Comments
 (0)