[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EHZP405QBMR3VN5A6XBMBJ":3,"skill-same:01M7EHZP405QBMR3VN5A6XBMBJ":67},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":28,"commitSha":29,"skillDirectory":30,"forksCount":13,"repositoryHtmlUrl":31,"repositoryHomepageUrl":6,"ownerHtmlUrl":32,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":33,"install":34,"resources":47},"01M7EHZP405QBMR3VN5A6XBMBJ","threejs-impl-physics",null,"Use when adding physics simulation to a Three.js scene: rigid bodies, collisions, constraints, or raycasting. Prevents the common mistake of wrong Vec3\u002FVector3 conversion, missing world.step(), or choosing the wrong engine. Covers cannon-es and Rapier with Three.js sync patterns, performance comparison. Keywords: physics, cannon-es, Rapier, rigid body, collider, collision, gravity, simulation, WASM, constraint, joint, objects fall, collision detection, bouncing, realistic movement.","mhyahya854\u002FAI-Second-Brain_Universal-Rules","mhyahya854","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F194078115?v=4","01M7EGSP2M9T858SDHJMXQ257Y","01M7EGSP3N6HN6879SVDPMD4DZ",0,"MIT","https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002FImpertio-Studio\u002FThree.js-Claude-Skill-Package\u002Fthreejs-impl-physics\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: threejs-impl-physics\ndescription: >\n  Use when adding physics simulation to a Three.js scene: rigid bodies,\n  collisions, constraints, or raycasting. Prevents the common mistake\n  of wrong Vec3\u002FVector3 conversion, missing world.step(), or choosing\n  the wrong engine. Covers cannon-es and Rapier with Three.js sync\n  patterns, performance comparison.\n  Keywords: physics, cannon-es, Rapier, rigid body, collider, collision, gravity, simulation, WASM, constraint, joint, objects fall, collision detection, bouncing, realistic movement.\nlicense: MIT\ncompatibility: \"Designed for Claude Code. Requires Three.js r160+.\"\nmetadata:\n  author: OpenAEC-Foundation\n  version: \"1.0\"\n---\n\n# threejs-impl-physics\n\n## Quick Reference\n\n### Engine Selection Decision Tree\n\n| Criterion | cannon-es | Rapier |\n|-----------|-----------|--------|\n| Scene size | \u003C 100 bodies | 100–10,000+ bodies |\n| Determinism needed | No | Yes (cross-platform) |\n| CCD (fast objects) | Limited | Full support |\n| Bundle size budget | ~100 KB | ~300–600 KB (WASM) |\n| Initialization | Synchronous | Async (MUST `await init()`) |\n| Prototyping speed | Faster (simpler API) | Slower (builder pattern) |\n| R3F integration | `@react-three\u002Fcannon` | `@react-three\u002Frapier` |\n\n**Rule:** ALWAYS use Rapier for production applications requiring determinism, CCD, or > 100 bodies. Use cannon-es for prototyping and simple scenes.\n\n### Critical Warnings\n\n**NEVER** forget to call `world.step()` in the animation loop — physics bodies will NOT move without it.\n\n**NEVER** use `mesh.position.copy(body.position)` with Rapier — Rapier returns plain `{x, y, z}` objects, NOT `CANNON.Vec3`. ALWAYS use `mesh.position.set(pos.x, pos.y, pos.z)`.\n\n**NEVER** use Rapier APIs before `await RAPIER.init()` completes — ALL Rapier classes are undefined until WASM loads.\n\n**NEVER** use `Trimesh` \u002F `trimesh` colliders on dynamic bodies — triangle meshes are STATIC only in both engines. Use `ConvexPolyhedron` \u002F `convexHull` for dynamic concave geometry.\n\n**NEVER** create physics bodies without corresponding Three.js meshes unless intentionally creating invisible colliders — orphaned bodies waste simulation budget.\n\n---\n\n## cannon-es\n\n### World Setup\n\n```js\nimport * as CANNON from 'cannon-es';\n\nconst world = new CANNON.World();\nworld.gravity.set(0, -9.82, 0);\nworld.broadphase = new CANNON.SAPBroadphase(world);\nworld.solver.iterations = 10;\nworld.allowSleep = true;\n```\n\nALWAYS set `world.allowSleep = true` — sleeping bodies skip simulation and dramatically improve performance.\n\nALWAYS use `SAPBroadphase` for scenes with > 20 bodies. `NaiveBroadphase` is O(n^2).\n\n### Body Types\n\n| Type | Mass | Behavior |\n|------|------|----------|\n| `CANNON.Body.DYNAMIC` | > 0 | Affected by forces and collisions |\n| `CANNON.Body.STATIC` | 0 | Immovable, infinite mass |\n| `CANNON.Body.KINEMATIC` | 0 | Moved programmatically, pushes dynamic bodies |\n\n```js\nconst body = new CANNON.Body({\n  mass: 5,\n  position: new CANNON.Vec3(0, 10, 0),\n  shape: new CANNON.Box(new CANNON.Vec3(1, 1, 1)), \u002F\u002F half-extents\n  linearDamping: 0.01,\n  angularDamping: 0.01,\n});\nworld.addBody(body);\n```\n\n### Shape Types\n\n| Shape | Constructor | Notes |\n|-------|------------|-------|\n| `Box` | `new CANNON.Box(halfExtents: Vec3)` | Axis-aligned box |\n| `Sphere` | `new CANNON.Sphere(radius)` | Cheapest collision shape |\n| `Cylinder` | `new CANNON.Cylinder(rTop, rBottom, height, segments)` | Cylinder |\n| `Plane` | `new CANNON.Plane()` | Infinite ground plane |\n| `ConvexPolyhedron` | `new CANNON.ConvexPolyhedron({vertices, faces})` | Custom convex hull |\n| `Trimesh` | `new CANNON.Trimesh(vertices, indices)` | STATIC only |\n| `Heightfield` | `new CANNON.Heightfield(data, {elementSize})` | Terrain |\n| `Particle` | `new CANNON.Particle()` | Point particle |\n\n### Materials and Contacts\n\n```js\nconst groundMat = new CANNON.Material('ground');\nconst ballMat = new CANNON.Material('ball');\nconst contact = new CANNON.ContactMaterial(groundMat, ballMat, {\n  friction: 0.4,\n  restitution: 0.6,\n});\nworld.addContactMaterial(contact);\n\n\u002F\u002F Assign materials to bodies\ngroundBody.material = groundMat;\nballBody.material = ballMat;\n```\n\nALWAYS assign materials to bodies after creating ContactMaterial — without assignment, the ContactMaterial has NO effect.\n\n### Constraints\n\n| Constraint | Constructor | Use Case |\n|-----------|------------|----------|\n| `PointToPointConstraint` | `(bodyA, pivotA, bodyB, pivotB)` | Ball joint |\n| `DistanceConstraint` | `(bodyA, bodyB, distance)` | Fixed distance rod |\n| `HingeConstraint` | `(bodyA, bodyB, {pivotA, axisA, pivotB, axisB})` | Door hinge |\n| `LockConstraint` | `(bodyA, bodyB)` | Rigid lock |\n| `ConeTwistConstraint` | `(bodyA, bodyB, options)` | Ragdoll joints |\n| `Spring` | `(bodyA, bodyB, options)` | Damped spring |\n\n```js\nconst hinge = new CANNON.HingeConstraint(bodyA, bodyB, {\n  pivotA: new CANNON.Vec3(0, 0, 0),\n  axisA: new CANNON.Vec3(0, 1, 0),\n  pivotB: new CANNON.Vec3(-2, 0, 0),\n  axisB: new CANNON.Vec3(0, 1, 0),\n});\nworld.addConstraint(hinge);\n```\n\n### Events\n\n```js\nbody.addEventListener('collide', (event) => {\n  const { contact } = event;\n  \u002F\u002F contact.ni = contact normal\n  \u002F\u002F contact.ri = contact point relative to bodyA\n  \u002F\u002F contact.rj = contact point relative to bodyB\n});\nbody.addEventListener('sleep', () => { \u002F* body went to sleep *\u002F });\nbody.addEventListener('wakeup', () => { \u002F* body woke up *\u002F });\n```\n\n### Stepping\n\n```js\n\u002F\u002F ALWAYS use three-argument step for deterministic simulation\nconst fixedTimeStep = 1 \u002F 60;\nconst maxSubSteps = 3;\n\nfunction animate() {\n  const delta = clock.getDelta();\n  world.step(fixedTimeStep, delta, maxSubSteps);\n}\n```\n\n---\n\n## Rapier\n\n### WASM Initialization\n\n```js\nimport RAPIER from '@dimforge\u002Frapier3d-compat';\n\nawait RAPIER.init(); \u002F\u002F MUST await — ALL APIs undefined before this resolves\n\nconst gravity = { x: 0.0, y: -9.81, z: 0.0 };\nconst world = new RAPIER.World(gravity);\n```\n\nALWAYS wrap Rapier usage in an async function or top-level await. Calling ANY Rapier constructor before `init()` resolves throws a runtime error.\n\n### RigidBody Creation (Builder Pattern)\n\n```js\n\u002F\u002F Dynamic body\nconst bodyDesc = RAPIER.RigidBodyDesc.dynamic()\n  .setTranslation(0, 10, 0)\n  .setLinvel(0, 0, 0)\n  .setAngvel({ x: 0, y: 0, z: 0 })\n  .setLinearDamping(0.01)\n  .setAngularDamping(0.01)\n  .setCcdEnabled(true);\nconst rigidBody = world.createRigidBody(bodyDesc);\n\n\u002F\u002F Static body\nconst staticDesc = RAPIER.RigidBodyDesc.fixed().setTranslation(0, 0, 0);\nconst staticBody = world.createRigidBody(staticDesc);\n\n\u002F\u002F Kinematic (position-based)\nconst kinDesc = RAPIER.RigidBodyDesc.kinematicPositionBased();\nconst kinBody = world.createRigidBody(kinDesc);\n\n\u002F\u002F Kinematic (velocity-based)\nconst kinVelDesc = RAPIER.RigidBodyDesc.kinematicVelocityBased();\n```\n\n### Collider Shapes\n\n```js\nconst colliderDesc = RAPIER.ColliderDesc.cuboid(1, 1, 1)\n  .setRestitution(0.5)\n  .setFriction(0.7);\nworld.createCollider(colliderDesc, rigidBody);\n```\n\n| Shape | Constructor | Notes |\n|-------|------------|-------|\n| `ColliderDesc.cuboid(hx, hy, hz)` | Box half-extents | Most common |\n| `ColliderDesc.ball(radius)` | Sphere | Cheapest shape |\n| `ColliderDesc.capsule(halfHeight, radius)` | Capsule | Good for characters |\n| `ColliderDesc.cylinder(halfHeight, radius)` | Cylinder | |\n| `ColliderDesc.cone(halfHeight, radius)` | Cone | |\n| `ColliderDesc.convexHull(vertices)` | Convex hull | From Float32Array |\n| `ColliderDesc.trimesh(vertices, indices)` | Triangle mesh | STATIC only |\n| `ColliderDesc.heightfield(nrows, ncols, heights, scale)` | Terrain | |\n| `ColliderDesc.roundCuboid(hx, hy, hz, borderRadius)` | Rounded box | |\n\n### Ray Casting\n\n```js\nconst ray = new RAPIER.Ray({ x: 0, y: 10, z: 0 }, { x: 0, y: -1, z: 0 });\nconst hit = world.castRay(ray, 100, true);\nif (hit) {\n  const hitPoint = ray.pointAt(hit.timeOfImpact);\n  const hitCollider = world.getCollider(hit.colliderHandle);\n}\n```\n\n### CCD (Continuous Collision Detection)\n\nALWAYS enable CCD on fast-moving bodies to prevent tunneling through thin geometry:\n\n```js\nconst desc = RAPIER.RigidBodyDesc.dynamic().setCcdEnabled(true);\n```\n\n### Collision Events\n\n```js\nconst eventQueue = new RAPIER.EventQueue(true);\nworld.step(eventQueue);\n\neventQueue.drainCollisionEvents((handle1, handle2, started) => {\n  \u002F\u002F started === true: collision began\n  \u002F\u002F started === false: collision ended\n});\n\neventQueue.drainContactForceEvents((event) => {\n  const force = event.totalForceMagnitude();\n});\n```\n\n### Debug Rendering\n\n```js\nconst { vertices, colors } = world.debugRender();\nconst geometry = new THREE.BufferGeometry();\ngeometry.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));\ngeometry.setAttribute('color', new THREE.Float32BufferAttribute(colors, 4));\nconst material = new THREE.LineBasicMaterial({ vertexColors: true });\nconst lines = new THREE.LineSegments(geometry, material);\nscene.add(lines);\n```\n\n---\n\n## Three.js Sync Pattern\n\n### cannon-es Sync\n\n```js\n\u002F\u002F Store body-mesh pairs\nconst pairs = [];\n\nfunction addPhysicsObject(mesh, body) {\n  scene.add(mesh);\n  world.addBody(body);\n  pairs.push({ mesh, body });\n}\n\nfunction updatePhysics(delta) {\n  world.step(1 \u002F 60, delta, 3);\n  for (const { mesh, body } of pairs) {\n    mesh.position.copy(body.position);       \u002F\u002F Vec3 → Vector3 (compatible)\n    mesh.quaternion.copy(body.quaternion);    \u002F\u002F Quaternion → Quaternion (compatible)\n  }\n}\n```\n\ncannon-es `Vec3` and `Quaternion` are directly compatible with Three.js `.copy()`.\n\n### Rapier Sync\n\n```js\nconst pairs = [];\n\nfunction addPhysicsObject(mesh, rigidBody) {\n  scene.add(mesh);\n  pairs.push({ mesh, rigidBody });\n}\n\nfunction updatePhysics() {\n  world.step();\n  for (const { mesh, rigidBody } of pairs) {\n    const pos = rigidBody.translation();   \u002F\u002F returns {x, y, z}\n    const rot = rigidBody.rotation();      \u002F\u002F returns {x, y, z, w}\n    mesh.position.set(pos.x, pos.y, pos.z);\n    mesh.quaternion.set(rot.x, rot.y, rot.z, rot.w);\n  }\n}\n```\n\nNEVER use `.copy()` with Rapier return values — they are plain objects, NOT Three.js types.\n\n---\n\n## React Three Fiber Integration\n\n### @react-three\u002Frapier\n\n```jsx\nimport { Physics, RigidBody } from '@react-three\u002Frapier';\n\nfunction Scene() {\n  return (\n    \u003CPhysics gravity={[0, -9.81, 0]}>\n      \u003CRigidBody type=\"fixed\">\n        \u003Cmesh position={[0, -1, 0]}>\n          \u003CboxGeometry args={[20, 1, 20]} \u002F>\n          \u003CmeshStandardMaterial \u002F>\n        \u003C\u002Fmesh>\n      \u003C\u002FRigidBody>\n      \u003CRigidBody>\n        \u003Cmesh position={[0, 5, 0]}>\n          \u003CsphereGeometry args={[1]} \u002F>\n          \u003CmeshStandardMaterial \u002F>\n        \u003C\u002Fmesh>\n      \u003C\u002FRigidBody>\n    \u003C\u002FPhysics>\n  );\n}\n```\n\n### @react-three\u002Fcannon\n\n```jsx\nimport { Physics, useBox, useSphere } from '@react-three\u002Fcannon';\n\nfunction Floor() {\n  const [ref] = useBox(() => ({ mass: 0, args: [20, 1, 20], position: [0, -1, 0] }));\n  return (\n    \u003Cmesh ref={ref}>\n      \u003CboxGeometry args={[20, 1, 20]} \u002F>\n      \u003CmeshStandardMaterial \u002F>\n    \u003C\u002Fmesh>\n  );\n}\n```\n\n---\n\n## Performance Comparison\n\n| Feature | cannon-es | Rapier |\n|---------|-----------|--------|\n| Language | JavaScript | Rust compiled to WASM |\n| Real-time bodies | ~1,000 | ~10,000+ |\n| Bundle size | ~100 KB | ~300–600 KB |\n| CCD | Limited | Full support |\n| Deterministic | No | Yes (cross-platform) |\n| Debug rendering | Manual | Built-in `world.debugRender()` |\n| API style | Constructor-based | Builder pattern |\n\n---\n\n## Reference Links\n\n- [references\u002Fmethods.md](references\u002Fmethods.md) — API signatures for cannon-es and Rapier\n- [references\u002Fexamples.md](references\u002Fexamples.md) — Working integration examples\n- [references\u002Fanti-patterns.md](references\u002Fanti-patterns.md) — Common physics mistakes and fixes\n\n### Official Sources\n\n- https:\u002F\u002Fpmndrs.github.io\u002Fcannon-es\u002Fdocs\u002F\n- https:\u002F\u002Frapier.rs\u002Fdocs\u002Fuser_guides\u002Fjavascript\u002Fgetting_started\n- https:\u002F\u002Fgithub.com\u002Fpmndrs\u002Freact-three-rapier\n- https:\u002F\u002Fgithub.com\u002Fpmndrs\u002Fuse-cannon\n","# threejs-impl-physics\n\n## Quick Reference\n\n### Engine Selection Decision Tree\n\n| Criterion | cannon-es | Rapier |\n|-----------|-----------|--------|\n| Scene size | \u003C 100 bodies | 100–10,000+ bodies |\n| Determinism needed | No | Yes (cross-platform) |\n| CCD (fast objects) | Limited | Full support |\n| Bundle size budget | ~100 KB | ~300–600 KB (WASM) |\n| Initialization | Synchronous | Async (MUST `await init()`) |\n| Prototyping speed | Faster (simpler API) | Slower (builder pattern) |\n| R3F integration | `@react-three\u002Fcannon` | `@react-three\u002Frapier` |\n\n**Rule:** ALWAYS use Rapier for production applications requiring determinism, CCD, or > 100 bodies. Use cannon-es for prototyping and simple scenes.\n\n### Critical Warnings\n\n**NEVER** forget to call `world.step()` in the animation loop — physics bodies will NOT move without it.\n\n**NEVER** use `mesh.position.copy(body.position)` with Rapier — Rapier returns plain `{x, y, z}` objects, NOT `CANNON.Vec3`. ALWAYS use `mesh.position.set(pos.x, pos.y, pos.z)`.\n\n**NEVER** use Rapier APIs before `await RAPIER.init()` completes — ALL Rapier classes are undefined until WASM loads.\n\n**NEVER** use `Trimesh` \u002F `trimesh` colliders on dynamic bodies — triangle meshes are STATIC only in both engines. Use `ConvexPolyhedron` \u002F `convexHull` for dynamic concave geometry.\n\n**NEVER** create physics bodies without corresponding Three.js meshes unless intentionally creating invisible colliders — orphaned bodies waste simulation budget.\n\n---\n\n## cannon-es\n\n### World Setup\n\n```js\nimport * as CANNON from 'cannon-es';\n\nconst world = new CANNON.World();\nworld.gravity.set(0, -9.82, 0);\nworld.broadphase = new CANNON.SAPBroadphase(world);\nworld.solver.iterations = 10;\nworld.allowSleep = true;\n```\n\nALWAYS set `world.allowSleep = true` — sleeping bodies skip simulation and dramatically improve performance.\n\nALWAYS use `SAPBroadphase` for scenes with > 20 bodies. `NaiveBroadphase` is O(n^2).\n\n### Body Types\n\n| Type | Mass | Behavior |\n|------|------|----------|\n| `CANNON.Body.DYNAMIC` | > 0 | Affected by forces and collisions |\n| `CANNON.Body.STATIC` | 0 | Immovable, infinite mass |\n| `CANNON.Body.KINEMATIC` | 0 | Moved programmatically, pushes dynamic bodies |\n\n```js\nconst body = new CANNON.Body({\n  mass: 5,\n  position: new CANNON.Vec3(0, 10, 0),\n  shape: new CANNON.Box(new CANNON.Vec3(1, 1, 1)), \u002F\u002F half-extents\n  linearDamping: 0.01,\n  angularDamping: 0.01,\n});\nworld.addBody(body);\n```\n\n### Shape Types\n\n| Shape | Constructor | Notes |\n|-------|------------|-------|\n| `Box` | `new CANNON.Box(halfExtents: Vec3)` | Axis-aligned box |\n| `Sphere` | `new CANNON.Sphere(radius)` | Cheapest collision shape |\n| `Cylinder` | `new CANNON.Cylinder(rTop, rBottom, height, segments)` | Cylinder |\n| `Plane` | `new CANNON.Plane()` | Infinite ground plane |\n| `ConvexPolyhedron` | `new CANNON.ConvexPolyhedron({vertices, faces})` | Custom convex hull |\n| `Trimesh` | `new CANNON.Trimesh(vertices, indices)` | STATIC only |\n| `Heightfield` | `new CANNON.Heightfield(data, {elementSize})` | Terrain |\n| `Particle` | `new CANNON.Particle()` | Point particle |\n\n### Materials and Contacts\n\n```js\nconst groundMat = new CANNON.Material('ground');\nconst ballMat = new CANNON.Material('ball');\nconst contact = new CANNON.ContactMaterial(groundMat, ballMat, {\n  friction: 0.4,\n  restitution: 0.6,\n});\nworld.addContactMaterial(contact);\n\n\u002F\u002F Assign materials to bodies\ngroundBody.material = groundMat;\nballBody.material = ballMat;\n```\n\nALWAYS assign materials to bodies after creating ContactMaterial — without assignment, the ContactMaterial has NO effect.\n\n### Constraints\n\n| Constraint | Constructor | Use Case |\n|-----------|------------|----------|\n| `PointToPointConstraint` | `(bodyA, pivotA, bodyB, pivotB)` | Ball joint |\n| `DistanceConstraint` | `(bodyA, bodyB, distance)` | Fixed distance rod |\n| `HingeConstraint` | `(bodyA, bodyB, {pivotA, axisA, pivotB, axisB})` | Door hinge |\n| `LockConstraint` | `(bodyA, bodyB)` | Rigid lock |\n| `ConeTwistConstraint` | `(bodyA, bodyB, options)` | Ragdoll joints |\n| `Spring` | `(bodyA, bodyB, options)` | Damped spring |\n\n```js\nconst hinge = new CANNON.HingeConstraint(bodyA, bodyB, {\n  pivotA: new CANNON.Vec3(0, 0, 0),\n  axisA: new CANNON.Vec3(0, 1, 0),\n  pivotB: new CANNON.Vec3(-2, 0, 0),\n  axisB: new CANNON.Vec3(0, 1, 0),\n});\nworld.addConstraint(hinge);\n```\n\n### Events\n\n```js\nbody.addEventListener('collide', (event) => {\n  const { contact } = event;\n  \u002F\u002F contact.ni = contact normal\n  \u002F\u002F contact.ri = contact point relative to bodyA\n  \u002F\u002F contact.rj = contact point relative to bodyB\n});\nbody.addEventListener('sleep', () => { \u002F* body went to sleep *\u002F });\nbody.addEventListener('wakeup', () => { \u002F* body woke up *\u002F });\n```\n\n### Stepping\n\n```js\n\u002F\u002F ALWAYS use three-argument step for deterministic simulation\nconst fixedTimeStep = 1 \u002F 60;\nconst maxSubSteps = 3;\n\nfunction animate() {\n  const delta = clock.getDelta();\n  world.step(fixedTimeStep, delta, maxSubSteps);\n}\n```\n\n---\n\n## Rapier\n\n### WASM Initialization\n\n```js\nimport RAPIER from '@dimforge\u002Frapier3d-compat';\n\nawait RAPIER.init(); \u002F\u002F MUST await — ALL APIs undefined before this resolves\n\nconst gravity = { x: 0.0, y: -9.81, z: 0.0 };\nconst world = new RAPIER.World(gravity);\n```\n\nALWAYS wrap Rapier usage in an async function or top-level await. Calling ANY Rapier constructor before `init()` resolves throws a runtime error.\n\n### RigidBody Creation (Builder Pattern)\n\n```js\n\u002F\u002F Dynamic body\nconst bodyDesc = RAPIER.RigidBodyDesc.dynamic()\n  .setTranslation(0, 10, 0)\n  .setLinvel(0, 0, 0)\n  .setAngvel({ x: 0, y: 0, z: 0 })\n  .setLinearDamping(0.01)\n  .setAngularDamping(0.01)\n  .setCcdEnabled(true);\nconst rigidBody = world.createRigidBody(bodyDesc);\n\n\u002F\u002F Static body\nconst staticDesc = RAPIER.RigidBodyDesc.fixed().setTranslation(0, 0, 0);\nconst staticBody = world.createRigidBody(staticDesc);\n\n\u002F\u002F Kinematic (position-based)\nconst kinDesc = RAPIER.RigidBodyDesc.kinematicPositionBased();\nconst kinBody = world.createRigidBody(kinDesc);\n\n\u002F\u002F Kinematic (velocity-based)\nconst kinVelDesc = RAPIER.RigidBodyDesc.kinematicVelocityBased();\n```\n\n### Collider Shapes\n\n```js\nconst colliderDesc = RAPIER.ColliderDesc.cuboid(1, 1, 1)\n  .setRestitution(0.5)\n  .setFriction(0.7);\nworld.createCollider(colliderDesc, rigidBody);\n```\n\n| Shape | Constructor | Notes |\n|-------|------------|-------|\n| `ColliderDesc.cuboid(hx, hy, hz)` | Box half-extents | Most common |\n| `ColliderDesc.ball(radius)` | Sphere | Cheapest shape |\n| `ColliderDesc.capsule(halfHeight, radius)` | Capsule | Good for characters |\n| `ColliderDesc.cylinder(halfHeight, radius)` | Cylinder | |\n| `ColliderDesc.cone(halfHeight, radius)` | Cone | |\n| `ColliderDesc.convexHull(vertices)` | Convex hull | From Float32Array |\n| `ColliderDesc.trimesh(vertices, indices)` | Triangle mesh | STATIC only |\n| `ColliderDesc.heightfield(nrows, ncols, heights, scale)` | Terrain | |\n| `ColliderDesc.roundCuboid(hx, hy, hz, borderRadius)` | Rounded box | |\n\n### Ray Casting\n\n```js\nconst ray = new RAPIER.Ray({ x: 0, y: 10, z: 0 }, { x: 0, y: -1, z: 0 });\nconst hit = world.castRay(ray, 100, true);\nif (hit) {\n  const hitPoint = ray.pointAt(hit.timeOfImpact);\n  const hitCollider = world.getCollider(hit.colliderHandle);\n}\n```\n\n### CCD (Continuous Collision Detection)\n\nALWAYS enable CCD on fast-moving bodies to prevent tunneling through thin geometry:\n\n```js\nconst desc = RAPIER.RigidBodyDesc.dynamic().setCcdEnabled(true);\n```\n\n### Collision Events\n\n```js\nconst eventQueue = new RAPIER.EventQueue(true);\nworld.step(eventQueue);\n\neventQueue.drainCollisionEvents((handle1, handle2, started) => {\n  \u002F\u002F started === true: collision began\n  \u002F\u002F started === false: collision ended\n});\n\neventQueue.drainContactForceEvents((event) => {\n  const force = event.totalForceMagnitude();\n});\n```\n\n### Debug Rendering\n\n```js\nconst { vertices, colors } = world.debugRender();\nconst geometry = new THREE.BufferGeometry();\ngeometry.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));\ngeometry.setAttribute('color', new THREE.Float32BufferAttribute(colors, 4));\nconst material = new THREE.LineBasicMaterial({ vertexColors: true });\nconst lines = new THREE.LineSegments(geometry, material);\nscene.add(lines);\n```\n\n---\n\n## Three.js Sync Pattern\n\n### cannon-es Sync\n\n```js\n\u002F\u002F Store body-mesh pairs\nconst pairs = [];\n\nfunction addPhysicsObject(mesh, body) {\n  scene.add(mesh);\n  world.addBody(body);\n  pairs.push({ mesh, body });\n}\n\nfunction updatePhysics(delta) {\n  world.step(1 \u002F 60, delta, 3);\n  for (const { mesh, body } of pairs) {\n    mesh.position.copy(body.position);       \u002F\u002F Vec3 → Vector3 (compatible)\n    mesh.quaternion.copy(body.quaternion);    \u002F\u002F Quaternion → Quaternion (compatible)\n  }\n}\n```\n\ncannon-es `Vec3` and `Quaternion` are directly compatible with Three.js `.copy()`.\n\n### Rapier Sync\n\n```js\nconst pairs = [];\n\nfunction addPhysicsObject(mesh, rigidBody) {\n  scene.add(mesh);\n  pairs.push({ mesh, rigidBody });\n}\n\nfunction updatePhysics() {\n  world.step();\n  for (const { mesh, rigidBody } of pairs) {\n    const pos = rigidBody.translation();   \u002F\u002F returns {x, y, z}\n    const rot = rigidBody.rotation();      \u002F\u002F returns {x, y, z, w}\n    mesh.position.set(pos.x, pos.y, pos.z);\n    mesh.quaternion.set(rot.x, rot.y, rot.z, rot.w);\n  }\n}\n```\n\nNEVER use `.copy()` with Rapier return values — they are plain objects, NOT Three.js types.\n\n---\n\n## React Three Fiber Integration\n\n### @react-three\u002Frapier\n\n```jsx\nimport { Physics, RigidBody } from '@react-three\u002Frapier';\n\nfunction Scene() {\n  return (\n    \u003CPhysics gravity={[0, -9.81, 0]}>\n      \u003CRigidBody type=\"fixed\">\n        \u003Cmesh position={[0, -1, 0]}>\n          \u003CboxGeometry args={[20, 1, 20]} \u002F>\n          \u003CmeshStandardMaterial \u002F>\n        \u003C\u002Fmesh>\n      \u003C\u002FRigidBody>\n      \u003CRigidBody>\n        \u003Cmesh position={[0, 5, 0]}>\n          \u003CsphereGeometry args={[1]} \u002F>\n          \u003CmeshStandardMaterial \u002F>\n        \u003C\u002Fmesh>\n      \u003C\u002FRigidBody>\n    \u003C\u002FPhysics>\n  );\n}\n```\n\n### @react-three\u002Fcannon\n\n```jsx\nimport { Physics, useBox, useSphere } from '@react-three\u002Fcannon';\n\nfunction Floor() {\n  const [ref] = useBox(() => ({ mass: 0, args: [20, 1, 20], position: [0, -1, 0] }));\n  return (\n    \u003Cmesh ref={ref}>\n      \u003CboxGeometry args={[20, 1, 20]} \u002F>\n      \u003CmeshStandardMaterial \u002F>\n    \u003C\u002Fmesh>\n  );\n}\n```\n\n---\n\n## Performance Comparison\n\n| Feature | cannon-es | Rapier |\n|---------|-----------|--------|\n| Language | JavaScript | Rust compiled to WASM |\n| Real-time bodies | ~1,000 | ~10,000+ |\n| Bundle size | ~100 KB | ~300–600 KB |\n| CCD | Limited | Full support |\n| Deterministic | No | Yes (cross-platform) |\n| Debug rendering | Manual | Built-in `world.debugRender()` |\n| API style | Constructor-based | Builder pattern |\n\n---\n\n## Reference Links\n\n- [references\u002Fmethods.md](references\u002Fmethods.md) — API signatures for cannon-es and Rapier\n- [references\u002Fexamples.md](references\u002Fexamples.md) — Working integration examples\n- [references\u002Fanti-patterns.md](references\u002Fanti-patterns.md) — Common physics mistakes and fixes\n\n### Official Sources\n\n- https:\u002F\u002Fpmndrs.github.io\u002Fcannon-es\u002Fdocs\u002F\n- https:\u002F\u002Frapier.rs\u002Fdocs\u002Fuser_guides\u002Fjavascript\u002Fgetting_started\n- https:\u002F\u002Fgithub.com\u002Fpmndrs\u002Freact-three-rapier\n- https:\u002F\u002Fgithub.com\u002Fpmndrs\u002Fuse-cannon\n",{"name":5,"license":14,"metadata":23,"description":26,"compatibility":27},{"author":24,"version":25},"OpenAEC-Foundation","1.0","Use when adding physics simulation to a Three.js scene: rigid bodies, collisions, constraints, or raycasting. Prevents the common mistake of wrong Vec3\u002FVector3 conversion, missing world.step(), or choosing the wrong engine. Covers cannon-es and Rapier with Three.js sync patterns, performance comparison. Keywords: physics, cannon-es, Rapier, rigid body, collider, collision, gravity, simulation, WASM, constraint, joint, objects fall, collision detection, bouncing, realistic movement.\n","Designed for Claude Code. Requires Three.js r160+.","main","4c174e06a831864e98c30f630a7aa6c04738b094","skills\u002F_intake\u002Fgithub\u002FImpertio-Studio\u002FThree.js-Claude-Skill-Package\u002Fthreejs-impl-physics","https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules","https:\u002F\u002Fgithub.com\u002Fmhyahya854","2026-11-06 02:03:37",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add mhyahya854\u002FAI-Second-Brain_Universal-Rules --skill threejs-impl-physics",{"tool":40,"command":41},"bunx","bunx skills add mhyahya854\u002FAI-Second-Brain_Universal-Rules --skill threejs-impl-physics",{"tool":43,"command":44},"pnpm","pnpm dlx skills add mhyahya854\u002FAI-Second-Brain_Universal-Rules --skill threejs-impl-physics","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002FImpertio-Studio\u002FThree.js-Claude-Skill-Package\u002Fthreejs-impl-physics\u002FSKILL.md",true,[48,53,59,63],{"path":49,"resourceType":50,"resourceTypeDesc":51,"sizeBytes":13,"sourceHtmlUrl":52},".gitkeep","OTHER","其他","https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002FImpertio-Studio\u002FThree.js-Claude-Skill-Package\u002Fthreejs-impl-physics\u002F.gitkeep",{"path":54,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":57,"sourceHtmlUrl":58},"references\u002Fanti-patterns.md","REFERENCE","参考文档",8444,"https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002FImpertio-Studio\u002FThree.js-Claude-Skill-Package\u002Fthreejs-impl-physics\u002Freferences\u002Fanti-patterns.md",{"path":60,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":61,"sourceHtmlUrl":62},"references\u002Fexamples.md",9718,"https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002FImpertio-Studio\u002FThree.js-Claude-Skill-Package\u002Fthreejs-impl-physics\u002Freferences\u002Fexamples.md",{"path":64,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":65,"sourceHtmlUrl":66},"references\u002Fmethods.md",13471,"https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002FImpertio-Studio\u002FThree.js-Claude-Skill-Package\u002Fthreejs-impl-physics\u002Freferences\u002Fmethods.md",[68,76,84,92,99,106],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":72,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":18},"01M7EX4T721AAH60R0239P8WBZ","frontend-slides","Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT\u002FPPTX to web, or create slides for a talk\u002Fpitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.","https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002Fzarazhangrui\u002Ffrontend-slides\u002Ffrontend-slides\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002Fzarazhangrui\u002Ffrontend-slides\u002Ffrontend-slides\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":80,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":18},"01M7EX495RSHTTCEJVX7C83FA3","design-dna","Extract, define, and apply design DNA across three dimensions: design system (tokens), design style (qualitative feel), and visual effects (Canvas, WebGL, 3D, particles, shaders, scroll effects, etc.). Use this skill when: (1) a user wants to see the full 3-dimension design structure\u002Fschema, (2) a user provides images, screenshots, or URLs of reference designs and wants them analyzed into a structured JSON profile covering all three dimensions, (3) a user has a Design DNA JSON and content and wants a design generated from it, or (4) any combination of these phases. Triggers on \"design DNA\", \"extract design style\", \"analyze design\", \"design tokens from reference\", \"generate design from JSON\", \"design system from screenshot\", \"design profile\", \"style guide JSON\", \"visual effects analysis\", \"design with effects\", \"3d design analysis\".","https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002Fzanwei\u002Fdesign-dna\u002Fdesign-dna\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002Fzanwei\u002Fdesign-dna\u002Fdesign-dna\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":88,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":18},"01M7EX45RF2XZKRC3KDJDTT1PH","wireframe","Generate JSON wireframe with HTML preview","https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002Fyhassy\u002Fwireframe-skill\u002Fwireframe-skill\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002Fyhassy\u002Fwireframe-skill\u002Fwireframe-skill\u002FSKILL.md",[],[],{"skillNo":93,"name":94,"nameZh":6,"description":95,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":18},"01M7EWZEM3MHD48AYSYFR2C9JP","social-publishing","Schedule and publish social media posts across 13 platforms (X, LinkedIn, Instagram, Facebook Pages, TikTok, Discord, Telegram, YouTube, Reddit, WordPress, Pinterest) via the SocialClaw API. Use when the user wants to publish, schedule, or manage social media content programmatically. Requires SOCIALCLAW_API_KEY.","https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002Fwshobson\u002Fagents\u002Fsocial-publishing\u002FSKILL.md",[],[],{"skillNo":100,"name":101,"nameZh":6,"description":102,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":103,"categories":104,"keywords":105,"publishedAt":18},"01M7EWKDEK9840C728VXT78EQ9","hermes-tweet","Install and operate Hermes Tweet, a Hermes Agent plugin for X\u002FTwitter research, timeline reading, tweet analysis, and approval-gated private or state-changing operations. Use this skill when installing Hermes Tweet, researching X\u002FTwitter accounts, monitoring launch signals, investigating mentions, auditing giveaways, or preparing gated X operations. Use proactively when a Hermes Agent workflow needs current X\u002FTwitter context. Requires XQUIK_API_KEY for read and action tools.","https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002Fwshobson\u002Fagents\u002Fhermes-tweet\u002FSKILL.md",[],[],{"skillNo":107,"name":108,"nameZh":6,"description":109,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":110,"categories":111,"keywords":112,"publishedAt":18},"01M7EWASXP3NZWW95CJPT2CRWN","refactoring-ui","Audit and fix visual hierarchy, spacing, color, and depth in web UIs. Use when the user mentions \"my UI looks off\" (or amateur\u002Funprofessional), \"fix the design\", \"Tailwind styling\", \"color palette\", \"visual hierarchy\", \"design system\", \"spacing scale\", or \"component styling\". Also trigger when building consistent design tokens, creating dark mode themes, improving data-visualization clarity, or polishing UI details before launch. Covers grayscale-first workflow, constrained design scales, shadows, and component styling. For typeface selection, see web-typography. For usability audits, see ux-heuristics.","https:\u002F\u002Fgithub.com\u002Fmhyahya854\u002FAI-Second-Brain_Universal-Rules\u002Fblob\u002Fmain\u002Fskills\u002F_intake\u002Fgithub\u002Fwondelai\u002Fskills\u002Frefactoring-ui\u002FSKILL.md",[],[]]