Skip to content

Commit

Permalink
Bevy 0.15 (#90)
Browse files Browse the repository at this point in the history
Co-authored-by: dmitry.lukichev <[email protected]>
  • Loading branch information
Plonq and dmlukichev authored Dec 7, 2024
1 parent ec5f400 commit a9c0113
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 269 deletions.
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ readme = "README.md"
bevy_egui = ["dep:bevy_egui"]

[dependencies]
bevy = { version = "0.14", default-features = false, features = [
bevy = { version = "0.15", default-features = false, features = [
"bevy_render",
"bevy_window"
] }
bevy_egui = { version = "0.30", optional = true, default-features = false }
bevy_egui = { version = "0.31", optional = true, default-features = false }

[dev-dependencies]
bevy = { version = "0.14" }
bevy = { version = "0.15" }
float-cmp = "0.9.0"
bevy_egui = { version = "0.30", default-features = false, features = [
bevy_egui = { version = "0.31", default-features = false, features = [
"render",
"default_fonts",
] }
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ Add `PanOrbitCamera` to a camera:

```rust ignore
commands.spawn((
Camera3dBundle {
transform: Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)),
..default()
},
Camera3d::default(),
Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)),
PanOrbitCamera::default(),
));
```
Expand Down
31 changes: 14 additions & 17 deletions examples/advanced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,29 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// Ground
commands.spawn(PbrBundle {
mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))),
MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))),
));
// Cube
commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),
Transform::from_xyz(0.0, 0.5, 0.0),
));
// Light
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
Transform::from_xyz(4.0, 8.0, 4.0),
));
// Camera
commands.spawn((
// Note we're setting the initial position below with yaw, pitch, and radius, hence
// we don't set transform on the camera.
Camera3dBundle::default(),
Camera3d::default(),
PanOrbitCamera {
// Set focal point (what the camera should look at)
focus: Vec3::new(0.0, 1.0, 0.0),
Expand Down
41 changes: 18 additions & 23 deletions examples/animate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,28 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// Ground
commands.spawn(PbrBundle {
mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))),
MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))),
));
// Cube
commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),
Transform::from_xyz(0.0, 0.5, 0.0),
));
// Light
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
Transform::from_xyz(4.0, 8.0, 4.0),
));
// Camera
commands.spawn((
Camera3dBundle {
transform: Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)),
..default()
},
Camera3d::default(),
Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)),
PanOrbitCamera {
// Disable smoothing, since the animation takes care of that
orbit_smoothness: 0.0,
Expand All @@ -60,10 +55,10 @@ fn setup(
fn animate(time: Res<Time>, mut pan_orbit_query: Query<&mut PanOrbitCamera>) {
for mut pan_orbit in pan_orbit_query.iter_mut() {
// Must set target values, not yaw/pitch directly
pan_orbit.target_yaw += 15f32.to_radians() * time.delta_seconds();
pan_orbit.target_pitch = time.elapsed_seconds_wrapped().sin() * TAU * 0.1;
pan_orbit.target_yaw += 15f32.to_radians() * time.delta_secs();
pan_orbit.target_pitch = time.elapsed_secs_wrapped().sin() * TAU * 0.1;
pan_orbit.radius =
Some((((time.elapsed_seconds_wrapped() * 2.0).cos() + 1.0) * 0.5) * 2.0 + 4.0);
Some((((time.elapsed_secs_wrapped() * 2.0).cos() + 1.0) * 0.5) * 2.0 + 4.0);

// Force camera to update its transform
pan_orbit.force_update = true;
Expand Down
35 changes: 15 additions & 20 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,28 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// Ground
commands.spawn(PbrBundle {
mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))),
MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))),
));
// Cube
commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),
Transform::from_xyz(0.0, 0.5, 0.0),
));
// Light
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
Transform::from_xyz(4.0, 8.0, 4.0),
));
// Camera
commands.spawn((
Camera3dBundle {
transform: Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)),
..default()
},
Camera3d::default(),
Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)),
PanOrbitCamera::default(),
));
}
35 changes: 15 additions & 20 deletions examples/egui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,28 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// Ground
commands.spawn(PbrBundle {
mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))),
MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))),
));
// Cube
commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),
Transform::from_xyz(0.0, 0.5, 0.0),
));
// Light
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
Transform::from_xyz(4.0, 8.0, 4.0),
));
// Camera
commands.spawn((
Camera3dBundle {
transform: Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)),
..default()
},
Camera3d::default(),
Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)),
PanOrbitCamera::default(),
));
}
Expand Down
37 changes: 16 additions & 21 deletions examples/follow_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,30 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// Ground
commands.spawn(PbrBundle {
mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))),
MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))),
));
// Cube
commands
.spawn(PbrBundle {
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
})
.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),
Transform::from_xyz(0.0, 0.5, 0.0),
))
.insert(Cube);
// Light
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
Transform::from_xyz(4.0, 8.0, 4.0),
));
// Camera
commands.spawn((
Camera3dBundle {
transform: Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)),
..default()
},
Camera3d::default(),
Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)),
PanOrbitCamera {
// Panning the camera changes the focus, and so you most likely want to disable
// panning when setting the focus manually
Expand All @@ -72,7 +67,7 @@ fn animate_cube(
) {
if let Ok(mut cube_tfm) = cube_q.get_single_mut() {
// Rotate 20 degrees a second, wrapping around to 0 after a full rotation
*angle += 20f32.to_radians() * time.delta_seconds() % TAU;
*angle += 20f32.to_radians() * time.delta_secs() % TAU;
// Convert angle to position
let pos = Vec3::new(angle.sin() * 1.5, 0.5, angle.cos() * 1.5);
cube_tfm.translation = pos;
Expand Down
Loading

0 comments on commit a9c0113

Please sign in to comment.