Skip to content

Commit

Permalink
Merge pull request #68 from Schmarni-Dev/runtime_sessions
Browse files Browse the repository at this point in the history
Allow XR Session starting and stopping at runtime, add pipelined rendering and fix on platforms without fb passthrough
  • Loading branch information
Schmarni-Dev authored Feb 22, 2024
2 parents 71a0879 + 4f753b6 commit 76cb11d
Show file tree
Hide file tree
Showing 35 changed files with 1,759 additions and 1,245 deletions.
17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ force-link = ["openxr/linked"]
members = ["examples/android", "examples/demo"]

[dependencies]
anyhow = "1.0.75"
# anyhow = "1.0.75"
ash = "0.37.3"
bevy = "0.12"
bevy = "0.13"
futures-lite = "2.0.1"
mint = "0.5.9"
wgpu = "0.17.1"
wgpu-core = { version = "0.17.1", features = ["vulkan"] }
wgpu-hal = "0.17.1"
wgpu = "0.19"
wgpu-core = { version = "0.19", features = ["vulkan"] }
wgpu-hal = "0.19"
eyre = "0.6.11"

[target.'cfg(windows)'.dependencies]
openxr = { git = "https://github.com/Ralith/openxrs", rev = "0177d2d", features = [
Expand All @@ -45,9 +46,9 @@ ndk-context = "0.1"
jni = "0.20"

[dev-dependencies]
bevy = "0.12"
color-eyre = "0.6.2"
bevy = "0.13"
bevy_rapier3d = { git = "https://github.com/devil-ira/bevy_rapier", branch = "bevy-0.12" }
color-eyre = "0.6.2"

[[example]]
name = "xr"
Expand All @@ -57,4 +58,4 @@ path = "examples/xr.rs"
debug = true

[patch.crates-io]
ndk = { git = "https://github.com/Schmarni-Dev/ndk.git", branch = "070" }
# ndk = { git = "https://github.com/Schmarni-Dev/ndk.git", branch = "070" }
10 changes: 5 additions & 5 deletions examples/android/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ crate-type = ["rlib", "cdylib"]

[dependencies]
bevy_oxr.path = "../.."
bevy = "0.12"
bevy = "0.13"
openxr = { git = "https://github.com/Ralith/openxrs", rev = "0177d2d", features = ["mint"] }

[profile.release]
lto = "fat"
codegen-units = 1
panic = "abort"
# [profile.release]
# lto = "fat"
# codegen-units = 1
# panic = "abort"

# This metadata is used by `cargo-apk` - `xbuild` uses the `manifest.yaml` instead.
[package.metadata.android]
Expand Down
2 changes: 2 additions & 0 deletions examples/android/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ android:
required: true
- name: "com.oculus.experimental.enabled"
required: true
uses_permission:
- name: "com.oculus.permission.HAND_TRACKING"
application:
label: "Bevy Openxr Android"
theme: "@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen"
Expand Down
61 changes: 41 additions & 20 deletions examples/android/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use bevy::prelude::*;
use bevy::transform::components::Transform;
use bevy_oxr::graphics::extensions::XrExtensions;
use bevy_oxr::graphics::XrAppInfo;
use bevy_oxr::graphics::XrPreferdBlendMode::AlphaBlend;
use bevy_oxr::passthrough::{passthrough_layer_pause, passthrough_layer_resume};
use bevy_oxr::xr_init::XrRenderData;
use bevy_oxr::passthrough::{PausePassthrough, ResumePassthrough, XrPassthroughState};
use bevy_oxr::xr_init::xr_only;
use bevy_oxr::xr_input::debug_gizmos::OpenXrDebugRenderer;
use bevy_oxr::xr_input::hands::common::HandInputDebugRenderer;
use bevy_oxr::xr_input::hands::HandBone;
use bevy_oxr::xr_input::prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig};
use bevy_oxr::xr_input::trackers::{
OpenXRController, OpenXRLeftController, OpenXRRightController, OpenXRTracker,
Expand All @@ -16,7 +17,8 @@ use bevy_oxr::DefaultXrPlugins;
#[bevy_main]
fn main() {
let mut xr_extensions = XrExtensions::default();
xr_extensions.enable_fb_passthrough();
// xr_extensions.enable_fb_passthrough();
xr_extensions.enable_hand_tracking();
App::new()
.add_plugins(DefaultXrPlugins {
reqeusted_extensions: xr_extensions,
Expand All @@ -25,16 +27,28 @@ fn main() {
},
prefered_blend_mode: bevy_oxr::graphics::XrPreferdBlendMode::Opaque,
})
.add_plugins(OpenXrDebugRenderer)
// .add_plugins(OpenXrDebugRenderer)
.add_plugins(LogDiagnosticsPlugin::default())
.add_plugins(FrameTimeDiagnosticsPlugin)
.add_plugins(HandInputDebugRenderer)
// .add_plugins(bevy_oxr::passthrough::EnablePassthroughStartup)
.add_systems(Startup, setup)
.add_systems(Update, (proto_locomotion, toggle_passthrough))
.add_systems(
Update,
(proto_locomotion, toggle_passthrough).run_if(xr_only()),
)
.add_systems(Update, debug_hand_render.run_if(xr_only()))
.add_systems(Startup, spawn_controllers_example)
.insert_resource(PrototypeLocomotionConfig::default())
.run();
}

fn debug_hand_render(query: Query<&GlobalTransform, With<HandBone>>, mut gizmos: Gizmos) {
for transform in &query {
gizmos.sphere(transform.translation(), Quat::IDENTITY, 0.01, Color::RED);
}
}

/// set up a simple 3D scene
fn setup(
mut commands: Commands,
Expand All @@ -43,21 +57,21 @@ fn setup(
) {
// plane
commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(5.0).into()),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
mesh: meshes.add(Plane3d::new(Vec3::Y)),
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
..default()
});
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
mesh: meshes.add(Cuboid::from_size(Vec3::splat(0.1)).mesh()),
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
material: materials.add(Color::rgb(0.8, 0.0, 0.0).into()),
mesh: meshes.add(Mesh::from(Cuboid::from_size(Vec3::splat(0.1)))),
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.0, 0.0))),
transform: Transform::from_xyz(0.0, 0.5, 1.0),
..default()
});
Expand Down Expand Up @@ -90,15 +104,22 @@ fn spawn_controllers_example(mut commands: Commands) {
));
}

