From 781270b2a05970bc190383c12d879fcc45c88513 Mon Sep 17 00:00:00 2001 From: Martin Lysell Date: Fri, 10 Nov 2023 02:10:15 +0100 Subject: [PATCH] Switch to using individual bevy crates instead of parent "bevy" crate (#101) * Initial conversion to separate crates * Fix "unused import" warnings when building without default features * Fix doc warnings due to bevy parent crate not being a dependency anymore --------- Co-authored-by: Aevyrie --- Cargo.toml | 20 ++++++++++++++------ src/deferred.rs | 20 ++++++++++++++++---- src/immediate.rs | 20 +++++++++++++------- src/lib.rs | 25 ++++++++++++++++--------- src/markers.rs | 5 +++-- src/primitives.rs | 13 +++++++------ src/raycast.rs | 12 +++++------- 7 files changed, 74 insertions(+), 41 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b8aec4d..b7e899b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,18 @@ categories = ["game-engines", "rendering"] resolver = "2" [dependencies] -bevy = { version = "0.12", default-features = false, features = [ - "bevy_render", - "bevy_asset", -] } +bevy_app = { version = "0.12", default-features = false } +bevy_asset = { version = "0.12", default-features = false } +bevy_derive = { version = "0.12", default-features = false } +bevy_ecs = { version = "0.12", default-features = false } +bevy_gizmos = { version = "0.12", optional = true, default-features = false } +bevy_math = { version = "0.12", default-features = false } +bevy_reflect = { version = "0.12", default-features = false } +bevy_render = { version = "0.12", default-features = false } +bevy_sprite = { version = "0.12", optional = true, default-features = false } +bevy_transform = { version = "0.12", default-features = false } +bevy_utils = { version = "0.12", default-features = false } +bevy_window = { version = "0.12", default-features = false } crossbeam-channel = "0.5" [dev-dependencies] @@ -29,8 +37,8 @@ criterion = "0.5" [features] default = ["2d", "debug"] -2d = ["bevy/bevy_sprite"] -debug = ["bevy/bevy_gizmos"] +2d = ["bevy_sprite"] +debug = ["bevy_gizmos"] [[bench]] name = "ray_mesh_intersection" diff --git a/src/deferred.rs b/src/deferred.rs index 7a83f88..ef799dc 100644 --- a/src/deferred.rs +++ b/src/deferred.rs @@ -21,7 +21,14 @@ use std::{ marker::PhantomData, }; -use bevy::{prelude::*, reflect::TypePath, render::camera::Camera, window::PrimaryWindow}; +use bevy_app::prelude::*; +use bevy_ecs::prelude::*; +use bevy_math::{Mat4, Vec2}; +use bevy_reflect::{Reflect, TypePath}; +use bevy_render::camera::Camera; +use bevy_transform::components::GlobalTransform; +use bevy_utils::{default, tracing::*}; +use bevy_window::{PrimaryWindow, Window}; use crate::{immediate::*, primitives::*}; @@ -146,7 +153,7 @@ impl RaycastPluginState { /// /// # Requirements /// -/// The marked entity must also have a [Mesh] component. +/// The marked entity must also have a [Mesh](bevy_render::mesh::Mesh) component. #[derive(Component, Debug, Reflect)] #[reflect(Component)] pub struct RaycastMesh { @@ -305,7 +312,7 @@ impl RaycastSource { /// present on this entity. /// /// # Warning - /// Only use this if the entity this is associated with will have its [Transform] or + /// Only use this if the entity this is associated with will have its [Transform](bevy_transform::components::Transform) or /// [GlobalTransform] specified elsewhere. If the [GlobalTransform] is not set, this ray casting /// source will never be able to generate a raycast. pub fn new_transform_empty() -> Self { @@ -493,7 +500,12 @@ pub fn update_target_intersections( pub mod debug { #![allow(unused)] - use bevy::{prelude::*, reflect::TypePath}; + use bevy_ecs::system::{Commands, Query}; + use bevy_gizmos::gizmos::Gizmos; + use bevy_math::{Quat, Vec3}; + use bevy_reflect::TypePath; + use bevy_render::color::Color; + use bevy_utils::tracing::info; use std::marker::PhantomData; use crate::prelude::*; diff --git a/src/immediate.rs b/src/immediate.rs index 0e422e0..995dbed 100644 --- a/src/immediate.rs +++ b/src/immediate.rs @@ -7,11 +7,17 @@ //! when you call the `cast_ray` method. See the [`Raycast`] documentation for more details. You //! don't even need to add a plugin to your application. -use bevy::{ - ecs::system::{lifetimeless::Read, SystemParam}, - prelude::*, - render::primitives::Aabb, - utils::FloatOrd, +use bevy_asset::{Assets, Handle}; +use bevy_ecs::{prelude::*, system::lifetimeless::Read, system::SystemParam}; +use bevy_reflect::Reflect; +use bevy_render::{prelude::*, primitives::Aabb}; +use bevy_transform::components::GlobalTransform; +use bevy_utils::{tracing::*, FloatOrd}; + +#[cfg(feature = "debug")] +use { + bevy_gizmos::gizmos::Gizmos, + bevy_math::{Quat, Vec3}, }; use crate::prelude::*; @@ -82,7 +88,7 @@ impl<'a> Default for RaycastSettings<'a> { } #[cfg(feature = "2d")] -type MeshFilter = Or<(With>, With)>; +type MeshFilter = Or<(With>, With)>; #[cfg(not(feature = "2d"))] type MeshFilter = With>; @@ -173,7 +179,7 @@ pub struct Raycast<'w, 's> { 'w, 's, ( - Read, + Read, Option>, Read, ), diff --git a/src/lib.rs b/src/lib.rs index c929559..127423b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -//! A small [`bevy`] plugin for raycasting against [`Mesh`]es. +//! A small `bevy` plugin for raycasting against [`Mesh`](bevy_render::mesh::Mesh)es. //! //! ``` //! # use bevy::prelude::*; @@ -58,7 +58,14 @@ pub mod markers; pub mod primitives; pub mod raycast; -use bevy::prelude::*; +use bevy_app::prelude::*; +use bevy_derive::Deref; +use bevy_ecs::prelude::*; +use bevy_render::camera::Camera; +use bevy_transform::components::GlobalTransform; +use bevy_utils::default; +use bevy_window::Window; + #[allow(unused_imports)] // Needed for docs use prelude::*; @@ -79,7 +86,7 @@ impl Plugin for DefaultRaycastingPlugin { app.add_systems(First, update_cursor_ray) .add_systems( PostUpdate, - update_cursor_ray.after(bevy::transform::TransformSystem::TransformPropagate), + update_cursor_ray.after(bevy_transform::TransformSystem::TransformPropagate), ) .init_resource::(); } @@ -96,7 +103,7 @@ pub struct CursorRay(pub Option); /// Updates the [`CursorRay`] every frame. pub fn update_cursor_ray( - primary_window: Query>, + primary_window: Query>, windows: Query<&Window>, cameras: Query<(&Camera, &GlobalTransform)>, mut cursor_ray: ResMut, @@ -104,7 +111,7 @@ pub fn update_cursor_ray( cursor_ray.0 = cameras .iter() .filter_map(|(camera, transform)| { - if let bevy::render::camera::RenderTarget::Window(window_ref) = camera.target { + if let bevy_render::camera::RenderTarget::Window(window_ref) = camera.target { Some(((camera, transform), window_ref)) } else { None @@ -126,10 +133,10 @@ pub fn update_cursor_ray( /// Used for examples to reduce picking latency. Not relevant code for the examples. #[doc(hidden)] #[allow(dead_code)] -pub fn low_latency_window_plugin() -> bevy::window::WindowPlugin { - bevy::window::WindowPlugin { - primary_window: Some(bevy::window::Window { - present_mode: bevy::window::PresentMode::AutoNoVsync, +pub fn low_latency_window_plugin() -> bevy_window::WindowPlugin { + bevy_window::WindowPlugin { + primary_window: Some(bevy_window::Window { + present_mode: bevy_window::PresentMode::AutoNoVsync, ..default() }), ..default() diff --git a/src/markers.rs b/src/markers.rs index 3bb695b..c1dc19f 100644 --- a/src/markers.rs +++ b/src/markers.rs @@ -1,8 +1,9 @@ -use bevy::prelude::*; +use bevy_asset::Handle; +use bevy_ecs::component::Component; #[derive(Component)] pub struct SimplifiedMesh { - pub mesh: Handle, + pub mesh: Handle, } #[derive(Component)] diff --git a/src/primitives.rs b/src/primitives.rs index de72922..afc5073 100644 --- a/src/primitives.rs +++ b/src/primitives.rs @@ -1,4 +1,5 @@ -use bevy::{math::Vec3A, prelude::*}; +use bevy_math::{Vec3, Vec3A}; +use bevy_reflect::Reflect; pub use rays::*; @@ -65,11 +66,11 @@ impl IntersectionData { /// the `Ray3d` direction is normalized, because it can only be instantiated with the constructor. pub mod rays { use super::Primitive3d; - use bevy::{ - math::{Ray, Vec3A}, - prelude::*, - render::{camera::Camera, primitives::Aabb}, - }; + use bevy_math::{prelude::*, Vec3A}; + use bevy_reflect::Reflect; + use bevy_render::{camera::Camera, primitives::Aabb}; + use bevy_transform::components::GlobalTransform; + use bevy_window::Window; pub struct PrimitiveIntersection { position: Vec3, diff --git a/src/raycast.rs b/src/raycast.rs index d092ecc..b4b879c 100644 --- a/src/raycast.rs +++ b/src/raycast.rs @@ -1,13 +1,11 @@ use std::f32::EPSILON; -use bevy::{ - math::Vec3A, - prelude::*, - render::{ - mesh::{Indices, VertexAttributeValues}, - render_resource::PrimitiveTopology, - }, +use bevy_math::{Mat4, Vec3A}; +use bevy_render::{ + mesh::{Indices, Mesh, VertexAttributeValues}, + render_resource::PrimitiveTopology, }; +use bevy_utils::tracing::{error, warn}; use crate::primitives::*;