Skip to content

Commit

Permalink
Bevy 0.13 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManevilleF authored Feb 22, 2024
1 parent 3121452 commit 2b47288
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 113 deletions.
22 changes: 14 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: build
run: cargo build --verbose

build_features:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: all features
run: cargo build --verbose --all-features
Expand All @@ -31,14 +31,16 @@ jobs:
build_examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: build baloon example
run: cargo clippy --example balloon
- name: build flag example
run: cargo clippy --example flag
- name: build moving example
run: cargo clippy --example moving
- name: build rapier example
run: cargo clippy --features xpbd_collisions --example xpbd_collision
- name: build rapier example
run: cargo clippy --features rapier_collisions --example rapier_collision
- name: build anchors example
Expand All @@ -47,7 +49,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: tests
run: cargo test --tests
Expand All @@ -57,7 +59,7 @@ jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: "rustfmt"
Expand All @@ -67,17 +69,21 @@ jobs:
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Cargo clippy installation
run: rustup component add clippy
- name: Cargo clippy check
- name: Default clippy check
run: cargo clippy --all --tests -- -D warnings
- name: Full clippy check
run: cargo clippy --all-features --all --tests -- -D warnings
- name: Minimal clippy check
run: cargo clippy --no-default-features --all --tests -- -D warnings

rustdoc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: rustdoc
run: cargo rustdoc --all-features -- -D warnings
18 changes: 8 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,30 @@ xpbd_collisions = ["bevy_xpbd_3d"]
thiserror = "1.0"

[dependencies.bevy]
version = "0.12"
version = "0.13"
default-features = false
features = ["bevy_render", "bevy_asset"]

[dependencies.bevy_rapier3d]
version = "0.23"
version = "0.25"
optional = true
default-features = false
features = ["dim3", "async-collider"]

[dependencies.bevy_xpbd_3d]
version = "0.3"
version = "0.4"
optional = true
default-features = false
features = ["3d", "f32", "async-collider"]
features = ["3d", "f32", "async-collider", "default-collider", "parry-f32"]

[dev-dependencies]
bevy-inspector-egui = "0.21"
bevy_rapier3d = "0.23"
bevy-inspector-egui = "0.23"
rand = "0.8"
bevy_xpbd_3d = "0.4"
bevy_rapier3d = "0.25"

