Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XR support with OpenXR backend #2319

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ default = [
"hdr",
"mp3",
"x11",
"bevy_openxr", # todo: remove
]


# Force dynamic linking, which improves iterative compile times
dynamic = ["bevy_dylib"]

Expand All @@ -50,13 +52,16 @@ render = [
"bevy_internal/bevy_ui",
]

xr = ["bevy_internal/bevy_xr"]

# Optional bevy crates
bevy_audio = ["bevy_internal/bevy_audio"]
bevy_dynamic_plugin = ["bevy_internal/bevy_dynamic_plugin"]
bevy_gilrs = ["bevy_internal/bevy_gilrs"]
bevy_gltf = ["bevy_internal/bevy_gltf"]
bevy_wgpu = ["bevy_internal/bevy_wgpu"]
bevy_winit = ["bevy_internal/bevy_winit"]
bevy_openxr = ["bevy_internal/bevy_xr", "bevy_internal/bevy_openxr"]

bevy_core_pipeline = ["bevy_internal/bevy_core_pipeline"]
bevy_render2 = ["bevy_internal/bevy_render2"]
Expand Down Expand Up @@ -551,6 +556,18 @@ name = "winit_wasm"
path = "examples/wasm/winit_wasm.rs"
required-features = ["bevy_winit"]

# XR
[[example]]
name = "vr_cubes"
path = "examples/xr/vr_cubes.rs"
required-features = ["bevy_openxr"]

[[example]]
name = "vr_cubes_android"
path = "examples/xr/vr_cubes.rs"
required-features = ["bevy_openxr"]
crate-type = ["cdylib"]

# Android
[[example]]
crate-type = ["cdylib"]
Expand All @@ -563,5 +580,30 @@ assets = "assets"
res = "assets/android-res"
icon = "@mipmap/ic_launcher"
build_targets = ["aarch64-linux-android", "armv7-linux-androideabi"]
runtime_libs = "libs"

[package.metadata.android.sdk]
min_sdk_version = 16
target_sdk_version = 29

[package.metadata.android.application]
icon = "@mipmap/ic_launcher"

[[package.metadata.android.application.meta_data]]
name = "com.samsung.android.vr.application.mode"
value = "vr_only"

[package.metadata.android.application.activity]
theme = "@android:style/Theme.Black.NoTitleBar.Fullscreen"
config_changes = "density|keyboard|keyboardHidden|navigation|orientation|screenLayout|screenSize|uiMode"
launch_mode = "singleTask"
orientation = "landscape"
resizeable_activity = "false"

[[package.metadata.android.application.activity.intent_filter]]
actions = ["android.intent.action.MAIN"]
categories = [
"com.oculus.intent.category.VR",
"android.intent.category.LAUNCHER",
"android.intent.category.INFO",
]
2 changes: 2 additions & 0 deletions crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ bevy_ui = { path = "../bevy_ui", optional = true, version = "0.5.0" }
bevy_wgpu = { path = "../bevy_wgpu", optional = true, version = "0.5.0" }
bevy_winit = { path = "../bevy_winit", optional = true, version = "0.5.0" }
bevy_gilrs = { path = "../bevy_gilrs", optional = true, version = "0.5.0" }
bevy_xr = { path = "../bevy_xr", optional = true, version = "0.5.0" }
bevy_openxr = { path = "../bevy_openxr", optional = true, version = "0.5.0" }


[target.'cfg(target_os = "android")'.dependencies]
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_internal/src/default_plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use bevy_gilrs::GilrsPlugin;
use bevy_gltf::GltfPlugin;
use bevy_input::InputPlugin;
use bevy_log::LogPlugin;
#[cfg(feature = "bevy_openxr")]
use bevy_openxr::OpenXrPlugin;
#[cfg(feature = "bevy_pbr")]
use bevy_pbr::PbrPlugin;
#[cfg(feature = "bevy_render")]
Expand All @@ -29,6 +31,8 @@ use bevy_wgpu::WgpuPlugin;
use bevy_window::WindowPlugin;
#[cfg(feature = "bevy_winit")]
use bevy_winit::WinitPlugin;
#[cfg(feature = "bevy_xr")]
use bevy_xr::XrPlugin;

