| Crates.io | bevy_eulerian_fluid |
| lib.rs | bevy_eulerian_fluid |
| version | 0.1.0 |
| created_at | 2025-01-10 16:33:41.942222+00 |
| updated_at | 2025-01-10 16:33:41.942222+00 |
| description | An eularian fluid simulation plugin for Bevy. |
| homepage | |
| repository | https://github.com/narasan49/bevy_eulerian_fluid |
| max_upload_size | |
| id | 1511453 |
| size | 8,117,932 |
This project is a fluid simulation plugin for Bevy.

Try it on here!
FluidPlugin to the app.FluidSettings, then FluidSimulationBundle will be inserted automatically to the entity. By querying components bundled with FluidSimulationBundle such as VelocityTextures, the simulation results can be retreived.Here is a short example. See examples for the detailed implementation!
use bevy_eulerian_fluid::{
definition::{FluidSettings, LevelsetTextures, VelocityTextures},
FluidPlugin,
};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(FluidPlugin)
.add_systems(Startup, setup_scene)
.add_systems(Update, on_initialized)
.run();
}
fn setup_scene(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(FluidSettings {
dx: 1.0f32,
dt: 0.5f32,
rho: 997f32, // water
gravity: Vec2::Y,
size: (512, 512),
initial_fluid_level: 0.9,
});
}
fn on_initialized(
mut commands: Commands,
query: Query<(Entity, &LevelsetTextures, &VelocityTextures), Added<LevelsetTextures>>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<CustomMaterial>>,
mut velocity_materials: ResMut<Assets<VelocityMaterial>>,
) {
for (entity, levelset_textures, velocity_textures) in &query {
// Implement your own code to visualize the results.
}
}
The simulation entity has LocalForces component, which holds arrays of forces (in m/s^2) and position (in pixels). forces can be applied to the simulation domain by setting LocalForces.
See also an interaction example for the detailed implementation.
There are some examples to demonstrate how to visualize and interact to the simulation results:
Imposing forces with mouse and touch input (Also available here)
cargo run --example interaction

Solid-to-fluid feedback
cargo run --example demo

Spawn multiple fluids
cargo run --example multiple

Fluid surface
cargo run --example water_surface

The simulation is inspired by and based on the algorithms described in these books:
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.