8000 GitHub - narasan49/bevy_eulerian_fluid
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

narasan49/bevy_eulerian_fluid

Repository files navigation

bevy_eulerian_fluid

This project is a fluid simulation plugin for Bevy.

img

Try it on here!

Basic Usage

  1. Add FluidPlugin to the app.
  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 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.
    }
}

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
    • Basic implementation
    • Fluid source/drain
  • Solid body interaction
    • One-way solid body to fluid interaction
    • Two-way coupling with solid body and fluid
    • Various shapes support
      • Circle
      • Rectangle

Examples

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

  • Solid-to-fluid feedback

    cargo run --example solid_body

    img

  • Fluid surface

    cargo run --example water_surface

    img

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

    cargo run --example interaction

    img

  • Spawn multiple fluids

    cargo run --example multiple

    img

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.

About

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published
0