cleaned up code and created webxr crate

This commit is contained in:
awtterpip
2024-04-18 17:06:56 -05:00
parent d98b9a4455
commit f585c9e2dc
17 changed files with 531 additions and 634 deletions

View File

@@ -1,25 +1,12 @@
//! A simple 3D scene with light shining over a cube sitting on a plane.
use std::any::TypeId;
use bevy::prelude::*;
use bevy_openxr::{
actions::{create_action_sets, ActionApp},
add_xr_plugins, resources::{TypedAction, XrActions, XrInstance},
};
use bevy_xr::actions::{Action, ActionState};
use openxr::Binding;
#[derive(Action)]
#[action(action_type = bool, name = "jump")]
pub struct Jump;
use bevy_openxr::add_xr_plugins;
fn main() {
App::new()
.add_plugins(add_xr_plugins(DefaultPlugins))
.add_systems(Startup, setup.after(create_action_sets))
.add_systems(Update, read_action_state)
.register_action::<Jump>()
.add_systems(Startup, setup)
.run();
}
@@ -28,15 +15,7 @@ fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
actions: Res<XrActions>,
instance: Res<XrInstance>,
) {
let TypedAction::Bool(action) = actions.get(&TypeId::of::<Jump>()).unwrap() else {
unreachable!()
};
instance.suggest_interaction_profile_bindings(instance.string_to_path("/interaction_profiles/oculus/touch_controller").unwrap(), &[
Binding::new(action, instance.string_to_path("/user/hand/right/input/a/click").unwrap())
]).unwrap();
// circular base
commands.spawn(PbrBundle {
mesh: meshes.add(Circle::new(4.0)),
@@ -60,20 +39,4 @@ fn setup(
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
// // camera
// commands.spawn(XrCameraBundle {
// transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
// camera: Camera {
// target: RenderTarget::TextureView(ManualTextureViewHandle(XR_TEXTURE_INDEX + 1)),
// ..default()
// },
// ..default()
// });
}
fn read_action_state(
state: Res<ActionState<Jump>>
) {
info!("{}", state.pressed())
}