feat: update to bevy 0.17 and use individual bevy crates
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -9,12 +9,20 @@ description = "utils for bevy_mod_xr and bevy_mod_openxr"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy = { workspace = true, features = ["bevy_gizmos"] }
|
||||
# bevy = { workspace = true, features = ["bevy_gizmos"] }
|
||||
bevy_mod_xr.workspace = true
|
||||
bevy_mod_openxr.workspace = true
|
||||
bevy_ecs.workspace=true
|
||||
bevy_app.workspace=true
|
||||
bevy_transform.workspace=true
|
||||
bevy_color.workspace=true
|
||||
bevy_gizmos.workspace=true
|
||||
bevy_log.workspace=true
|
||||
bevy_derive.workspace=true
|
||||
bevy_math.workspace=true
|
||||
|
||||
[dev-dependencies]
|
||||
bevy = { workspace = true, default-features = true }
|
||||
bevy.workspace = true
|
||||
|
||||
[target.'cfg(not(target_family = "wasm"))'.dependencies]
|
||||
openxr.workspace = true
|
||||
|
||||
@@ -3,7 +3,7 @@ use bevy::{math::vec3, prelude::*};
|
||||
use bevy_mod_openxr::{add_xr_plugins, helper_traits::ToQuat, resources::OxrViews};
|
||||
use bevy_mod_xr::session::XrTrackingRoot;
|
||||
use bevy_xr_utils::xr_utils_actions::{
|
||||
ActiveSet, XRUtilsAction, XRUtilsActionSet, XRUtilsActionState, XRUtilsActionSystemSet,
|
||||
ActiveSet, XRUtilsAction, XRUtilsActionSet, XRUtilsActionState, XRUtilsActionSystems,
|
||||
XRUtilsActionsPlugin, XRUtilsBinding,
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ fn main() {
|
||||
.add_systems(Startup, setup_scene)
|
||||
.add_systems(
|
||||
Startup,
|
||||
create_action_entities.before(XRUtilsActionSystemSet::CreateEvents),
|
||||
create_action_entities.before(XRUtilsActionSystems::CreateEvents),
|
||||
)
|
||||
.add_plugins(XRUtilsActionsPlugin)
|
||||
.add_systems(Update, read_action_with_marker_component)
|
||||
|
||||
@@ -4,7 +4,7 @@ use bevy::prelude::*;
|
||||
use bevy_mod_openxr::add_xr_plugins;
|
||||
use bevy_xr_utils::transform_utils::{self, SnapToPosition, SnapToRotation};
|
||||
use bevy_xr_utils::xr_utils_actions::{
|
||||
ActiveSet, XRUtilsAction, XRUtilsActionSet, XRUtilsActionState, XRUtilsActionSystemSet,
|
||||
ActiveSet, XRUtilsAction, XRUtilsActionSet, XRUtilsActionState, XRUtilsActionSystems,
|
||||
XRUtilsActionsPlugin, XRUtilsBinding,
|
||||
};
|
||||
|
||||
@@ -17,15 +17,15 @@ fn main() -> AppExit {
|
||||
.add_plugins(XRUtilsActionsPlugin)
|
||||
.add_systems(
|
||||
Startup,
|
||||
create_action_entities.before(XRUtilsActionSystemSet::CreateEvents),
|
||||
create_action_entities.before(XRUtilsActionSystems::CreateEvents),
|
||||
)
|
||||
.add_systems(
|
||||
Update,
|
||||
send_look_at_red_cube_event.after(XRUtilsActionSystemSet::SyncActionStates),
|
||||
send_look_at_red_cube_event.after(XRUtilsActionSystems::SyncActionStates),
|
||||
)
|
||||
.add_systems(
|
||||
Update,
|
||||
send_recenter.after(XRUtilsActionSystemSet::SyncActionStates),
|
||||
send_recenter.after(XRUtilsActionSystems::SyncActionStates),
|
||||
)
|
||||
.insert_resource(AmbientLight {
|
||||
brightness: 500.0,
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
use bevy::{color::palettes::css, prelude::*};
|
||||
use bevy_app::{App, Plugin, PostUpdate};
|
||||
use bevy_color::palettes::css;
|
||||
use bevy_ecs::{component::Component, query::With, schedule::IntoScheduleConfigs as _, system::Query};
|
||||
use bevy_gizmos::gizmos::Gizmos;
|
||||
use bevy_transform::{TransformSystems, components::{GlobalTransform, Transform}};
|
||||
|
||||
#[derive(Clone, Copy, Component)]
|
||||
#[require(Transform)]
|
||||
@@ -8,10 +12,7 @@ pub struct GenericTrackerGizmoPlugin;
|
||||
|
||||
impl Plugin for GenericTrackerGizmoPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(
|
||||
PostUpdate,
|
||||
draw_gizmos.after(TransformSystem::TransformPropagate),
|
||||
);
|
||||
app.add_systems(PostUpdate, draw_gizmos.after(TransformSystems::Propagate));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use std::convert::identity;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_app::{App, Plugin, PreUpdate};
|
||||
use bevy_derive::{Deref, DerefMut};
|
||||
use bevy_ecs::{component::Component, entity::Entity, query::With, resource::Resource, schedule::{IntoScheduleConfigs as _, common_conditions::resource_exists}, system::{Commands, Query, Res, ResMut}};
|
||||
use bevy_log::{error, info};
|
||||
use bevy_mod_openxr::{
|
||||
resources::{OxrInstance, OxrSystemId},
|
||||
session::OxrSession,
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_app::{App, Plugin, PreUpdate, Startup};
|
||||
use bevy_ecs::{
|
||||
component::Component,
|
||||
message::MessageWriter,
|
||||
query::{With, Without},
|
||||
resource::Resource,
|
||||
schedule::IntoScheduleConfigs as _,
|
||||
system::{Commands, Query, Res},
|
||||
};
|
||||
use bevy_math::{EulerRot, Isometry3d, Quat};
|
||||
use bevy_mod_openxr::{
|
||||
action_binding::OxrSuggestActionBinding,
|
||||
action_set_attaching::OxrAttachActionSet,
|
||||
@@ -13,6 +22,7 @@ use bevy_mod_xr::{
|
||||
session::{XrSessionCreated, XrTracker, XrTrackingRoot},
|
||||
spaces::{XrPrimaryReferenceSpace, XrReferenceSpace, XrSpaceSyncSet},
|
||||
};
|
||||
use bevy_transform::components::Transform;
|
||||
use openxr::Posef;
|
||||
|
||||
//exernal api
|
||||
@@ -203,14 +213,9 @@ fn spawn_tracking_rig(
|
||||
) {
|
||||
//head
|
||||
let head_space = session
|
||||
.create_reference_space(openxr::ReferenceSpaceType::VIEW, Transform::IDENTITY)
|
||||
.create_reference_space(openxr::ReferenceSpaceType::VIEW, Isometry3d::IDENTITY)
|
||||
.unwrap();
|
||||
cmds.spawn((
|
||||
Transform::default(),
|
||||
Visibility::default(),
|
||||
XrTracker,
|
||||
HeadXRSpace(head_space),
|
||||
));
|
||||
cmds.spawn((Transform::default(), XrTracker, HeadXRSpace(head_space)));
|
||||
// let local_floor = cmds.spawn((SpatialBundle::default(), LocalFloor)).id();
|
||||
|
||||
let left_space = session
|
||||
@@ -227,7 +232,7 @@ fn spawn_tracking_rig(
|
||||
//TODO figure out how to make these better, specifically not be controller specific
|
||||
pub fn suggest_action_bindings(
|
||||
actions: Res<ControllerActions>,
|
||||
mut bindings: EventWriter<OxrSuggestActionBinding>,
|
||||
mut bindings: MessageWriter<OxrSuggestActionBinding>,
|
||||
) {
|
||||
bindings.write(OxrSuggestActionBinding {
|
||||
action: actions.left.as_raw(),
|
||||
@@ -241,11 +246,11 @@ pub fn suggest_action_bindings(
|
||||
});
|
||||
}
|
||||
|
||||
fn sync_actions(actions: Res<ControllerActions>, mut sync: EventWriter<OxrSyncActionSet>) {
|
||||
fn sync_actions(actions: Res<ControllerActions>, mut sync: MessageWriter<OxrSyncActionSet>) {
|
||||
sync.write(OxrSyncActionSet(actions.set.clone()));
|
||||
}
|
||||
|
||||
fn attach_set(actions: Res<ControllerActions>, mut attach: EventWriter<OxrAttachActionSet>) {
|
||||
fn attach_set(actions: Res<ControllerActions>, mut attach: MessageWriter<OxrAttachActionSet>) {
|
||||
attach.write(OxrAttachActionSet(actions.set.clone()));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +1,36 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_app::{App, Plugin, PostUpdate};
|
||||
use bevy_ecs::{message::{Message, MessageReader}, query::With, system::{Query, ResMut}};
|
||||
use bevy_log::debug;
|
||||
use bevy_math::{Quat, Vec3};
|
||||
use bevy_mod_openxr::{
|
||||
helper_traits::{ToQuat, ToVec3},
|
||||
resources::OxrViews,
|
||||
};
|
||||
use bevy_mod_xr::session::XrTrackingRoot;
|
||||
use bevy_transform::components::Transform;
|
||||
|
||||
pub struct TransformUtilitiesPlugin;
|
||||
|
||||
impl Plugin for TransformUtilitiesPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_event::<SnapToRotation>();
|
||||
app.add_event::<SnapToPosition>();
|
||||
app.add_message::<SnapToRotation>();
|
||||
app.add_message::<SnapToPosition>();
|
||||
app.add_systems(PostUpdate, handle_transform_events);
|
||||
}
|
||||
}
|
||||
|
||||
//events
|
||||
#[derive(Event, Debug)]
|
||||
#[derive(Message, Debug)]
|
||||
pub struct SnapToRotation(pub Quat);
|
||||
|
||||
#[derive(Event, Debug)]
|
||||
#[derive(Message, Debug)]
|
||||
pub struct SnapToPosition(pub Vec3);
|
||||
|
||||
pub fn handle_transform_events(
|
||||
mut root_query: Query<&mut Transform, With<XrTrackingRoot>>,
|
||||
views: ResMut<OxrViews>,
|
||||
mut position_reader: EventReader<SnapToPosition>,
|
||||
mut rotation_reader: EventReader<SnapToRotation>,
|
||||
mut position_reader: MessageReader<SnapToPosition>,
|
||||
mut rotation_reader: MessageReader<SnapToRotation>,
|
||||
) {
|
||||
let result = root_query.single_mut();
|
||||
match result {
|
||||
@@ -52,11 +56,11 @@ pub fn handle_transform_events(
|
||||
let root_rot = root_transform.rotation;
|
||||
let view_global_rotation = root_rot.mul_quat(view_rot).normalize();
|
||||
let (global_view_yaw, _pitch, _roll) =
|
||||
view_global_rotation.to_euler(bevy::math::EulerRot::YXZ);
|
||||
view_global_rotation.to_euler(bevy_math::EulerRot::YXZ);
|
||||
let up = Vec3::Y;
|
||||
for rotation in rotation_reader.read() {
|
||||
let (target_yaw, _pitch, _roll) =
|
||||
rotation.0.normalize().to_euler(bevy::math::EulerRot::YXZ);
|
||||
rotation.0.normalize().to_euler(bevy_math::EulerRot::YXZ);
|
||||
let diff_yaw = target_yaw - global_view_yaw;
|
||||
|
||||
//build a rotation quat?
|
||||
|
||||
@@ -53,7 +53,9 @@
|
||||
//! }
|
||||
//!
|
||||
//!
|
||||
use bevy::prelude::*;
|
||||
use bevy_app::{App, Plugin, PreUpdate, Startup, Update};
|
||||
use bevy_ecs::{component::Component, entity::Entity, hierarchy::Children, message::MessageWriter, query::With, schedule::{IntoScheduleConfigs as _, SystemSet}, system::{Commands, Query, Res, ResMut}};
|
||||
use bevy_log::info;
|
||||
use bevy_mod_openxr::{
|
||||
action_binding::OxrSuggestActionBinding,
|
||||
action_set_attaching::OxrAttachActionSet,
|
||||
@@ -71,16 +73,16 @@ impl Plugin for XRUtilsActionsPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.configure_sets(
|
||||
Startup,
|
||||
XRUtilsActionSystemSet::CreateEvents.run_if(openxr_session_available),
|
||||
XRUtilsActionSystems::CreateEvents.run_if(openxr_session_available),
|
||||
);
|
||||
app.configure_sets(
|
||||
PreUpdate,
|
||||
XRUtilsActionSystemSet::SyncActionStates.run_if(openxr_session_running),
|
||||
XRUtilsActionSystems::SyncActionStates.run_if(openxr_session_running),
|
||||
);
|
||||
app.add_systems(
|
||||
Startup,
|
||||
create_openxr_events
|
||||
.in_set(XRUtilsActionSystemSet::CreateEvents)
|
||||
.in_set(XRUtilsActionSystems::CreateEvents)
|
||||
.run_if(openxr_session_available),
|
||||
);
|
||||
app.add_systems(
|
||||
@@ -91,21 +93,21 @@ impl Plugin for XRUtilsActionsPlugin {
|
||||
PreUpdate,
|
||||
sync_and_update_action_states_f32
|
||||
.run_if(openxr_session_running)
|
||||
.in_set(XRUtilsActionSystemSet::SyncActionStates)
|
||||
.in_set(XRUtilsActionSystems::SyncActionStates)
|
||||
.after(OxrActionSetSyncSet),
|
||||
);
|
||||
app.add_systems(
|
||||
PreUpdate,
|
||||
sync_and_update_action_states_bool
|
||||
.run_if(openxr_session_running)
|
||||
.in_set(XRUtilsActionSystemSet::SyncActionStates)
|
||||
.in_set(XRUtilsActionSystems::SyncActionStates)
|
||||
.after(OxrActionSetSyncSet),
|
||||
);
|
||||
app.add_systems(
|
||||
PreUpdate,
|
||||
sync_and_update_action_states_vector
|
||||
.run_if(openxr_session_running)
|
||||
.in_set(XRUtilsActionSystemSet::SyncActionStates)
|
||||
.in_set(XRUtilsActionSystems::SyncActionStates)
|
||||
.after(OxrActionSetSyncSet),
|
||||
);
|
||||
}
|
||||
@@ -116,8 +118,8 @@ fn create_openxr_events(
|
||||
actions_query: Query<(&XRUtilsAction, &Children)>,
|
||||
bindings_query: Query<&XRUtilsBinding>,
|
||||
instance: ResMut<OxrInstance>,
|
||||
mut binding_writer: EventWriter<OxrSuggestActionBinding>,
|
||||
mut attach_writer: EventWriter<OxrAttachActionSet>,
|
||||
mut binding_writer: MessageWriter<OxrSuggestActionBinding>,
|
||||
mut attach_writer: MessageWriter<OxrAttachActionSet>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
//lets create some sets!
|
||||
@@ -131,7 +133,7 @@ fn create_openxr_events(
|
||||
commands.entity(id).insert(oxr_action_set);
|
||||
|
||||
//since the actions are made from the sets lets go
|
||||
for child in children.iter() {
|
||||
for child in children.iter().copied() {
|
||||
//first get the action entity and stuff
|
||||
let (create_action, bindings) = actions_query.get(child).unwrap();
|
||||
//lets create dat action
|
||||
@@ -158,7 +160,7 @@ fn create_openxr_events(
|
||||
}),
|
||||
));
|
||||
//since we need actions for bindings lets go!!
|
||||
for bind in bindings.iter() {
|
||||
for bind in bindings.iter().copied() {
|
||||
//interaction profile
|
||||
//get the binding entity and stuff
|
||||
let create_binding = bindings_query.get(bind).unwrap();
|
||||
@@ -197,7 +199,7 @@ fn create_openxr_events(
|
||||
}),
|
||||
));
|
||||
//since we need actions for bindings lets go!!
|
||||
for bind in bindings.iter() {
|
||||
for bind in bindings.iter().copied() {
|
||||
//interaction profile
|
||||
//get the binding entity and stuff
|
||||
let create_binding = bindings_query.get(bind).unwrap();
|
||||
@@ -236,7 +238,7 @@ fn create_openxr_events(
|
||||
}),
|
||||
));
|
||||
//since we need actions for bindings lets go!!
|
||||
for bind in bindings.iter() {
|
||||
for bind in bindings.iter().copied() {
|
||||
//interaction profile
|
||||
//get the binding entity and stuff
|
||||
let create_binding = bindings_query.get(bind).unwrap();
|
||||
@@ -260,7 +262,7 @@ fn create_openxr_events(
|
||||
}
|
||||
|
||||
fn sync_active_action_sets(
|
||||
mut sync_set: EventWriter<OxrSyncActionSet>,
|
||||
mut sync_set: MessageWriter<OxrSyncActionSet>,
|
||||
active_action_set_query: Query<&XRUtilsActionSetReference, With<ActiveSet>>,
|
||||
) {
|
||||
for set in &active_action_set_query {
|
||||
@@ -344,7 +346,7 @@ fn sync_and_update_action_states_vector(
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, SystemSet)]
|
||||
pub enum XRUtilsActionSystemSet {
|
||||
pub enum XRUtilsActionSystems {
|
||||
/// Runs in Startup
|
||||
CreateEvents,
|
||||
/// Runs in PreUpdate
|
||||
|
||||
Reference in New Issue
Block a user