1
1
use bevy_asset:: AssetId ;
2
2
use bevy_log:: { debug, error, warn} ;
3
- use bevy_math:: { Rect , UVec2 , Vec2 } ;
3
+ use bevy_math:: { URect , UVec2 } ;
4
4
use bevy_render:: {
5
5
render_asset:: RenderAssetUsages ,
6
6
render_resource:: { Extent3d , TextureDimension , TextureFormat } ,
@@ -31,9 +31,9 @@ pub struct TextureAtlasBuilder<'a> {
31
31
/// Collection of texture's asset id (optional) and image data to be packed into an atlas
32
32
textures_to_place : Vec < ( Option < AssetId < Image > > , & ' a Image ) > ,
33
33
/// The initial atlas size in pixels.
34
- initial_size : Vec2 ,
34
+ initial_size : UVec2 ,
35
35
/// The absolute maximum size of the texture atlas in pixels.
36
- max_size : Vec2 ,
36
+ max_size : UVec2 ,
37
37
/// The texture format for the textures that will be loaded in the atlas.
38
38
format : TextureFormat ,
39
39
/// Enable automatic format conversion for textures if they are not in the atlas format.
@@ -46,8 +46,8 @@ impl Default for TextureAtlasBuilder<'_> {
46
46
fn default ( ) -> Self {
47
47
Self {
48
48
textures_to_place : Vec :: new ( ) ,
49
- initial_size : Vec2 :: new ( 256. , 256. ) ,
50
- max_size : Vec2 :: new ( 2048. , 2048. ) ,
49
+ initial_size : UVec2 :: splat ( 256 ) ,
50
+ max_size : UVec2 :: splat ( 2048 ) ,
51
51
format : TextureFormat :: Rgba8UnormSrgb ,
52
52
auto_format_conversion : true ,
53
53
padding : UVec2 :: ZERO ,
@@ -59,13 +59,13 @@ pub type TextureAtlasBuilderResult<T> = Result<T, TextureAtlasBuilderError>;
59
59
60
60
impl < ' a > TextureAtlasBuilder < ' a > {
61
61
/// Sets the initial size of the atlas in pixels.
62
- pub fn initial_size ( mut self , size : Vec2 ) -> Self {
62
+ pub fn initial_size ( mut self , size : UVec2 ) -> Self {
63
63
self . initial_size = size;
64
64
self
65
65
}
66
66
67
67
/// Sets the max size of the atlas in pixels.
68
- pub fn max_size ( mut self , size : Vec2 ) -> Self {
68
+ pub fn max_size ( mut self , size : UVec2 ) -> Self {
69
69
self . max_size = size;
70
70
self
71
71
}
@@ -189,10 +189,10 @@ impl<'a> TextureAtlasBuilder<'a> {
189
189
/// If there is not enough space in the atlas texture, an error will
190
190
/// be returned. It is then recommended to make a larger sprite sheet.
191
191
pub fn finish ( self ) -> Result < ( TextureAtlasLayout , Image ) , TextureAtlasBuilderError > {
192
- let initial_width = self . initial_size . x as u32 ;
193
- let initial_height = self . initial_size . y as u32 ;
194
- let max_width = self . max_size . x as u32 ;
195
- let max_height = self . max_size . y as u32 ;
192
+ let initial_width = self . initial_size . x ;
193
+ let initial_height = self . initial_size . y ;
194
+ let max_width = self . max_size . x ;
195
+ let max_height = self . max_size . y ;
196
196
197
197
let mut current_width = initial_width;
198
198
let mut current_height = initial_height;
@@ -265,16 +265,16 @@ impl<'a> TextureAtlasBuilder<'a> {
265
265
for ( index, ( image_id, texture) ) in self . textures_to_place . iter ( ) . enumerate ( ) {
266
266
let ( _, packed_location) = rect_placements. packed_locations ( ) . get ( & index) . unwrap ( ) ;
267
267
268
- let min = Vec2 :: new ( packed_location. x ( ) as f32 , packed_location. y ( ) as f32 ) ;
268
+ let min = UVec2 :: new ( packed_location. x ( ) , packed_location. y ( ) ) ;
269
269
let max = min
270
- + Vec2 :: new (
271
- ( packed_location. width ( ) - self . padding . x ) as f32 ,
272
- ( packed_location. height ( ) - self . padding . y ) as f32 ,
270
+ + UVec2 :: new (
271
+ packed_location. width ( ) - self . padding . x ,
272
+ packed_location. height ( ) - self . padding . y ,
273
273
) ;
274
274
if let Some ( image_id) = image_id {
275
275
texture_ids. insert ( * image_id, index) ;
276
276
}
277
- texture_rects. push ( Rect { min, max } ) ;
277
+ texture_rects. push ( URect { min, max } ) ;
278
278
if texture. texture_descriptor . format != self . format && !self . auto_format_conversion {
279
279
warn ! (
280
280
"Loading a texture of format '{:?}' in an atlas with format '{:?}'" ,
0 commit comments