diff --git a/.envrc.example b/.envrc.example new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc.example @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.gitignore b/.gitignore index c9090ae..b459a22 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ **/Cargo.lock **/runtime_libs/arm64-v8a/* .vscode -\.DS_Store \ No newline at end of file +\.DS_Store +.envrc +.direnv \ No newline at end of file diff --git a/crates/bevy_openxr/src/actions.rs b/crates/bevy_openxr/src/actions.rs new file mode 100644 index 0000000..e69de29 diff --git a/crates/bevy_openxr/src/lib.rs b/crates/bevy_openxr/src/lib.rs index 71e24c2..2567062 100644 --- a/crates/bevy_openxr/src/lib.rs +++ b/crates/bevy_openxr/src/lib.rs @@ -8,6 +8,7 @@ use bevy_xr::camera::XrCameraPlugin; use init::XrInitPlugin; use render::XrRenderPlugin; +pub mod actions; pub mod camera; pub mod error; pub mod extensions; diff --git a/crates/bevy_openxr/src/render.rs b/crates/bevy_openxr/src/render.rs index 543f2d0..d294744 100644 --- a/crates/bevy_openxr/src/render.rs +++ b/crates/bevy_openxr/src/render.rs @@ -93,6 +93,7 @@ pub fn init_views( )); views.push(default()); } + commands.spawn(XrCameraBundle::default()); commands.insert_resource(XrViews(views)); } diff --git a/examples/3d_scene.rs b/examples/3d_scene.rs index 1ce5628..560f7c2 100644 --- a/examples/3d_scene.rs +++ b/examples/3d_scene.rs @@ -1,53 +1,46 @@ -// //! A simple 3D scene with light shining over a cube sitting on a plane. +//! A simple 3D scene with light shining over a cube sitting on a plane. -// use bevy::{prelude::*, render::camera::RenderTarget}; -// use bevy_oxr::openxr::{render::LEFT_XR_TEXTURE_HANDLE, DefaultXrPlugins}; +use bevy::prelude::*; -// fn main() { -// App::new() -// .add_plugins(DefaultXrPlugins) -// .add_systems(Startup, setup) -// .run(); -// } +fn main() { + App::new() + .add_plugins(DefaultPlugins) + .add_systems(Startup, setup) + .run(); +} -// /// set up a simple 3D scene -// fn setup( -// mut commands: Commands, -// mut meshes: ResMut>, -// mut materials: ResMut>, -// ) { -// // circular base -// commands.spawn(PbrBundle { -// mesh: meshes.add(Circle::new(4.0)), -// material: materials.add(Color::WHITE), -// transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), -// ..default() -// }); -// // cube -// commands.spawn(PbrBundle { -// mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), -// material: materials.add(Color::rgb_u8(124, 144, 255)), -// transform: Transform::from_xyz(0.0, 0.5, 0.0), -// ..default() -// }); -// // light -// commands.spawn(PointLightBundle { -// point_light: PointLight { -// shadows_enabled: true, -// ..default() -// }, -// transform: Transform::from_xyz(4.0, 8.0, 4.0), -// ..default() -// }); -// // camera -// commands.spawn(Camera3dBundle { -// transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), -// camera: Camera { -// target: RenderTarget::TextureView(LEFT_XR_TEXTURE_HANDLE), -// ..default() -// }, -// ..default() -// }); -// } - -fn main() {} +/// set up a simple 3D scene +fn setup( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, +) { + // circular base + commands.spawn(PbrBundle { + mesh: meshes.add(Circle::new(4.0)), + material: materials.add(Color::WHITE), + transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), + ..default() + }); + // cube + commands.spawn(PbrBundle { + mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), + material: materials.add(Color::rgb_u8(124, 144, 255)), + transform: Transform::from_xyz(0.0, 0.5, 0.0), + ..default() + }); + // light + commands.spawn(PointLightBundle { + point_light: PointLight { + shadows_enabled: true, + ..default() + }, + transform: Transform::from_xyz(4.0, 8.0, 4.0), + ..default() + }); + // camera + commands.spawn(Camera3dBundle { + transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), + ..default() + }); +} \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..120eaa0 --- /dev/null +++ b/flake.lock @@ -0,0 +1,100 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1711088506, + "narHash": "sha256-USdlY7Tx2oJWqFBpp10+03+h7eVhpkQ4s9t1ERjeIJE=", + "owner": "nix-community", + "repo": "fenix", + "rev": "85f4139f3c092cf4afd9f9906d7ed218ef262c97", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1711001935, + "narHash": "sha256-URtGpHue7HHZK0mrHnSf8wJ6OmMKYSsoLmJybrOLFSQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "20f77aa09916374aa3141cbc605c955626762c9a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1711052942, + "narHash": "sha256-lLsAhLgm/Nbin41wdfGKU7Rgd6ONBxYCUAMv53NXPjo=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "7ef7f442fc34b5eadb1c6ad6433bd6d0c51b056b", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6a082d6 --- /dev/null +++ b/flake.nix @@ -0,0 +1,90 @@ +{ + description = "bevy xr flake"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + # eachDefaultSystem and other utility functions + utils.url = "github:numtide/flake-utils"; + # Replacement for rustup + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { + self, + nixpkgs, + utils, + fenix, + }: + # This helper function abstracts over the host platform. + # See https://github.com/numtide/flake-utils#eachdefaultsystem--system---attrs + utils.lib.eachDefaultSystem ( + system: let + pkgs = nixpkgs.legacyPackages.${system}; + # Brings in the rust toolchain from the standard file + # that rustup/cargo uses. + rustToolchain = fenix.packages.${system}.fromToolchainFile { + file = ./rust-toolchain.toml; + sha256 = "sha256-+syqAd2kX8KVa8/U2gz3blIQTTsYYt3U63xBWaGOSc8="; + }; + rustPlatform = pkgs.makeRustPlatform { + inherit (rustToolchain) cargo rustc; + }; + in + # See https://nixos.wiki/wiki/Flakes#Output_schema + { + # `nix develop` pulls all of this in to become your shell. + devShells.default = pkgs.mkShell rec { + nativeBuildInputs = with pkgs; [ + rustToolchain + pkg-config + + # Common cargo tools we often use + cargo-deny + cargo-expand + cargo-binutils + # cmake for openxr + cmake + ]; + + # see https://github.com/NixOS/nixpkgs/blob/95b81c96f863ca8911dffcda45d1937efcd66a4b/pkgs/games/jumpy/default.nix#L60C5-L60C38 + buildInputs = + [ + pkgs.zstd + ] + ++ pkgs.lib.optionals pkgs.stdenv.isLinux (with pkgs; [ + # bevy dependencies + udev + alsa-lib + # vulkan + vulkan-loader + vulkan-headers + vulkan-tools + vulkan-validation-layers + # x11 + xorg.libX11 + xorg.libXcursor + xorg.libXi + xorg.libXrandr + # wayland + libxkbcommon + wayland + ]) + ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ + pkgs.darwin.apple_sdk.frameworks.Cocoa + rustPlatform.bindgenHook + # # This is missing on mac m1 nix, for some reason. + # # see https://stackoverflow.com/a/69732679 + pkgs.libiconv + ]; + + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs; + # this is most likely not needed. for some reason shadows flicker without it. + AMD_VULKAN_ICD = "RADV"; + }; + # This only formats the nix files. + formatter = pkgs.nixpkgs-fmt; + } + ); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..fba7d7e --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.77.0" +components = ["rust-src", "rust-analyzer"] +profile = "default" \ No newline at end of file