update to bevy 0.15 rc
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -10,11 +10,11 @@ keywords = ["gamedev", "bevy", "Xr", "Vr", "OpenXR"]
|
||||
[features]
|
||||
default = ["vulkan", "d3d12", "passthrough"]
|
||||
vulkan = ["dep:ash"]
|
||||
d3d12 = ["wgpu/dx12", "wgpu-hal/dx12", "dep:winapi", "dep:d3d12"]
|
||||
d3d12 = ["wgpu/dx12", "wgpu-hal/dx12", "dep:winapi"]
|
||||
passthrough = []
|
||||
|
||||
[dev-dependencies]
|
||||
bevy_xr_utils.path = "../bevy_xr_utils"
|
||||
bevy_xr_utils.workspace = true
|
||||
bevy = { workspace = true, default-features = true }
|
||||
|
||||
[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
|
||||
[target.'cfg(not(target_family = "wasm"))'.dependencies]
|
||||
openxr = "0.18.0"
|
||||
thiserror = "1.0.57"
|
||||
wgpu = "0.20"
|
||||
wgpu-hal = "0.21"
|
||||
bevy_mod_xr = { path = "../bevy_xr", version = "0.1.0-rc1" }
|
||||
|
||||
ash = { version = "0.37.3", optional = true }
|
||||
bevy_mod_xr.workspace = true
|
||||
openxr.workspace = true
|
||||
thiserror.workspace = true
|
||||
wgpu.workspace = true
|
||||
wgpu-hal.workspace = true
|
||||
ash = { version = "0.38", optional = true }
|
||||
|
||||
[target.'cfg(target_family = "unix")'.dependencies]
|
||||
openxr = { version = "0.18.0", features = ["mint"] }
|
||||
wgpu = { version = "0.20", features = ["vulkan-portability"] }
|
||||
openxr = { workspace = true, features = ["mint"] }
|
||||
wgpu = { workspace = true, features = ["vulkan-portability"] }
|
||||
|
||||
[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 }
|
||||
d3d12 = { version = "0.20", features = ["libloading"], optional = true }
|
||||
|
||||
[lints.clippy]
|
||||
too_many_arguments = "allow"
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
//! A simple 3D scene with light shining over a cube sitting on a plane.
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_mod_openxr::add_xr_plugins;
|
||||
use bevy::{prelude::*, render::pipelined_rendering::PipelinedRenderingPlugin};
|
||||
use bevy_mod_openxr::{add_xr_plugins, init::OxrInitPlugin};
|
||||
use openxr::EnvironmentBlendMode;
|
||||
|
||||
fn main() {
|
||||
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_systems(Startup, setup)
|
||||
.insert_resource(ClearColor(Color::NONE))
|
||||
.run();
|
||||
}
|
||||
|
||||
@@ -18,30 +30,27 @@ fn setup(
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
// 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()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Circle::new(4.0))),
|
||||
MeshMaterial3d(materials.add(Color::WHITE)),
|
||||
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
||||
));
|
||||
// cube
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||
material: materials.add(Color::srgb_u8(124, 144, 255)),
|
||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
..default()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
|
||||
Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
));
|
||||
// light
|
||||
commands.spawn(PointLightBundle {
|
||||
point_light: PointLight {
|
||||
commands.spawn((
|
||||
PointLight {
|
||||
shadows_enabled: true,
|
||||
..default()
|
||||
},
|
||||
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
..default()
|
||||
});
|
||||
commands.spawn(Camera3dBundle {
|
||||
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..default()
|
||||
});
|
||||
Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
));
|
||||
commands.spawn((
|
||||
Camera3d::default(),
|
||||
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -34,24 +34,22 @@ fn setup_scene(
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
// 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()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Circle::new(4.0))),
|
||||
MeshMaterial3d(materials.add(Color::WHITE)),
|
||||
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
||||
));
|
||||
// cube
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||
material: materials.add(Color::srgb_u8(124, 144, 255)),
|
||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
..default()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
|
||||
Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
));
|
||||
|
||||
commands.spawn(Camera3dBundle {
|
||||
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..default()
|
||||
});
|
||||
commands.spawn((
|
||||
Camera3d::default(),
|
||||
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
));
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
@@ -145,7 +143,7 @@ fn handle_flight_input(
|
||||
let locomotion_vector = reference_quat.mul_vec3(input_vector);
|
||||
|
||||
root_position.translation +=
|
||||
locomotion_vector * speed * time.delta_seconds();
|
||||
locomotion_vector * speed * time.delta_secs();
|
||||
}
|
||||
None => return,
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ publish = false
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy_mod_openxr.path = "../.."
|
||||
bevy_mod_openxr.workspace = true
|
||||
bevy = { workspace = true, default-features = true }
|
||||
bevy_xr_utils.path = "../../../bevy_xr_utils"
|
||||
bevy_xr_utils.workspace = true
|
||||
|
||||
[build-dependencies]
|
||||
reqwest = { version = "0.12", features = ["blocking"] }
|
||||
|
||||
@@ -21,8 +21,8 @@ fn main() {
|
||||
synchronous_pipeline_compilation: default(),
|
||||
}))
|
||||
.add_plugins(bevy_xr_utils::hand_gizmos::HandGizmosPlugin)
|
||||
.insert_resource(Msaa::Off)
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, modify_msaa)
|
||||
.insert_resource(AmbientLight {
|
||||
color: Default::default(),
|
||||
brightness: 500.0,
|
||||
@@ -31,6 +31,15 @@ fn main() {
|
||||
.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
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
@@ -40,19 +49,17 @@ fn setup(
|
||||
let mut white: StandardMaterial = Color::WHITE.into();
|
||||
white.unlit = true;
|
||||
// circular base
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Circle::new(4.0)),
|
||||
material: materials.add(white),
|
||||
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
||||
..default()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Circle::new(4.0))),
|
||||
MeshMaterial3d(materials.add(white)),
|
||||
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
||||
));
|
||||
let mut cube_mat: StandardMaterial = Color::srgb_u8(124, 144, 255).into();
|
||||
cube_mat.unlit = true;
|
||||
// cube
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||
material: materials.add(cube_mat),
|
||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
..default()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||
MeshMaterial3d(materials.add(cube_mat)),
|
||||
Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -79,30 +79,27 @@ fn setup(
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
// 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()
|
||||
// });
|
||||
// commands.spawn((
|
||||
// Mesh3d(meshes.add(Circle::new(4.0))),
|
||||
// MeshMaterial3d(materials.add(Color::WHITE)),
|
||||
// Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
||||
// ));
|
||||
// cube
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||
material: materials.add(Color::srgb_u8(124, 144, 255)),
|
||||
transform: Transform::from_xyz(0.0, 2.5, 0.0),
|
||||
..default()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
|
||||
Transform::from_xyz(0.0, 2.5, 0.0),
|
||||
));
|
||||
// light
|
||||
commands.spawn(PointLightBundle {
|
||||
point_light: PointLight {
|
||||
commands.spawn((
|
||||
PointLight {
|
||||
shadows_enabled: true,
|
||||
..default()
|
||||
},
|
||||
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
..default()
|
||||
});
|
||||
commands.spawn(Camera3dBundle {
|
||||
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..default()
|
||||
});
|
||||
Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
));
|
||||
commands.spawn((
|
||||
Camera3d::default(),
|
||||
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ use bevy_mod_openxr::{
|
||||
use bevy_mod_xr::{
|
||||
session::{session_available, session_running, XrSessionCreated, XrTrackingRoot},
|
||||
spaces::XrSpace,
|
||||
types::XrPose,
|
||||
};
|
||||
use openxr::Posef;
|
||||
|
||||
@@ -55,32 +54,29 @@ fn setup(
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
// 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()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Circle::new(4.0))),
|
||||
MeshMaterial3d(materials.add(Color::WHITE)),
|
||||
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
||||
));
|
||||
// cube
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||
material: materials.add(Color::srgb_u8(124, 144, 255)),
|
||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
..default()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
|
||||
Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
));
|
||||
// light
|
||||
commands.spawn(PointLightBundle {
|
||||
point_light: PointLight {
|
||||
commands.spawn((
|
||||
PointLight {
|
||||
shadows_enabled: true,
|
||||
..default()
|
||||
},
|
||||
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
..default()
|
||||
});
|
||||
commands.spawn(Camera3dBundle {
|
||||
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..default()
|
||||
});
|
||||
Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
));
|
||||
commands.spawn((
|
||||
Camera3d::default(),
|
||||
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
));
|
||||
}
|
||||
fn suggest_action_bindings(
|
||||
actions: Res<ControllerActions>,
|
||||
@@ -130,34 +126,28 @@ fn spawn_hands(
|
||||
.unwrap(),
|
||||
);
|
||||
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();
|
||||
let left = cmds
|
||||
.spawn((
|
||||
PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(0.1, 0.1, 0.05)),
|
||||
material: materials.add(Color::srgb_u8(124, 144, 255)),
|
||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
..default()
|
||||
},
|
||||
Mesh3d(meshes.add(Cuboid::new(0.1, 0.1, 0.05))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
|
||||
Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
left_space,
|
||||
Controller,
|
||||
))
|
||||
.id();
|
||||
let right = cmds
|
||||
.spawn((
|
||||
PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(0.1, 0.1, 0.05)),
|
||||
material: materials.add(Color::srgb_u8(124, 144, 255)),
|
||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
..default()
|
||||
},
|
||||
Mesh3d(meshes.add(Cuboid::new(0.1, 0.1, 0.05))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
|
||||
Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
right_space,
|
||||
Controller,
|
||||
))
|
||||
.id();
|
||||
|
||||
cmds.entity(root.single()).push_children(&[left, right]);
|
||||
cmds.entity(root.single()).add_children(&[left, right]);
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
|
||||
@@ -55,21 +55,19 @@ fn setup(
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
// 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()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Circle::new(4.0))),
|
||||
MeshMaterial3d(materials.add(Color::WHITE)),
|
||||
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
||||
));
|
||||
// cube
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||
material: materials.add(Color::srgb_u8(124, 144, 255)),
|
||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
..default()
|
||||
});
|
||||
commands.spawn(Camera3dBundle {
|
||||
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..default()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
|
||||
Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
));
|
||||
commands.spawn((
|
||||
Camera3d::default(),
|
||||
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use bevy::prelude::*;
|
||||
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::{
|
||||
TrackingUtilitiesPlugin, XrTrackedLeftGrip, XrTrackedLocalFloor, XrTrackedRightGrip,
|
||||
XrTrackedStage, XrTrackedView,
|
||||
@@ -29,25 +29,23 @@ fn setup(
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
// 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()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Circle::new(4.0))),
|
||||
MeshMaterial3d(materials.add(Color::WHITE)),
|
||||
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
||||
));
|
||||
// light
|
||||
commands.spawn(PointLightBundle {
|
||||
point_light: PointLight {
|
||||
commands.spawn((
|
||||
PointLight {
|
||||
shadows_enabled: true,
|
||||
..default()
|
||||
},
|
||||
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
..default()
|
||||
});
|
||||
commands.spawn(Camera3dBundle {
|
||||
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..default()
|
||||
});
|
||||
Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
));
|
||||
commands.spawn((
|
||||
Camera3d::default(),
|
||||
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
));
|
||||
}
|
||||
|
||||
fn spawn_hands(
|
||||
@@ -57,22 +55,16 @@ fn spawn_hands(
|
||||
) {
|
||||
let left = cmds
|
||||
.spawn((
|
||||
PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(0.1, 0.1, 0.05)),
|
||||
material: materials.add(Color::srgb_u8(124, 144, 255)),
|
||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
..default()
|
||||
},
|
||||
Mesh3d(meshes.add(Cuboid::new(0.1, 0.1, 0.05))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
|
||||
Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
XrTrackedLeftGrip,
|
||||
))
|
||||
.id();
|
||||
let bundle = (
|
||||
PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(0.1, 0.1, 0.05)),
|
||||
material: materials.add(Color::srgb_u8(124, 144, 255)),
|
||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
..default()
|
||||
},
|
||||
Mesh3d(meshes.add(Cuboid::new(0.1, 0.1, 0.05))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
|
||||
Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
XrTrackedRightGrip,
|
||||
);
|
||||
let right = cmds.spawn(bundle).id();
|
||||
@@ -80,40 +72,31 @@ fn spawn_hands(
|
||||
|
||||
let head = cmds
|
||||
.spawn((
|
||||
PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(0.2, 0.2, 0.2)),
|
||||
material: materials.add(Color::srgb_u8(255, 144, 144)),
|
||||
transform: Transform::from_xyz(0.0, 0.0, 0.0),
|
||||
..default()
|
||||
},
|
||||
Mesh3d(meshes.add(Cuboid::new(0.2, 0.2, 0.2))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(255, 144, 144))),
|
||||
Transform::from_xyz(0.0, 0.0, 0.0),
|
||||
XrTrackedView,
|
||||
))
|
||||
.id();
|
||||
//local_floor emulated
|
||||
let local_floor = cmds
|
||||
.spawn((
|
||||
PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(0.5, 0.1, 0.5)),
|
||||
material: materials.add(Color::srgb_u8(144, 255, 144)),
|
||||
transform: Transform::from_xyz(0.0, 0.0, 0.0),
|
||||
..default()
|
||||
},
|
||||
Mesh3d(meshes.add(Cuboid::new(0.5, 0.1, 0.5))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(144, 255, 144))),
|
||||
Transform::from_xyz(0.0, 0.0, 0.0),
|
||||
XrTrackedLocalFloor,
|
||||
))
|
||||
.id();
|
||||
|
||||
let stage = cmds
|
||||
.spawn((
|
||||
PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(0.5, 0.1, 0.5)),
|
||||
material: materials.add(Color::srgb_u8(144, 255, 255)),
|
||||
transform: Transform::from_xyz(0.0, 0.0, 0.0),
|
||||
..default()
|
||||
},
|
||||
Mesh3d(meshes.add(Cuboid::new(0.5, 0.1, 0.5))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(144, 255, 255))),
|
||||
Transform::from_xyz(0.0, 0.0, 0.0),
|
||||
XrTrackedStage,
|
||||
))
|
||||
.id();
|
||||
|
||||
cmds.entity(stage)
|
||||
.push_children(&[left, right, head, local_floor]);
|
||||
.add_children(&[left, right, head, local_floor]);
|
||||
}
|
||||
|
||||
@@ -41,52 +41,46 @@ fn setup(
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
// 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()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Circle::new(4.0))),
|
||||
MeshMaterial3d(materials.add(Color::WHITE)),
|
||||
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
||||
));
|
||||
// red cube
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||
material: materials.add(Color::srgb_u8(252, 44, 3)),
|
||||
transform: Transform::from_xyz(4.0, 0.5, 0.0).with_scale(Vec3::splat(0.5)),
|
||||
..default()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(252, 44, 3))),
|
||||
Transform::from_xyz(4.0, 0.5, 0.0).with_scale(Vec3::splat(0.5)),
|
||||
));
|
||||
// blue cube
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||
material: materials.add(Color::srgb_u8(3, 28, 252)),
|
||||
transform: Transform::from_xyz(-4.0, 0.5, 0.0).with_scale(Vec3::splat(0.5)),
|
||||
..default()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(3, 28, 252))),
|
||||
Transform::from_xyz(-4.0, 0.5, 0.0).with_scale(Vec3::splat(0.5)),
|
||||
));
|
||||
// green cube
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||
material: materials.add(Color::srgb_u8(3, 252, 32)),
|
||||
transform: Transform::from_xyz(0.0, 0.5, 4.0).with_scale(Vec3::splat(0.5)),
|
||||
..default()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(3, 252, 32))),
|
||||
Transform::from_xyz(0.0, 0.5, 4.0).with_scale(Vec3::splat(0.5)),
|
||||
));
|
||||
// white cube
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||
material: materials.add(Color::srgb_u8(250, 250, 250)),
|
||||
transform: Transform::from_xyz(0.0, 0.5, -4.0).with_scale(Vec3::splat(0.5)),
|
||||
..default()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(250, 250, 250))),
|
||||
Transform::from_xyz(0.0, 0.5, -4.0).with_scale(Vec3::splat(0.5)),
|
||||
));
|
||||
// black cube
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||
material: materials.add(Color::srgb_u8(0, 0, 0)),
|
||||
transform: Transform::from_xyz(0.0, 0.1, 0.0).with_scale(Vec3::splat(0.2)),
|
||||
..default()
|
||||
});
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(0, 0, 0))),
|
||||
Transform::from_xyz(0.0, 0.1, 0.0).with_scale(Vec3::splat(0.2)),
|
||||
));
|
||||
|
||||
commands.spawn(Camera3dBundle {
|
||||
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..default()
|
||||
});
|
||||
commands.spawn((
|
||||
Camera3d::default(),
|
||||
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
));
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
|
||||
@@ -16,7 +16,7 @@ impl Plugin for OxrActionBindingPlugin {
|
||||
app.add_event::<OxrSuggestActionBinding>();
|
||||
app.add_systems(
|
||||
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
|
||||
pub(crate) fn run_action_binding_sugestion(world: &mut World) {
|
||||
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>) {
|
||||
|
||||
@@ -8,7 +8,7 @@ impl Plugin for OxrActionAttachingPlugin {
|
||||
app.add_systems(
|
||||
PostUpdate,
|
||||
attach_sets
|
||||
.run_if(on_event::<XrSessionCreatedEvent>())
|
||||
.run_if(on_event::<XrSessionCreatedEvent>)
|
||||
.after(run_action_binding_sugestion),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -90,14 +90,14 @@ fn spawn_default_hands(mut cmds: Commands, root: Query<Entity, With<XrTrackingRo
|
||||
OxrSpaceLocationFlags(openxr::SpaceLocationFlags::default()),
|
||||
)
|
||||
});
|
||||
cmds.entity(root).push_children(&left_bones);
|
||||
cmds.entity(root).push_children(&right_bones);
|
||||
cmds.push(SpawnHandTracker {
|
||||
cmds.entity(root).add_children(&left_bones);
|
||||
cmds.entity(root).add_children(&right_bones);
|
||||
cmds.queue(SpawnHandTracker {
|
||||
joints: XrHandBoneEntities(left_bones),
|
||||
tracker_bundle: DefaultHandTracker,
|
||||
side: HandSide::Left,
|
||||
});
|
||||
cmds.push(SpawnHandTracker {
|
||||
cmds.queue(SpawnHandTracker {
|
||||
joints: XrHandBoneEntities(right_bones),
|
||||
tracker_bundle: DefaultHandTracker,
|
||||
side: HandSide::Right,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#[cfg(all(feature = "d3d12", windows))]
|
||||
mod d3d12;
|
||||
// #[cfg(all(feature = "d3d12", windows))]
|
||||
// mod d3d12;
|
||||
#[cfg(feature = "vulkan")]
|
||||
pub mod vulkan;
|
||||
|
||||
@@ -8,7 +8,10 @@ use std::any::TypeId;
|
||||
use bevy::math::UVec2;
|
||||
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.
|
||||
pub unsafe trait GraphicsExt: openxr::Graphics {
|
||||
@@ -37,7 +40,7 @@ pub unsafe trait GraphicsExt: openxr::Graphics {
|
||||
instance: &openxr::Instance,
|
||||
system_id: openxr::SystemId,
|
||||
) -> Result<(WgpuGraphics, Self::SessionCreateInfo)>;
|
||||
unsafe fn create_session(
|
||||
unsafe fn create_session(
|
||||
instance: &openxr::Instance,
|
||||
system_id: openxr::SystemId,
|
||||
info: &Self::SessionCreateInfo,
|
||||
@@ -74,8 +77,8 @@ impl GraphicsBackend {
|
||||
const ALL: &'static [Self] = &[
|
||||
#[cfg(feature = "vulkan")]
|
||||
Self::Vulkan(()),
|
||||
#[cfg(all(feature = "d3d12", windows))]
|
||||
Self::D3D12(()),
|
||||
// #[cfg(all(feature = "d3d12", windows))]
|
||||
// Self::D3D12(()),
|
||||
];
|
||||
|
||||
pub fn available_backends(exts: &OxrExtensions) -> Vec<Self> {
|
||||
@@ -103,8 +106,8 @@ impl GraphicsBackend {
|
||||
pub enum GraphicsWrap<T: GraphicsType> {
|
||||
#[cfg(feature = "vulkan")]
|
||||
Vulkan(T::Inner<openxr::Vulkan>),
|
||||
#[cfg(all(feature = "d3d12", windows))]
|
||||
D3D12(T::Inner<openxr::D3D12>),
|
||||
// #[cfg(all(feature = "d3d12", windows))]
|
||||
// D3D12(T::Inner<openxr::D3D12>),
|
||||
}
|
||||
|
||||
impl<T: GraphicsType> GraphicsWrap<T> {
|
||||
@@ -173,12 +176,12 @@ macro_rules! graphics_match {
|
||||
type Api = openxr::Vulkan;
|
||||
graphics_match!(@arm_impl Vulkan; $expr $(=> $($return)*)?)
|
||||
},
|
||||
#[cfg(all(feature = "d3d12", windows))]
|
||||
$crate::graphics::GraphicsWrap::D3D12($var) => {
|
||||
#[allow(unused)]
|
||||
type Api = openxr::D3D12;
|
||||
graphics_match!(@arm_impl D3D12; $expr $(=> $($return)*)?)
|
||||
},
|
||||
// #[cfg(all(feature = "d3d12", windows))]
|
||||
// $crate::graphics::GraphicsWrap::D3D12($var) => {
|
||||
// #[allow(unused)]
|
||||
// type Api = openxr::D3D12;
|
||||
// graphics_match!(@arm_impl D3D12; $expr $(=> $($return)*)?)
|
||||
// },
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ const VK_TARGET_VERSION_ASH: u32 = ash::vk::make_api_version(
|
||||
0,
|
||||
VK_TARGET_VERSION.major() as u32,
|
||||
VK_TARGET_VERSION.minor() as u32,
|
||||
VK_TARGET_VERSION.patch() as u32,
|
||||
VK_TARGET_VERSION.patch(),
|
||||
);
|
||||
|
||||
unsafe impl GraphicsExt for openxr::Vulkan {
|
||||
@@ -63,7 +63,7 @@ unsafe impl GraphicsExt for openxr::Vulkan {
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: format,
|
||||
format,
|
||||
usage: wgpu_hal::TextureUses::COLOR_TARGET | wgpu_hal::TextureUses::COPY_DST,
|
||||
memory_flags: wgpu_hal::MemoryFlags::empty(),
|
||||
view_formats: vec![],
|
||||
@@ -84,7 +84,7 @@ unsafe impl GraphicsExt for openxr::Vulkan {
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: format,
|
||||
format,
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST,
|
||||
view_formats: &[],
|
||||
},
|
||||
@@ -113,20 +113,20 @@ unsafe impl GraphicsExt for openxr::Vulkan {
|
||||
let flags = wgpu::InstanceFlags::empty();
|
||||
let extensions =
|
||||
<Vulkan as Api>::Instance::desired_extensions(&vk_entry, VK_TARGET_VERSION_ASH, flags)?;
|
||||
let device_extensions = vec![
|
||||
ash::extensions::khr::Swapchain::name(),
|
||||
ash::extensions::khr::DrawIndirectCount::name(),
|
||||
#[cfg(target_os = "android")]
|
||||
ash::extensions::khr::TimelineSemaphore::name(),
|
||||
ash::vk::KhrImagelessFramebufferFn::name(),
|
||||
ash::vk::KhrImageFormatListFn::name(),
|
||||
let device_extensions = [
|
||||
ash::khr::swapchain::NAME,
|
||||
ash::khr::draw_indirect_count::NAME,
|
||||
// #[cfg(target_os = "android")]
|
||||
ash::khr::timeline_semaphore::NAME,
|
||||
ash::khr::imageless_framebuffer::NAME,
|
||||
ash::khr::image_format_list::NAME,
|
||||
];
|
||||
|
||||
let vk_instance = unsafe {
|
||||
let extensions_cchar: Vec<_> = extensions.iter().map(|s| s.as_ptr()).collect();
|
||||
|
||||
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_version(1)
|
||||
.engine_name(&app_name)
|
||||
@@ -136,8 +136,9 @@ unsafe impl GraphicsExt for openxr::Vulkan {
|
||||
let vk_instance = instance
|
||||
.create_vulkan_instance(
|
||||
system_id,
|
||||
#[allow(clippy::missing_transmute_annotations)]
|
||||
std::mem::transmute(vk_entry.static_fn().get_instance_proc_addr),
|
||||
&ash::vk::InstanceCreateInfo::builder()
|
||||
&ash::vk::InstanceCreateInfo::default()
|
||||
.application_info(&vk_app_info)
|
||||
.enabled_extension_names(&extensions_cchar) as *const _
|
||||
as *const _,
|
||||
@@ -181,7 +182,7 @@ unsafe impl GraphicsExt for openxr::Vulkan {
|
||||
extensions,
|
||||
flags,
|
||||
false,
|
||||
Some(Box::new(())),
|
||||
None,
|
||||
)?
|
||||
};
|
||||
|
||||
@@ -205,26 +206,26 @@ unsafe impl GraphicsExt for openxr::Vulkan {
|
||||
.adapter
|
||||
.physical_device_features(&enabled_extensions, wgpu_features);
|
||||
let family_index = 0;
|
||||
let family_info = ash::vk::DeviceQueueCreateInfo::builder()
|
||||
let family_info = ash::vk::DeviceQueueCreateInfo::default()
|
||||
.queue_family_index(family_index)
|
||||
.queue_priorities(&[1.0])
|
||||
.build();
|
||||
.queue_priorities(&[1.0]);
|
||||
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
|
||||
.add_to_device_create_builder(
|
||||
ash::vk::DeviceCreateInfo::builder()
|
||||
.add_to_device_create(
|
||||
ash::vk::DeviceCreateInfo::default()
|
||||
.queue_create_infos(&family_infos)
|
||||
.push_next(&mut ash::vk::PhysicalDeviceMultiviewFeatures {
|
||||
multiview: ash::vk::TRUE,
|
||||
..Default::default()
|
||||
}),
|
||||
.push_next(&mut physical_device_multiview_features),
|
||||
)
|
||||
.enabled_extension_names(&extensions_cchar)
|
||||
.build();
|
||||
.enabled_extension_names(&extensions_cchar);
|
||||
let vk_device = unsafe {
|
||||
let vk_device = instance
|
||||
.create_vulkan_device(
|
||||
system_id,
|
||||
#[allow(clippy::missing_transmute_annotations)]
|
||||
std::mem::transmute(vk_entry.static_fn().get_instance_proc_addr),
|
||||
vk_physical_device.as_raw() as _,
|
||||
&info as *const _ as *const _,
|
||||
@@ -241,9 +242,10 @@ unsafe impl GraphicsExt for openxr::Vulkan {
|
||||
let wgpu_open_device = unsafe {
|
||||
wgpu_exposed_adapter.adapter.device_from_raw(
|
||||
vk_device,
|
||||
true,
|
||||
None,
|
||||
&enabled_extensions,
|
||||
wgpu_features,
|
||||
&wgpu::MemoryHints::Performance,
|
||||
family_info.queue_family_index,
|
||||
0,
|
||||
)
|
||||
@@ -273,6 +275,7 @@ unsafe impl GraphicsExt for openxr::Vulkan {
|
||||
max_push_constant_size: 4,
|
||||
..Default::default()
|
||||
},
|
||||
memory_hints: wgpu::MemoryHints::Performance,
|
||||
},
|
||||
None,
|
||||
)
|
||||
@@ -320,7 +323,7 @@ unsafe impl GraphicsExt for openxr::Vulkan {
|
||||
ty: sys::SessionCreateInfo::TYPE,
|
||||
next: &binding as *const _ as *const _,
|
||||
create_flags: Default::default(),
|
||||
system_id: system_id,
|
||||
system_id,
|
||||
};
|
||||
let mut out = sys::Session::NULL;
|
||||
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::A2B10G10R10_UINT_PACK32 => Tf::Rgb10a2Uint,
|
||||
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_SINT => Tf::Rg32Sint,
|
||||
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::Rgb10a2Uint => F::A2B10G10R10_UINT_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::Rg32Sint => F::R32G32_SINT,
|
||||
Tf::Rg32Float => F::R32G32_SFLOAT,
|
||||
@@ -724,4 +727,3 @@ fn wgpu_to_vulkan(format: wgpu::TextureFormat) -> Option<ash::vk::Format> {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_mod_xr::types::XrPose;
|
||||
use bevy::{math::Vec3A, prelude::*};
|
||||
|
||||
pub trait ToPosef {
|
||||
fn to_posef(&self) -> openxr::Posef;
|
||||
@@ -7,8 +6,8 @@ pub trait ToPosef {
|
||||
pub trait ToTransform {
|
||||
fn to_transform(&self) -> Transform;
|
||||
}
|
||||
pub trait ToXrPose {
|
||||
fn to_xr_pose(&self) -> XrPose;
|
||||
pub trait ToIsometry3d {
|
||||
fn to_xr_pose(&self) -> Isometry3d;
|
||||
}
|
||||
pub trait ToQuaternionf {
|
||||
fn to_quaternionf(&self) -> openxr::Quaternionf;
|
||||
@@ -42,15 +41,15 @@ impl ToTransform for openxr::Posef {
|
||||
.with_rotation(self.orientation.to_quat())
|
||||
}
|
||||
}
|
||||
impl ToXrPose for openxr::Posef {
|
||||
fn to_xr_pose(&self) -> XrPose {
|
||||
XrPose {
|
||||
translation: self.position.to_vec3(),
|
||||
impl ToIsometry3d for openxr::Posef {
|
||||
fn to_xr_pose(&self) -> Isometry3d {
|
||||
Isometry3d {
|
||||
translation: self.position.to_vec3().into(),
|
||||
rotation: self.orientation.to_quat(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ToPosef for XrPose {
|
||||
impl ToPosef for Isometry3d {
|
||||
fn to_posef(&self) -> openxr::Posef {
|
||||
openxr::Posef {
|
||||
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 {
|
||||
fn to_vec3(&self) -> Vec3 {
|
||||
Vec3 {
|
||||
|
||||
@@ -113,7 +113,7 @@ impl Plugin for OxrInitPlugin {
|
||||
(
|
||||
create_xr_session
|
||||
.run_if(state_equals(XrState::Available))
|
||||
.run_if(on_event::<XrCreateSessionEvent>()),
|
||||
.run_if(on_event::<XrCreateSessionEvent>),
|
||||
(
|
||||
destroy_xr_session,
|
||||
(|v: Res<XrDestroySessionRender>| {
|
||||
@@ -122,16 +122,16 @@ impl Plugin for OxrInitPlugin {
|
||||
}),
|
||||
)
|
||||
.run_if(state_matches!(XrState::Exiting { .. }))
|
||||
.run_if(on_event::<XrDestroySessionEvent>()),
|
||||
.run_if(on_event::<XrDestroySessionEvent>),
|
||||
begin_xr_session
|
||||
.run_if(state_equals(XrState::Ready))
|
||||
.run_if(on_event::<XrBeginSessionEvent>()),
|
||||
.run_if(on_event::<XrBeginSessionEvent>),
|
||||
end_xr_session
|
||||
.run_if(state_equals(XrState::Stopping))
|
||||
.run_if(on_event::<XrEndSessionEvent>()),
|
||||
.run_if(on_event::<XrEndSessionEvent>),
|
||||
request_exit_xr_session
|
||||
.run_if(session_created)
|
||||
.run_if(on_event::<XrRequestExitEvent>()),
|
||||
.run_if(on_event::<XrRequestExitEvent>),
|
||||
)
|
||||
.in_set(XrHandleEvents::SessionStateUpdateEvents),
|
||||
)
|
||||
@@ -146,9 +146,6 @@ impl Plugin for OxrInitPlugin {
|
||||
.insert_non_send_resource(session_create_info)
|
||||
.init_non_send_resource::<OxrSessionCreateNextChain>();
|
||||
|
||||
app.world_mut()
|
||||
.spawn((SpatialBundle::default(), XrTrackingRoot));
|
||||
|
||||
app.world_mut()
|
||||
.resource_mut::<Events<XrStateChanged>>()
|
||||
.send(XrStateChanged(XrState::Available));
|
||||
@@ -178,7 +175,7 @@ impl Plugin for OxrInitPlugin {
|
||||
})
|
||||
.run_if(
|
||||
resource_exists::<XrDestroySessionRender>
|
||||
.and_then(|v: Res<XrDestroySessionRender>| v.0.load(Ordering::Relaxed)),
|
||||
.and(|v: Res<XrDestroySessionRender>| v.0.load(Ordering::Relaxed)),
|
||||
)
|
||||
.chain(),
|
||||
);
|
||||
@@ -467,7 +464,7 @@ pub fn create_xr_session(world: &mut World) {
|
||||
let system_id = world.resource::<OxrSystemId>();
|
||||
match init_xr_session(
|
||||
device.wgpu_device(),
|
||||
&instance,
|
||||
instance,
|
||||
**system_id,
|
||||
&mut chain,
|
||||
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)) => {
|
||||
world.insert_resource(session.clone());
|
||||
world.insert_resource(frame_waiter);
|
||||
world.insert_resource(images.clone());
|
||||
world.insert_resource(graphics_info.clone());
|
||||
world.insert_resource(images);
|
||||
world.insert_resource(graphics_info);
|
||||
world.insert_resource(OxrRenderResources {
|
||||
session,
|
||||
frame_stream,
|
||||
|
||||
@@ -37,14 +37,14 @@ impl LayerProvider for ProjectionLayer {
|
||||
Some(Box::new(
|
||||
CompositionLayerProjection::new()
|
||||
.layer_flags(CompositionLayerFlags::BLEND_TEXTURE_SOURCE_ALPHA)
|
||||
.space(&stage)
|
||||
.space(stage)
|
||||
.views(&[
|
||||
CompositionLayerProjectionView::new()
|
||||
.pose(openxr_views.0[0].pose)
|
||||
.fov(openxr_views.0[0].fov)
|
||||
.sub_image(
|
||||
SwapchainSubImage::new()
|
||||
.swapchain(&swapchain)
|
||||
.swapchain(swapchain)
|
||||
.image_array_index(0)
|
||||
.image_rect(rect),
|
||||
),
|
||||
@@ -53,7 +53,7 @@ impl LayerProvider for ProjectionLayer {
|
||||
.fov(openxr_views.0[1].fov)
|
||||
.sub_image(
|
||||
SwapchainSubImage::new()
|
||||
.swapchain(&swapchain)
|
||||
.swapchain(swapchain)
|
||||
.image_array_index(1)
|
||||
.image_rect(rect),
|
||||
),
|
||||
@@ -235,9 +235,15 @@ impl<'a> Default for CompositionLayerProjection<'a> {
|
||||
pub struct CompositionLayerPassthrough {
|
||||
inner: sys::CompositionLayerPassthroughFB,
|
||||
}
|
||||
impl Default for CompositionLayerPassthrough {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl CompositionLayerPassthrough {
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
inner: openxr::sys::CompositionLayerPassthroughFB {
|
||||
ty: openxr::sys::CompositionLayerPassthroughFB::TYPE,
|
||||
|
||||
@@ -60,8 +60,8 @@ pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
|
||||
.build()
|
||||
.disable::<RenderPlugin>()
|
||||
// .disable::<PipelinedRenderingPlugin>()
|
||||
.add_before::<RenderPlugin, _>(XrSessionPlugin { auto_handle: true })
|
||||
.add_before::<RenderPlugin, _>(OxrInitPlugin::default())
|
||||
.add_before::<RenderPlugin>(XrSessionPlugin { auto_handle: true })
|
||||
.add_before::<RenderPlugin>(OxrInitPlugin::default())
|
||||
.add(OxrEventsPlugin)
|
||||
.add(OxrReferenceSpacePlugin::default())
|
||||
.add(OxrRenderPlugin)
|
||||
|
||||
@@ -150,16 +150,18 @@ pub fn init_views(
|
||||
info!("{}", graphics_info.resolution);
|
||||
let view_handle =
|
||||
add_texture_view(&mut manual_texture_views, temp_tex, &graphics_info, index);
|
||||
|
||||
let cam = commands
|
||||
.spawn((XrCameraBundle {
|
||||
camera: Camera {
|
||||
target: RenderTarget::TextureView(view_handle),
|
||||
.spawn(
|
||||
(XrCameraBundle {
|
||||
camera: Camera {
|
||||
target: RenderTarget::TextureView(view_handle),
|
||||
..Default::default()
|
||||
},
|
||||
view: XrCamera(index),
|
||||
..Default::default()
|
||||
},
|
||||
view: XrCamera(index),
|
||||
..Default::default()
|
||||
},))
|
||||
}),
|
||||
)
|
||||
.remove::<Projection>()
|
||||
.id();
|
||||
match root.get_single() {
|
||||
Ok(root) => {
|
||||
|
||||
@@ -43,6 +43,7 @@ impl OxrEntry {
|
||||
application_version: app_info.version.to_u32(),
|
||||
engine_name: "Bevy",
|
||||
engine_version: Version::BEVY.to_u32(),
|
||||
api_version: openxr::Version::new(1, 1, 36),
|
||||
},
|
||||
&required_exts.into(),
|
||||
layers,
|
||||
@@ -108,7 +109,7 @@ impl OxrInstance {
|
||||
graphics_match!(
|
||||
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))))
|
||||
}
|
||||
@@ -185,7 +186,7 @@ impl OxrFrameStream {
|
||||
stream => {
|
||||
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 !swapchain.0.using_graphics::<Api>() {
|
||||
error!(
|
||||
@@ -196,7 +197,10 @@ impl OxrFrameStream {
|
||||
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())?)
|
||||
|
||||
@@ -7,7 +7,6 @@ use bevy_mod_xr::{
|
||||
XrDestroySpace, XrPrimaryReferenceSpace, XrReferenceSpace, XrSpace, XrSpaceLocationFlags,
|
||||
XrSpaceVelocityFlags, XrVelocity,
|
||||
},
|
||||
types::XrPose,
|
||||
};
|
||||
use openxr::{
|
||||
sys, HandJointLocation, HandJointLocations, HandJointVelocities, HandJointVelocity,
|
||||
@@ -51,28 +50,11 @@ impl Plugin for OxrSpatialPlugin {
|
||||
.in_set(OxrSpaceSyncSet)
|
||||
.run_if(openxr_session_running),
|
||||
)
|
||||
.observe(add_location_flags)
|
||||
.observe(add_velocity_flags);
|
||||
.register_required_components::<XrSpaceLocationFlags, OxrSpaceLocationFlags>()
|
||||
.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>) {
|
||||
for space in events.read() {
|
||||
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);
|
||||
impl OxrSpaceLocationFlags {
|
||||
pub fn pos_valid(&self) -> bool {
|
||||
@@ -135,7 +117,7 @@ impl OxrSpaceLocationFlags {
|
||||
self.0.contains(SpaceLocationFlags::ORIENTATION_TRACKED)
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Copy, Component)]
|
||||
#[derive(Clone, Copy, Component, Default)]
|
||||
pub struct OxrSpaceVelocityFlags(pub openxr::SpaceVelocityFlags);
|
||||
impl OxrSpaceVelocityFlags {
|
||||
pub fn linear_valid(&self) -> bool {
|
||||
@@ -231,7 +213,7 @@ impl OxrSession {
|
||||
&self,
|
||||
action: &openxr::Action<T>,
|
||||
subaction_path: openxr::Path,
|
||||
pose_in_space: XrPose,
|
||||
pose_in_space: Isometry3d,
|
||||
) -> openxr::Result<XrSpace> {
|
||||
let info = sys::ActionSpaceCreateInfo {
|
||||
ty: sys::ActionSpaceCreateInfo::TYPE,
|
||||
|
||||
@@ -24,7 +24,7 @@ pub struct Version(pub u8, pub u8, pub u16);
|
||||
|
||||
impl Version {
|
||||
/// 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 {
|
||||
let major = (self.0 as u32) << 24;
|
||||
|
||||
Reference in New Issue
Block a user