Skip to content

Commit

Permalink
Added demo example from skilltree repo
Browse files Browse the repository at this point in the history
  • Loading branch information
TheButlah committed Nov 21, 2023
1 parent fd7278b commit 07049b0
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[target.aarch64-linux-android.openxr_loader]
rustc-link-search = ["assets/runtime_libs/arm64-v8a"]
rustc-link-lib = ["openxr_loader"]
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install bevy dependencies
run: |
sudo apt-get update && sudo apt-get install -y \
g++ pkg-config libx11-dev libasound2-dev libudev-dev
g++ pkg-config libx11-dev libasound2-dev libudev-dev libopenxr-loader1 libopenxr-dev
- name: Cache cargo dependencies
uses: Swatinem/rust-cache@v2

Expand All @@ -44,7 +44,7 @@ jobs:
- name: Install bevy dependencies
run: |
sudo apt-get update && sudo apt-get install -y \
g++ pkg-config libx11-dev libasound2-dev libudev-dev
g++ pkg-config libx11-dev libasound2-dev libudev-dev libopenxr-loader1 libopenxr-dev
- name: Cache cargo dependencies
uses: Swatinem/rust-cache@v2

Expand Down
84 changes: 82 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ rust-version = "1.74.0"
[workspace.dependencies]
bevy = "0.12"
bevy_oxr = "0.1.0"
color-eyre = "0.6"
eyre = "0.6"
openxr = { verison = "0.17.1", git="https://github.com/TheButlah/openxrs", branch = "add-links" }

[profile.dev]
# Enable a small amount of optimization in debug mode
opt-level = 1
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ cargo install xbuild --git https://github.com/rust-mobile/xbuild
```
- Get the [Oculus SDK](https://developer.oculus.com/downloads/package/oculus-openxr-mobile-sdk/) and place `OpenXR/Libs/Android/arm64-v8a/Release/libopenxr_loader.so` into the `rumtime_libs/arm64-v8a/` folder.
- Install the [android command line tools](https://developer.android.com/tools/releases/platform-tools#downloads).
- Install an openxr openxr loader to be able to build the code natively. If you just want to cross compile to quest, this step is optional. See [here](https://monado.freedesktop.org/getting-started.html#deb) for installation of monado for linux.

## License

Expand Down
5 changes: 5 additions & 0 deletions apps/rvid/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ edition.workspace = true
rust-version.workspace = true
description = "A rust based wireless PCVR solution"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
bevy.workspace = true
bevy_oxr.workspace = true
color-eyre.workspace = true
openxr.workspace = true
93 changes: 93 additions & 0 deletions apps/rvid/client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::prelude::*;
use bevy::transform::components::Transform;
use bevy_oxr::input::XrInput;
use bevy_oxr::resources::XrFrameState;
use bevy_oxr::xr_input::oculus_touch::OculusController;
use bevy_oxr::xr_input::{QuatConv, Vec3Conv};
use bevy_oxr::DefaultXrPlugins;

#[bevy_main]
pub fn main() {
color_eyre::install().unwrap();

info!("Running `rvid-client`");
App::new()
.add_plugins(DefaultXrPlugins)
.add_plugins(LogDiagnosticsPlugin::default())
.add_plugins(FrameTimeDiagnosticsPlugin)
.add_systems(Startup, setup)
.add_systems(Update, hands)
.run();
}

/// set up a simple 3D scene
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// 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()),
..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()),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
// light
commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 1500.0,
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
// camera
commands.spawn((Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},));
}

fn hands(
mut gizmos: Gizmos,
oculus_controller: Res<OculusController>,
frame_state: Res<XrFrameState>,
xr_input: Res<XrInput>,
) {
let mut func = || -> color_eyre::Result<()> {
let frame_state = *frame_state.lock().unwrap();

let right_controller = oculus_controller
.grip_space
.right
.relate(&xr_input.stage, frame_state.predicted_display_time)?;
let left_controller = oculus_controller
.grip_space
.left
.relate(&xr_input.stage, frame_state.predicted_display_time)?;
gizmos.rect(
right_controller.0.pose.position.to_vec3(),
right_controller.0.pose.orientation.to_quat(),
Vec2::new(0.05, 0.2),
Color::YELLOW_GREEN,
);
gizmos.rect(
left_controller.0.pose.position.to_vec3(),
left_controller.0.pose.orientation.to_quat(),
Vec2::new(0.05, 0.2),
Color::YELLOW_GREEN,
);
Ok(())
};

let _ = func();
}
2 changes: 1 addition & 1 deletion apps/rvid/client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
println!("Hello, world!");
rvid_client::main()
}

0 comments on commit 07049b0

Please sign in to comment.