[dev-dependencies.bevy]
version = "0.12"
version = "0.13"
features = [
"bevy_asset",
"bevy_winit",
Expand All @@ -54,9 +55,6 @@ features = [
"bevy_sprite",
"png",
"x11",
# The following features are required because of https://github.com/bevyengine/bevy/discussions/9100
"ktx2",
"zstd",
"tonemapping_luts",
]
default-features = false
Expand Down
16 changes: 6 additions & 10 deletions examples/anchors_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
App::new()
.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0,
brightness: 500.0,
})
.add_plugins(DefaultPlugins)
.add_plugins(ResourceInspectorPlugin::<ClothConfig>::new())
Expand All @@ -28,7 +28,7 @@ fn setup(
transform: Transform::from_rotation(Quat::from_rotation_y(5.0)),
..Default::default()
});
let mesh_handle = meshes.add(shape::Cube::new(1.0).into());
let mesh_handle = meshes.add(Cuboid::default());
[
(Color::BLUE, [-10.0, 0.0]),
(Color::GREEN, [10.0, 0.0]),
Expand All @@ -39,11 +39,7 @@ fn setup(
commands.spawn(PbrBundle {
mesh: mesh_handle.clone(),
transform: Transform::from_xyz(x, 1.0, z),
material: materials.add(StandardMaterial {
base_color: color,
double_sided: true,
..Default::default()
}),
material: materials.add(color),
..Default::default()
});
});
Expand All @@ -58,12 +54,12 @@ fn spawn_cloth(
let flag_texture = asset_server.load("Bevy.png");
let (size_x, size_y) = (60, 40);

let anchor_mesh = meshes.add(shape::Cube::new(1.0).into());
let anchor_mesh = meshes.add(Cuboid::default());
let entity_a = commands
.spawn((
PbrBundle {
mesh: anchor_mesh.clone(),
material: materials.add(Color::RED.into()),
material: materials.add(Color::RED),
transform: Transform::from_xyz(-15.0, 15.0, 15.0),
..Default::default()
},
Expand All @@ -74,7 +70,7 @@ fn spawn_cloth(
.spawn((
PbrBundle {
mesh: anchor_mesh,
material: materials.add(Color::GREEN.into()),
material: materials.add(Color::GREEN),
transform: Transform::from_xyz(15.0, 15.0, 15.0),
..Default::default()
},
Expand Down
15 changes: 4 additions & 11 deletions examples/balloon_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
App::new()
.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0,
brightness: 100.0,
})
.add_plugins(DefaultPlugins)
.add_plugins(WorldInspectorPlugin::default())
Expand All @@ -29,7 +29,7 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
) {
commands.spawn(DirectionalLightBundle::default());
let mesh_handle = meshes.add(shape::Cube::new(1.0).into());
let mesh_handle = meshes.add(Cuboid::default());
[
(Color::BLUE, [-10.0, 0.0]),
(Color::GREEN, [10.0, 0.0]),
Expand Down Expand Up @@ -57,15 +57,8 @@ fn spawn_cloth(
) {
commands.spawn((
PbrBundle {
mesh: meshes.add(
shape::Icosphere {
radius: 5.0,
subdivisions: 10,
}
.try_into()
.unwrap(),
),
material: materials.add(Color::YELLOW.into()),
mesh: meshes.add(Sphere::new(5.).mesh().ico(10).unwrap()),
material: materials.add(Color::YELLOW),
transform: Transform::from_xyz(0.0, 2.0, 0.0),
..Default::default()
},
Expand Down
64 changes: 35 additions & 29 deletions examples/camera_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,63 @@ use bevy::{

pub struct CameraPlugin;

#[derive(Debug, Component)]
pub struct OrbitController;

#[derive(Debug, Component)]
pub struct CameraController;

impl Plugin for CameraPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup)
.add_systems(PostUpdate, handle_camera);
.add_systems(PostUpdate, (handle_rotation, handle_zoom));
log::info!("Camera Plugin loaded");
}
}

pub fn setup(mut commands: Commands) {
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(-30.0, 30.0, -30.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
CameraController,
));
commands
.spawn((
TransformBundle::from_transform(Transform::from_rotation(Quat::from_rotation_z(-1.0))),
OrbitController,
))
.with_children(|b| {
b.spawn((
Camera3dBundle {
transform: Transform::from_xyz(0.0, 30.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
CameraController,
));
});
}

pub fn handle_camera(
mut cam_controls: Query<&mut Transform, With<CameraController>>,
pub fn handle_rotation(
mut cam_controls: Query<&mut Transform, With<OrbitController>>,
mut motion_evr: EventReader<MouseMotion>,
mut scroll_evr: EventReader<MouseWheel>,
buttons: Res<Input<MouseButton>>,
buttons: Res<ButtonInput<MouseButton>>,
time: Res<Time>,
) {
let delta_time = time.delta_seconds();
let mut transform = cam_controls.single_mut();
let forward = transform.local_z();
let right = transform.local_x();
let up = transform.local_y();
// Rotate
if buttons.pressed(MouseButton::Left) {
for ev in motion_evr.read() {
let delta = -ev.delta * delta_time * 0.1;
transform.rotate_y(delta.x);
transform.rotate_local_x(delta.y);
let delta = ev.delta * delta_time * 0.1;
transform.rotate_y(-delta.x);
transform.rotate_local_z(delta.y);
}
}
// Pan
if buttons.pressed(MouseButton::Right) {
for ev in motion_evr.read() {
let delta = ev.delta * delta_time;
transform.translation += -right * delta.x;
transform.translation += up * delta.y;
}
}
// Zoom
}

pub fn handle_zoom(
mut cam_controls: Query<&mut Transform, With<CameraController>>,
mut scroll_evr: EventReader<MouseWheel>,
time: Res<Time>,
) {
let delta_time = time.delta_seconds();
let mut transform = cam_controls.single_mut();
let forward = transform.forward();
for ev in scroll_evr.read() {
transform.translation += ev.y * delta_time * forward * 10.0;
transform.translation += forward * ev.y * delta_time * 10.0;
}
}
4 changes: 2 additions & 2 deletions examples/flag_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
App::new()
.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0,
brightness: 100.0,
})
.add_plugins(DefaultPlugins)
.add_plugins(WorldInspectorPlugin::default())
Expand Down Expand Up @@ -43,7 +43,7 @@ fn setup(
transform: Transform::from_rotation(Quat::from_rotation_y(5.0)),
..Default::default()
});
let mesh_handle = meshes.add(shape::Cube::new(1.0).into());
let mesh_handle = meshes.add(Cuboid::default());
[
(Color::BLUE, [-10.0, 0.0]),
(Color::GREEN, [10.0, 0.0]),
Expand Down
8 changes: 4 additions & 4 deletions examples/moving_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() {
.register_type::<MovingAnimation>()
.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0,
brightness: 500.0,
})
.add_plugins(DefaultPlugins)
.add_plugins(WorldInspectorPlugin::default())
Expand All @@ -42,7 +42,7 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
mut meshes: ResMut<Assets<Mesh>>,
) {
let mesh_handle = meshes.add(shape::Cube::new(1.0).into());
let mesh_handle = meshes.add(Cuboid::default());
[
(Color::BLUE, [-10.0, 0.0]),
(Color::GREEN, [10.0, 0.0]),
Expand Down Expand Up @@ -85,8 +85,8 @@ fn spawn_cloth(
.with_children(|b| {
b.spawn((
PbrBundle {
mesh: meshes.add(shape::Cube::new(2.0).into()),
material: materials.add(Color::WHITE.into()),
mesh: meshes.add(Cuboid::new(2.0, 2.0, 2.0)),
material: materials.add(Color::WHITE),
transform: Transform::from_xyz(10.0, 0.0, 0.0),
..Default::default()
},
Expand Down
Loading

0 comments on commit 2b47288

Please sign in to comment.