Skip to content

@web-engine-dev/physics2d-rapier

Rapier WASM backend for the @web-engine-dev/physics2d interface. Provides production-grade 2D physics simulation powered by the Rapier physics engine compiled to WebAssembly for near-native performance.

Layer 4 · Simulation

Features

  • Rapier WASM Backend: High-performance 2D physics via Rapier's Rust-based engine compiled to WASM
  • Drop-in Replacement: Implements the @web-engine-dev/physics2d interface — swap backends without changing game code
  • All Shape Types: Circle, polygon, edge, chain, compound shapes
  • 10 Joint Types: Revolute, prismatic, distance, weld, rope, gear, motor, mouse, friction, wheel
  • CCD Support: Continuous collision detection for fast-moving objects
  • Collision Filtering: Category/mask bitmask system (16 categories)
  • Debug Rendering: Wireframe colliders, contact points, AABB bounds, constraint anchors

Installation

bash
npm install @web-engine-dev/physics2d-rapier
# or
pnpm add @web-engine-dev/physics2d-rapier

Quick Start

typescript
import { createRapier2DBackend } from '@web-engine-dev/physics2d-rapier';
import { PhysicsWorld2D } from '@web-engine-dev/physics2d';

// Create a Rapier-backed 2D physics world
const backend = await createRapier2DBackend();
const world = new PhysicsWorld2D(backend);

// Add bodies and colliders using the standard physics2d API
const body = world.createRigidBody({
  type: 'dynamic',
  position: { x: 0, y: 10 },
});

world.createCollider(body, {
  shape: 'circle',
  radius: 0.5,
  restitution: 0.7,
});

// Step simulation (called in fixed update loop)
world.step(1 / 60);

Backend Architecture

The Rapier backend implements the same Physics2DBackend interface as the built-in solver:

typescript
// Game code uses the interface — backend is swappable
import { PhysicsWorld2D } from '@web-engine-dev/physics2d';

// Development: use built-in lightweight solver
const devWorld = new PhysicsWorld2D(builtInBackend);

// Production: use Rapier for accuracy
const prodWorld = new PhysicsWorld2D(rapierBackend);

// Same game code works with both

Dependencies

  • @web-engine-dev/physics2d — Physics interface definitions
  • @web-engine-dev/math — Vector and matrix types
  • @dimforge/rapier2d — Rapier 2D WASM module

Proprietary software. All rights reserved.