Skip to content

Commit e01cea0

Browse files
authored
build!: upgrade to bevy 0.14
1 parent c9b3733 commit e01cea0

9 files changed

Lines changed: 176 additions & 137 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ documentation = "https://docs.rs/bevy_generative"
1414

1515
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1616
[dependencies]
17-
bevy = { version = "0.14.0", default-features = false, features = [
17+
bevy = { version = "0.16.1", default-features = false, features = [
1818
"bevy_core_pipeline",
1919
"bevy_pbr",
2020
"bevy_ui",
2121
] }
22-
colorgrad = "0.6.2"
22+
colorgrad = "0.7.2"
2323
gltf = "1.3.0"
2424
image = "0.25"
2525
noise = { version = "0.9.0", git = "https://github.com/Razaekel/noise-rs.git" }
26-
rfd = "0.12.1"
26+
rfd = "0.15.4"
2727
serde = "1.0.195"
2828
serde_json = "1.0.111"
2929
wasm-bindgen = "0.2.89"
3030

3131
[dev-dependencies]
32-
bevy = "0.14.0"
32+
bevy = "0.16.1"
3333

3434
# Enable max optimizations for dependencies, but not for our code:
3535
[profile.dev.package."*"]

examples/export.rs

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,47 @@ fn main() {
1111
}
1212

1313
fn setup(mut commands: Commands) {
14-
commands.spawn(PointLightBundle {
15-
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
16-
..default()
17-
});
18-
commands.spawn(Camera3dBundle {
19-
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
20-
..default()
21-
});
14+
let light_bundle = (
15+
PointLight::default(),
16+
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
17+
);
18+
19+
commands.spawn(light_bundle);
20+
21+
let camera_bundle = (
22+
Camera3d::default(),
23+
Projection::Perspective(PerspectiveProjection::default()),
24+
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
25+
);
26+
commands.spawn(camera_bundle);
27+
2228
commands.spawn(TerrainBundle::default());
2329

24-
commands
25-
.spawn(ButtonBundle {
26-
style: Style {
27-
padding: UiRect::all(Val::Px(12.)),
28-
justify_content: JustifyContent::Center,
29-
align_items: AlignItems::Center,
30-
margin: UiRect::all(Val::Px(12.)),
31-
..default()
32-
},
33-
border_radius: BorderRadius::all(Val::Px(5.)),
34-
background_color: NORMAL_BUTTON.into(),
30+
let button_bundle = (
31+
Button,
32+
Node {
33+
padding: UiRect::all(Val::Px(12.)),
34+
justify_content: JustifyContent::Center,
35+
align_items: AlignItems::Center,
36+
margin: UiRect::all(Val::Px(12.)),
3537
..default()
36-
})
37-
.with_children(|parent| {
38-
parent.spawn(TextBundle::from_section(
39-
"Export",
40-
TextStyle {
41-
font_size: 30.0,
42-
color: BUTTON_TEXT.into(),
43-
..default()
44-
},
45-
));
46-
});
38+
},
39+
BorderRadius::all(Val::Px(5.)),
40+
BackgroundColor(NORMAL_BUTTON.into()),
41+
);
42+
43+
commands.spawn(button_bundle).with_children(|parent| {
44+
let text_bundle = (
45+
Text::from("Export"),
46+
TextFont {
47+
font_size: 30.0,
48+
..Default::default()
49+
},
50+
TextColor(BUTTON_TEXT.into()),
51+
);
52+
53+
parent.spawn(text_bundle);
54+
});
4755
}
4856

4957
fn export_button(

examples/map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fn main() {
1010
}
1111

1212
fn setup(mut commands: Commands) {
13-
commands.spawn(Camera2dBundle::default());
13+
let camera_bundle = (Camera2d::default(),);
14+
commands.spawn(camera_bundle);
1415
commands.spawn(MapBundle::default());
1516
}

examples/planet.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ fn main() {
1010
}
1111

1212
fn setup(mut commands: Commands) {
13-
commands.spawn(PointLightBundle {
14-
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
15-
..default()
16-
});
17-
commands.spawn(Camera3dBundle {
18-
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
19-
..default()
20-
});
13+
let light_bundle = (
14+
PointLight::default(),
15+
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
16+
);
17+
18+
commands.spawn(light_bundle);
19+
20+
let camera_bundle = (
21+
Camera3d::default(),
22+
Projection::Perspective(PerspectiveProjection::default()),
23+
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
24+
);
25+
commands.spawn(camera_bundle);
2126
commands.spawn(PlanetBundle::default());
2227
}

examples/terrain.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@ fn main() {
1010
}
1111

1212
fn setup(mut commands: Commands) {
13-
commands.spawn(PointLightBundle {
14-
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
15-
..default()
16-
});
17-
commands.spawn(Camera3dBundle {
18-
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
19-
..default()
20-
});
13+
let light_bundle = (
14+
PointLight::default(),
15+
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
16+
);
17+
18+
commands.spawn(light_bundle);
19+
20+
let camera_bundle = (
21+
Camera3d::default(),
22+
Projection::Perspective(PerspectiveProjection::default()),
23+
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
24+
);
25+
commands.spawn(camera_bundle);
2126
commands.spawn(TerrainBundle {
2227
terrain: bevy_generative::terrain::Terrain {
2328
resolution: 4,

src/map.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
//! }
1515
//!
1616
//! fn setup(mut commands: Commands) {
17-
//! commands.spawn(Camera2dBundle::default());
18-
//! commands.spawn(MapBundle::default());
17+
//! let camera_bundle = (
18+
//! Camera2d::default(),
19+
//! );
20+
//! commands.spawn(camera_bundle);
21+
//! commands.spawn(MapBundle::default());
1922
//! }
2023
//! ```
2124
use bevy::{
2225
prelude::*,
2326
render::{render_asset::RenderAssetUsages, render_resource::TextureFormat},
2427
};
28+
use colorgrad::{Gradient, LinearGradient};
2529
use image::{imageops::FilterType, DynamicImage, Pixel};
2630
use serde::{Deserialize, Serialize};
2731

@@ -64,7 +68,7 @@ pub struct MapBundle {
6468
/// See [`Map`](./struct.Map.html)
6569
pub map: Map,
6670
/// See [`ImageBundle`](../../bevy/prelude/struct.ImageBundle.html)
67-
pub image_bundle: ImageBundle,
71+
pub image_bundle: ImageNode,
6872
}
6973

7074
impl Default for Map {
@@ -79,38 +83,34 @@ impl Default for Map {
7983
}
8084
}
8185
}
82-
fn generate_map(mut images: ResMut<Assets<Image>>, mut query: Query<(&mut Map, &mut UiImage)>) {
86+
fn generate_map(mut images: ResMut<Assets<Image>>, mut query: Query<(&mut Map, &mut ImageNode)>) {
8387
for (mut map, mut ui_image) in &mut query {
8488
map.noise.size = map.size;
8589
let noise_values = generate_noise_map(&map.noise);
8690
let noise = &mut map.noise;
8791

8892
let mut colors: Vec<colorgrad::Color> = Vec::with_capacity(noise.regions.len());
89-
let mut domain: Vec<f64> = Vec::with_capacity(noise.regions.len());
93+
let mut domain: Vec<f32> = Vec::with_capacity(noise.regions.len());
9094
for region in &noise.regions {
9195
colors.push(colorgrad::Color {
92-
r: f64::from(region.color[0]) / 255.0,
93-
g: f64::from(region.color[1]) / 255.0,
94-
b: f64::from(region.color[2]) / 255.0,
95-
a: f64::from(region.color[3]) / 255.0,
96+
r: f32::from(region.color[0]) / 255.0,
97+
g: f32::from(region.color[1]) / 255.0,
98+
b: f32::from(region.color[2]) / 255.0,
99+
a: f32::from(region.color[3]) / 255.0,
96100
});
97101
domain.push(region.position);
98102
}
99-
let mut grad = colorgrad::CustomGradient::new()
103+
let grad = colorgrad::GradientBuilder::new()
100104
.colors(&colors)
101105
.domain(&domain)
102-
.build()
106+
.build::<LinearGradient>()
103107
.unwrap_or_else(|_| {
104-
colorgrad::CustomGradient::new()
108+
colorgrad::GradientBuilder::new()
105109
.colors(&colors)
106-
.build()
110+
.build::<LinearGradient>()
107111
.expect("Gradient generation failed")
108112
});
109113

110-
if noise.gradient.segments != 0 {
111-
grad = grad.sharp(noise.gradient.segments, noise.gradient.smoothness);
112-
}
113-
114114
let mut gradient_buffer = image::ImageBuffer::from_pixel(
115115
noise.gradient.size[0],
116116
noise.gradient.size[1],
@@ -119,7 +119,7 @@ fn generate_map(mut images: ResMut<Assets<Image>>, mut query: Query<(&mut Map, &
119119

120120
for (x, _, pixel) in gradient_buffer.enumerate_pixels_mut() {
121121
let rgba = grad
122-
.at(f64::from(x) * 100.0 / f64::from(noise.gradient.size[0]))
122+
.at((f64::from(x) * 100.0 / f64::from(noise.gradient.size[0])) as f32)
123123
.to_rgba8();
124124
pixel.blend(&image::Rgba(rgba));
125125
}
@@ -142,7 +142,7 @@ fn generate_map(mut images: ResMut<Assets<Image>>, mut query: Query<(&mut Map, &
142142

143143
for (x, y, pixel) in image_buffer.enumerate_pixels_mut() {
144144
let height = noise_values[x as usize][y as usize];
145-
let target_color = grad.at(height).to_rgba8();
145+
let target_color = grad.at(height as f32).to_rgba8();
146146
pixel.blend(&image::Rgba(target_color));
147147
}
148148
if !map.same_size {
@@ -167,6 +167,6 @@ fn generate_map(mut images: ResMut<Assets<Image>>, mut query: Query<(&mut Map, &
167167
.convert(TextureFormat::Rgba8UnormSrgb)
168168
.expect("Could not convert to Rgba8UnormSrgb");
169169

170-
ui_image.texture = images.add(map_texture);
170+
ui_image.image = images.add(map_texture);
171171
}
172172
}

src/noise.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub struct Region {
103103
/// Label of the region
104104
pub label: String,
105105
/// Percentage below which the region should render
106-
pub position: f64,
106+
pub position: f32,
107107
/// Color representing the region
108108
pub color: [u8; 4],
109109
}

0 commit comments

Comments
 (0)