Skip to content

Commit

Permalink
make app close when requested by os and other stuff (#61)
Browse files Browse the repository at this point in the history
* idk

* mr stuff

* done

* fix windows

* add patches to Readme
  • Loading branch information
Schmarni-Dev authored Dec 31, 2023
1 parent fcedb9c commit 65a30ca
Show file tree
Hide file tree
Showing 22 changed files with 666 additions and 165 deletions.
10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ license = "MIT/Apache-2.0"


[features]
default = ["linked"]
linked = ["openxr/linked"]
default = []
force-link = ["openxr/linked"]

[workspace]
members = ["examples/android", "examples/demo"]
Expand All @@ -24,9 +24,10 @@ wgpu = "0.17.1"
wgpu-core = { version = "0.17.1", features = ["vulkan"] }
wgpu-hal = "0.17.1"

[target.'cfg(windows)'.dependencies]
openxr = { version = "0.17.1", features = ["linked","static","mint"] }
[target.'cfg(all(target_family = "unix", not(target_arch = "wasm32")) )'.dependencies]
openxr = { version = "0.17.1", features = ["mint"] }

[target.'cfg(all(not(target_family = "unix"), not(target_arch = "wasm32")))'.dependencies]
openxr = { version = "0.17.1", features = ["mint", "static"] }

Expand All @@ -41,3 +42,6 @@ path = "examples/xr.rs"

[profile.release]
debug = true

[patch.crates-io]
ndk = { git = "https://github.com/Schmarni-Dev/ndk.git", branch = "070" }
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@ To see it in action run the example in `examples` with `cargo run --example xr`
- Make sure, if you're on Linux, that you have the `openxr` package installed on your system.
- I'm getting poor performance.
- Like other bevy projects, make sure you're building in release (example: `cargo run --example xr --release`)

## Recommendations

for now we recommend you to add the folowing to your root Cargo.toml
```
[patch.crates-io]
ndk = { git = "https://github.com/Schmarni-Dev/ndk.git", branch = "070" }
ndk-sys = { package = "ndk-sys", git = "https://github.com/Schmarni-Dev/ndk.git", branch = "070" }
ndk-context = { package = "ndk-context", git = "https://github.com/Schmarni-Dev/ndk.git", branch = "070" }
bevy_pbr = { package = "bevy_pbr", git = "https://github.com/MalekiRe/bevy", branch = "release-0.12.1" }
```
6 changes: 1 addition & 5 deletions examples/android/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ license = "MIT OR Apache-2.0"
name = "bevy_openxr_android"
crate-type = ["rlib", "cdylib"]

[target.'cfg(not(target_os="android"))'.dependencies.bevy_oxr]
path = "../../"
default-features = true


[dependencies]
bevy_oxr = { path = "../..", default-features = false }
bevy_oxr.path = "../.."
bevy = "0.12"
openxr = { git = "https://github.com/Ralith/openxrs", features = ["mint"] }

Expand Down
8 changes: 7 additions & 1 deletion examples/android/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::prelude::*;
use bevy::transform::components::Transform;
use bevy_oxr::graphics::XrAppInfo;
use bevy_oxr::xr_input::debug_gizmos::OpenXrDebugRenderer;
use bevy_oxr::xr_input::prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig};
use bevy_oxr::xr_input::trackers::{
Expand All @@ -11,7 +12,12 @@ use bevy_oxr::DefaultXrPlugins;
#[bevy_main]
fn main() {
App::new()
.add_plugins(DefaultXrPlugins)
.add_plugins(DefaultXrPlugins {
app_info: XrAppInfo {
name: "Bevy OXR Android Example".into(),
},
..default()
})
.add_plugins(OpenXrDebugRenderer)
.add_plugins(LogDiagnosticsPlugin::default())
.add_plugins(FrameTimeDiagnosticsPlugin)
Expand Down
19 changes: 14 additions & 5 deletions examples/demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ crate-type = ["rlib", "cdylib"]

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


[target.'cfg(not(target_os="android"))'.dependencies.bevy_oxr]
path = "../../"
# May need to be more specific. needs to be false at least on linux without an active runtime to run in flat
default-features = true
# [target.'cfg(not(target_os="android"))'.dependencies.bevy_oxr]
# path = "../../"
# # May need to be more specific. needs to be false at least on linux without an active runtime to run in flat
# default-features = true

[profile.release]
debug = true

[patch.crates-io]
ndk = { git = "https://github.com/Schmarni-Dev/ndk.git", branch = "070" }
ndk-sys = { package = "ndk-sys", git = "https://github.com/Schmarni-Dev/ndk.git", branch = "070" }
ndk-context = { package = "ndk-context", git = "https://github.com/Schmarni-Dev/ndk.git", branch = "070" }
ndk-glue = { package = "ndk-glue", git = "https://github.com/Schmarni-Dev/ndk.git", branch = "070" }
5 changes: 3 additions & 2 deletions examples/demo/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ 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.experimental.enabled"
required: true
# - name: "com.oculus.feature.PASSTHROUGH"
# required: true
uses_permission:
- name: "com.oculus.permission.HAND_TRACKING"
application:
Expand Down
21 changes: 17 additions & 4 deletions examples/demo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ use bevy::{
transform::TransformSystem,
};
use bevy_oxr::{
graphics::{extensions::XrExtensions, XrAppInfo, XrPreferdBlendMode},
input::XrInput,
xr_init::{XrEnableRequest, XrEnableStatus, xr_only},
resources::{XrFrameState, XrInstance, XrSession},
xr_init::{xr_only, XrEnableRequest, XrEnableStatus},
xr_input::{
actions::XrActionSets,
debug_gizmos::OpenXrDebugRenderer,
Expand All @@ -31,7 +32,10 @@ use bevy_oxr::{
},
oculus_touch::OculusController,
prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig},
trackers::{OpenXRController, OpenXRLeftController, OpenXRRightController, OpenXRTracker},
trackers::{
OpenXRController, OpenXRLeftController, OpenXRRightController, OpenXRTracker,
OpenXRTrackingRoot,
},
Hand,
},
DefaultXrPlugins,
Expand Down Expand Up @@ -61,13 +65,20 @@ pub fn main() {

info!("Running bevy_openxr demo");
let mut app = App::new();
let mut xr_extensions = XrExtensions::default();

app.add_systems(Update, input_stuff)
//lets get the usual diagnostic stuff added
.add_plugins(LogDiagnosticsPlugin::default())
.add_plugins(FrameTimeDiagnosticsPlugin)
//lets get the xr defaults added
.add_plugins(DefaultXrPlugins)
.add_plugins(DefaultXrPlugins {
reqeusted_extensions: xr_extensions,
prefered_blend_mode: XrPreferdBlendMode::Opaque,
app_info: XrAppInfo {
name: "Bevy OXR Demo".into(),
},
})
//lets add the debug renderer for the controllers
.add_plugins(OpenXrDebugRenderer)
//rapier goes here
Expand All @@ -93,7 +104,9 @@ pub fn main() {
//draw the interaction gizmos
.add_systems(
Update,
draw_interaction_gizmos.run_if(xr_only()).after(update_interactable_states),
draw_interaction_gizmos
.run_if(xr_only())
.after(update_interactable_states),
)
.add_systems(Update, draw_socket_gizmos.after(update_interactable_states))
//add our cube spawning system
Expand Down
4 changes: 2 additions & 2 deletions examples/demo/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bevy::{
};
use bevy_oxr::xr_input::interactions::{Touched, XRInteractable, XRInteractableState};
use bevy_rapier3d::{
prelude::{Collider, RigidBody, Group, CollisionGroups},
prelude::{Collider, CollisionGroups, Group, RigidBody},
render::ColliderDebugColor,
};

Expand Down Expand Up @@ -67,7 +67,7 @@ pub fn setup_scene(
// });
// camera
commands.spawn((Camera3dBundle {
transform: Transform::from_xyz(0.25, 1.25, 0.0).looking_at(
transform: Transform::from_xyz(5.25, 5.25, 5.0).looking_at(
Vec3 {
x: -0.548,
y: -0.161,
Expand Down
8 changes: 7 additions & 1 deletion examples/globe.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bevy::diagnostic::LogDiagnosticsPlugin;
use bevy::prelude::*;
use bevy::transform::components::Transform;
use bevy_oxr::graphics::XrAppInfo;
use bevy_oxr::resources::XrViews;
use bevy_oxr::xr_input::hands::common::{HandInputDebugRenderer, OpenXrHandInput};
use bevy_oxr::xr_input::interactions::{
Expand All @@ -19,7 +20,12 @@ fn main() {
color_eyre::install().unwrap();

App::new()
.add_plugins(DefaultXrPlugins)
.add_plugins(DefaultXrPlugins {
app_info: XrAppInfo {
name: "Bevy OXR Globe Example".into(),
},
..default()
})
.add_plugins(LogDiagnosticsPlugin::default())
.add_systems(Startup, setup)
.add_systems(Update, (proto_locomotion, pull_to_ground).chain())
Expand Down
8 changes: 7 additions & 1 deletion examples/xr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};

use bevy::prelude::*;
use bevy::transform::components::Transform;
use bevy_oxr::graphics::XrAppInfo;
use bevy_oxr::input::XrInput;
use bevy_oxr::resources::{XrFrameState, XrSession};

Expand All @@ -25,7 +26,12 @@ fn main() {

info!("Running `openxr-6dof` skill");
App::new()
.add_plugins(DefaultXrPlugins)
.add_plugins(DefaultXrPlugins {
app_info: XrAppInfo {
name: "Bevy OXR Example".into(),
},
..default()
})
//.add_plugins(OpenXrDebugRenderer) //new debug renderer adds gizmos to
.add_plugins(LogDiagnosticsPlugin::default())
.add_plugins(FrameTimeDiagnosticsPlugin)
Expand Down
Loading

0 comments on commit 65a30ca

Please sign in to comment.