Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up #35

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
- name: "Checks"
run: |
cargo update
#cargo fmt --check
#cargo clippy --no-deps --tests -- -D warnings
#cargo rustdoc -- -D warnings
cargo fmt --check
cargo clippy --no-deps --tests -- -D warnings
cargo rustdoc -- -D warnings
- name: "Build"
run: |
cargo build
Expand Down
37 changes: 8 additions & 29 deletions examples/demo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::{f32::consts::PI, ops::Mul, time::Duration};
use std::time::Duration;

use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
ecs::schedule::ScheduleLabel,
log::info,
prelude::{
default, shape, App, Assets, Color, Commands, Component, Entity, Event, EventReader,
EventWriter, FixedUpdate, Gizmos, GlobalTransform, IntoSystemConfigs, IntoSystemSetConfigs,
Mesh, PbrBundle, PostUpdate, Quat, Query, Res, ResMut, Resource, Schedule, SpatialBundle,
StandardMaterial, Startup, Transform, Update, Vec3, Vec3Swizzles, With, Without, World,
EventWriter, FixedUpdate, GlobalTransform, IntoSystemConfigs, IntoSystemSetConfigs, Mesh,
PbrBundle, PostUpdate, Query, Res, ResMut, Resource, Schedule, SpatialBundle,
StandardMaterial, Startup, Transform, Update, Vec3, With, Without, World,
},
time::{Fixed, Time, Timer},
transform::TransformSystem,
Expand Down Expand Up @@ -282,10 +282,8 @@ fn spawn_physics_hands(mut commands: Commands) {
let right_hand_membership_group = Group::GROUP_2;
let floor_membership = Group::GROUP_3;


for hand in hands.iter() {
let hand_membership = match hand
{
let hand_membership = match hand {
Hand::Left => left_hand_membership_group,
Hand::Right => right_hand_membership_group,
};
Expand Down Expand Up @@ -338,7 +336,6 @@ fn update_physics_hands(
)>,
hand_query: Query<(&Transform, &HandBone, &Hand, Without<PhysicsHandBone>)>,
time: Res<Time>,
mut gizmos: Gizmos,
) {
let matching = MatchingType::VelocityMatching;
//sanity check do we even have hands?
Expand Down Expand Up @@ -383,26 +380,15 @@ fn update_physics_hands(
/ time.delta_seconds();
bone.5.linvel = diff;
//calculate angular velocity?
// gizmos.ray(bone.0.translation, bone.0.forward(), Color::WHITE);
let desired_forward = start_components
.unwrap()
.0
.clone()
.looking_at(end_components.unwrap().0.translation, Vec3::Y)
.rotation;
// gizmos.ray(
// bone.0.translation,
// desired_forward.mul_vec3(-Vec3::Z),
// Color::GREEN,
// );
let cross =
bone.0.forward().cross(desired_forward.mul_vec3(-Vec3::Z));

// gizmos.ray(
// bone.0.translation,
// cross,
// Color::RED,
// );
bone.5.angvel = cross / time.delta_seconds();
}
}
Expand Down Expand Up @@ -494,13 +480,6 @@ fn get_start_and_end_entities(
};
}

fn get_hand_res(res: &Res<'_, HandsResource>, hand: Hand) -> HandResource {
match hand {
Hand::Left => res.left.clone(),
Hand::Right => res.right.clone(),
}
}

#[derive(Event, Default)]
pub struct SpawnCubeRequest;

Expand Down Expand Up @@ -543,7 +522,7 @@ fn cube_spawner(
mut materials: ResMut<Assets<StandardMaterial>>,
mut events: EventReader<SpawnCubeRequest>,
) {
for request in events.read() {
for _request in events.read() {
// cube
commands.spawn((
PbrBundle {
Expand Down Expand Up @@ -571,15 +550,15 @@ fn prototype_interaction_input(
instance: Res<XrInstance>,
session: Res<XrSession>,
mut right_interactor_query: Query<
(&mut XRInteractorState),
&mut XRInteractorState,
(
With<XRDirectInteractor>,
With<OpenXRRightController>,
Without<OpenXRLeftController>,
),
>,
mut left_interactor_query: Query<
(&mut XRInteractorState),
&mut XRInteractorState,
(
With<XRDirectInteractor>,
With<OpenXRLeftController>,
Expand Down
5 changes: 2 additions & 3 deletions examples/demo/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use bevy::{
prelude::{
shape, Assets, Camera3dBundle, Color, Commands, Mesh, PbrBundle, PointLight,
PointLightBundle, ResMut, SpatialBundle, StandardMaterial, Transform, Vec3,
PointLightBundle, ResMut, StandardMaterial, Transform, Vec3,
},
transform::TransformBundle,
utils::default,
};
use bevy_oxr::xr_input::interactions::{Touched, XRInteractable, XRInteractableState};
use bevy_rapier3d::{
prelude::{Collider, RigidBody, Group, CollisionGroups},
prelude::{Collider, CollisionGroups, Group, RigidBody},
render::ColliderDebugColor,
};

Expand Down
8 changes: 3 additions & 5 deletions examples/xr.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@


use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};

use bevy::prelude::*;
use bevy::transform::components::Transform;
use bevy_oxr::input::XrInput;
use bevy_oxr::resources::{XrFrameState, XrInstance, XrSession};

use bevy_oxr::xr_input::hand::{OpenXrHandInput, HandInputDebugRenderer};
use bevy_oxr::xr_input::hand::{HandInputDebugRenderer, OpenXrHandInput};
use bevy_oxr::xr_input::interactions::{
draw_interaction_gizmos, draw_socket_gizmos, interactions, socket_interactions,
update_interactable_states, InteractionEvent, Touched, XRDirectInteractor, XRInteractable,
Expand Down Expand Up @@ -146,15 +144,15 @@ fn prototype_interaction_input(
instance: Res<XrInstance>,
session: Res<XrSession>,
mut right_interactor_query: Query<
(&mut XRInteractorState),
&mut XRInteractorState,
(
With<XRDirectInteractor>,
With<OpenXRRightController>,
Without<OpenXRLeftController>,
),
>,
mut left_interactor_query: Query<
(&mut XRInteractorState),
&mut XRInteractorState,
(
With<XRRayInteractor>,
With<OpenXRLeftController>,
Expand Down
1 change: 1 addition & 0 deletions src/graphics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::resources::{

use openxr as xr;

#[allow(clippy::type_complexity)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could add this to cargo.toml (latest Rust version has a section for it):

[lints.clippy]
type_complexity = "allow"
too_many_arguments = "allow"

pub fn initialize_xr_graphics(
window: Option<RawHandleWrapper>,
) -> anyhow::Result<(
Expand Down
10 changes: 5 additions & 5 deletions src/graphics/vulkan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::resources::{
};
use crate::VIEW_TYPE;

#[allow(clippy::type_complexity)]
pub fn initialize_xr_graphics(
window: Option<RawHandleWrapper>,
) -> anyhow::Result<(
Expand Down Expand Up @@ -57,7 +58,6 @@ pub fn initialize_xr_graphics(
}
enabled_extensions.ext_hand_tracking = available_extensions.ext_hand_tracking;
// enabled_extensions.ext_hand_joints_motion_range = available_extensions.ext_hand_joints_motion_range;


let available_layers = xr_entry.enumerate_layers()?;
info!("available xr layers: {:#?}", available_layers);
Expand Down Expand Up @@ -113,7 +113,7 @@ pub fn initialize_xr_graphics(
let flags = wgpu_hal::InstanceFlags::empty();
let extensions =
<V as Api>::Instance::required_extensions(&vk_entry, vk_target_version, flags)?;
let device_extensions = vec![
let device_extensions = [
ash::extensions::khr::Swapchain::name(),
ash::extensions::khr::DrawIndirectCount::name(),
#[cfg(target_os = "android")]
Expand Down Expand Up @@ -353,7 +353,8 @@ pub fn initialize_xr_graphics(
None,
)
};
let texture = unsafe {

unsafe {
wgpu_device.create_texture_from_hal::<V>(
wgpu_hal_texture,
&wgpu::TextureDescriptor {
Expand All @@ -372,8 +373,7 @@ pub fn initialize_xr_graphics(
view_formats: &[],
},
)
};
texture
}
})
.collect();

Expand Down
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub const RIGHT_XR_TEXTURE_HANDLE: ManualTextureViewHandle = ManualTextureViewHa
/// Adds OpenXR support to an App
#[derive(Default)]
pub struct OpenXrPlugin;

#[allow(clippy::type_complexity)]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be simplified, but lacked the expertise to be sure

#[derive(Resource)]
pub struct FutureXrResources(
pub Arc<
Expand Down Expand Up @@ -162,7 +162,8 @@ impl Plugin for OpenXrPlugin {
let mut manual_texture_views = app.world.resource_mut::<ManualTextureViews>();
manual_texture_views.insert(LEFT_XR_TEXTURE_HANDLE, left);
manual_texture_views.insert(RIGHT_XR_TEXTURE_HANDLE, right);
drop(manual_texture_views);
//drop non drop
//drop(manual_texture_views);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a change I wasn't sure of

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea this seems fine to just remove. Probably leftover from an older bevy version where this was Drop

let render_app = app.sub_app_mut(RenderApp);

render_app
Expand Down Expand Up @@ -219,6 +220,7 @@ impl PluginGroup for DefaultXrPlugins {
}
}

#[allow(clippy::too_many_arguments)]
pub fn xr_begin_frame(
instance: Res<XrInstance>,
session: Res<XrSession>,
Expand Down Expand Up @@ -334,7 +336,7 @@ pub fn end_frame(
let _span = info_span!("xr_end_frame").entered();
let result = swapchain.end(
xr_frame_state.lock().unwrap().predicted_display_time,
&*views.lock().unwrap(),
&views.lock().unwrap(),
&input.stage,
**resolution,
**environment_blend_mode,
Expand Down
2 changes: 1 addition & 1 deletion src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<G: xr::Graphics> SwapchainInner<G> {
},
};
let swapchain = self.handle.lock().unwrap();
if views.len() == 0 {
if views.is_empty() {
warn!("views are len of 0");
return Ok(());
}
Expand Down
15 changes: 7 additions & 8 deletions src/xr_input/debug_gizmos.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use bevy::prelude::{
info, Color, Gizmos, GlobalTransform, Plugin, Quat, Query, Res, Transform, Update, Vec2, Vec3,
With, Without,
};

use crate::{
input::XrInput,
resources::{XrFrameState, XrInstance, XrSession},
};
use bevy::log::info;
use bevy::prelude::{
Color, Gizmos, GlobalTransform, Plugin, Quat, Query, Res, Transform, Update, Vec2, Vec3, With,
Without,
};

use crate::xr_input::{
oculus_touch::{OculusController, OculusControllerRef},
Hand,
};

use super::{
handtracking::{HandTrackingRef, HandTrackingTracker},
handtracking::HandTrackingTracker,
trackers::{OpenXRLeftController, OpenXRRightController, OpenXRTrackingRoot},
QuatConv,
};
Expand All @@ -29,6 +29,7 @@ impl Plugin for OpenXrDebugRenderer {
}
}

#[allow(clippy::type_complexity, clippy::too_many_arguments)]
pub fn draw_gizmos(
mut gizmos: Gizmos,
oculus_controller: Res<OculusController>,
Expand Down Expand Up @@ -93,7 +94,6 @@ pub fn draw_gizmos(
//get controller
let controller = oculus_controller.get_ref(&instance, &session, &frame_state, &xr_input);
//tracking root?
let mut tracking_transform = &Transform::IDENTITY;
let root = tracking_root_query.get_single();
match root {
Ok(position) => {
Expand All @@ -108,7 +108,6 @@ pub fn draw_gizmos(
0.2,
Color::RED,
);
tracking_transform = position.0;
}
Err(_) => info!("too many tracking roots"),
}
Expand Down
Loading