Tweaks to TextureAtlasBuilder.finish() (#887)
Tweaks to TextureAtlasBuilder.finish()
This commit is contained in:
parent
106486bd99
commit
85ecab8bb9
@ -86,28 +86,37 @@ impl TextureAtlasBuilder {
|
|||||||
|
|
||||||
while rect_placements.is_none() {
|
while rect_placements.is_none() {
|
||||||
if current_width > max_width || current_height > max_height {
|
if current_width > max_width || current_height > max_height {
|
||||||
rect_placements = None;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let last_attempt = current_height == max_height && current_width == max_width;
|
||||||
|
|
||||||
let mut target_bins = std::collections::BTreeMap::new();
|
let mut target_bins = std::collections::BTreeMap::new();
|
||||||
target_bins.insert(0, TargetBin::new(current_width, current_height, 1));
|
target_bins.insert(0, TargetBin::new(current_width, current_height, 1));
|
||||||
atlas_texture = Texture::new_fill(
|
|
||||||
Vec2::new(current_width as f32, current_height as f32),
|
|
||||||
&[0, 0, 0, 0],
|
|
||||||
TextureFormat::Rgba8UnormSrgb,
|
|
||||||
);
|
|
||||||
rect_placements = match pack_rects(
|
rect_placements = match pack_rects(
|
||||||
&self.rects_to_place,
|
&self.rects_to_place,
|
||||||
target_bins,
|
target_bins,
|
||||||
&volume_heuristic,
|
&volume_heuristic,
|
||||||
&contains_smallest_box,
|
&contains_smallest_box,
|
||||||
) {
|
) {
|
||||||
Ok(rect_placements) => Some(rect_placements),
|
Ok(rect_placements) => {
|
||||||
|
atlas_texture = Texture::new_fill(
|
||||||
|
Vec2::new(current_width as f32, current_height as f32),
|
||||||
|
&[0, 0, 0, 0],
|
||||||
|
TextureFormat::Rgba8UnormSrgb,
|
||||||
|
);
|
||||||
|
Some(rect_placements)
|
||||||
|
}
|
||||||
Err(rectangle_pack::RectanglePackError::NotEnoughBinSpace) => {
|
Err(rectangle_pack::RectanglePackError::NotEnoughBinSpace) => {
|
||||||
current_width *= 2;
|
current_height = bevy_math::clamp(current_height * 2, 0, max_height);
|
||||||
current_height *= 2;
|
current_width = bevy_math::clamp(current_width * 2, 0, max_width);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if last_attempt {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user