// Does this work? Not getting logs
fn toggle_passthrough(keys: Res<Input<KeyCode>>, mut xr_data: ResMut<XrRenderData>) {
// TODO: make this a vr button
fn toggle_passthrough(
keys: Res<ButtonInput<KeyCode>>,
passthrough_state: Res<XrPassthroughState>,
mut resume: EventWriter<ResumePassthrough>,
mut pause: EventWriter<PausePassthrough>,
) {
if keys.just_pressed(KeyCode::Space) {
if xr_data.xr_passthrough_active {
passthrough_layer_pause(xr_data);
bevy::log::info!("Passthrough paused");
} else {
passthrough_layer_resume(xr_data);
bevy::log::info!("Passthrough resumed");
match *passthrough_state {
XrPassthroughState::Unsupported => {}
XrPassthroughState::Running => {
pause.send_default();
}
XrPassthroughState::Paused => {
resume.send_default();
}
}
}
}
5 changes: 3 additions & 2 deletions examples/demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ crate-type = ["rlib", "cdylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = "0.12"
bevy = "0.13"
bevy_oxr.path = "../../"
bevy_rapier3d = { git = "https://github.com/devil-ira/bevy_rapier", branch = "bevy-0.12" }
# bevy_rapier3d = { git = "https://github.com/devil-ira/bevy_rapier", branch = "bevy-0.12" }
bevy_rapier3d = "0.25"
color-eyre = "0.6.2"


Expand Down
16 changes: 10 additions & 6 deletions examples/demo/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@ android:
- "runtime_libs"
manifest:
package: "org.bevyengine.demo_openxr_android"
# Are features and permissions fliped?
uses_feature:
- name: "android.hardware.vr.headtracking"
required: true
- name: "oculus.software.handtracking"
required: false
# - name: "com.oculus.feature.PASSTHROUGH"
# required: true
required: true
- name: "com.oculus.feature.PASSTHROUGH"
required: true
- name: "com.oculus.experimental.enabled"
required: true
uses_permission:
- name: "com.oculus.permission.HAND_TRACKING"
application:
label: "Bevy Openxr Android"
theme: "@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen"
meta_data:
- name: "com.oculus.intent.category.VR"
value: "vr_only"
- name: "com.samsung.android.vr.application.mode"
value: "vr_only"
- name: "com.oculus.supportedDevices"
value: "quest|quest2|quest3"
value: "quest|quest2|quest3|questpro"
activities:
- config_changes: "density|keyboard|keyboardHidden|navigation|orientation|screenLayout|screenSize|uiMode"
- config_changes: "density|keyboard|keyboardHidden|navigation|orientation|screenLayout|screenSize|uiMode|screenLayout"
launch_mode: "singleTask"
orientation: "landscape"
intent_filters:
Expand All @@ -31,5 +34,6 @@ android:
categories:
- "com.oculus.intent.category.VR"
- "android.intent.category.LAUNCHER"
- "org.khronos.openxr.intent.category.IMMERSIVE_HMD"
sdk:
target_sdk_version: 32
Loading

0 comments on commit 76cb11d

Please sign in to comment.