Getting started
Setting up Rapier with Cargo
rapier relies on the official Rust package manager
Cargo for dependency resolution and compilation. Therefore,
making rapier ready to use in your project is simply a matter of
adding a new dependency to your Cargo.toml file. You can either use the rapier2d
crate for 2D physics simulation or the rapier3d crate
for 3D physics simulation. For high-precision simulation using 64-bits floats, use the rapier2d-f64
crate or the rapier3d-f64 crate.
Until rapier reaches 1.0, it is strongly recommended to always use its latest published version, though you may encounter breaking changes from time to time.
To get the best of rapier multiple features can be enabled optionally:
parallel: enables parallelism of the physics pipeline with therayoncrate.serde-serialize: enables serialization of the physics components withserde.enhanced-determinism: enables cross-platform determinism (assuming the rest of your code is also deterministic) across all 32-bit and 64-bit platforms that implements the IEEE 754-2008 standard strictly. This includes most modern processors as well as WASM targets.simd8: widens the SIMD of the solver from 4 to 8 lanes (32-bit floats only). Note that the compiler only emits actual 256-bit instructions on an AVX-enabled target (e.g. withRUSTFLAGS="-C target-cpu=native"); otherwise the 8-lanes path will be much slower (it will be emulated as two 128-bit halves).block-solver: couples the two normal constraints of a contact pair into a single 2x2 solve. This is enabled by default in 2D, and disabled by default in 3D where it is less effective.fem: adds an alternative FEM solver for the soft-bodies, selected body by body.unsync-callbacks: drops theSyncrequirement from the physics hooks and the event handlers. As a side effect, this removes the thread-pool API of the physics pipeline.debug-render: enables the debug-renderer of Rapier.profiler: enables the internal profiler, which gives the time spent by each stage of a timestep.
SIMD optimizations (based on the wide crate) are always enabled: the
solver processes 4 contact manifolds per instruction (8 with the simd8 feature), and falls back to scalar code on
targets without SIMD support.
Currently, the enhanced-determinism feature cannot be enabled at the same time as the simd8 feature,
which changes the SIMD lane width and therefore the simulation results compared to when simd8 isn’t enabled.