Configs2026年5月30日·1 分钟阅读

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.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Rapier
直接安装命令
npx -y tokrepo@latest install ccb8bee3-5bdf-11f1-9bc6-00163e2b0d79 --target codex

先 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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产