Skip to content

Commit

Permalink
Collisions happen in fixed update (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManevilleF authored Dec 2, 2023
1 parent c94e650 commit c397174
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 25 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Added `xpbd_collisions` feature
* Added `xpbd_collision` example
* Split `collisions` into `rapier` and `xpbd` sub-modules
* Collisions happen on fixed update schedule (#20)
* Fixed clippy warnings for rust 1.72.0 (#19)
* Added rustfmt config (#19)
* Added vertex colors in flag example (#19)
Expand All @@ -31,7 +32,8 @@

### Fixes

* Fixed visibility issues with cloths. Now the `Aabb` is directly handled by the cloth engine.
* Fixed visibility issues with cloths. Now the `Aabb` is directly handled by
the cloth engine.

### bevy_inspector_egui

Expand Down
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,3 @@ crate-type = ["staticlib"]
[profile.dev]
opt-level = 1

# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"]
opt-level = 3
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,27 +325,27 @@ in `ClothConfig::acceleration_smoothing`.

1. Flag example

run `cargo run --example flag`
run `cargo run --example flag`

2. Balloon example

run `cargo run --example balloon`
run `cargo run --example balloon`

3. Moving example

run `cargo run --example moving`
run `cargo run --example moving`

4. [`bevy_rapier`] collision example

run `cargo run --example rapier_collision --features rapier_collisions`
run `cargo run --example rapier_collision --features rapier_collisions`

5. [`bevy_xpbd`] collision example

run `cargo run --example xpbd_collision --features xpbd_collisions`
run `cargo run --example xpbd_collision --features xpbd_collisions`

6. Anchors example

run `cargo run --example anchors`
run `cargo run --example anchors`

[`bevy_rapier`]: https://github.com/dimforge/bevy_rapier
[`bevy_xpbd`]: https://github.com/Jondolf/bevy_xpbd
21 changes: 6 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,22 +372,13 @@ impl Plugin for ClothPlugin {
);

#[cfg(feature = "rapier_collisions")]
app.register_type::<ClothCollider>().add_systems(
Update,
(
systems::collisions::rapier::init_cloth_collider,
systems::collisions::rapier::handle_collisions.before(systems::cloth::render),
),
);
app.register_type::<ClothCollider>()
.add_systems(Update, systems::collisions::rapier::init_cloth_collider)
.add_systems(FixedUpdate, systems::collisions::rapier::handle_collisions);
#[cfg(feature = "xpbd_collisions")]
app.register_type::<ClothCollider>().add_systems(
Update,
(
systems::collisions::xpbd::init_cloth_collider,
systems::collisions::xpbd::handle_collisions.before(systems::cloth::render),
),
);

app.register_type::<ClothCollider>()
.add_systems(Update, systems::collisions::xpbd::init_cloth_collider)
.add_systems(FixedUpdate, systems::collisions::xpbd::handle_collisions);
bevy::log::info!("Loaded Cloth Plugin");
}
}
1 change: 1 addition & 0 deletions src/systems/cloth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub fn render(
if let Some(mesh) = meshes.get_mut(handle) {
rendering.update_positions(cloth.compute_vertex_positions(transform));
rendering.apply(mesh);
// TODO set_if_neq
*aabb = rendering.compute_aabb();
} else {
log::warn!("A Cloth has a `ClothRendering` component without a loaded mesh handle");
Expand Down

0 comments on commit c397174

Please sign in to comment.