@web-engine-dev/physics3d-rapier
Rapier WASM backend for the @web-engine-dev/physics3d interface. Provides production-grade 3D physics simulation powered by Rapier's Rust-based engine compiled to WebAssembly.
Layer 4 · Simulation
Features
- Rapier WASM Backend: High-performance 3D physics via Rapier's Rust engine compiled to WASM
- Drop-in Replacement: Implements the
@web-engine-dev/physics3dinterface — swap backends without code changes - All Shape Types: Sphere, box, capsule, cylinder, cone, convex hull, trimesh, heightfield, compound
- 10 Joint Types: Fixed, revolute, prismatic, spherical, distance, rope, gear, motor, universal, D6
- Raycasting & Shape Casting: Full query support with hit normals and collision filtering
- CCD: Continuous collision detection for bullets, fast projectiles, and ragdoll limbs
- Sleep/Wake Management: Automatic sleep for resting bodies with wake-on-contact
- Debug Visualization: Wireframe colliders, contact points, AABB bounds, joint anchors, velocity vectors
Installation
bash
npm install @web-engine-dev/physics3d-rapier
# or
pnpm add @web-engine-dev/physics3d-rapierQuick Start
typescript
import { createRapier3DBackend } from '@web-engine-dev/physics3d-rapier';
import { PhysicsWorld3D } from '@web-engine-dev/physics3d';
// Create a Rapier-backed 3D physics world
const backend = await createRapier3DBackend();
const world = new PhysicsWorld3D(backend);
// Create a dynamic rigid body
const body = world.createRigidBody({
type: 'dynamic',
position: { x: 0, y: 10, z: 0 },
});
// Attach a sphere collider
world.createCollider(body, {
shape: 'sphere',
radius: 1.0,
restitution: 0.5,
friction: 0.3,
});
// Step simulation at fixed timestep
world.step(1 / 60);
// Raycasting
const hit = world.raycast({
origin: { x: 0, y: 20, z: 0 },
direction: { x: 0, y: -1, z: 0 },
maxDistance: 100,
});Backend Swapping
typescript
import { PhysicsWorld3D } from '@web-engine-dev/physics3d';
// All backends implement the same Physics3DBackend interface
// Game code remains identical regardless of backend choice:
const world = new PhysicsWorld3D(rapierBackend); // Production
const world = new PhysicsWorld3D(builtInBackend); // Simple gamesDependencies
@web-engine-dev/physics3d— Physics interface definitions@web-engine-dev/math— Vector, quaternion, and matrix types@dimforge/rapier3d— Rapier 3D WASM module