The year 2022 in Dimforge and our objectives for 2023

🎊🎊🎊 Happy new year 2023 everyone! 🎊🎊🎊

This article summarizes the most significant additions made in 2022 to our open-source crates for linear-algebra and physics simulation that we develop for the Rust community. We also present our main objectives for 2023.

Help us sustain our open-source work by sponsoring us on GitHub sponsors
Join us on discord!

Rapier: 2D and 3D physics

rapier logo

Rapier is a 2D and 3D physics engine for games, robotics, and animation written in Rust. Our goal for 2022 was to work on the missing high-level features of Rapier. This month we released the version 0.17 of Rapier with significant feature additions since the version 0.12 released in January 2022:

We were also amazed to see Rapier being used by Resolution Games for one of their latest VR multiplayer game: Ultimechs.

Kinematic character controller

We added a kinematic character controller to Rapier (as well as bevy-rapier and the JS bindings for rapier). The character controller was designed mostly with platformers in mind, supporting the following operations:

  • Slide on uneven terrains.
  • Interaction with dynamic bodies.
  • Climb stairs automatically.
  • Automatically snap the body to the floor when going downstairs.
  • Prevent sliding up slopes that are too steep.
  • Prevent sliding down slopes that are not steep enough.
  • Interactions with moving platforms.
  • Report information about the obstacles it hit on its path.

Dynamic vehicle controller

A dynamic vehicle controller was also a very popular feature request. We ported to Rust the vehicle controller from the Bullet physics engine, and integrated it to Rapier. This vehicle controller is based on ray-casting (one ray per wheel) to detect the ground. It simulates wheel friction, suspension, and braking.

note

Dynamic vehicle controllers are only usable with the main Rapier crates (rapier2d, rapier3d, rapier2d-f64, rapier3d-f64). It is not integrated yet into bevy-rapier and it is not usable yet with the JS bindings either.

Debug renderer

Foresight Mining Software Corporation

We added a debug-renderer to let the user see the scene as is actually seen by the physics engine, in order to easily spot common mistakes on objects dimentions and placements relative to their game assets.

Despite its name, Rapier’s debug-renderer doesn’t actually draw anything to the screen directly (except for the RapierDebugRenderPlugin of bevy-rapier which actually draws lines using Bevy’s rendering capabilities). Instead, the user is responsible for providing a method to draw lines using their favorite graphics engine. The DebugRenderPipeline simply returns the lines that need to be rendered. This makes it very easy to integrate to any game engine for quick physics debugging!

In JS, the lines to draw can be obtained with World.debugRender() which returns the vertex buffer and color buffer to render. See rapier.js#119 for integration examples with THREE.js, PIXI, and PlayCanvas.

Exploring destructible voxel-based physics

We explored the feasibility of destructible voxel physics with Rapier. This requires three parts:

  • A new Voxels shape in parry. This Voxels shape is composed of several grid-aligned voxels, where each voxel is represented as a pseudo-sphere (a sphere with cube-like corners along faces were the adjacent voxel exists). Using pseudo-spheres makes the collision-detection more efficient than using actual cubes.
  • Collision-detection (also implemented in parry) with these new Voxels shape, and, in particular, between two Voxels shapes.
  • The definition of a VoxelFracturePipeline in rapier responsible for calculating approximate stress values within a single Voxels shape in order to detected potential fracture locations.

This first exploration resulted in the following proof-of-concept: a room collapsing under its own weight. Each new colored body appearing is a fractured piece that separates from the main body:

note

This work on voxels hasn’t been merged yet because it is not efficient enough nor feature-complete enough for production use yet. It is only available on the voxels branch of Rapier and Parry.

Bevy-rapier: ergonomics improvements

The bevy-rapier2d and bevy-rapier3d crates provide plugins to use rapier easily with the bevy game engine. In April 2022 we released a complete rewrite of this plugin to make the API significantly more "bevy-friendly":

  • Colliders and rigid-bodies can be configured through multiple components.
  • Collider and rigid-body positioning operates through the familiar Transform/GlobalTransform components directly.
  • Mesh colliders can be created automatically after a Mesh asset is done loading, using the AsyncCollider or AsyncSceneCollider components.
  • All the components and query functions now rely on glam types instead of nalgebra. nalgebra types are only needed when calling into the raw Rapier objects (which can be used for niche operations that are not exposed explicitly by the plugin yet).
  • A wireframe debug-renderer can be enabled with the new RapierDebugRenderPlugin.

