 8b7b44d839
			
		
	
	
		8b7b44d839
		
	
	
	
	
		
			
			# Objective Promote the `Rect` utility of `sprite::Rect`, which defines a rectangle by its minimum and maximum corners, to the `bevy_math` crate to make it available as a general math type to all crates without the need to depend on the `bevy_sprite` crate. Fixes #5575 ## Solution Move `sprite::Rect` into `bevy_math` and fix all uses. Implement `Reflect` for `Rect` directly into the `bevy_reflect` crate by having `bevy_reflect` depend on `bevy_math`. This looks like a new dependency, but the `bevy_reflect` was "cheating" for other math types by directly depending on `glam` to reflect other math types, thereby giving the illusion that there was no dependency on `bevy_math`. In practice conceptually Bevy's math types are reflected into the `bevy_reflect` crate to avoid a dependency of that crate to a "lower level" utility crate like `bevy_math` (which in turn would make `bevy_reflect` be a dependency of most other crates, and increase the risk of circular dependencies). So this change simply formalizes that dependency in `Cargo.toml`. The `Rect` struct is also augmented in this change with a collection of utility methods to improve its usability. A few uses cases are updated to use those new methods, resulting is more clear and concise syntax. --- ## Changelog ### Changed - Moved the `sprite::Rect` type into `bevy_math`. ### Added - Added several utility methods to the `math::Rect` type. ## Migration Guide The `bevy::sprite::Rect` type moved to the math utility crate as `bevy::math::Rect`. You should change your imports from `use bevy::sprite::Rect` to `use bevy::math::Rect`.
		
			
				
	
	
		
			81 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| mod bundle;
 | |
| mod dynamic_texture_atlas_builder;
 | |
| mod mesh2d;
 | |
| mod render;
 | |
| mod sprite;
 | |
| mod texture_atlas;
 | |
| mod texture_atlas_builder;
 | |
| 
 | |
| pub mod collide_aabb;
 | |
| 
 | |
| pub mod prelude {
 | |
|     #[doc(hidden)]
 | |
|     pub use crate::{
 | |
|         bundle::{SpriteBundle, SpriteSheetBundle},
 | |
|         sprite::Sprite,
 | |
|         texture_atlas::{TextureAtlas, TextureAtlasSprite},
 | |
|         ColorMaterial, ColorMesh2dBundle, TextureAtlasBuilder,
 | |
|     };
 | |
| }
 | |
| 
 | |
| pub use bundle::*;
 | |
| pub use dynamic_texture_atlas_builder::*;
 | |
| pub use mesh2d::*;
 | |
| pub use render::*;
 | |
| pub use sprite::*;
 | |
| pub use texture_atlas::*;
 | |
| pub use texture_atlas_builder::*;
 | |
| 
 | |
| use bevy_app::prelude::*;
 | |
| use bevy_asset::{AddAsset, Assets, HandleUntyped};
 | |
| use bevy_core_pipeline::core_2d::Transparent2d;
 | |
| use bevy_ecs::schedule::{ParallelSystemDescriptorCoercion, SystemLabel};
 | |
| use bevy_reflect::TypeUuid;
 | |
| use bevy_render::{
 | |
|     render_phase::AddRenderCommand,
 | |
|     render_resource::{Shader, SpecializedRenderPipelines},
 | |
|     RenderApp, RenderStage,
 | |
| };
 | |
| 
 | |
| #[derive(Default)]
 | |
| pub struct SpritePlugin;
 | |
| 
 | |
| pub const SPRITE_SHADER_HANDLE: HandleUntyped =
 | |
|     HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 2763343953151597127);
 | |
| 
 | |
| #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)]
 | |
| pub enum SpriteSystem {
 | |
|     ExtractSprites,
 | |
| }
 | |
| 
 | |
| impl Plugin for SpritePlugin {
 | |
|     fn build(&self, app: &mut App) {
 | |
|         let mut shaders = app.world.resource_mut::<Assets<Shader>>();
 | |
|         let sprite_shader = Shader::from_wgsl(include_str!("render/sprite.wgsl"));
 | |
|         shaders.set_untracked(SPRITE_SHADER_HANDLE, sprite_shader);
 | |
|         app.add_asset::<TextureAtlas>()
 | |
|             .register_type::<Sprite>()
 | |
|             .register_type::<Anchor>()
 | |
|             .register_type::<Mesh2dHandle>()
 | |
|             .add_plugin(Mesh2dRenderPlugin)
 | |
|             .add_plugin(ColorMaterialPlugin);
 | |
| 
 | |
|         if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
 | |
|             render_app
 | |
|                 .init_resource::<ImageBindGroups>()
 | |
|                 .init_resource::<SpritePipeline>()
 | |
|                 .init_resource::<SpecializedRenderPipelines<SpritePipeline>>()
 | |
|                 .init_resource::<SpriteMeta>()
 | |
|                 .init_resource::<ExtractedSprites>()
 | |
|                 .init_resource::<SpriteAssetEvents>()
 | |
|                 .add_render_command::<Transparent2d, DrawSprite>()
 | |
|                 .add_system_to_stage(
 | |
|                     RenderStage::Extract,
 | |
|                     render::extract_sprites.label(SpriteSystem::ExtractSprites),
 | |
|                 )
 | |
|                 .add_system_to_stage(RenderStage::Extract, render::extract_sprite_events)
 | |
|                 .add_system_to_stage(RenderStage::Queue, queue_sprites);
 | |
|         };
 | |
|     }
 | |
| }
 |