LumosLab-Innovation/3D-lab-skills / plugins/threejs-lab/skills/threejs-physics-simulation
threejs-physics-simulation
VerifiedBuild calibrated physics and numerical simulations for Three.js or learning labs. Use for forces, motion, collisions, rigid bodies, springs, pendulums, levers, fluids approximations, fields, electricity, density, heat, optics, particles, Babylon/cannon-es physics, timestep logic, units, and deterministic simulation controls.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 1.7 KB |
| agents/openai.yaml | config | 216 B |
| references/physics-patterns.md | markdown | 1.9 KB |
references/physics-patterns.md
View on GitHub# Physics Simulation Patterns
## Core Pattern
Keep three layers separate:
1. Constants and state: mass, velocity, charge, volume, temperature, unit labels.
2. Solver: deterministic function that updates state.
3. View sync: transforms, labels, vectors, charts, sounds.
This makes reset, testing, and agent `state_snapshot` straightforward.
## Common Lab Models
- Density: `rho = m / V`; show mass, volume, ratio, material comparison.
- Coulomb: `F = k q1 q2 / r^2`; clamp `r` to avoid singularity in UI.
- Capacitance: `C = epsilon A / d`; show plate area, distance, dielectric.
- Lever: torque balance `tau = F * r`; show pivot, arm, force vector.
- Projectile: fixed-step `v += g*dt`, `x += v*dt`; show trail and range.
- Pendulum: small-angle or numerical; expose damping/calibration.
- Heat: lumped model for school labs; show energy, mass, specific heat, temperature.
- Optics: ray lines and intersections are clearer than full wave simulation.
## Engine Use
Use `cannon-es` when collision/contact matters:
- world gravity as explicit vector.
- fixed timestep.
- one physics body per moving object.
- copy body position/quaternion to mesh after stepping.
- dispose event listeners and remove bodies on teardown.
For Babylon physics in an existing app, follow the local `enableScenePhysics` pattern and avoid mixing Babylon and Three.js in the same viewport.
## Calibration
Real labs drift. Keep knobs such as:
- damping coefficient
- restitution
- friction
- sensor bias
- display rounding
- timestep cap
Mark deliberate approximations in code with a short `ponytail:` comment and the upgrade path.
## Validation
Add the smallest check that catches broken physics:
- assert formula outputs for known inputs.
- assert reset returns initial state.
- assert conserved/invariant quantity where applicable.
- assert collision body count equals rendered moving object count.
For visual-only effects, browser screenshot QA is still required.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |