bevy_eulerian_fluid

Crates.iobevy_eulerian_fluid
lib.rsbevy_eulerian_fluid
version0.3.0
created_at2025-01-10 16:33:41.942222+00
updated_at2025-11-18 08:55:09.224548+00
descriptionAn eularian fluid simulation plugin for Bevy.
homepage
repositoryhttps://github.com/narasan49/bevy_eulerian_fluid
max_upload_size
id1511453
size9,733,293
Yusuke Nara (narasan49)

documentation

README

bevy_eulerian_fluid

This project is a fluid simulation plugin for Bevy.

img

Try it on here!

Basic Usage

  1. Add FluidPlugin and PhysicsPlugins to the app with the same length unit.
  2. Spawn 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 avian2d::PhysicsPlugins;
use bevy_eulerian_fluid::{
    definition::{FluidSettings, LevelsetTextures, VelocityTextures},
    FluidPlugin,
};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(FluidPlugin::new(10.0))
        .add_plugins(PhysicsPlugins::default().with_length_unit(10.0))
        .add_systems(Startup, setup_scene)
        .add_systems(Update, on_initialized)
        .run();
}

fn setup_scene(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());

    commands.spawn(FluidSettings {
        rho: 997f32, // water
        gravity: Vec2::Y,
        size: UVec2::new(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.
    }
}

Interact to the fluid

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.

Features

  • Incompressible 2D fluid simulation
  • Viscosity
  • Fluid surface
  • Fluid source/drain
  • Solid body interaction
    • One-way solid body to fluid interaction
    • Two-way coupling with solid body and fluid
    • Various shape support: Circle, Rectangle, Capsule, Triangle

Examples

There are some examples to demonstrate how to visualize and interact to the simulation results:

  • Fluid-Solid two-way interaction

    cargo run --example various_shapes
    

    img

  • Imposing forces with mouse and touch input (Also available here)

    cargo run --example interaction
    

    img

Versions

Bevy Bevy Eularian Fluid
0.17 0.2, 0.3
0.15 0.1

Acknowledgments

The simulation is inspired by and based on the algorithms described in these books:

License

Licensed under either of

at your option.

Contribution

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.

Commit count: 195

cargo fmt