A powerful, general-purpose framework for particle-based simulations in Rust.
This Rust-based engine provides a flexible framework for particle-based simulations, supporting methods like Force-Based Dynamics (FBD) and Extended Position-Based Dynamics (XPBD). XPBD enables both rigid and soft body simulations, along with arbitrary constraints like collisions, joints, and springs.
Examples include simulations of colliding bodies, a breaking chain under stress, a frictionless rigid block, Lennard-Jones gases, and phase transitions. A basic real-time 2D renderer is included as an example implementation to visualize these systems, built using low-level Rust libraries like winit and softbuffer for efficient and lightweight rendering.
Smoothed Particle Hydrodynamics (SPH) is a planned feature that will enable fluid and other continuous material simulations, such as modeling liquid flow or astrophysical phenomena.
The engine is modular, allowing users to create custom interactions and constraints to suit their needs.
- Multiple simulation methods: Force-based Dynamics (FBD), Extended Position-Based Dynamics (XPBD), and Smoothed-Particle Hydrodynamics (SPH) (Planned)
- Rigid body simulation using both XPBD and FBD
- Fluid simulation using SPH (Planned)
- Modular architecture for easy extension
- Real-time 2D rendering
- Pre-implemented interactions and constraints
- Support for custom user-defined interactions and constraints
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
More examples can be found in the examples/examples directory.
-
Install Rust and Cargo: https://www.rust-lang.org/tools/install
-
Clone the repository:
git clone https://github.com/aydencook03/simulation_engine.git cd simulation_engine -
Run an example:
cargo run --release --example collision
To run other examples, replace collision with the name of any example file found in the examples/examples directory.
-
Force-based Dynamics (FBD): Applies Newtonian mechanics directly to particles, suitable for rigid body dynamics, gravitational systems, and force fields.
-
Extended Position-Based Dynamics (XPBD): A constraint-based method that directly manipulates particle positions, effective for complex interactions like collisions and joint constraints.
-
Smoothed-Particle Hydrodynamics (SPH): A mesh-free approach for simulating fluids and continuous materials, versatile for fluid flow, astrophysics, soft matter, and thermodynamic simulations.
engine: Core simulation enginerendering: Visualization utilitiesexamples: Example simulations
- System: Central component managing particles, interactions, and constraints
- Particles: Fundamental units with properties like position, velocity, and mass
- Interactions: Define inter-particle interactions (e.g., generic forces, gravity, Lennard-Jones potential)
- Constraints: Enforce conditions on particles (e.g., distance constraints, collisions)
The engine uses a distinct simulation loop that separates interactions and constraints:
- Apply interactions (forces) to particles
- Integrate particle positions
- Apply constraints to enforce specific conditions
- Update particle velocities
This separation allows for efficient handling of both dynamic force-based behaviors and precise geometric constraints.
- Implement the
Interactiontrait for new interactions - Implement the
Constrainttrait for new constraints - Use
XpbdParametersto integrate new constraints with the XPBD solver
Contributions are welcome! Please feel free to submit a Pull Request.
Dual-licensed under the MIT License and the Apache License 2.0.





