About the future of nphysics: a pure rust 2D and 3D real-time physics engine

Hello everyone! I’ve been asked a few times about the future of physics (https://nphysics.org), i.e., what are my plans regarding this crate in the next few years. So I thought I could share the answer with everybody.

First, I’d like to recall what nphysics is and what are its overall goals. The nphysics project is composed of four free and open-source crates:

  • nphysics2d: a pure rust 2D real-time physics engine.
  • nphysics3d: a pure rust 3D real-time physics engine.
  • nphysics-testbed2d: a tool to easily test nphysics2d, and render a 2D physics scene.
  • nphysics-testbed3d: a tool to easily test nphysics3d, and render a 3D physics scene.

All those are pure-rust and multi-platform, including WebAssembly targets.

When I talk about “the nphysics crate”, I actually mean both the nphysics2d and nphysics3d crates. My overall goal for those is to provide a solid solution for real-time and interactive physics simulation in Rust. The target applications are mostly video-games as well as, to some extents, animation. Here “solid solution” implies a comprehensive set of features one would expect from a general-purpose physics engine: rigid bodies, deformable bodies, fluids, joints, and triggers. This also implies a level of performance comparable to existing popular C++ open-source physics engine like Box2D and Bullet Physics.

It is worth noting that nphysics is based on other crates I develop as part of the Rustsim community:

  • nalgebra: a general-purpose linear-algebra library un pure-rust (compatible with all platforms, including WASM and #[no-std]). https://nalgebra.org 
  • ncollide: a collision-detection project which is composed of two crates: ncollide2d and ncollide3d. It covers all the geometrical requirement of nphysics (determination of contact points, proximity detection, ray casting, etc.) https://ncollide.org 

Now that I described the overall idea of what nphysics is aimed to be, I’ll describe my goals for nphysics in the next couple of years.

The year 2019: adding features

The current year is about adding features. I added conveyor belts and several kinds of deformable bodies at the beginning of this year. The next nphysics release (as well as the next This Month In Rustsim edition) will happen in two days (Tuesday 4th of August) and will include:

  • Linear and non-linear continuous-collision detection (CCD) with colliders on rigid bodies and sensors (surprisingly other existing open-source physics engine, including PhysX, don’t support CCD on sensors/triggers).
  • Rigid body velocity damping.
  • Rigid body maximum velocity limit.
  • The possibility to use custom containers for bodies, colliders, joints, and force generators. This helps overcoming some difficulties related to borrowing, and also help for the integration of nphysics with other solutions. The physics World structure will no longer own those containers.

The next objectives will be to add CCD for multibodies and deformable bodies, and to add support for fluids based on Smoothed Particle Hydrodynamics (SPH).

Once all those features land, nphysics will have a pretty solid set of features for a general-purpose real-time-oriented physics engine. This goes somewhat beyond what most open-source physics engines like Bullet Physics and Box2d (as well as PhysX if we only consider what is provided open-source) currently offer in term of simulation of physical phenomena. Though we will still lack a few things in term of game-oriented physics features, namely character controllers and custom models for vehicles. Though I believe both of those could (and should) be implemented in a separate crate.

Year 2020: performances and bug fixes

Next year will be about improving performances, fixing bugs, and completing the documentation. While the current implementation is fast enough for lots of purposes, it is still a couple of times slower than popular physics engines like Box2D and Bullet Physics.

The goal will be to not add new big new features in order to focus on what already exists and can be improved. This includes:

  • Performing fine-grained performance optimization, both in term of algorithms (for example rewriting a more efficient broad-phase approach) and in term of implementation (for example writing a SIMD-powered constraints solver).
  • Performance improvements on nalgebra itself (the linear-algebra crate nphysics is based on).
  • Adding parallelism to nphysics and ncollide.

The end-goal is to be at least as fast as Box2D and Bullet Physics, while keeping our broader set of features.

Finally, note that I have no plan to work on a GPU-based solution anytime soon.

Year 2021: integration and FFI

The year 2021 will be about the integration of nphysics with other solutions. This includes two major subjects:

  • Creating binding to allow the of nphysics from other programming languages. The first targets will be C/C++, C# (and perhaps python) in order to allow writing plugins for popular tools like Blender and Unity.
  • Start working on an open-source solution for networked physics based on nphysics.

This will extend the audience of nphysics to communities using other programming languages. This will also simplify its usage in popular game-development frameworks.

Subsequent years and conclusion

I believe it is too soon for me to tell what I project for years after 2021. There are many way things that can evolve, and this strongly depends on the needs of the community. For example we could improve existing algorithms to increase, e.g., the accuracy of fluid simulation and deformable bodies so they can reach a level of realism suitable for offline rendering.

In any case, I believe that nphysics will be ready to reach 1.0 either during 2021 or 2022. Hopefully major features like const-generics and specialization will have landed in the rustc compiler until then. Both these features will significantly alter the public method and type signatures of, e.g., nalgebra and thus will cause changes considered as breaking changes into nphysics too.

Finally, keep in mind nphysics is 100% free and open-source and is currently developed during my free time (and contributors do this in their free time too). So things may happen both in personal life, or financially, that can slow down or accelerate my developments. According to GitHub, the first commit on nphysics happened five years ago, though I’ve only been able to work on it steadily during the past couple of years: since the day I decided to work only part-time (3/5) so more time can be dedicated to contributing to the Rust ecosystem. 

My hope is to be able to maintain this part-time by compensating the reduced income with donations here on Patreon (for the most part) and Liberapay. Your help have been, is, and will remain extremely useful on that matter, so I owe you all huge thanks! My dream remain to be able to work full-time of my Rust open-source projects, though I must admit I don’t know exactly how to make this happen. So please let me know if you have any idea or guideline to secure more sustainable funding to reach this goal!

Thank you all for reading this, and for your support!

Please share any comments or advice you have!

Tier Benefits
Recent Posts