update to bevy 0.15 rc

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2024-11-20 10:04:49 +01:00
parent 690b433516
commit 7320ae8dac
34 changed files with 1338 additions and 1079 deletions

1588
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -10,10 +10,17 @@ resolver = "2"
members = ["crates/*", "crates/bevy_openxr/examples/android"] members = ["crates/*", "crates/bevy_openxr/examples/android"]
[workspace.dependencies] [workspace.dependencies]
bevy = { version = "0.14.0", default-features = false, features = [ bevy = { version = "0.15.0-rc.3", default-features = false, features = [
"bevy_render", "bevy_render",
"bevy_core_pipeline", "bevy_core_pipeline",
"bevy_winit", "bevy_winit",
"bevy_pbr", "bevy_pbr",
"x11", "x11",
] } ] }
bevy_mod_xr.path = "crates/bevy_xr"
bevy_mod_openxr.path = "crates/bevy_openxr"
bevy_xr_utils.path = "crates/bevy_xr_utils"
openxr = "0.19.0"
thiserror = "2.0.3"
wgpu = "23"
wgpu-hal = "23"

View File

@@ -10,11 +10,11 @@ keywords = ["gamedev", "bevy", "Xr", "Vr", "OpenXR"]
[features] [features]
default = ["vulkan", "d3d12", "passthrough"] default = ["vulkan", "d3d12", "passthrough"]
vulkan = ["dep:ash"] vulkan = ["dep:ash"]
d3d12 = ["wgpu/dx12", "wgpu-hal/dx12", "dep:winapi", "dep:d3d12"] d3d12 = ["wgpu/dx12", "wgpu-hal/dx12", "dep:winapi"]
passthrough = [] passthrough = []
[dev-dependencies] [dev-dependencies]
bevy_xr_utils.path = "../bevy_xr_utils" bevy_xr_utils.workspace = true
bevy = { workspace = true, default-features = true } bevy = { workspace = true, default-features = true }
[target.'cfg(target_os = "android")'.dependencies] [target.'cfg(target_os = "android")'.dependencies]
@@ -27,22 +27,20 @@ bevy.workspace = true
# all other dependencies are placed under this since on wasm, this crate is completely empty # all other dependencies are placed under this since on wasm, this crate is completely empty
[target.'cfg(not(target_family = "wasm"))'.dependencies] [target.'cfg(not(target_family = "wasm"))'.dependencies]
openxr = "0.18.0" bevy_mod_xr.workspace = true
thiserror = "1.0.57" openxr.workspace = true
wgpu = "0.20" thiserror.workspace = true
wgpu-hal = "0.21" wgpu.workspace = true
bevy_mod_xr = { path = "../bevy_xr", version = "0.1.0-rc1" } wgpu-hal.workspace = true
ash = { version = "0.38", optional = true }
ash = { version = "0.37.3", optional = true }
[target.'cfg(target_family = "unix")'.dependencies] [target.'cfg(target_family = "unix")'.dependencies]
openxr = { version = "0.18.0", features = ["mint"] } openxr = { workspace = true, features = ["mint"] }
wgpu = { version = "0.20", features = ["vulkan-portability"] } wgpu = { workspace = true, features = ["vulkan-portability"] }
[target.'cfg(target_family = "windows")'.dependencies] [target.'cfg(target_family = "windows")'.dependencies]
openxr = { version = "0.18.0", features = ["mint", "static"] } openxr = { workspace=true, features = ["mint", "static"] }
winapi = { version = "0.3.9", optional = true } winapi = { version = "0.3.9", optional = true }
d3d12 = { version = "0.20", features = ["libloading"], optional = true }
[lints.clippy] [lints.clippy]
too_many_arguments = "allow" too_many_arguments = "allow"

View File

@@ -1,13 +1,25 @@
//! 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::*; use bevy::{prelude::*, render::pipelined_rendering::PipelinedRenderingPlugin};
use bevy_mod_openxr::add_xr_plugins; use bevy_mod_openxr::{add_xr_plugins, init::OxrInitPlugin};
use openxr::EnvironmentBlendMode;
fn main() { fn main() {
App::new() App::new()
.add_plugins(add_xr_plugins(DefaultPlugins)) .add_plugins(
add_xr_plugins(DefaultPlugins.build().disable::<PipelinedRenderingPlugin>()).set(
OxrInitPlugin {
blend_modes: Some(vec![
EnvironmentBlendMode::ALPHA_BLEND,
EnvironmentBlendMode::ADDITIVE,
]),
..Default::default()
},
),
)
.add_plugins(bevy_xr_utils::hand_gizmos::HandGizmosPlugin) .add_plugins(bevy_xr_utils::hand_gizmos::HandGizmosPlugin)
.add_systems(Startup, setup) .add_systems(Startup, setup)
.insert_resource(ClearColor(Color::NONE))
.run(); .run();
} }
@@ -18,30 +30,27 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
// circular base // circular base
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Circle::new(4.0)), Mesh3d(meshes.add(Circle::new(4.0))),
material: materials.add(Color::WHITE), MeshMaterial3d(materials.add(Color::WHITE)),
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
..default() ));
});
// cube // cube
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
material: materials.add(Color::srgb_u8(124, 144, 255)), MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
transform: Transform::from_xyz(0.0, 0.5, 0.0), Transform::from_xyz(0.0, 0.5, 0.0),
..default() ));
});
// light // light
commands.spawn(PointLightBundle { commands.spawn((
point_light: PointLight { PointLight {
shadows_enabled: true, shadows_enabled: true,
..default() ..default()
}, },
transform: Transform::from_xyz(4.0, 8.0, 4.0), Transform::from_xyz(4.0, 8.0, 4.0),
..default() ));
}); commands.spawn((
commands.spawn(Camera3dBundle { Camera3d::default(),
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
..default() ));
});
} }

View File

@@ -34,24 +34,22 @@ fn setup_scene(
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
// circular base // circular base
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Circle::new(4.0)), Mesh3d(meshes.add(Circle::new(4.0))),
material: materials.add(Color::WHITE), MeshMaterial3d(materials.add(Color::WHITE)),
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
..default() ));
});
// cube // cube
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
material: materials.add(Color::srgb_u8(124, 144, 255)), MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
transform: Transform::from_xyz(0.0, 0.5, 0.0), Transform::from_xyz(0.0, 0.5, 0.0),
..default() ));
});
commands.spawn(Camera3dBundle { commands.spawn((
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), Camera3d::default(),
..default() Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
}); ));
} }
#[derive(Component)] #[derive(Component)]
@@ -145,7 +143,7 @@ fn handle_flight_input(
let locomotion_vector = reference_quat.mul_vec3(input_vector); let locomotion_vector = reference_quat.mul_vec3(input_vector);
root_position.translation += root_position.translation +=
locomotion_vector * speed * time.delta_seconds(); locomotion_vector * speed * time.delta_secs();
} }
None => return, None => return,
} }

View File

@@ -7,9 +7,9 @@ publish = false
# 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_mod_openxr.path = "../.." bevy_mod_openxr.workspace = true
bevy = { workspace = true, default-features = true } bevy = { workspace = true, default-features = true }
bevy_xr_utils.path = "../../../bevy_xr_utils" bevy_xr_utils.workspace = true
[build-dependencies] [build-dependencies]
reqwest = { version = "0.12", features = ["blocking"] } reqwest = { version = "0.12", features = ["blocking"] }

View File

@@ -21,8 +21,8 @@ fn main() {
synchronous_pipeline_compilation: default(), synchronous_pipeline_compilation: default(),
})) }))
.add_plugins(bevy_xr_utils::hand_gizmos::HandGizmosPlugin) .add_plugins(bevy_xr_utils::hand_gizmos::HandGizmosPlugin)
.insert_resource(Msaa::Off)
.add_systems(Startup, setup) .add_systems(Startup, setup)
.add_systems(Update, modify_msaa)
.insert_resource(AmbientLight { .insert_resource(AmbientLight {
color: Default::default(), color: Default::default(),
brightness: 500.0, brightness: 500.0,
@@ -31,6 +31,15 @@ fn main() {
.run(); .run();
} }
#[derive(Component)]
struct MsaaModified;
fn modify_msaa(cams: Query<Entity, (With<Camera>, Without<MsaaModified>)>, mut commands: Commands) {
for cam in &cams {
commands.entity(cam).insert(Msaa::Off).insert(MsaaModified);
}
}
/// set up a simple 3D scene /// set up a simple 3D scene
fn setup( fn setup(
mut commands: Commands, mut commands: Commands,
@@ -40,19 +49,17 @@ fn setup(
let mut white: StandardMaterial = Color::WHITE.into(); let mut white: StandardMaterial = Color::WHITE.into();
white.unlit = true; white.unlit = true;
// circular base // circular base
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Circle::new(4.0)), Mesh3d(meshes.add(Circle::new(4.0))),
material: materials.add(white), MeshMaterial3d(materials.add(white)),
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
..default() ));
});
let mut cube_mat: StandardMaterial = Color::srgb_u8(124, 144, 255).into(); let mut cube_mat: StandardMaterial = Color::srgb_u8(124, 144, 255).into();
cube_mat.unlit = true; cube_mat.unlit = true;
// cube // cube
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
material: materials.add(cube_mat), MeshMaterial3d(materials.add(cube_mat)),
transform: Transform::from_xyz(0.0, 0.5, 0.0), Transform::from_xyz(0.0, 0.5, 0.0),
..default() ));
});
} }

