Skip to content

Commit

Permalink
Feat/bevy 0.14 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManevilleF authored Jul 12, 2024
1 parent fb9094c commit f74a7d3
Show file tree
Hide file tree
Showing 18 changed files with 166 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: build moving example
run: cargo clippy --example moving
- name: build rapier example
run: cargo clippy --features xpbd_collisions --example xpbd_collision
run: cargo clippy --features avian_collisions --example avian_collision
- name: build rapier example
run: cargo clippy --features rapier_collisions --example rapier_collision
- name: build anchors example
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

* Physics improvements (#25)
* Bevy `0.14`
* Migrated from `bevy_xpbd` to `avian`
* (**BREAKING**) Renamed `xpbd_collisions` feature to `avian_collisions`
* Renamed `xpbd_collision_example` to `avian_collision_example`

## 0.8.0

* Bump `bevy` to `0.13.x`
Expand Down
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@ documentation = "https://docs.rs/bevy_silk"
[features]
default = []
rapier_collisions = ["bevy_rapier3d"]
xpbd_collisions = ["bevy_xpbd_3d"]
avian_collisions = ["avian3d"]

[dependencies]
# Error handling
thiserror = "1.0"

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

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

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

[dev-dependencies]
bevy-inspector-egui = "0.24"
bevy-inspector-egui = "0.25"
rand = "0.8"
bevy_xpbd_3d = "0.4"
bevy_rapier3d = "0.26"
avian3d = "0.1"
bevy_rapier3d = "0.27"

[dev-dependencies.bevy]
version = "0.13"
version = "0.14"
features = [
"bevy_asset",
"bevy_winit",
Expand Down Expand Up @@ -77,9 +77,9 @@ path = "examples/rapier_collision_example.rs"
required-features = ["rapier_collisions"]

[[example]]
name = "xpbd_collision"
path = "examples/xpbd_collision_example.rs"
required-features = ["xpbd_collisions"]
name = "avian_collision"
path = "examples/avian_collision_example.rs"
required-features = ["avian_collisions"]

[[example]]
name = "anchors"
Expand Down
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ For example you can pin some cloth vertices to the cloth entity's
`GlobalTransform`:

```rust
use bevy::prelude::Color;
use bevy::color::{palettes::css::*, Color};
use bevy_silk::prelude::*;

let cloth = ClothBuilder::new()
Expand All @@ -105,9 +105,9 @@ let cloth = ClothBuilder::new()
// Adds a single pinned vertex id
.with_pinned_vertex_id(10)
// Adds pinned vertex colors using an Iterator
.with_pinned_vertex_colors([Color::WHITE, Color::BLACK].into_iter())
.with_pinned_vertex_colors([Color::from(WHITE), Color::from(BLACK)].into_iter())
// Adds a single pinned vertex color
.with_pinned_vertex_color(Color::YELLOW)
.with_pinned_vertex_color(Color::from(YELLOW))
// Adds pinned vertex positions
.with_pinned_vertex_positions(|pos| pos.x > 0.0 && pos.z <= 5.0);
```
Expand All @@ -116,7 +116,7 @@ For more anchoring options, for example to specify a custom entity to pin
the vertices to:

```rust
use bevy::prelude::*;
use bevy::{color::palettes::css::*, prelude::*};
use bevy_silk::prelude::*;

fn spawn(mut commands: Commands) {
Expand Down Expand Up @@ -148,9 +148,12 @@ fn spawn(mut commands: Commands) {
// Adds a single pinned vertex id
.with_anchored_vertex_id(10, anchor_to_self)
// Adds pinned vertex colors using an Iterator
.with_anchored_vertex_colors([Color::WHITE, Color::BLACK].into_iter(), anchor_to_a)
.with_anchored_vertex_colors(
[Color::from(WHITE), Color::from(BLACK)].into_iter(),
anchor_to_a,
)
// Adds a single pinned vertex color
.with_anchored_vertex_color(Color::YELLOW, anchor_to_self)
.with_anchored_vertex_color(Color::from(YELLOW), anchor_to_self)
// Adds pinned vertex positions
.with_anchored_vertex_positions(|pos| pos.x > 0.0 && pos.z <= 5.0, anchor_to_self);
}
Expand Down Expand Up @@ -226,9 +229,9 @@ fn main() {
## Collisions

Both [`bevy_rapier`] and [`bevy_xpbd`] are supported for cloth interactions
Both [`bevy_rapier`] and [`avian`] are supported for cloth interactions
with colliders. They can be enabled with the `rapier_collisions` and
`xpbd_collisions` features respectively.
`avian_collisions` features respectively.

> Note: Collision support is still experimental for now and is not suited
> for production use. Feedback is welcome!
Expand Down Expand Up @@ -265,9 +268,9 @@ Three `bevy_rapier` components will be automatically inserted:
You can customize what collisions will be checked by specifying
`CollisionGroups`. (See the [`bevy_rapier` docs](https://rapier.rs/docs/user_guides/bevy_plugin/colliders#collision-groups-and-solver-groups)).

### `bevy_xpbd`
### `avian` (previously `bevy_xpbd`)

Add `bevy_xpbd_3d::PhysicsPlugins` to your app and a `ClothCollider`
Add `avian3d::PhysicsPlugins` to your app and a `ClothCollider`
to your entity to enable collisions:

```rust
Expand All @@ -286,15 +289,15 @@ fn spawn(mut commands: Commands) {
}
```

Three `bevy_xpbd` components will be automatically inserted:
Three `avian3d` components will be automatically inserted:

* a `RigidBody::Kinematic`
* a `Collider` which will be updated every frame to follow the cloth bounds
(AABB)
* a `Sensor` used for avoiding default collision solving.

You can customize what collisions will be checked by specifying
`CollisionLayers`. (See the [`bevy_xpbd` docs](https://docs.rs/bevy_xpbd_3d/latest/bevy_xpbd_3d/components/struct.CollisionLayers.html)).
`CollisionLayers`. (See the [`avian` docs](https://docs.rs/avian3d/latest/avian3d/collision/struct.CollisionLayers.html)).

## Mesh utils

Expand All @@ -318,7 +321,7 @@ useful for classic cloth uses like flags or capes
value in `ClothConfig::acceleration_smoothing`.

[`bevy_rapier`]: https://github.com/dimforge/bevy_rapier
[`bevy_xpbd`]: https://github.com/Jondolf/bevy_xpbd
[`avian`]: https://github.com/Jondolf/avian

<!-- cargo-sync-readme end -->

Expand Down
17 changes: 10 additions & 7 deletions examples/anchors_example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use bevy::prelude::*;
use bevy::{
color::palettes::css::{BLUE, GREEN, RED, YELLOW},
prelude::*,
};
use bevy_inspector_egui::quick::{ResourceInspectorPlugin, WorldInspectorPlugin};
use bevy_silk::prelude::*;

Expand Down Expand Up @@ -30,10 +33,10 @@ fn setup(
});
let mesh_handle = meshes.add(Cuboid::default());
[
(Color::BLUE, [-10.0, 0.0]),
(Color::GREEN, [10.0, 0.0]),
(Color::YELLOW, [0.0, -10.0]),
(Color::RED, [0.0, 10.0]),
(Color::from(BLUE), [-10.0, 0.0]),
(Color::from(GREEN), [10.0, 0.0]),
(Color::from(YELLOW), [0.0, -10.0]),
(Color::from(RED), [0.0, 10.0]),
]
.map(|(color, [x, z])| {
commands.spawn(PbrBundle {
Expand All @@ -59,7 +62,7 @@ fn spawn_cloth(
.spawn((
PbrBundle {
mesh: anchor_mesh.clone(),
material: materials.add(Color::RED),
material: materials.add(Color::from(RED)),
transform: Transform::from_xyz(-15.0, 15.0, 15.0),
..Default::default()
},
Expand All @@ -70,7 +73,7 @@ fn spawn_cloth(
.spawn((
PbrBundle {
mesh: anchor_mesh,
material: materials.add(Color::GREEN),
material: materials.add(Color::from(GREEN)),
transform: Transform::from_xyz(15.0, 15.0, 15.0),
..Default::default()
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use std::time::Duration;

use bevy::{prelude::*, time::common_conditions::on_timer};
use avian3d::prelude::*;
use bevy::{
color::palettes::css::{BLUE, GREEN, RED, YELLOW},
prelude::*,
time::common_conditions::on_timer,
};
use bevy_inspector_egui::quick::{ResourceInspectorPlugin, WorldInspectorPlugin};
use bevy_silk::prelude::*;
use bevy_xpbd_3d::prelude::*;
use rand::{thread_rng, Rng};

mod camera_plugin;
Expand Down Expand Up @@ -49,10 +53,10 @@ fn setup(
});
let mesh_handle = meshes.add(Cuboid::new(2.0, 2.0, 2.0));
[
(Color::BLUE, [-10.0, 0.0]),
(Color::GREEN, [10.0, 0.0]),
(Color::YELLOW, [0.0, -10.0]),
(Color::RED, [0.0, 10.0]),
(Color::from(BLUE), [-10.0, 0.0]),
(Color::from(GREEN), [10.0, 0.0]),
(Color::from(YELLOW), [0.0, -10.0]),
(Color::from(RED), [0.0, 10.0]),
]
.map(|(color, [x, z])| {
commands.spawn((
Expand Down
15 changes: 9 additions & 6 deletions examples/balloon_example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use bevy::prelude::*;
use bevy::{
color::palettes::css::{BLUE, GREEN, RED, YELLOW},
prelude::*,
};
use bevy_inspector_egui::quick::{ResourceInspectorPlugin, WorldInspectorPlugin};
use bevy_silk::prelude::*;

Expand Down Expand Up @@ -31,10 +34,10 @@ fn setup(
commands.spawn(DirectionalLightBundle::default());
let mesh_handle = meshes.add(Cuboid::default());
[
(Color::BLUE, [-10.0, 0.0]),
(Color::GREEN, [10.0, 0.0]),
(Color::YELLOW, [0.0, -10.0]),
(Color::RED, [0.0, 10.0]),
(Color::from(BLUE), [-10.0, 0.0]),
(Color::from(GREEN), [10.0, 0.0]),
(Color::from(YELLOW), [0.0, -10.0]),
(Color::from(RED), [0.0, 10.0]),
]
.map(|(color, [x, z])| {
commands.spawn(PbrBundle {
Expand All @@ -58,7 +61,7 @@ fn spawn_cloth(
commands.spawn((
PbrBundle {
mesh: meshes.add(Sphere::new(5.).mesh().ico(10).unwrap()),
material: materials.add(Color::YELLOW),
material: materials.add(Color::from(YELLOW)),
transform: Transform::from_xyz(0.0, 2.0, 0.0),
..Default::default()
},
Expand Down
15 changes: 9 additions & 6 deletions examples/flag_example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use bevy::prelude::*;
use bevy::{
color::palettes::css::{BLUE, GREEN, RED, YELLOW},
prelude::*,
};
use bevy_inspector_egui::quick::{ResourceInspectorPlugin, WorldInspectorPlugin};
use bevy_silk::prelude::*;

Expand Down Expand Up @@ -45,10 +48,10 @@ fn setup(
});
let mesh_handle = meshes.add(Cuboid::default());
[
(Color::BLUE, [-10.0, 0.0]),
(Color::GREEN, [10.0, 0.0]),
(Color::YELLOW, [0.0, -10.0]),
(Color::RED, [0.0, 10.0]),
(Color::from(BLUE), [-10.0, 0.0]),
(Color::from(GREEN), [10.0, 0.0]),
(Color::from(YELLOW), [0.0, -10.0]),
(Color::from(RED), [0.0, 10.0]),
]
.map(|(color, [x, z])| {
commands.spawn(PbrBundle {
Expand Down Expand Up @@ -121,7 +124,7 @@ fn spawn_cloth(
})
.collect();
mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, colors);
let cloth = ClothBuilder::new().with_pinned_vertex_color(Color::RED);
let cloth = ClothBuilder::new().with_pinned_vertex_color(Color::from(RED));
commands.spawn((
PbrBundle {
mesh: meshes.add(mesh),
Expand Down
13 changes: 8 additions & 5 deletions examples/moving_example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use bevy::prelude::*;
use bevy::{
color::palettes::css::{BLUE, GREEN, RED, YELLOW},
prelude::*,
};
use bevy_inspector_egui::quick::{ResourceInspectorPlugin, WorldInspectorPlugin};
use bevy_silk::prelude::*;

Expand Down Expand Up @@ -44,10 +47,10 @@ fn setup(
) {
let mesh_handle = meshes.add(Cuboid::default());
[
(Color::BLUE, [-10.0, 0.0]),
(Color::GREEN, [10.0, 0.0]),
(Color::YELLOW, [0.0, -10.0]),
(Color::RED, [0.0, 10.0]),
(Color::from(GREEN), [10.0, 0.0]),
(Color::from(BLUE), [-10.0, 0.0]),
(Color::from(YELLOW), [0.0, -10.0]),
(Color::from(RED), [0.0, 10.0]),
]
.map(|(color, [x, z])| {
commands.spawn(PbrBundle {
Expand Down
14 changes: 9 additions & 5 deletions examples/rapier_collision_example.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use std::time::Duration;

use bevy::{prelude::*, time::common_conditions::on_timer};
use bevy::{
color::palettes::css::{BLUE, GREEN, RED, YELLOW},
prelude::*,
time::common_conditions::on_timer,
};
use bevy_inspector_egui::quick::{ResourceInspectorPlugin, WorldInspectorPlugin};
use bevy_rapier3d::prelude::*;
use bevy_silk::prelude::*;
Expand Down Expand Up @@ -49,10 +53,10 @@ fn setup(
});
let mesh_handle = meshes.add(Cuboid::new(2.0, 2.0, 2.0));
[
(Color::BLUE, [-10.0, 0.0]),
(Color::GREEN, [10.0, 0.0]),
(Color::YELLOW, [0.0, -10.0]),
(Color::RED, [0.0, 10.0]),
(Color::from(BLUE), [-10.0, 0.0]),
(Color::from(GREEN), [10.0, 0.0]),
(Color::from(YELLOW), [0.0, -10.0]),
(Color::from(RED), [0.0, 10.0]),
]
.map(|(color, [x, z])| {
commands.spawn((
Expand Down
1 change: 1 addition & 0 deletions src/components/cloth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ impl Cloth {
}

#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
use crate::mesh::rectangle_mesh;
Expand Down
Loading

0 comments on commit f74a7d3

Please sign in to comment.