added bare minimum to render a basic scene
This commit is contained in:
3878
examples/demo/Cargo.lock
generated
Normal file
3878
examples/demo/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -6,3 +6,6 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
bevy = "0.11.3"
|
||||||
|
bevy_openxr = "0.0.1"
|
||||||
|
bevy_rapier3d = { git = "https://github.com/alexichepura/bevy_rapier", version = "0.22.0" }
|
||||||
|
|||||||
@@ -1,3 +1,49 @@
|
|||||||
|
use bevy::{
|
||||||
|
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
||||||
|
prelude::{info, App, Startup, Commands, SpatialBundle},
|
||||||
|
};
|
||||||
|
use bevy_openxr::{xr_input::{debug_gizmos::OpenXrDebugRenderer, trackers::{OpenXRLeftController, OpenXRController, OpenXRTracker, OpenXRRightController}}, DefaultXrPlugins};
|
||||||
|
|
||||||
|
mod setup;
|
||||||
|
use crate::setup::setup_scene;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
color_eyre::install().unwrap();
|
||||||
|
|
||||||
|
info!("Running bevy_openxr demo");
|
||||||
|
App::new()
|
||||||
|
//lets get the usual diagnostic stuff added
|
||||||
|
.add_plugins(LogDiagnosticsPlugin::default())
|
||||||
|
.add_plugins(FrameTimeDiagnosticsPlugin)
|
||||||
|
//lets get the xr defaults added
|
||||||
|
.add_plugins(DefaultXrPlugins)
|
||||||
|
//lets add the debug renderer for the controllers
|
||||||
|
.add_plugins(OpenXrDebugRenderer)
|
||||||
|
//lets setup the starting scene
|
||||||
|
.add_systems(Startup, setup_scene)
|
||||||
|
.add_systems(Startup, spawn_controllers_example) //you need to spawn controllers or it crashes TODO:: Fix this
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn spawn_controllers_example(mut commands: Commands) {
|
||||||
|
//left hand
|
||||||
|
commands.spawn((
|
||||||
|
OpenXRLeftController,
|
||||||
|
OpenXRController,
|
||||||
|
OpenXRTracker,
|
||||||
|
SpatialBundle::default(),
|
||||||
|
// XRRayInteractor,
|
||||||
|
// AimPose(Transform::default()),
|
||||||
|
// XRInteractorState::default(),
|
||||||
|
));
|
||||||
|
//right hand
|
||||||
|
commands.spawn((
|
||||||
|
OpenXRRightController,
|
||||||
|
OpenXRController,
|
||||||
|
OpenXRTracker,
|
||||||
|
SpatialBundle::default(),
|
||||||
|
// XRDirectInteractor,
|
||||||
|
// XRInteractorState::default(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
45
examples/demo/src/setup.rs
Normal file
45
examples/demo/src/setup.rs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
use bevy::{prelude::{Commands, ResMut, Assets, Mesh, StandardMaterial, PbrBundle, shape, Color, Transform, SpatialBundle, Camera3dBundle, Vec3, PointLight, PointLightBundle}, utils::default};
|
||||||
|
|
||||||
|
/// set up a simple 3D scene
|
||||||
|
pub fn setup_scene(
|
||||||
|
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(0.25, 1.25, 0.0).looking_at(
|
||||||
|
Vec3 {
|
||||||
|
x: -0.548,
|
||||||
|
y: -0.161,
|
||||||
|
z: -0.137,
|
||||||
|
},
|
||||||
|
Vec3::Y,
|
||||||
|
),
|
||||||
|
..default()
|
||||||
|
},));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user