Bevy Silk
CPU driven Cloth engine for Bevy using Verlet integration.
Get started
Dependency
Add bevy_silk as a dependency in the Cargo.toml
bevy_silk = "0.7"
Or follow the main git branch
bevy_silk = { git = "https://github.com/ManevilleF/bevy_silk" }
Supported Bevy Versions
bevy_silk |
bevy |
|---|---|
| 0.1.0 | 0.7 |
| 0.2.0 | 0.7 |
| 0.3.0 | 0.8 |
| 0.4.0 | 0.9 |
| 0.5.0 | 0.10 |
| 0.6.0 | 0.11 |
| 0.7.0 | 0.12 |
Plugin
Add the ClothPlugin to your bevy app
use *;
use *;
Add cloth to a mesh
For a mesh to be used as cloth, add the ClothBuilder component to any
entity with a Handle<Mesh> component.
Note:
TransformandGlobalTransformare also required
cloth data which will be populated automatically from the associated
Handle<Mesh>.
use *;
use *;
Vertex anchoring
Specifying vertex anchors allows to pin some cloth vertices to various
entities. The ClothBuilder has multiple methods allowing to anchor
vertices through their id or color.
For example you can pin some cloth vertices to the cloth entity's
GlobalTransform:
use Color;
use *;
let cloth = new
// Adds pinned vertices ids using an Iterator
.with_pinned_vertex_ids
// Adds a single pinned vertex id
.with_pinned_vertex_id
// Adds pinned vertex colors using an Iterator
.with_pinned_vertex_colors
// Adds a single pinned vertex color
.with_pinned_vertex_color
// Adds pinned vertex positions
.with_pinned_vertex_positions;
For more anchoring options, for example to specify a custom entity to pin the vertices to:
use *;
use *;
Custom anchoring allows to :
- pin vertices to various entities, like skeletal mesh joints
- define custom offsets to customize the distance between the anchored vertices an the target
- use world space pinning and ignore the target's rotation for example
- override the vertex positions, using only the offset
Configuration
You can customize the global cloth physics by inserting the ClothConfig
resource to your app:
use *;
use *;
ClothConfig can also be used as a component to override the global
configuration.
Wind
You may add wind forces to the simulation for a more dynamic clothing effect, for each force you may choose from:
Wind::Constantfor constant wind forceWind::SinWavefor a sin wave following wind intensity with custom force and frequency.
Wind forces can be added as a resource to your app through the Winds
container:
use *;
use *;
Check the flag example for simple wind effect.
Collisions
Both bevy_rapier and bevy_xpbd are supported for cloth interactions
with colliders. They can be enabled with the rapier_collisions and
xpbd_collisions features respectively.
Note: Collision support is still experimental for now and is not suited for production use. Feedback is welcome!
bevy_rapier
Add bevy_rapier3d::RapierPhysicsPlugin to your app and a ClothCollider
to your entity to enable collisions:
use *;
use *;
Three bevy_rapier components will be automatically inserted:
- a
RigidBody::KinematicPositionBased - a
Colliderwhich will be updated every frame to follow the cloth bounds (AABB) - a
SolverGroupset to 0 (Group::NONE) in everything, avoiding default collision solving.
You can customize what collisions will be checked by specifying
CollisionGroups. (See the bevy_rapier docs).
bevy_xpbd
Add bevy_xpbd_3d::PhysicsPlugins to your app and a ClothCollider
to your entity to enable collisions:
use *;
use *;
Three bevy_xpbd components will be automatically inserted:
- a
RigidBody::Kinematic - a
Colliderwhich will be updated every frame to follow the cloth bounds (AABB) - a
Sensorused for avoiding default collision solving.
You can customize what collisions will be checked by specifying
CollisionLayers. (See the bevy_xpbd docs).
Mesh utils
bevy_silk provides a plane mesh generation function rectangle_mesh
useful for classic cloth uses like flags or capes
Q&A
-
My mesh falls immediately and infinitely when I add a Cloth component, how to fix it?You probably didn't specify any pinned points, meaning there are no vertices anchored to your entity's
GlobalTransform. -
My cloth jitters a lot/ suddenly falls down/ has strange sudden behaviourGravity and winds are by default smoothed out by the framerate, if the framerate drops suddenly gravity and wind get much stronger. If your simulation suffers from this you can specify a custom smooth value in
ClothConfig::acceleration_smoothing.
TODO list
- World and per cloth simulation pause/ filter out cloth update
- Cloth update batching
- Cloth cutting maybe?
Examples

-
Flag example
run
cargo run --example flag -
Balloon example
run
cargo run --example balloon -
Moving example
run
cargo run --example moving -
bevy_rapiercollision examplerun
cargo run --example rapier_collision --features rapier_collisions -
bevy_xpbdcollision examplerun
cargo run --example xpbd_collision --features xpbd_collisions -
Anchors example
run
cargo run --example anchors