View File

@@ -79,30 +79,27 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
// circular base // circular base
// commands.spawn(PbrBundle { // commands.spawn((
// mesh: meshes.add(Circle::new(4.0)), // Mesh3d(meshes.add(Circle::new(4.0))),
// material: materials.add(Color::WHITE), // MeshMaterial3d(materials.add(Color::WHITE)),
// transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), // Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
// ..default() // ));
// });
// cube // cube
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
material: materials.add(Color::srgb_u8(124, 144, 255)), MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
transform: Transform::from_xyz(0.0, 2.5, 0.0), Transform::from_xyz(0.0, 2.5, 0.0),
..default() ));
});
// light // light
commands.spawn(PointLightBundle { commands.spawn((
point_light: PointLight { PointLight {
shadows_enabled: true, shadows_enabled: true,
..default() ..default()
}, },
transform: Transform::from_xyz(4.0, 8.0, 4.0), Transform::from_xyz(4.0, 8.0, 4.0),
..default() ));
}); commands.spawn((
commands.spawn(Camera3dBundle { Camera3d::default(),
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
..default() ));
});
} }

View File

@@ -13,7 +13,6 @@ use bevy_mod_openxr::{
use bevy_mod_xr::{ use bevy_mod_xr::{
session::{session_available, session_running, XrSessionCreated, XrTrackingRoot}, session::{session_available, session_running, XrSessionCreated, XrTrackingRoot},
spaces::XrSpace, spaces::XrSpace,
types::XrPose,
}; };
use openxr::Posef; use openxr::Posef;
@@ -55,32 +54,29 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
// circular base // circular base
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Circle::new(4.0)), Mesh3d(meshes.add(Circle::new(4.0))),
material: materials.add(Color::WHITE), MeshMaterial3d(materials.add(Color::WHITE)),
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
..default() ));
});
// cube // cube
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
material: materials.add(Color::srgb_u8(124, 144, 255)), MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
transform: Transform::from_xyz(0.0, 0.5, 0.0), Transform::from_xyz(0.0, 0.5, 0.0),
..default() ));
});
// light // light
commands.spawn(PointLightBundle { commands.spawn((
point_light: PointLight { PointLight {
shadows_enabled: true, shadows_enabled: true,
..default() ..default()
}, },
transform: Transform::from_xyz(4.0, 8.0, 4.0), Transform::from_xyz(4.0, 8.0, 4.0),
..default() ));
}); commands.spawn((
commands.spawn(Camera3dBundle { Camera3d::default(),
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
..default() ));
});
} }
fn suggest_action_bindings( fn suggest_action_bindings(
actions: Res<ControllerActions>, actions: Res<ControllerActions>,
@@ -130,34 +126,28 @@ fn spawn_hands(
.unwrap(), .unwrap(),
); );
let right_space = session let right_space = session
.create_action_space(&actions.right, openxr::Path::NULL, XrPose::IDENTITY) .create_action_space(&actions.right, openxr::Path::NULL, Isometry3d::IDENTITY)
.unwrap(); .unwrap();
let left = cmds let left = cmds
.spawn(( .spawn((
PbrBundle { Mesh3d(meshes.add(Cuboid::new(0.1, 0.1, 0.05))),
mesh: meshes.add(Cuboid::new(0.1, 0.1, 0.05)), MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
material: materials.add(Color::srgb_u8(124, 144, 255)), Transform::from_xyz(0.0, 0.5, 0.0),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
},
left_space, left_space,
Controller, Controller,
)) ))
.id(); .id();
let right = cmds let right = cmds
.spawn(( .spawn((
PbrBundle { Mesh3d(meshes.add(Cuboid::new(0.1, 0.1, 0.05))),
mesh: meshes.add(Cuboid::new(0.1, 0.1, 0.05)), MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
material: materials.add(Color::srgb_u8(124, 144, 255)), Transform::from_xyz(0.0, 0.5, 0.0),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
},
right_space, right_space,
Controller, Controller,
)) ))
.id(); .id();
cmds.entity(root.single()).push_children(&[left, right]); cmds.entity(root.single()).add_children(&[left, right]);
} }
#[derive(Component)] #[derive(Component)]

View File

@@ -55,21 +55,19 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
// circular base // circular base
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Circle::new(4.0)), Mesh3d(meshes.add(Circle::new(4.0))),
material: materials.add(Color::WHITE), MeshMaterial3d(materials.add(Color::WHITE)),
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
..default() ));
});
// cube // cube
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
material: materials.add(Color::srgb_u8(124, 144, 255)), MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
transform: Transform::from_xyz(0.0, 0.5, 0.0), Transform::from_xyz(0.0, 0.5, 0.0),
..default() ));
}); commands.spawn((
commands.spawn(Camera3dBundle { Camera3d::default(),
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
..default() ));
});
} }

View File

