Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsMay 30, 2026·3 min de lecture

Rapier — Fast 2D and 3D Physics Engine in Rust

A high-performance open-source physics engine for rigid body simulation, collision detection, and joint constraints, with native Rust and JavaScript/WASM bindings.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Rapier
Commande d'installation directe
npx -y tokrepo@latest install ccb8bee3-5bdf-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

Rapier is a set of 2D and 3D physics simulation libraries written in Rust with first-class WebAssembly support. It provides rigid body dynamics, collision detection, and joint constraints suitable for games, robotics simulations, and interactive applications.

What Rapier Does

  • Simulates rigid body dynamics with gravity, forces, and impulses
  • Detects collisions between convex shapes, trimeshes, and heightfields
  • Supports joints and constraints including revolute, prismatic, and fixed types
  • Provides continuous collision detection (CCD) to prevent tunneling
  • Exposes a deterministic simulation mode for lockstep multiplayer

Architecture Overview

Rapier is built on the nalgebra linear algebra library and uses an island-based constraint solver with SIMD acceleration. The collision detection pipeline implements a broad-phase sweep-and-prune algorithm followed by narrow-phase GJK/EPA queries. The engine compiles natively to Rust targets and to WebAssembly via wasm-bindgen, sharing the same core simulation code across platforms.

Self-Hosting & Configuration

  • Add rapier2d or rapier3d as a Cargo dependency for Rust projects
  • Use the @dimforge/rapier2d or rapier3d npm packages for JavaScript/WASM
  • Configure gravity, timestep, and solver iterations via IntegrationParameters
  • Enable CCD on fast-moving bodies to prevent objects passing through walls
  • Use debug rendering with Bevy or other engines via the rapier-debug-render feature

Key Features

  • Cross-platform via native Rust and WebAssembly compilation
  • Deterministic simulation for reproducible physics across clients
  • Bevy integration through the bevy_rapier plugin for game development
  • Event system for collision start/stop and contact force reporting
  • Serialization support for saving and restoring simulation state

Comparison with Similar Tools

  • Box2D — mature 2D engine but C++ only, no built-in Rust or WASM support
  • Bullet — feature-rich 3D engine but heavier and more complex API
  • PhysX — high-performance but proprietary NVIDIA SDK
  • Cannon.js — JavaScript-native physics but slower than WASM-based Rapier
  • Avian (formerly heron) — Bevy-specific wrapper but Rapier powers it underneath

FAQ

Q: Can Rapier handle soft bodies or fluids? A: No. Rapier focuses on rigid body simulation. For soft bodies, consider complementary libraries.

Q: Is the WASM build slower than native Rust? A: WASM performance is typically 1.5-3x slower than native, but still fast enough for real-time game physics in the browser.

Q: Does Rapier support multithreading? A: Yes. The parallel feature enables rayon-based multithreaded simulation on native targets.

Q: What game engines integrate with Rapier? A: Bevy (via bevy_rapier), Godot (via godot-rapier), and any engine that can call Rust or WASM code.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires