Rapier Physics Engine

repository·master·Indexed 26 days ago

https://github.com/dimforge/rapier

High-performance 2D and 3D physics engines written in Rust for games, animation, and robotics, with bindings for Python and JavaScript/TypeScript. Includes specialized crates such as mjcf-rs for MuJoCo XML parsing, rapier3d-mjcf for MJCF simulation, rapier3d-urdf for URDF file loading, and rapier3d-meshloader for STL, Collada, and Wavefront OBJ files. Also features a Panda3D-based visual gallery called rapier-testbed for exploring 3D examples.

Tokens
25.5K
Snippets
54
Records
192
Agent score
84%

What's inside Rapier

  1. Overview of Rapier physics engines

    master

    Rapier is a high-performance set of 2D and 3D physics engines written in Rust. It is designed for real-time applications such as video games, animation, and robotics, prioritizing speed, stability, and optional cross-platform determinism.

    Key features include:

    • Rigid-body collisions and forces
    • Joint constraints
    • Contact events and sensors
    • Snapshotting
    • Optional cross-platform determinism
    • JavaScript bindings
  2. Overview of mjcf-rs

    master

    mjcf-rs is a pure-Rust parser for the MuJoCo XML format (MJCF). It generates a typed Abstract Syntax Tree (AST) that mirrors the MJCF specification 1:1. The parser automatically handles preprocessing tasks such as:

    • <include> resolution
    • <default> class inheritance
    • Angle unit normalization

    This allows consumers to use the parsed AST directly without manually implementing MJCF preprocessing logic.

  3. Use high-level controllers in Rapier (Python)

    master

    Rapier provides higher-level helpers built on top of the core physics pipeline to simplify complex movement and control tasks. These include:

    • Kinematic character controller: For managing character movement, including stepping over obstacles and handling collisions.
    • PD / PID controllers: For precise position or velocity control using Proportional-Derivative or Proportional-Integral-Derivative logic.
    • Ray-cast vehicle controller (3D-only): For simulating vehicles using ray-casting for wheels.

    These controllers are available in the rapier3d module.

  4. Use rapier3d-urdf to load URDF files

    master
    The rapier3d-urdf crate allows you to convert URDF (Unified Robot Description Format) files into a collection of rigid-bodies, colliders, and joints compatible with the rapier3d physics engine. This is useful for simulating robots or articulated structures in Rapier.
  5. Understand the TypeScript configuration structure in rapier-compat

    master

    The rapier-compat package uses several tsconfig.json files to manage different compilation targets:

    • tsconfig.common.json: Contains shared TypeScript options used across the project.
    • tsconfig.pkg2d.json: Configuration specifically for compiling rapier2d-compat.
    • tsconfig.pkg3d.json: Configuration specifically for compiling rapier3d-compat.
    • tsconfig.json: Used for IDE support (e.g., VSCode) and running unit tests. This file includes Jest types.
  6. Get started with Rapier physics engines

    master

    Rapier provides 2D and 3D physics engines for Rust. To begin using the library:

    1. Consult the User Guides: Visit the official documentation at https://www.rapier.rs/docs/.
    2. Run Examples: You can explore the engine's capabilities by running the built-in examples using Cargo:
      • For 2D examples: cargo run --release --bin all_examples2
      • For 3D examples: cargo run --release --bin all_examples3 The source code for these examples is located in the examples2d/ and examples3d/ directories.
    3. Community Support: Ask questions or suggest features on the Discord server or by opening a GitHub issue.
  7. Build rapier-compat projects

    master

    To build the projects, use the scripts defined in the ./package.json file. The build process follows these steps:

    1. Build Rust WASM projects into their dedicated folders within ./builds/.
    2. Copy common JavaScript and generate dimension-specific JavaScript into a common ./pkg folder.
    3. Copy the contents of the ./pkg folder into each individual folder within ./builds.
  8. Contribute to the Rapier website

    master

    The Rapier website is built using Docusaurus 3 and consists of markdown files in the rapier.rs repository. To contribute:

    1. Fork the rapier.rs repository.
    2. Fix or improve the content.
    3. Create a pull request targeting the master branch.

    Rules for contributions:

    • All compilable code used to generate illustrations must be located in the src folder.
    • Downloadable examples must be located in the examples directory of the main rapier repository.
  9. Run Rapier Python test suite

    master

    To run the tests, first build the package with the --release flag, then install the necessary testing dependencies and execute pytest.

    maturin develop --release -m python/rapier-py-3d/Cargo.toml
    pip install pytest pytest-timeout hypothesis numpy matplotlib
    python -m pytest python/tests
    maturin develop --release -m python/rapier-py-3d/Cargo.toml
    pip install pytest pytest-timeout hypothesis numpy matplotlib
    python -m pytest python/tests