@@ -2,7 +2,7 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_mod_openxr::add_xr_plugins; use bevy_mod_openxr::add_xr_plugins;
use bevy_mod_xr::session::{XrSessionCreated, XrTrackingRoot}; use bevy_mod_xr::session::XrSessionCreated;
use bevy_xr_utils::tracking_utils::{ use bevy_xr_utils::tracking_utils::{
TrackingUtilitiesPlugin, XrTrackedLeftGrip, XrTrackedLocalFloor, XrTrackedRightGrip, TrackingUtilitiesPlugin, XrTrackedLeftGrip, XrTrackedLocalFloor, XrTrackedRightGrip,
XrTrackedStage, XrTrackedView, XrTrackedStage, XrTrackedView,
@@ -29,25 +29,23 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
// circular base // circular base
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Circle::new(4.0)), Mesh3d(meshes.add(Circle::new(4.0))),
material: materials.add(Color::WHITE), MeshMaterial3d(materials.add(Color::WHITE)),
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
..default() ));
});
// light // light
commands.spawn(PointLightBundle { commands.spawn((
point_light: PointLight { PointLight {
shadows_enabled: true, shadows_enabled: true,
..default() ..default()
}, },
transform: Transform::from_xyz(4.0, 8.0, 4.0), Transform::from_xyz(4.0, 8.0, 4.0),
..default() ));
}); commands.spawn((
commands.spawn(Camera3dBundle { Camera3d::default(),
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
..default() ));
});
} }
fn spawn_hands( fn spawn_hands(
@@ -57,22 +55,16 @@ fn spawn_hands(
) { ) {
let left = cmds let left = cmds
.spawn(( .spawn((
PbrBundle { Mesh3d(meshes.add(Cuboid::new(0.1, 0.1, 0.05))),
mesh: meshes.add(Cuboid::new(0.1, 0.1, 0.05)), MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
material: materials.add(Color::srgb_u8(124, 144, 255)), Transform::from_xyz(0.0, 0.5, 0.0),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
},
XrTrackedLeftGrip, XrTrackedLeftGrip,
)) ))
.id(); .id();
let bundle = ( let bundle = (
PbrBundle { Mesh3d(meshes.add(Cuboid::new(0.1, 0.1, 0.05))),
mesh: meshes.add(Cuboid::new(0.1, 0.1, 0.05)), MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
material: materials.add(Color::srgb_u8(124, 144, 255)), Transform::from_xyz(0.0, 0.5, 0.0),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
},
XrTrackedRightGrip, XrTrackedRightGrip,
); );
let right = cmds.spawn(bundle).id(); let right = cmds.spawn(bundle).id();
@@ -80,40 +72,31 @@ fn spawn_hands(
let head = cmds let head = cmds
.spawn(( .spawn((
PbrBundle { Mesh3d(meshes.add(Cuboid::new(0.2, 0.2, 0.2))),
mesh: meshes.add(Cuboid::new(0.2, 0.2, 0.2)), MeshMaterial3d(materials.add(Color::srgb_u8(255, 144, 144))),
material: materials.add(Color::srgb_u8(255, 144, 144)), Transform::from_xyz(0.0, 0.0, 0.0),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default()
},
XrTrackedView, XrTrackedView,
)) ))
.id(); .id();
//local_floor emulated //local_floor emulated
let local_floor = cmds let local_floor = cmds
.spawn(( .spawn((
PbrBundle { Mesh3d(meshes.add(Cuboid::new(0.5, 0.1, 0.5))),
mesh: meshes.add(Cuboid::new(0.5, 0.1, 0.5)), MeshMaterial3d(materials.add(Color::srgb_u8(144, 255, 144))),
material: materials.add(Color::srgb_u8(144, 255, 144)), Transform::from_xyz(0.0, 0.0, 0.0),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default()
},
XrTrackedLocalFloor, XrTrackedLocalFloor,
)) ))
.id(); .id();
let stage = cmds let stage = cmds
.spawn(( .spawn((
PbrBundle { Mesh3d(meshes.add(Cuboid::new(0.5, 0.1, 0.5))),
mesh: meshes.add(Cuboid::new(0.5, 0.1, 0.5)), MeshMaterial3d(materials.add(Color::srgb_u8(144, 255, 255))),
material: materials.add(Color::srgb_u8(144, 255, 255)), Transform::from_xyz(0.0, 0.0, 0.0),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default()
},
XrTrackedStage, XrTrackedStage,
)) ))
.id(); .id();
cmds.entity(stage) cmds.entity(stage)
.push_children(&[left, right, head, local_floor]); .add_children(&[left, right, head, local_floor]);
} }

View File

@@ -41,52 +41,46 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
// circular base // circular base
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Circle::new(4.0)), Mesh3d(meshes.add(Circle::new(4.0))),
material: materials.add(Color::WHITE), MeshMaterial3d(materials.add(Color::WHITE)),
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
..default() ));
});
// red cube // red cube
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
material: materials.add(Color::srgb_u8(252, 44, 3)), MeshMaterial3d(materials.add(Color::srgb_u8(252, 44, 3))),
transform: Transform::from_xyz(4.0, 0.5, 0.0).with_scale(Vec3::splat(0.5)), Transform::from_xyz(4.0, 0.5, 0.0).with_scale(Vec3::splat(0.5)),
..default() ));
});
// blue cube // blue cube
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
material: materials.add(Color::srgb_u8(3, 28, 252)), MeshMaterial3d(materials.add(Color::srgb_u8(3, 28, 252))),
transform: Transform::from_xyz(-4.0, 0.5, 0.0).with_scale(Vec3::splat(0.5)), Transform::from_xyz(-4.0, 0.5, 0.0).with_scale(Vec3::splat(0.5)),
..default() ));
});
// green cube // green cube
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
material: materials.add(Color::srgb_u8(3, 252, 32)), MeshMaterial3d(materials.add(Color::srgb_u8(3, 252, 32))),
transform: Transform::from_xyz(0.0, 0.5, 4.0).with_scale(Vec3::splat(0.5)), Transform::from_xyz(0.0, 0.5, 4.0).with_scale(Vec3::splat(0.5)),
..default() ));
});
// white cube // white cube
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
material: materials.add(Color::srgb_u8(250, 250, 250)), MeshMaterial3d(materials.add(Color::srgb_u8(250, 250, 250))),
transform: Transform::from_xyz(0.0, 0.5, -4.0).with_scale(Vec3::splat(0.5)), Transform::from_xyz(0.0, 0.5, -4.0).with_scale(Vec3::splat(0.5)),
..default() ));
});
// black cube // black cube
commands.spawn(PbrBundle { commands.spawn((
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
material: materials.add(Color::srgb_u8(0, 0, 0)), MeshMaterial3d(materials.add(Color::srgb_u8(0, 0, 0))),
transform: Transform::from_xyz(0.0, 0.1, 0.0).with_scale(Vec3::splat(0.2)), Transform::from_xyz(0.0, 0.1, 0.0).with_scale(Vec3::splat(0.2)),
..default() ));
});
commands.spawn(Camera3dBundle { commands.spawn((
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), Camera3d::default(),
..default() Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
}); ));
} }
#[derive(Component)] #[derive(Component)]

View File

