Skip to content

Commit

Permalink
Bump Bevy to 0.15 (#46)
Browse files Browse the repository at this point in the history
* Start update to bevy 0.15

I think the library is ready now, I just need to go through the examples and update them to the new component structure. The main thing I had to adjust is the way Handles are represented in components; while I was there, I deprecated the Bundles and added Component dependencies.

* finish removing compile errors

* fix diagnostic visibility switch

* add required MeshMaterial#d component and update its handles

* insert MeshMaterial with hooks rather than required components

---------

Co-authored-by: Ray Redondo <rdredond@lcdev.xyz>
  • Loading branch information
shakesbeare and Ray Redondo authored Dec 30, 2024
1 parent 7d908ef commit c8ab332
Show file tree
Hide file tree
Showing 23 changed files with 382 additions and 423 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ default = ["2d", "3d"]
3d = ["bevy/bevy_pbr"]

[dependencies]
bevy = { version = "0.14", default-features = false, features = ["bevy_asset", "bevy_core_pipeline", "bevy_render"] }
bevy = { version = "0.15", default-features = false, features = ["bevy_asset", "bevy_core_pipeline", "bevy_render"] }
copyless = "0.1"

lyon_geom = "1.0"
Expand All @@ -34,7 +34,7 @@ anyhow = "1.0"
thiserror = "1.0"

[dev-dependencies]
bevy = { version = "0.14", default-features = true }
bevy = { version = "0.15", default-features = true }

#### 2D examples ####
[[example]]
Expand Down
14 changes: 6 additions & 8 deletions examples/2d/complex_one_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod common;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "2d_complex_one_color".to_string(),
Expand All @@ -22,14 +21,13 @@ fn main() {

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let svg = asset_server.load("asteroid_field.svg");
commands.spawn(Camera2dBundle::default());
commands.spawn(Svg2dBundle {
svg,
origin: Origin::Center,
transform: Transform {
commands.spawn((Camera2d::default(), Msaa::Sample4));
commands.spawn((
Svg2d(svg),
Origin::Center,
Transform {
scale: Vec3::new(2.0, 2.0, 1.0),
..Default::default()
},
..Default::default()
});
));
}
31 changes: 10 additions & 21 deletions examples/2d/multiple_translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod common;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "2d_multiple_translation".to_string(),
Expand All @@ -23,30 +22,20 @@ fn main() {

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let svg = asset_server.load("asteroid_field.svg");
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d::default());
commands.spawn((
Svg2dBundle {
svg,
origin: Origin::Center,
transform: Transform {
translation: Vec3::new(100.0, 0.0, 0.0),
scale: Vec3::new(2.0, 2.0, 1.0),
..Default::default()
},
Svg2d(svg),
Origin::Center,
Transform {
translation: Vec3::new(100.0, 0.0, 0.0),
scale: Vec3::new(2.0, 2.0, 1.0),
..Default::default()
},
Direction::Up,
));

let svg = asset_server.load("neutron_star.svg");
commands.spawn((
Svg2dBundle {
svg,
origin: Origin::Center,
..Default::default()
},
Direction::Up,
));
commands.spawn((Svg2d(svg), Origin::Center, Direction::Up));
}

#[derive(Component)]
Expand All @@ -57,12 +46,12 @@ enum Direction {

fn svg_movement(
time: Res<Time>,
mut svg_position: Query<(&mut Direction, &mut Transform), With<Handle<Svg>>>,
mut svg_position: Query<(&mut Direction, &mut Transform), With<Svg2d>>,
) {
for (mut direction, mut transform) in &mut svg_position {
match *direction {
Direction::Up => transform.translation.y += 150. * time.delta_seconds(),
Direction::Down => transform.translation.y -= 150. * time.delta_seconds(),
Direction::Up => transform.translation.y += 150. * time.delta_secs(),
Direction::Down => transform.translation.y -= 150. * time.delta_secs(),
}

if transform.translation.y > 200. {
Expand Down
18 changes: 3 additions & 15 deletions examples/2d/origin_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod common;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "origin_check".to_string(),
Expand All @@ -22,18 +21,7 @@ fn main() {

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let svg = asset_server.load("box.svg");
commands.spawn(Camera2dBundle::default());
commands.spawn(Svg2dBundle {
svg: svg.clone(),
origin: Origin::Center,
..Default::default()
});
commands.spawn((
Svg2dBundle {
svg,
origin: Origin::TopLeft,
..Default::default()
},
common::DontChange,
));
commands.spawn(Camera2d::default());
commands.spawn((Svg2d(svg.clone()), Origin::Center));
commands.spawn((Svg2d(svg), Origin::TopLeft, common::DontChange));
}
9 changes: 2 additions & 7 deletions examples/2d/preloading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod common;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "preloading".to_string(),
Expand All @@ -23,7 +22,7 @@ fn main() {
}

fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d::default());
}

#[derive(Default, Eq, PartialEq)]
Expand All @@ -50,11 +49,7 @@ fn run(mut commands: Commands, asset_server: Res<AssetServer>, mut fsm: Local<Tu
if *frames > 0 {
*fsm = TutorialFsm::Wait(handle.clone(), *frames - 1);
} else if let Some(svg) = asset_server.get_handle("neutron_star.svg") {
commands.spawn(Svg2dBundle {
svg,
origin: Origin::Center,
..Default::default()
});
commands.spawn((Svg2d(svg), Origin::Center));

*fsm = TutorialFsm::Loaded;
dbg!("We loaded");
Expand Down
9 changes: 2 additions & 7 deletions examples/2d/twinkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod common;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "2d_twinkle".to_string(),
Expand All @@ -22,10 +21,6 @@ fn main() {

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let svg = asset_server.load("twinkle.svg");
commands.spawn(Camera2dBundle::default());
commands.spawn(Svg2dBundle {
svg,
origin: Origin::Center,
..Default::default()
});
commands.spawn(Camera2d::default());
commands.spawn((Svg2d(svg), Origin::Center));
}
9 changes: 2 additions & 7 deletions examples/2d/two_colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod common;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "2d_two_colors".to_string(),
Expand All @@ -22,10 +21,6 @@ fn main() {

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let svg = asset_server.load("neutron_star.svg");
commands.spawn(Camera2dBundle::default());
commands.spawn(Svg2dBundle {
svg,
origin: Origin::Center,
..Default::default()
});
commands.spawn(Camera2d::default());
commands.spawn((Svg2d(svg), Origin::Center));
}
14 changes: 6 additions & 8 deletions examples/3d/complex_one_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod common;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "3d_complex_one_color".to_string(),
Expand All @@ -22,15 +21,14 @@ fn main() {

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let svg = asset_server.load("asteroid_field.svg");
commands.spawn(Camera3dBundle::default());
commands.spawn(Svg3dBundle {
svg,
origin: Origin::Center,
transform: Transform {
commands.spawn(Camera3d::default());
commands.spawn((
Svg3d(svg),
Origin::Center,
Transform {
translation: Vec3::new(0.0, 0.0, -600.0),
scale: Vec3::new(2.0, 2.0, 1.0),
..Default::default()
},
..Default::default()
});
));
}
43 changes: 19 additions & 24 deletions examples/3d/multiple_perspective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod common;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "3d_multiple_perspective".to_string(),
Expand All @@ -22,39 +21,35 @@ fn main() {

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let svg = asset_server.load("neutron_star.svg");
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(100.0, 175.0, 0.0)
.looking_at(Vec3::new(0.0, 0.0, -600.0), Vec3::Y),
..Default::default()
});
commands.spawn(Svg3dBundle {
svg: svg.clone(),
origin: Origin::Center,
transform: Transform {
commands.spawn((
Camera3d::default(),
Transform::from_xyz(100.0, 175.0, 0.0).looking_at(Vec3::new(0.0, 0.0, -600.0), Vec3::Y),
));
commands.spawn((
Svg3d(svg.clone()),
Origin::Center,
Transform {
translation: Vec3::new(0.0, 0.0, -600.0),
rotation: Quat::from_rotation_x(-std::f32::consts::PI * 3.0),
..Default::default()
},
..Default::default()
});
commands.spawn(Svg3dBundle {
svg: svg.clone(),
origin: Origin::Center,
transform: Transform {
));
commands.spawn((
Svg3d(svg.clone()),
Origin::Center,
Transform {
translation: Vec3::new(0.0, 0.0, -700.0),
rotation: Quat::from_rotation_x(-std::f32::consts::PI * 3.0),
..Default::default()
},
..Default::default()
});
commands.spawn(Svg3dBundle {
svg,
origin: Origin::Center,
transform: Transform {
));
commands.spawn((
Svg3d(svg),
Origin::Center,
Transform {
translation: Vec3::new(0.0, 0.0, -800.0),
rotation: Quat::from_rotation_x(-std::f32::consts::PI * 3.0),
..Default::default()
},
..Default::default()
});
));
}
32 changes: 12 additions & 20 deletions examples/3d/multiple_translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod common;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "3d_multiple_translation".to_string(),
Expand All @@ -23,30 +22,23 @@ fn main() {

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let svg = asset_server.load("asteroid_field.svg");
commands.spawn(Camera3dBundle::default());
commands.spawn(Camera3d::default());
commands.spawn((
Svg3dBundle {
svg,
origin: Origin::Center,
transform: Transform {
translation: Vec3::new(100.0, 0.0, -600.0),
scale: Vec3::new(2.0, 2.0, 1.0),
..Default::default()
},
Svg3d(svg.clone()),
Origin::Center,
Transform {
translation: Vec3::new(100.0, 0.0, -600.0),
scale: Vec3::new(2.0, 2.0, 1.0),
..Default::default()
},
Direction::Up,
));

let svg = asset_server.load("neutron_star.svg");
commands.spawn((
Svg3dBundle {
svg,
origin: Origin::Center,
transform: Transform {
translation: Vec3::new(0.0, 0.0, -600.0),
..Default::default()
},
Svg3d(svg.clone()),
Transform {
translation: Vec3::new(0.0, 0.0, -600.0),
..Default::default()
},
Direction::Up,
Expand All @@ -61,12 +53,12 @@ enum Direction {

fn svg_movement(
time: Res<Time>,
mut svg_position: Query<(&mut Direction, &mut Transform), With<Handle<Svg>>>,
mut svg_position: Query<(&mut Direction, &mut Transform), With<Svg3d>>,
) {
for (mut direction, mut transform) in &mut svg_position {
match *direction {
Direction::Up => transform.translation.y += 150.0 * time.delta_seconds(),
Direction::Down => transform.translation.y -= 150.0 * time.delta_seconds(),
Direction::Up => transform.translation.y += 150.0 * time.delta_secs(),
Direction::Down => transform.translation.y -= 150.0 * time.delta_secs(),
}

if transform.translation.y > 200.0 {
Expand Down
Loading

0 comments on commit c8ab332

Please sign in to comment.