threejs-impl-physics

Implements physics simulation in Three.js scenes using cannon-es or Rapier engines.

1|Updated Aug 20, 2023
One-click install
npx skills add https://github.com/imanlangaran/mini-projects --skill threejs-impl-physics-imanlangaran
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: threejs-impl-physics
Source: https://github.com/imanlangaran/mini-projects/tree/main/react/three-gsap/.claude/skills/threejs-impl-physics
Command: npx skills add https://github.com/imanlangaran/mini-projects --skill threejs-impl-physics-imanlangaran

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires three, cannon-es, @dimforge/rapier3d-compat, @react-three/rapier, @react-three/cannon, and includes references (resource) components.

What problem does it solve? Adding realistic physics to a Three.js scene is error-prone: developers commonly forget world.step(), misuse Vec3/Vector3 conversions between engines, pick the wrong physics engine for their scale, or use trimesh colliders on dynamic bodies. This Skill provides correct, production-tested patterns for integrating cannon-es and Rapier with Three.js. ## Core Features & Use Cases - Engine Selection Guidance: Decision tree comparing cannon-es vs Rapier across scene size, determinism, CCD, bundle size, and React Three Fiber integration. - Complete API Coverage: World setup, body types, collider shapes, materials, constraints, raycasting, collision events, and debug rendering for both engines. - Anti-Pattern Prevention: Documents 10 common mistakes (missing world.step(), wrong half-extents, variable timesteps, WASM memory leaks) with wrong/correct code pairs. - Use Case: You are building a 3D product configurator where objects must fall, collide, and stack realistically. Use this Skill to set up a Rapier world with CCD-enabled dynamic bodies, sync them to Three.js meshes, and avoid tunneling through thin geometry. ## Quick Start Add physics to my Three.js scene with falling boxes that collide with a ground plane using Rapier.

Frequently Asked Questions about threejs-impl-physics

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add physics to a Three.js scene?

Create a physics world with cannon-es or Rapier, add rigid bodies matching your Three.js meshes, then call world.step() each animation frame and sync body positions to mesh positions. Rapier requires awaiting RAPIER.init() before any API calls.

cannon-es vs Rapier: which physics engine for Three.js?

Use Rapier for production apps needing determinism, CCD, or over 100 bodies; it handles 10,000+ bodies but adds 300-600 KB of WASM. Use cannon-es for prototyping and simple scenes under 100 bodies with its simpler API and ~100 KB bundle.

Why are my physics objects not moving in Three.js?

Bodies stay frozen when world.step() is missing from the animation loop. Call world.step(1/60, delta, 3) for cannon-es or world.step() for Rapier every frame before syncing mesh positions.

Why does mesh.position.copy() fail with Rapier?

Rapier's translation() and rotation() return plain {x, y, z} objects, not Three.js Vector3 instances. Use mesh.position.set(pos.x, pos.y, pos.z) instead. cannon-es Vec3 works with .copy() directly.

Can I use trimesh colliders on dynamic bodies?

No, trimesh colliders are static-only in both cannon-es and Rapier; dynamic trimesh causes tunneling and undefined behavior. Use ConvexPolyhedron or convexHull for dynamic concave geometry, decomposing with tools like v-hacd.

Does Rapier work with React Three Fiber?

Yes, use @react-three/rapier which provides declarative Physics and RigidBody components. For cannon-es, use @react-three/cannon with hooks like useBox and useSphere.