@@ -16,7 +16,7 @@ impl Plugin for OxrActionBindingPlugin {
app.add_event::<OxrSuggestActionBinding>(); app.add_event::<OxrSuggestActionBinding>();
app.add_systems( app.add_systems(
Update, Update,
run_action_binding_sugestion.run_if(on_event::<XrSessionCreatedEvent>()), run_action_binding_sugestion.run_if(on_event::<XrSessionCreatedEvent>),
); );
} }
} }
@@ -25,7 +25,7 @@ impl Plugin for OxrActionBindingPlugin {
// Event to allow requesting binding suggestion for new actions // Event to allow requesting binding suggestion for new actions
pub(crate) fn run_action_binding_sugestion(world: &mut World) { pub(crate) fn run_action_binding_sugestion(world: &mut World) {
world.run_schedule(OxrSendActionBindings); world.run_schedule(OxrSendActionBindings);
world.run_system_once(bind_actions); _ = world.run_system_once(bind_actions);
} }
fn bind_actions(instance: Res<OxrInstance>, mut actions: EventReader<OxrSuggestActionBinding>) { fn bind_actions(instance: Res<OxrInstance>, mut actions: EventReader<OxrSuggestActionBinding>) {

View File

@@ -8,7 +8,7 @@ impl Plugin for OxrActionAttachingPlugin {
app.add_systems( app.add_systems(
PostUpdate, PostUpdate,
attach_sets attach_sets
.run_if(on_event::<XrSessionCreatedEvent>()) .run_if(on_event::<XrSessionCreatedEvent>)
.after(run_action_binding_sugestion), .after(run_action_binding_sugestion),
); );
} }

View File

@@ -90,14 +90,14 @@ fn spawn_default_hands(mut cmds: Commands, root: Query<Entity, With<XrTrackingRo
OxrSpaceLocationFlags(openxr::SpaceLocationFlags::default()), OxrSpaceLocationFlags(openxr::SpaceLocationFlags::default()),
) )
}); });
cmds.entity(root).push_children(&left_bones); cmds.entity(root).add_children(&left_bones);
cmds.entity(root).push_children(&right_bones); cmds.entity(root).add_children(&right_bones);
cmds.push(SpawnHandTracker { cmds.queue(SpawnHandTracker {
joints: XrHandBoneEntities(left_bones), joints: XrHandBoneEntities(left_bones),
tracker_bundle: DefaultHandTracker, tracker_bundle: DefaultHandTracker,
side: HandSide::Left, side: HandSide::Left,
}); });
cmds.push(SpawnHandTracker { cmds.queue(SpawnHandTracker {
joints: XrHandBoneEntities(right_bones), joints: XrHandBoneEntities(right_bones),
tracker_bundle: DefaultHandTracker, tracker_bundle: DefaultHandTracker,
side: HandSide::Right, side: HandSide::Right,

View File

@@ -1,5 +1,5 @@
#[cfg(all(feature = "d3d12", windows))] // #[cfg(all(feature = "d3d12", windows))]
mod d3d12; // mod d3d12;
#[cfg(feature = "vulkan")] #[cfg(feature = "vulkan")]
pub mod vulkan; pub mod vulkan;
@@ -8,7 +8,10 @@ use std::any::TypeId;
use bevy::math::UVec2; use bevy::math::UVec2;
use openxr::{FrameStream, FrameWaiter, Session}; use openxr::{FrameStream, FrameWaiter, Session};
use crate::{session::OxrSessionCreateNextChain, types::{AppInfo, OxrExtensions, Result, WgpuGraphics}}; use crate::{
session::OxrSessionCreateNextChain,
types::{AppInfo, OxrExtensions, Result, WgpuGraphics},
};
/// This is an extension trait to the [`Graphics`](openxr::Graphics) trait and is how the graphics API should be interacted with. /// This is an extension trait to the [`Graphics`](openxr::Graphics) trait and is how the graphics API should be interacted with.
pub unsafe trait GraphicsExt: openxr::Graphics { pub unsafe trait GraphicsExt: openxr::Graphics {
@@ -37,7 +40,7 @@ pub unsafe trait GraphicsExt: openxr::Graphics {
instance: &openxr::Instance, instance: &openxr::Instance,
system_id: openxr::SystemId, system_id: openxr::SystemId,
) -> Result<(WgpuGraphics, Self::SessionCreateInfo)>; ) -> Result<(WgpuGraphics, Self::SessionCreateInfo)>;
unsafe fn create_session( unsafe fn create_session(
instance: &openxr::Instance, instance: &openxr::Instance,
system_id: openxr::SystemId, system_id: openxr::SystemId,
info: &Self::SessionCreateInfo, info: &Self::SessionCreateInfo,
@@ -74,8 +77,8 @@ impl GraphicsBackend {
const ALL: &'static [Self] = &[ const ALL: &'static [Self] = &[
#[cfg(feature = "vulkan")] #[cfg(feature = "vulkan")]
Self::Vulkan(()), Self::Vulkan(()),
#[cfg(all(feature = "d3d12", windows))] // #[cfg(all(feature = "d3d12", windows))]
Self::D3D12(()), // Self::D3D12(()),
]; ];
pub fn available_backends(exts: &OxrExtensions) -> Vec<Self> { pub fn available_backends(exts: &OxrExtensions) -> Vec<Self> {
@@ -103,8 +106,8 @@ impl GraphicsBackend {
pub enum GraphicsWrap<T: GraphicsType> { pub enum GraphicsWrap<T: GraphicsType> {
#[cfg(feature = "vulkan")] #[cfg(feature = "vulkan")]
Vulkan(T::Inner<openxr::Vulkan>), Vulkan(T::Inner<openxr::Vulkan>),
#[cfg(all(feature = "d3d12", windows))] // #[cfg(all(feature = "d3d12", windows))]
D3D12(T::Inner<openxr::D3D12>), // D3D12(T::Inner<openxr::D3D12>),
} }
impl<T: GraphicsType> GraphicsWrap<T> { impl<T: GraphicsType> GraphicsWrap<T> {
@@ -173,12 +176,12 @@ macro_rules! graphics_match {
type Api = openxr::Vulkan; type Api = openxr::Vulkan;
graphics_match!(@arm_impl Vulkan; $expr $(=> $($return)*)?) graphics_match!(@arm_impl Vulkan; $expr $(=> $($return)*)?)
}, },
#[cfg(all(feature = "d3d12", windows))] // #[cfg(all(feature = "d3d12", windows))]
$crate::graphics::GraphicsWrap::D3D12($var) => { // $crate::graphics::GraphicsWrap::D3D12($var) => {
#[allow(unused)] // #[allow(unused)]
type Api = openxr::D3D12; // type Api = openxr::D3D12;
graphics_match!(@arm_impl D3D12; $expr $(=> $($return)*)?) // graphics_match!(@arm_impl D3D12; $expr $(=> $($return)*)?)
}, // },
} }
}; };

View File

@@ -21,7 +21,7 @@ const VK_TARGET_VERSION_ASH: u32 = ash::vk::make_api_version(
0, 0,
VK_TARGET_VERSION.major() as u32, VK_TARGET_VERSION.major() as u32,
VK_TARGET_VERSION.minor() as u32, VK_TARGET_VERSION.minor() as u32,
VK_TARGET_VERSION.patch() as u32, VK_TARGET_VERSION.patch(),
); );
unsafe impl GraphicsExt for openxr::Vulkan { unsafe impl GraphicsExt for openxr::Vulkan {
@@ -63,7 +63,7 @@ unsafe impl GraphicsExt for openxr::Vulkan {
mip_level_count: 1, mip_level_count: 1,
sample_count: 1, sample_count: 1,
dimension: wgpu::TextureDimension::D2, dimension: wgpu::TextureDimension::D2,
format: format, format,
usage: wgpu_hal::TextureUses::COLOR_TARGET | wgpu_hal::TextureUses::COPY_DST, usage: wgpu_hal::TextureUses::COLOR_TARGET | wgpu_hal::TextureUses::COPY_DST,
memory_flags: wgpu_hal::MemoryFlags::empty(), memory_flags: wgpu_hal::MemoryFlags::empty(),
view_formats: vec![], view_formats: vec![],
@@ -84,7 +84,7 @@ unsafe impl GraphicsExt for openxr::Vulkan {
mip_level_count: 1, mip_level_count: 1,
sample_count: 1, sample_count: 1,
dimension: wgpu::TextureDimension::D2, dimension: wgpu::TextureDimension::D2,
format: format, format,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST, usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST,
view_formats: &[], view_formats: &[],
}, },
@@ -113,20 +113,20 @@ unsafe impl GraphicsExt for openxr::Vulkan {
let flags = wgpu::InstanceFlags::empty(); let flags = wgpu::InstanceFlags::empty();
let extensions = let extensions =
<Vulkan as Api>::Instance::desired_extensions(&vk_entry, VK_TARGET_VERSION_ASH, flags)?; <Vulkan as Api>::Instance::desired_extensions(&vk_entry, VK_TARGET_VERSION_ASH, flags)?;
let device_extensions = vec![ let device_extensions = [
ash::extensions::khr::Swapchain::name(), ash::khr::swapchain::NAME,
ash::extensions::khr::DrawIndirectCount::name(), ash::khr::draw_indirect_count::NAME,
#[cfg(target_os = "android")] // #[cfg(target_os = "android")]
ash::extensions::khr::TimelineSemaphore::name(), ash::khr::timeline_semaphore::NAME,
ash::vk::KhrImagelessFramebufferFn::name(), ash::khr::imageless_framebuffer::NAME,
ash::vk::KhrImageFormatListFn::name(), ash::khr::image_format_list::NAME,
]; ];
let vk_instance = unsafe { let vk_instance = unsafe {
let extensions_cchar: Vec<_> = extensions.iter().map(|s| s.as_ptr()).collect(); let extensions_cchar: Vec<_> = extensions.iter().map(|s| s.as_ptr()).collect();
let app_name = CString::new(app_info.name.clone().into_owned())?; let app_name = CString::new(app_info.name.clone().into_owned())?;
let vk_app_info = ash::vk::ApplicationInfo::builder() let vk_app_info = ash::vk::ApplicationInfo::default()
.application_name(&app_name) .application_name(&app_name)
.application_version(1) .application_version(1)
.engine_name(&app_name) .engine_name(&app_name)
@@ -136,8 +136,9 @@ unsafe impl GraphicsExt for openxr::Vulkan {
let vk_instance = instance let vk_instance = instance
.create_vulkan_instance( .create_vulkan_instance(
system_id, system_id,
#[allow(clippy::missing_transmute_annotations)]
std::mem::transmute(vk_entry.static_fn().get_instance_proc_addr), std::mem::transmute(vk_entry.static_fn().get_instance_proc_addr),
&ash::vk::InstanceCreateInfo::builder() &ash::vk::InstanceCreateInfo::default()
.application_info(&vk_app_info) .application_info(&vk_app_info)
.enabled_extension_names(&extensions_cchar) as *const _ .enabled_extension_names(&extensions_cchar) as *const _
as *const _, as *const _,
@@ -181,7 +182,7 @@ unsafe impl GraphicsExt for openxr::Vulkan {
extensions, extensions,
flags, flags,
false, false,
Some(Box::new(())), None,
)? )?
}; };
@@ -205,26 +206,26 @@ unsafe impl GraphicsExt for openxr::Vulkan {
.adapter .adapter
.physical_device_features(&enabled_extensions, wgpu_features); .physical_device_features(&enabled_extensions, wgpu_features);
let family_index = 0; let family_index = 0;
let family_info = ash::vk::DeviceQueueCreateInfo::builder() let family_info = ash::vk::DeviceQueueCreateInfo::default()
.queue_family_index(family_index) .queue_family_index(family_index)
.queue_priorities(&[1.0]) .queue_priorities(&[1.0]);
.build();
let family_infos = [family_info]; let family_infos = [family_info];
let mut physical_device_multiview_features = ash::vk::PhysicalDeviceMultiviewFeatures {
multiview: ash::vk::TRUE,
..Default::default()
};
let info = enabled_phd_features let info = enabled_phd_features
.add_to_device_create_builder( .add_to_device_create(
ash::vk::DeviceCreateInfo::builder() ash::vk::DeviceCreateInfo::default()
.queue_create_infos(&family_infos) .queue_create_infos(&family_infos)
.push_next(&mut ash::vk::PhysicalDeviceMultiviewFeatures { .push_next(&mut physical_device_multiview_features),
multiview: ash::vk::TRUE,
..Default::default()
}),
) )
.enabled_extension_names(&extensions_cchar) .enabled_extension_names(&extensions_cchar);
.build();
let vk_device = unsafe { let vk_device = unsafe {
let vk_device = instance let vk_device = instance
.create_vulkan_device( .create_vulkan_device(
system_id, system_id,
#[allow(clippy::missing_transmute_annotations)]
std::mem::transmute(vk_entry.static_fn().get_instance_proc_addr), std::mem::transmute(vk_entry.static_fn().get_instance_proc_addr),
vk_physical_device.as_raw() as _, vk_physical_device.as_raw() as _,
&info as *const _ as *const _, &info as *const _ as *const _,
@@ -241,9 +242,10 @@ unsafe impl GraphicsExt for openxr::Vulkan {
let wgpu_open_device = unsafe { let wgpu_open_device = unsafe {
wgpu_exposed_adapter.adapter.device_from_raw( wgpu_exposed_adapter.adapter.device_from_raw(
vk_device, vk_device,
true, None,
&enabled_extensions, &enabled_extensions,
wgpu_features, wgpu_features,
&wgpu::MemoryHints::Performance,
family_info.queue_family_index, family_info.queue_family_index,
0, 0,
) )
@@ -273,6 +275,7 @@ unsafe impl GraphicsExt for openxr::Vulkan {
max_push_constant_size: 4, max_push_constant_size: 4,
..Default::default() ..Default::default()
}, },
memory_hints: wgpu::MemoryHints::Performance,
}, },
None, None,
) )
@@ -320,7 +323,7 @@ unsafe impl GraphicsExt for openxr::Vulkan {
ty: sys::SessionCreateInfo::TYPE, ty: sys::SessionCreateInfo::TYPE,
next: &binding as *const _ as *const _, next: &binding as *const _ as *const _,
create_flags: Default::default(), create_flags: Default::default(),
system_id: system_id, system_id,
}; };
let mut out = sys::Session::NULL; let mut out = sys::Session::NULL;
cvt((instance.fp().create_session)( cvt((instance.fp().create_session)(
@@ -379,7 +382,7 @@ fn vulkan_to_wgpu(format: ash::vk::Format) -> Option<wgpu::TextureFormat> {
F::R8G8B8A8_SINT => Tf::Rgba8Sint, F::R8G8B8A8_SINT => Tf::Rgba8Sint,
F::A2B10G10R10_UINT_PACK32 => Tf::Rgb10a2Uint, F::A2B10G10R10_UINT_PACK32 => Tf::Rgb10a2Uint,
F::A2B10G10R10_UNORM_PACK32 => Tf::Rgb10a2Unorm, F::A2B10G10R10_UNORM_PACK32 => Tf::Rgb10a2Unorm,
F::B10G11R11_UFLOAT_PACK32 => Tf::Rg11b10Float, F::B10G11R11_UFLOAT_PACK32 => Tf::Rg11b10Ufloat,
F::R32G32_UINT => Tf::Rg32Uint, F::R32G32_UINT => Tf::Rg32Uint,
F::R32G32_SINT => Tf::Rg32Sint, F::R32G32_SINT => Tf::Rg32Sint,
F::R32G32_SFLOAT => Tf::Rg32Float, F::R32G32_SFLOAT => Tf::Rg32Float,
@@ -630,7 +633,7 @@ fn wgpu_to_vulkan(format: wgpu::TextureFormat) -> Option<ash::vk::Format> {
Tf::Rgba8Sint => F::R8G8B8A8_SINT, Tf::Rgba8Sint => F::R8G8B8A8_SINT,
Tf::Rgb10a2Uint => F::A2B10G10R10_UINT_PACK32, Tf::Rgb10a2Uint => F::A2B10G10R10_UINT_PACK32,
Tf::Rgb10a2Unorm => F::A2B10G10R10_UNORM_PACK32, Tf::Rgb10a2Unorm => F::A2B10G10R10_UNORM_PACK32,
Tf::Rg11b10Float => F::B10G11R11_UFLOAT_PACK32, Tf::Rg11b10Ufloat => F::B10G11R11_UFLOAT_PACK32,
Tf::Rg32Uint => F::R32G32_UINT, Tf::Rg32Uint => F::R32G32_UINT,
Tf::Rg32Sint => F::R32G32_SINT, Tf::Rg32Sint => F::R32G32_SINT,
Tf::Rg32Float => F::R32G32_SFLOAT, Tf::Rg32Float => F::R32G32_SFLOAT,
@@ -724,4 +727,3 @@ fn wgpu_to_vulkan(format: wgpu::TextureFormat) -> Option<ash::vk::Format> {
}, },
}) })
} }

View File

@@ -1,5 +1,4 @@
use bevy::prelude::*; use bevy::{math::Vec3A, prelude::*};
use bevy_mod_xr::types::XrPose;
pub trait ToPosef { pub trait ToPosef {
fn to_posef(&self) -> openxr::Posef; fn to_posef(&self) -> openxr::Posef;
@@ -7,8 +6,8 @@ pub trait ToPosef {
pub trait ToTransform { pub trait ToTransform {
fn to_transform(&self) -> Transform; fn to_transform(&self) -> Transform;
} }
pub trait ToXrPose { pub trait ToIsometry3d {
fn to_xr_pose(&self) -> XrPose; fn to_xr_pose(&self) -> Isometry3d;
} }
pub trait ToQuaternionf { pub trait ToQuaternionf {
fn to_quaternionf(&self) -> openxr::Quaternionf; fn to_quaternionf(&self) -> openxr::Quaternionf;
@@ -42,15 +41,15 @@ impl ToTransform for openxr::Posef {
.with_rotation(self.orientation.to_quat()) .with_rotation(self.orientation.to_quat())
} }
} }
impl ToXrPose for openxr::Posef { impl ToIsometry3d for openxr::Posef {
fn to_xr_pose(&self) -> XrPose { fn to_xr_pose(&self) -> Isometry3d {
XrPose { Isometry3d {
translation: self.position.to_vec3(), translation: self.position.to_vec3().into(),
rotation: self.orientation.to_quat(), rotation: self.orientation.to_quat(),
} }
} }
} }
impl ToPosef for XrPose { impl ToPosef for Isometry3d {
fn to_posef(&self) -> openxr::Posef { fn to_posef(&self) -> openxr::Posef {
openxr::Posef { openxr::Posef {
orientation: self.rotation.to_quaternionf(), orientation: self.rotation.to_quaternionf(),
@@ -90,6 +89,15 @@ impl ToVector3f for Vec3 {
} }
} }
} }
impl ToVector3f for Vec3A {
fn to_vector3f(&self) -> openxr::Vector3f {
openxr::Vector3f {
x: self.x,
y: self.y,
z: self.z,
}
}
}
impl ToVec3 for openxr::Vector3f { impl ToVec3 for openxr::Vector3f {
fn to_vec3(&self) -> Vec3 { fn to_vec3(&self) -> Vec3 {
Vec3 { Vec3 {

View File

@@ -113,7 +113,7 @@ impl Plugin for OxrInitPlugin {
( (
create_xr_session create_xr_session
.run_if(state_equals(XrState::Available)) .run_if(state_equals(XrState::Available))
.run_if(on_event::<XrCreateSessionEvent>()), .run_if(on_event::<XrCreateSessionEvent>),
( (
destroy_xr_session, destroy_xr_session,
(|v: Res<XrDestroySessionRender>| { (|v: Res<XrDestroySessionRender>| {
@@ -122,16 +122,16 @@ impl Plugin for OxrInitPlugin {
}), }),
) )
.run_if(state_matches!(XrState::Exiting { .. })) .run_if(state_matches!(XrState::Exiting { .. }))
.run_if(on_event::<XrDestroySessionEvent>()), .run_if(on_event::<XrDestroySessionEvent>),
begin_xr_session begin_xr_session
.run_if(state_equals(XrState::Ready)) .run_if(state_equals(XrState::Ready))
.run_if(on_event::<XrBeginSessionEvent>()), .run_if(on_event::<XrBeginSessionEvent>),
end_xr_session end_xr_session
.run_if(state_equals(XrState::Stopping)) .run_if(state_equals(XrState::Stopping))
.run_if(on_event::<XrEndSessionEvent>()), .run_if(on_event::<XrEndSessionEvent>),
request_exit_xr_session request_exit_xr_session
.run_if(session_created) .run_if(session_created)
.run_if(on_event::<XrRequestExitEvent>()), .run_if(on_event::<XrRequestExitEvent>),
) )
.in_set(XrHandleEvents::SessionStateUpdateEvents), .in_set(XrHandleEvents::SessionStateUpdateEvents),
) )
@@ -146,9 +146,6 @@ impl Plugin for OxrInitPlugin {
.insert_non_send_resource(session_create_info) .insert_non_send_resource(session_create_info)
.init_non_send_resource::<OxrSessionCreateNextChain>(); .init_non_send_resource::<OxrSessionCreateNextChain>();
app.world_mut()
.spawn((SpatialBundle::default(), XrTrackingRoot));
app.world_mut() app.world_mut()
.resource_mut::<Events<XrStateChanged>>() .resource_mut::<Events<XrStateChanged>>()
.send(XrStateChanged(XrState::Available)); .send(XrStateChanged(XrState::Available));
@@ -178,7 +175,7 @@ impl Plugin for OxrInitPlugin {
}) })
.run_if( .run_if(
resource_exists::<XrDestroySessionRender> resource_exists::<XrDestroySessionRender>
.and_then(|v: Res<XrDestroySessionRender>| v.0.load(Ordering::Relaxed)), .and(|v: Res<XrDestroySessionRender>| v.0.load(Ordering::Relaxed)),
) )
.chain(), .chain(),
); );
@@ -467,7 +464,7 @@ pub fn create_xr_session(world: &mut World) {
let system_id = world.resource::<OxrSystemId>(); let system_id = world.resource::<OxrSystemId>();
match init_xr_session( match init_xr_session(
device.wgpu_device(), device.wgpu_device(),
&instance, instance,
**system_id, **system_id,
&mut chain, &mut chain,
create_info.clone(), create_info.clone(),
@@ -475,8 +472,8 @@ pub fn create_xr_session(world: &mut World) {
Ok((session, frame_waiter, frame_stream, swapchain, images, graphics_info)) => { Ok((session, frame_waiter, frame_stream, swapchain, images, graphics_info)) => {
world.insert_resource(session.clone()); world.insert_resource(session.clone());
world.insert_resource(frame_waiter); world.insert_resource(frame_waiter);
world.insert_resource(images.clone()); world.insert_resource(images);
world.insert_resource(graphics_info.clone()); world.insert_resource(graphics_info);
world.insert_resource(OxrRenderResources { world.insert_resource(OxrRenderResources {
session, session,
frame_stream, frame_stream,

View File

@@ -37,14 +37,14 @@ impl LayerProvider for ProjectionLayer {
Some(Box::new( Some(Box::new(
CompositionLayerProjection::new() CompositionLayerProjection::new()
.layer_flags(CompositionLayerFlags::BLEND_TEXTURE_SOURCE_ALPHA) .layer_flags(CompositionLayerFlags::BLEND_TEXTURE_SOURCE_ALPHA)
.space(&stage) .space(stage)
.views(&[ .views(&[
CompositionLayerProjectionView::new() CompositionLayerProjectionView::new()
.pose(openxr_views.0[0].pose) .pose(openxr_views.0[0].pose)
.fov(openxr_views.0[0].fov) .fov(openxr_views.0[0].fov)
.sub_image( .sub_image(
SwapchainSubImage::new() SwapchainSubImage::new()
.swapchain(&swapchain) .swapchain(swapchain)
.image_array_index(0) .image_array_index(0)
.image_rect(rect), .image_rect(rect),
), ),
@@ -53,7 +53,7 @@ impl LayerProvider for ProjectionLayer {
.fov(openxr_views.0[1].fov) .fov(openxr_views.0[1].fov)
.sub_image( .sub_image(
SwapchainSubImage::new() SwapchainSubImage::new()
.swapchain(&swapchain) .swapchain(swapchain)
.image_array_index(1) .image_array_index(1)
.image_rect(rect), .image_rect(rect),
), ),
@@ -235,9 +235,15 @@ impl<'a> Default for CompositionLayerProjection<'a> {
pub struct CompositionLayerPassthrough { pub struct CompositionLayerPassthrough {
inner: sys::CompositionLayerPassthroughFB, inner: sys::CompositionLayerPassthroughFB,
} }
impl Default for CompositionLayerPassthrough {
fn default() -> Self {
Self::new()
}
}
impl CompositionLayerPassthrough { impl CompositionLayerPassthrough {
#[inline] #[inline]
pub fn new() -> Self { pub const fn new() -> Self {
Self { Self {
inner: openxr::sys::CompositionLayerPassthroughFB { inner: openxr::sys::CompositionLayerPassthroughFB {
ty: openxr::sys::CompositionLayerPassthroughFB::TYPE, ty: openxr::sys::CompositionLayerPassthroughFB::TYPE,

View File

@@ -60,8 +60,8 @@ pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
.build() .build()
.disable::<RenderPlugin>() .disable::<RenderPlugin>()
// .disable::<PipelinedRenderingPlugin>() // .disable::<PipelinedRenderingPlugin>()
.add_before::<RenderPlugin, _>(XrSessionPlugin { auto_handle: true }) .add_before::<RenderPlugin>(XrSessionPlugin { auto_handle: true })
.add_before::<RenderPlugin, _>(OxrInitPlugin::default()) .add_before::<RenderPlugin>(OxrInitPlugin::default())
.add(OxrEventsPlugin) .add(OxrEventsPlugin)
.add(OxrReferenceSpacePlugin::default()) .add(OxrReferenceSpacePlugin::default())
.add(OxrRenderPlugin) .add(OxrRenderPlugin)

View File

@@ -150,16 +150,18 @@ pub fn init_views(
info!("{}", graphics_info.resolution); info!("{}", graphics_info.resolution);
let view_handle = let view_handle =
add_texture_view(&mut manual_texture_views, temp_tex, &graphics_info, index); add_texture_view(&mut manual_texture_views, temp_tex, &graphics_info, index);
let cam = commands let cam = commands
.spawn((XrCameraBundle { .spawn(
camera: Camera { (XrCameraBundle {
target: RenderTarget::TextureView(view_handle), camera: Camera {
target: RenderTarget::TextureView(view_handle),
..Default::default()
},
view: XrCamera(index),
..Default::default() ..Default::default()
}, }),
view: XrCamera(index), )
..Default::default() .remove::<Projection>()
},))
.id(); .id();
match root.get_single() { match root.get_single() {
Ok(root) => { Ok(root) => {

View File

@@ -43,6 +43,7 @@ impl OxrEntry {
application_version: app_info.version.to_u32(), application_version: app_info.version.to_u32(),
engine_name: "Bevy", engine_name: "Bevy",
engine_version: Version::BEVY.to_u32(), engine_version: Version::BEVY.to_u32(),
api_version: openxr::Version::new(1, 1, 36),
}, },
&required_exts.into(), &required_exts.into(),
layers, layers,
@@ -108,7 +109,7 @@ impl OxrInstance {
graphics_match!( graphics_match!(
self.1; self.1;
_ => { _ => {
let (graphics, session_info) = Api::init_graphics(&self.2, &self, system_id)?; let (graphics, session_info) = Api::init_graphics(&self.2, self, system_id)?;
Ok((graphics, SessionCreateInfo(Api::wrap(session_info)))) Ok((graphics, SessionCreateInfo(Api::wrap(session_info))))
} }
@@ -185,7 +186,7 @@ impl OxrFrameStream {
stream => { stream => {
let mut new_layers = vec![]; let mut new_layers = vec![];
for (i, layer) in layers.into_iter().enumerate() { for (i, layer) in layers.iter().enumerate() {
if let Some(swapchain) = layer.swapchain() { if let Some(swapchain) = layer.swapchain() {
if !swapchain.0.using_graphics::<Api>() { if !swapchain.0.using_graphics::<Api>() {
error!( error!(
@@ -196,7 +197,10 @@ impl OxrFrameStream {
continue; continue;
} }
} }
new_layers.push(unsafe { std::mem::transmute(layer.header()) }); new_layers.push(unsafe {
#[allow(clippy::missing_transmute_annotations)]
std::mem::transmute(layer.header())
});
} }
Ok(stream.end(display_time, environment_blend_mode, new_layers.as_slice())?) Ok(stream.end(display_time, environment_blend_mode, new_layers.as_slice())?)

View File

@@ -7,7 +7,6 @@ use bevy_mod_xr::{
XrDestroySpace, XrPrimaryReferenceSpace, XrReferenceSpace, XrSpace, XrSpaceLocationFlags, XrDestroySpace, XrPrimaryReferenceSpace, XrReferenceSpace, XrSpace, XrSpaceLocationFlags,
XrSpaceVelocityFlags, XrVelocity, XrSpaceVelocityFlags, XrVelocity,
}, },
types::XrPose,
}; };
use openxr::{ use openxr::{
sys, HandJointLocation, HandJointLocations, HandJointVelocities, HandJointVelocity, sys, HandJointLocation, HandJointLocations, HandJointVelocities, HandJointVelocity,
@@ -51,28 +50,11 @@ impl Plugin for OxrSpatialPlugin {
.in_set(OxrSpaceSyncSet) .in_set(OxrSpaceSyncSet)
.run_if(openxr_session_running), .run_if(openxr_session_running),
) )
.observe(add_location_flags) .register_required_components::<XrSpaceLocationFlags, OxrSpaceLocationFlags>()
.observe(add_velocity_flags); .register_required_components::<XrSpaceVelocityFlags, OxrSpaceVelocityFlags>();
} }
} }
fn add_velocity_flags(event: Trigger<OnAdd, XrVelocity>, mut cmds: Commands) {
if event.entity() == Entity::PLACEHOLDER {
error!("called add_location_flags observer without entity");
return;
}
cmds.entity(event.entity())
.insert(OxrSpaceLocationFlags(openxr::SpaceLocationFlags::default()));
}
fn add_location_flags(event: Trigger<OnAdd, XrSpace>, mut cmds: Commands) {
if event.entity() == Entity::PLACEHOLDER {
error!("called add_location_flags observer without entity");
return;
}
cmds.entity(event.entity())
.insert(OxrSpaceLocationFlags(openxr::SpaceLocationFlags::default()));
}
fn destroy_space_event(instance: Res<OxrInstance>, mut events: EventReader<XrDestroySpace>) { fn destroy_space_event(instance: Res<OxrInstance>, mut events: EventReader<XrDestroySpace>) {
for space in events.read() { for space in events.read() {
match instance.destroy_space(space.0) { match instance.destroy_space(space.0) {
@@ -119,7 +101,7 @@ unsafe extern "system" fn patched_destroy_space(space: openxr::sys::Space) -> op
} }
} }
#[derive(Clone, Copy, Component)] #[derive(Clone, Copy, Component, Default)]
pub struct OxrSpaceLocationFlags(pub openxr::SpaceLocationFlags); pub struct OxrSpaceLocationFlags(pub openxr::SpaceLocationFlags);
impl OxrSpaceLocationFlags { impl OxrSpaceLocationFlags {
pub fn pos_valid(&self) -> bool { pub fn pos_valid(&self) -> bool {
@@ -135,7 +117,7 @@ impl OxrSpaceLocationFlags {
self.0.contains(SpaceLocationFlags::ORIENTATION_TRACKED) self.0.contains(SpaceLocationFlags::ORIENTATION_TRACKED)
} }
} }
#[derive(Clone, Copy, Component)] #[derive(Clone, Copy, Component, Default)]
pub struct OxrSpaceVelocityFlags(pub openxr::SpaceVelocityFlags); pub struct OxrSpaceVelocityFlags(pub openxr::SpaceVelocityFlags);
impl OxrSpaceVelocityFlags { impl OxrSpaceVelocityFlags {
pub fn linear_valid(&self) -> bool { pub fn linear_valid(&self) -> bool {
@@ -231,7 +213,7 @@ impl OxrSession {
&self, &self,
action: &openxr::Action<T>, action: &openxr::Action<T>,
subaction_path: openxr::Path, subaction_path: openxr::Path,
pose_in_space: XrPose, pose_in_space: Isometry3d,
) -> openxr::Result<XrSpace> { ) -> openxr::Result<XrSpace> {
let info = sys::ActionSpaceCreateInfo { let info = sys::ActionSpaceCreateInfo {
ty: sys::ActionSpaceCreateInfo::TYPE, ty: sys::ActionSpaceCreateInfo::TYPE,

View File

@@ -24,7 +24,7 @@ pub struct Version(pub u8, pub u8, pub u16);
impl Version { impl Version {
/// Bevy's version number /// Bevy's version number
pub const BEVY: Self = Self(0, 13, 0); pub const BEVY: Self = Self(0, 15, 0);
pub const fn to_u32(self) -> u32 { pub const fn to_u32(self) -> u32 {
let major = (self.0 as u32) << 24; let major = (self.0 as u32) << 24;

View File

@@ -12,11 +12,11 @@ bevy.workspace = true
# all dependencies are placed under this since on anything but wasm, this crate is completely empty # all dependencies are placed under this since on anything but wasm, this crate is completely empty
[target.'cfg(target_family = "wasm")'.dependencies] [target.'cfg(target_family = "wasm")'.dependencies]
thiserror = "1.0.57" thiserror.workspace = true
wgpu = "0.19.3" wgpu.workspace = true
wgpu-hal = "0.19.3" wgpu-hal.workspace = true
bevy_mod_xr = { path = "../bevy_xr", version = "0.1.0-rc1" } bevy_mod_xr.workspace = true
[lints.clippy] [lints.clippy]
too_many_arguments = "allow" too_many_arguments = "allow"

View File

@@ -94,11 +94,11 @@ impl<A: Action<ActionType = bool>> ActionState<A> {
} }
pub fn just_pressed(&self) -> bool { pub fn just_pressed(&self) -> bool {
self.previous_state == false && self.current_state == true !self.previous_state && self.current_state
} }
pub fn just_released(&self) -> bool { pub fn just_released(&self) -> bool {
self.previous_state == true && self.current_state == false self.previous_state && !self.current_state
} }
pub fn press(&mut self) { pub fn press(&mut self) {

View File

@@ -1,3 +1,5 @@
use core::panic;
use bevy::app::{App, Plugin, PostUpdate}; use bevy::app::{App, Plugin, PostUpdate};
use bevy::core_pipeline::core_3d::graph::Core3d; use bevy::core_pipeline::core_3d::graph::Core3d;
use bevy::core_pipeline::core_3d::Camera3d; use bevy::core_pipeline::core_3d::Camera3d;
@@ -7,7 +9,9 @@ use bevy::ecs::component::Component;
use bevy::ecs::reflect::ReflectComponent; use bevy::ecs::reflect::ReflectComponent;
use bevy::ecs::schedule::IntoSystemConfigs; use bevy::ecs::schedule::IntoSystemConfigs;
use bevy::math::{Mat4, Vec3A}; use bevy::math::{Mat4, Vec3A};
use bevy::pbr::{build_directional_light_cascades, clear_directional_light_cascades, SimulationLightSystems}; use bevy::pbr::{
build_directional_light_cascades, clear_directional_light_cascades, SimulationLightSystems,
};
use bevy::reflect::std_traits::ReflectDefault; use bevy::reflect::std_traits::ReflectDefault;
use bevy::reflect::Reflect; use bevy::reflect::Reflect;
use bevy::render::camera::{ use bevy::render::camera::{
@@ -68,10 +72,8 @@ impl CameraProjection for XrProjection {
fn update(&mut self, _width: f32, _height: f32) {} fn update(&mut self, _width: f32, _height: f32) {}
fn far(&self) -> f32 { fn far(&self) -> f32 {
let far = self.projection_matrix.to_cols_array()[14] self.projection_matrix.to_cols_array()[14]
/ (self.projection_matrix.to_cols_array()[10] + 1.0); / (self.projection_matrix.to_cols_array()[10] + 1.0)
far
} }
// TODO calculate this properly // TODO calculate this properly
@@ -99,6 +101,10 @@ impl CameraProjection for XrProjection {
fn get_clip_from_view(&self) -> Mat4 { fn get_clip_from_view(&self) -> Mat4 {
self.projection_matrix self.projection_matrix
} }
fn get_clip_from_view_for_sub(&self, _sub_view: &bevy::render::camera::SubCameraView) -> Mat4 {
panic!("sub view not supported for xr camera");
}
} }
#[derive(Bundle)] #[derive(Bundle)]

View File

@@ -1,15 +1,11 @@
use bevy::{ use bevy::{
ecs::{component::Component, entity::Entity, world::Command}, ecs::{component::Component, entity::Entity, world::Command},
hierarchy::BuildWorldChildren,
log::{error, warn}, log::{error, warn},
math::bool, math::bool,
prelude::{Bundle, Commands, Deref, DerefMut, Resource, SpatialBundle, With, World}, prelude::{BuildChildren, Bundle, Commands, Deref, DerefMut, Resource, Transform, Visibility, With, World},
}; };
use crate::{ use crate::{session::XrTrackingRoot, spaces::XrSpaceLocationFlags};
session:: XrTrackingRoot,
spaces::XrSpaceLocationFlags,
};
pub const HAND_JOINT_COUNT: usize = 26; pub const HAND_JOINT_COUNT: usize = 26;
pub fn spawn_hand_bones<T: Bundle>( pub fn spawn_hand_bones<T: Bundle>(
@@ -20,7 +16,8 @@ pub fn spawn_hand_bones<T: Bundle>(
for bone in HandBone::get_all_bones().into_iter() { for bone in HandBone::get_all_bones().into_iter() {
bones[bone as usize] = cmds bones[bone as usize] = cmds
.spawn(( .spawn((
SpatialBundle::default(), Transform::default(),
Visibility::default(),
bone, bone,
HandBoneRadius(0.0), HandBoneRadius(0.0),
XrSpaceLocationFlags::default(), XrSpaceLocationFlags::default(),
@@ -205,9 +202,9 @@ impl<B: Bundle> Command for SpawnHandTracker<B> {
HandSide::Right => tracker.insert(LeftHand), HandSide::Right => tracker.insert(LeftHand),
}; };
let tracker = tracker.id(); let tracker = tracker.id();
world.entity_mut(root).push_children(&[tracker]); world.entity_mut(root).add_children(&[tracker]);
executor.0(world, tracker, self.side); executor.0(world, tracker, self.side);
if let Some(mut tracker) = world.get_entity_mut(tracker) { if let Ok(mut tracker) = world.get_entity_mut(tracker) {
tracker.insert(self.side); tracker.insert(self.side);
tracker.insert(self.tracker_bundle); tracker.insert(self.tracker_bundle);
} }

View File

@@ -121,7 +121,7 @@ impl Plugin for XrSessionPlugin {
.add_systems( .add_systems(
XrFirst, XrFirst,
exits_session_on_app_exit exits_session_on_app_exit
.run_if(on_event::<AppExit>()) .run_if(on_event::<AppExit>)
.run_if(session_created) .run_if(session_created)
.in_set(XrHandleEvents::ExitEvents), .in_set(XrHandleEvents::ExitEvents),
); );
@@ -129,6 +129,8 @@ impl Plugin for XrSessionPlugin {
.resource_mut::<MainScheduleOrder>() .resource_mut::<MainScheduleOrder>()
.labels .labels
.insert(0, XrFirst.intern()); .insert(0, XrFirst.intern());
app.world_mut()
.spawn((Transform::default(), Visibility::default(), XrTrackingRoot));
if self.auto_handle { if self.auto_handle {
app.add_systems(PreUpdate, auto_handle_session); app.add_systems(PreUpdate, auto_handle_session);
@@ -153,7 +155,7 @@ impl Plugin for XrSessionPlugin {
XrFirst, XrFirst,
exits_session_on_app_exit exits_session_on_app_exit
.before(XrHandleEvents::ExitEvents) .before(XrHandleEvents::ExitEvents)
.run_if(on_event::<AppExit>().and_then(session_running)), .run_if(on_event::<AppExit>.and(session_running)),
); );
let render_app = app.sub_app_mut(RenderApp); let render_app = app.sub_app_mut(RenderApp);

View File

@@ -1,26 +1,4 @@
use bevy::{ use bevy::math::Isometry3d;
math::{Quat, Vec3},
reflect::Reflect,
transform::components::Transform,
};
#[derive(Clone, Copy, PartialEq, Reflect, Debug)] #[deprecated = "Use Isometry3d instead"]
pub struct XrPose { pub type XrPose = Isometry3d;
pub translation: Vec3,
pub rotation: Quat,
}
impl Default for XrPose {
fn default() -> Self {
Self::IDENTITY
}
}
impl XrPose {
pub const IDENTITY: XrPose = XrPose {
translation: Vec3::ZERO,
rotation: Quat::IDENTITY,
};
pub const fn to_transform(self) -> Transform {
Transform::from_translation(self.translation).with_rotation(self.rotation)
}
}

View File

@@ -10,11 +10,11 @@ description = "utils for bevy_mod_xr and bevy_mod_openxr"
[dependencies] [dependencies]
bevy = { workspace = true, features = ["bevy_gizmos"] } bevy = { workspace = true, features = ["bevy_gizmos"] }
bevy_mod_xr = { path = "../bevy_xr", version = "0.1.0-rc1" } bevy_mod_xr.workspace = true
bevy_mod_openxr = { path = "../bevy_openxr", version = "0.1.0-rc1" } bevy_mod_openxr.workspace = true
[target.'cfg(not(target_family = "wasm"))'.dependencies] [target.'cfg(not(target_family = "wasm"))'.dependencies]
openxr = "0.18.0" openxr.workspace = true
[lints.clippy] [lints.clippy]
too_many_arguments = "allow" too_many_arguments = "allow"

View File

@@ -16,7 +16,11 @@ fn draw_hand_gizmos(
) { ) {
for (transform, bone, radius) in &query { for (transform, bone, radius) in &query {
let pose = transform.compute_transform(); let pose = transform.compute_transform();
gizmos.sphere(pose.translation, pose.rotation, **radius, gizmo_color(bone)); let pose = Isometry3d {
translation: pose.translation.into(),
rotation: pose.rotation,
};
gizmos.sphere(pose, **radius, gizmo_color(bone));
} }
} }

View File

@@ -1,11 +1,17 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_mod_openxr::{ use bevy_mod_openxr::{
action_binding::{OxrSendActionBindings, OxrSuggestActionBinding}, action_set_attaching::OxrAttachActionSet, action_set_syncing::{OxrActionSetSyncSet, OxrSyncActionSet}, helper_traits::{ToQuat, ToVec3}, openxr_session_available, openxr_session_running, resources::{OxrFrameState, OxrInstance, Pipelined}, session::OxrSession, spaces::{OxrSpaceLocationFlags, OxrSpaceSyncSet} action_binding::{OxrSendActionBindings, OxrSuggestActionBinding},
action_set_attaching::OxrAttachActionSet,
action_set_syncing::{OxrActionSetSyncSet, OxrSyncActionSet},
helper_traits::{ToQuat, ToVec3},
openxr_session_available, openxr_session_running,
resources::{OxrFrameState, OxrInstance, Pipelined},
session::OxrSession,
spaces::{OxrSpaceLocationFlags, OxrSpaceSyncSet},
}; };
use bevy_mod_xr::{ use bevy_mod_xr::{
session::{session_available, session_running, XrSessionCreated, XrTrackingRoot}, session::{XrSessionCreated, XrTrackingRoot},
spaces::{XrPrimaryReferenceSpace, XrReferenceSpace}, spaces::{XrPrimaryReferenceSpace, XrReferenceSpace},
types::XrPose,
}; };
use openxr::Posef; use openxr::Posef;
@@ -78,13 +84,10 @@ fn update_stage(
mut stage_query: Query<&mut Transform, (With<XrTrackedStage>, Without<XrTrackingRoot>)>, mut stage_query: Query<&mut Transform, (With<XrTrackedStage>, Without<XrTrackingRoot>)>,
) { ) {
let tracking_root_transform = root_query.get_single_mut(); let tracking_root_transform = root_query.get_single_mut();
match tracking_root_transform { if let Ok(root) = tracking_root_transform {
Ok(root) => { for mut transform in &mut stage_query {
for (mut transform) in &mut stage_query { *transform = *root;
*transform = root.clone();
}
} }
Err(_) => (),
} }
} }
@@ -128,13 +131,10 @@ fn update_view(
mut view_query: Query<&mut Transform, (With<XrTrackedView>, Without<HeadXRSpace>)>, mut view_query: Query<&mut Transform, (With<XrTrackedView>, Without<HeadXRSpace>)>,
) { ) {
let head_transform = head_query.get_single_mut(); let head_transform = head_query.get_single_mut();
match head_transform { if let Ok(root) = head_transform {
Ok(root) => { for mut transform in &mut view_query {
for (mut transform) in &mut view_query { *transform = *root;
*transform = root.clone();
}
} }
Err(_) => (),
} }
} }
@@ -144,19 +144,16 @@ fn update_local_floor_transforms(
mut local_floor: Query<&mut Transform, (With<XrTrackedLocalFloor>, Without<HeadXRSpace>)>, mut local_floor: Query<&mut Transform, (With<XrTrackedLocalFloor>, Without<HeadXRSpace>)>,
) { ) {
let head_transform = head_space.get_single_mut(); let head_transform = head_space.get_single_mut();
match head_transform { if let Ok(head) = head_transform {
Ok(head) => { let mut calc_floor = *head;
let mut calc_floor = head.clone(); calc_floor.translation.y = 0.0;
calc_floor.translation.y = 0.0; //TODO: use yaw
//TODO: use yaw let (y, x, z) = calc_floor.rotation.to_euler(EulerRot::YXZ);
let (y, x, z) = calc_floor.rotation.to_euler(EulerRot::YXZ); let new_rot = Quat::from_rotation_y(y);
let new_rot = Quat::from_rotation_y(y); calc_floor.rotation = new_rot;
calc_floor.rotation = new_rot; for (mut transform) in &mut local_floor {
for (mut transform) in &mut local_floor { *transform = calc_floor;
*transform = calc_floor;
}
} }
Err(_) => (),
} }
} }
@@ -222,20 +219,30 @@ fn spawn_tracking_rig(
// let local_floor = cmds.spawn((SpatialBundle::default(), LocalFloor)).id(); // let local_floor = cmds.spawn((SpatialBundle::default(), LocalFloor)).id();
let left_space = session let left_space = session
.create_action_space(&actions.left, openxr::Path::NULL, XrPose::IDENTITY) .create_action_space(&actions.left, openxr::Path::NULL, Isometry3d::IDENTITY)
.unwrap(); .unwrap();
let right_space = session let right_space = session
.create_action_space(&actions.right, openxr::Path::NULL, XrPose::IDENTITY) .create_action_space(&actions.right, openxr::Path::NULL, Isometry3d::IDENTITY)
.unwrap(); .unwrap();
let left = cmds let left = cmds
.spawn((SpatialBundle::default(), left_space, LeftGrip)) .spawn((
Transform::default(),
Visibility::default(),
left_space,
LeftGrip,
))
.id(); .id();
let right = cmds let right = cmds
.spawn((SpatialBundle::default(), right_space, RightGrip)) .spawn((
Transform::default(),
Visibility::default(),
right_space,
RightGrip,
))
.id(); .id();
cmds.entity(root.single()) cmds.entity(root.single())
.push_children(&[head, left, right]); .add_children(&[head, left, right]);
} }
//bindings //bindings