These changes were strongly inspired by the heron crate which had a way nicer API than bevy-rapier before this rewrite

Game highlight: Ultimechs

In September 2022, our sponsor Resolution Games launched the exciting free-to-play multiplayer VR game: Ultimechs. Based on Unity, Ultimechs relies on our Rapier physics engine for physics. You can read more about Resolution Games’ use of Rust alongside Unity in their May 20 Insight.

Sparkl: exploring MPM physics simulation

The Sparkl project is entirely sponsored by Foresight Mining Software Corporation which currently leverages it in production for industrial applications.

Foresight Mining Software Corporation

We silently released in December 2022 our open-source MPM (Material Point Method) physics simulation libraries: sparkl2d, sparkl3d. In their current form, they supports 2D and 3D particle-based deformable physics simulation with various materials, including sand, snow, elasticity and fracture. They do not support two-way coupling with rapier yet, meaning that Rapier colliders can be used to define the ground using boxes or heightfields, but interaction with dynamic bodies isn’t implemented yet.

Sparkl runs on CUDA-enabled GPUs only (running on multiple GPUs is supported). All the CUDA kernels are written 100% in Rust thanks to the Rust CUDA Project.

nalgebra: linear-algebra

nalgebra logo

nalgebra is a general-purpose linear-algebra library for Rust. It supports low-dimensional, high-dimensional, sparse matrices, as well as geometric transformations (rotations, isometries, etc.)

In 2022, most of our efforts went in Rapier rather than nalgebra itself. Most new features were added by the community, including:

  • Matrix slices were renamed as matrix views to avoid confusion with rust slices (by Andlon #1178).
  • Enabling the rayon feature of nalgebra will enable theMatrix::par_column_iter and Matrix::par_column_iter_mut methods. As their names suggest, these are rayon-based parallel iterators on the matrix’s columns (by geo-ant #1165).
  • Generalized eigenvalues problem resolution, generalized eigenvalues/eigenvector calculations, and QZ decomposition have been added to nalgebra-lapack (by metric-space #1067 and geoeo #1106).
  • Performance of the product of two sparse matrices in nalgebra-sparse has been improved significantly (by smr97 #1081).

Check out the Changelog for details on the other additions.


What’s next in 2023

Because we focused on features during the past two years, we will take a different route for 2023. In its current form, Rapier looks complete enough feature-wise to fit most game use-cases. So our main objective will be to work on bug fixes, user-experience improvements, and documentation. This quality improvement effort will be focused mainly on Rapier, and include for example:

  • Addressing most bugs reported on GitHub in 2022 and before, as well as complaints that are frequently reported on Discord (for example, related to some limitations of the character-controller when it hits vertical walls).
  • Reduce risks of internal panics in Rapier (for example when a rigid-body has a NaN position).
  • Make the debugging experience nicer with the JS bindings by detecting potential problems (and raising an exception) before reaching the WASM module.

In order to get a better awareness of Rapier’s ergonomics issues and bugs, we will be working on a small physics sandbox app. It is currently closed-source, but will be open-sourced once it is more fleshed-out and usable. Think of something similar Phun/Algodoo but written in Rust, based on Rapier, compatible with WASM (i.e. runs on the browser), and handling both 2D and 3D (in two different apps. sharing the same codebase).

Writing this physics sandbox will also be the opportunity to explore the scaling large-scale distributed physics simulation. This exploratory work is sponsored by Futurewei.


Thanks

We can’t thank enough:

Thanks to all the former, current and new supporters through GitHub sponsors! This helps us tremendously to sustain our Free and Open-Source work.

Foresight Mining Software Corporation





This help is greatly appreciated and allows us to continue working on our open-source projects. Finally, a huge thanks to the whole community and code contributors!