/// This plugin group will add all the default plugins:
/// * [`LogPlugin`]
Expand All @@ -48,6 +52,8 @@ use bevy_winit::WinitPlugin;
/// * [`GilrsPlugin`] - with feature `bevy_gilrs`
/// * [`GltfPlugin`] - with feature `bevy_gltf`
/// * [`WinitPlugin`] - with feature `bevy_winit`
/// * [`XrPlugin`] - with feature `bevy_xr`
/// * [`OpenXrPlugin`] - with feature `bevy_openxr`
/// * [`WgpuPlugin`] - with feature `bevy_wgpu`
pub struct DefaultPlugins;

Expand Down
12 changes: 12 additions & 0 deletions crates/bevy_internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ pub mod wgpu {
pub use bevy_wgpu::*;
}

#[cfg(feature = "bevy_xr")]
pub mod xr {
//! Common interface for XR backends
pub use bevy_xr::*;
}

#[cfg(feature = "bevy_openxr")]
pub mod openxr {
//! OpenXR backend
pub use bevy_openxr::*;
}

#[cfg(feature = "bevy_dynamic_plugin")]
pub mod dynamic_plugin {
pub use bevy_dynamic_plugin::*;
Expand Down
34 changes: 34 additions & 0 deletions crates/bevy_openxr/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "bevy_openxr"
version = "0.5.0"
edition = "2018"
authors = [
"Bevy Contributors <[email protected]>",
"Carter Anderson <[email protected]>",
]
description = "OpenXR presentation and input backend for Bevy Engine"
homepage = "https://bevyengine.org"
repository = "https://github.com/bevyengine/bevy"
license = "MIT"
keywords = ["bevy"]

[dependencies]
# bevy
bevy_app = { path = "../bevy_app", version = "0.5.0" }
bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" }
bevy_log = { path = "../bevy_log", version = "0.5.0" }
bevy_math = { path = "../bevy_math", version = "0.5.0" }
bevy_utils = { path = "../bevy_utils", version = "0.5.0" }
bevy_xr = { path = "../bevy_xr", version = "0.5.0" }

# other
openxr = { git = "https://github.com/Ralith/openxrs" }
serde = "1"
ash = "0.33"
wgpu = "0.11"
wgpu-hal = { version = "0.11", features = ["vulkan"] }
thiserror = "1.0"
parking_lot = "0.11"

[target.'cfg(target_os = "android")'.dependencies]
ndk-glue = "0.4.0"
17 changes: 17 additions & 0 deletions crates/bevy_openxr/lifecycle graphs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Lifecycle

## Android

```mermaid
graph
start(( )) -- Startup --> Idle -- Resume --> Running -- Pause --> Idle -- Exit --> start
```

## OpenXR

```mermaid
graph
start(( )) -- Startup --> WaitingForDevice -- SessionCreated --> Idle
Idle -- Resume --> running["Running (Hidden/Visible/Focused)"] -- Pause --> Idle
Idle -- SessionEnd --> WaitingForDevice -- Exit --> start
```
15 changes: 15 additions & 0 deletions crates/bevy_openxr/src/conversion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use bevy_math::{Quat, Vec3};
use bevy_utils::Duration;
use openxr as xr;

pub fn from_duration(duration: Duration) -> xr::Duration {
xr::Duration::from_nanos(duration.as_nanos() as _)
}

pub fn to_vec3(v: xr::Vector3f) -> Vec3 {
Vec3::new(v.x, v.y, v.z)
}

pub fn to_quat(q: xr::Quaternionf) -> Quat {
Quat::from_xyzw(q.x, q.y, q.z, q.w)
}
Loading