Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/narasan49/bevy_eulerian_fluid
https://github.com/narasan49/bevy_eulerian_fluid
bevy fluid-simulation
Last synced: about 5 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/narasan49/bevy_eulerian_fluid
- Owner: narasan49
- License: apache-2.0
- Created: 2024-06-17T12:41:49.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-01-07T23:35:55.000Z (3 days ago)
- Last Synced: 2025-01-08T00:27:27.714Z (3 days ago)
- Topics: bevy, fluid-simulation
- Language: Rust
- Homepage: https://narasan49.github.io/bevy_eulerian_fluid/
- Size: 83.9 MB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# bevy_eulerian_fluid
This project is a fluid simulation plugin for [Bevy](https://bevyengine.org/).
![img](./docs/bevy-fluid-surface.gif)
Try it on [here](https://narasan49.github.io/bevy_eulerian_fluid/)!
## 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](./examples/) for the detailed implementation!
```rust
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>,
mut meshes: ResMut>,
mut materials: ResMut>,
mut velocity_materials: ResMut>,
) {
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](./examples/interaction.rs) for the detailed implementation.
## Features
- [x] Incompressible 2D fluid simulation
- [ ] Viscosity
- [ ] Fluid surface
- [x] Basic implementation
- [ ] Fluid source/drain
- [ ] Solid body interaction
- [x] One-way solid body to fluid interaction
- [ ] Two-way coupling with solid body and fluid
- [ ] Various shapes support
- [x] Circle## Examples
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](https://narasan49.github.io/bevy_eulerian_fluid/))
```ps1
cargo run --example interaction
```
![img](./docs/bevy-fluid-interaction.gif)- **Solid-to-fluid feedback**
```ps1
cargo run --example demo
```
![img](./docs/bevy-fluid-solid-to-fluid.gif)- **Spawn multiple fluids**
```ps1
cargo run --example multiple
```
![img](./docs/bevy-fluid-multiple-fluids.gif)- **Fluid surface**
```ps1
cargo run --example water_surface
```
![img](./docs/bevy-fluid-surface.gif)## Acknowledgments
The simulation is inspired by and based on the algorithms described in these books:- [Fluid Simulation for Computer Graphics](https://www.amazon.co.jp/dp/1482232839) by Robert Bridson
- [GPU Gems Chapter 38](https://developer.nvidia.com/gpugems/gpugems/part-vi-beyond-triangles/chapter-38-fast-fluid-dynamics-simulation-gpu) by Mark J. Harris## License
Licensed under either of
* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)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.