diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b254df5..d522457 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ jobs: - name: "Cache" uses: Swatinem/rust-cache@v2 - name: "External dependencies" - run: sudo apt-get install -y libasound2-dev portaudio19-dev build-essential libpulse-dev libdbus-1-dev libudev-dev + run: sudo apt-get install -y libasound2-dev portaudio19-dev build-essential libpulse-dev libdbus-1-dev libudev-dev libopenxr-loader1 libopenxr-dev - name: "Checks" run: | cargo update diff --git a/Cargo.toml b/Cargo.toml index c2a6787..1957797 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,24 +1,34 @@ [package] -name = "bevy_openxr" +name = "bevy_oxr" version = "0.1.0" edition = "2021" +description = "Community crate for OpenXR in Bevy" +license = "MIT/Apache-2.0" [features] -default = ["linked"] -linked = ["openxr/linked", "openxr/static"] +default = ["openxr/mint", "linked"] +linked = ["openxr/linked"] + +[workspace] +members = [ "examples/android" ] [dependencies] anyhow = "1.0.75" ash = "0.37.3" -bevy = { git = "https://github.com/bevyengine/bevy.git" } -openxr = { version = "0.17.1", features = ["mint"] } +bevy = "0.12" mint = "0.5.9" wgpu = "0.17.1" wgpu-core = { version = "0.17.1", features = ["vulkan"] } wgpu-hal = "0.17.1" +[target.'cfg( target_family = "unix" )'.dependencies] +openxr = "0.17.1" + +[target.'cfg(not(target_family = "unix"))'.dependencies] +openxr = { version = "0.17.1", features = ["static"] } + [dev-dependencies] -bevy = { git = "https://github.com/bevyengine/bevy.git" } +bevy = "0.12" color-eyre = "0.6.2" bevy_rapier3d = { git = "https://github.com/Schmarni-Dev/bevy_rapier" } # bevy_rapier3d = { git = "https://github.com/alexichepura/bevy_rapier", version = "0.22.0", branch = "bevy-012"} diff --git a/README.md b/README.md index a0c7eb2..8fe5d79 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,9 @@ An in-progress crate for adding openxr support to Bevy without forking. ![image](https://github.com/awtterpip/bevy_openxr/assets/50841145/aa01fde4-7915-49b9-b486-ff61ce6d57a9) To see it in action run the example in `examples` with `cargo run --example xr` + +## Troubleshooting + +- 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`) diff --git a/examples/android/Cargo.toml b/examples/android/Cargo.toml index bf21875..a0ac90c 100644 --- a/examples/android/Cargo.toml +++ b/examples/android/Cargo.toml @@ -29,8 +29,8 @@ target_sdk_version = 32 # label = "Bevy Example" [dependencies] -bevy_openxr = { path = "../..", default-features = false } -bevy = { git = "https://github.com/bevyengine/bevy.git" } +bevy_oxr = { path = "../..", default-features = false } +bevy = "0.12" openxr = { git = "https://github.com/Ralith/openxrs", features = ["mint"] } [profile.release] diff --git a/examples/android/src/lib.rs b/examples/android/src/lib.rs index d5501df..4f8bdeb 100644 --- a/examples/android/src/lib.rs +++ b/examples/android/src/lib.rs @@ -1,12 +1,12 @@ use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}; use bevy::prelude::*; use bevy::transform::components::Transform; -use bevy_openxr::xr_input::debug_gizmos::OpenXrDebugRenderer; -use bevy_openxr::xr_input::prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig}; -use bevy_openxr::xr_input::trackers::{ +use bevy_oxr::xr_input::debug_gizmos::OpenXrDebugRenderer; +use bevy_oxr::xr_input::prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig}; +use bevy_oxr::xr_input::trackers::{ OpenXRController, OpenXRLeftController, OpenXRRightController, OpenXRTracker, }; -use bevy_openxr::DefaultXrPlugins; +use bevy_oxr::DefaultXrPlugins; #[bevy_main] fn main() { diff --git a/examples/xr.rs b/examples/xr.rs index 8644265..b8dc849 100644 --- a/examples/xr.rs +++ b/examples/xr.rs @@ -4,22 +4,22 @@ use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}; use bevy::prelude::*; use bevy::transform::components::Transform; -use bevy_openxr::input::XrInput; -use bevy_openxr::resources::{XrFrameState, XrInstance, XrSession}; +use bevy_oxr::input::XrInput; +use bevy_oxr::resources::{XrFrameState, XrInstance, XrSession}; -use bevy_openxr::xr_input::hand::{OpenXrHandInput, HandInputDebugRenderer}; -use bevy_openxr::xr_input::interactions::{ +use bevy_oxr::xr_input::hand::{OpenXrHandInput, HandInputDebugRenderer}; +use bevy_oxr::xr_input::interactions::{ draw_interaction_gizmos, draw_socket_gizmos, interactions, socket_interactions, update_interactable_states, InteractionEvent, Touched, XRDirectInteractor, XRInteractable, XRInteractableState, XRInteractorState, XRRayInteractor, XRSocketInteractor, }; -use bevy_openxr::xr_input::oculus_touch::OculusController; -use bevy_openxr::xr_input::prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig}; -use bevy_openxr::xr_input::trackers::{ +use bevy_oxr::xr_input::oculus_touch::OculusController; +use bevy_oxr::xr_input::prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig}; +use bevy_oxr::xr_input::trackers::{ AimPose, OpenXRController, OpenXRLeftController, OpenXRRightController, OpenXRTracker, }; -use bevy_openxr::xr_input::Hand; -use bevy_openxr::DefaultXrPlugins; +use bevy_oxr::xr_input::Hand; +use bevy_oxr::DefaultXrPlugins; fn main() { color_eyre::install().unwrap(); diff --git a/src/xr_input/xr_camera.rs b/src/xr_input/xr_camera.rs index 50edeaa..64528f8 100644 --- a/src/xr_input/xr_camera.rs +++ b/src/xr_input/xr_camera.rs @@ -1,6 +1,7 @@ use crate::xr_input::{QuatConv, Vec3Conv}; use crate::{LEFT_XR_TEXTURE_HANDLE, RIGHT_XR_TEXTURE_HANDLE}; use bevy::core_pipeline::tonemapping::{DebandDither, Tonemapping}; +use bevy::math::Vec3A; use bevy::prelude::*; use bevy::render::camera::{CameraProjection, CameraRenderGraph, RenderTarget}; use bevy::render::primitives::Frustum; @@ -216,6 +217,26 @@ impl CameraProjection for XRProjection { fn far(&self) -> f32 { self.far } + + fn get_frustum_corners(&self, z_near: f32, z_far: f32) -> [Vec3A; 8] { + let tan_angle_left = self.fov.angle_left.tan(); + let tan_angle_right = self.fov.angle_right.tan(); + + let tan_angle_bottom = self.fov.angle_down.tan(); + let tan_angle_top = self.fov.angle_up.tan(); + + // NOTE: These vertices are in the specific order required by [`calculate_cascade`]. + [ + Vec3A::new(tan_angle_right, tan_angle_bottom, 1.0) * z_near, // bottom right + Vec3A::new(tan_angle_right, tan_angle_top, 1.0) * z_near, // top right + Vec3A::new(tan_angle_left, tan_angle_top, 1.0) * z_near, // top left + Vec3A::new(tan_angle_left, tan_angle_bottom, 1.0) * z_near, // bottom left + Vec3A::new(tan_angle_right, tan_angle_bottom, 1.0) * z_far, // bottom right + Vec3A::new(tan_angle_right, tan_angle_top, 1.0) * z_far, // top right + Vec3A::new(tan_angle_left, tan_angle_top, 1.0) * z_far, // top left + Vec3A::new(tan_angle_left, tan_angle_bottom, 1.0) * z_far, // bottom left + ] + } } pub fn xr_camera_head_sync(