A real-time cloth physics simulation engine built with JavaScript and Verlet integration. Features dynamic mesh cutting, constraint solving, and comprehensive performance benchmarking.
- Real-time Verlet physics integration with constraint solving
- Dynamic mesh topology - cut fabric and watch it separate
- Mouse-based interactive cloth manipulation
- Built-in performance monitoring and stress testing
- 800+ FPS with 5,200 particles (0.8-2.3ms frame time)
| Scenario | Grid Size | Particles | Edges | Purpose |
|---|---|---|---|---|
| Baseline | 40x20 | 800 | 1,520 | Standard reference |
| Heavy | 60x30 | 1,800 | 3,420 | Increased complexity |
| Very Heavy | 80x40 | 3,200 | 7,281 | Stress test |
| Multiple Cloths | 20x15 (x2) | 600 each | 1,140 each | Multi-system |
| Metric | Baseline | Heavy | Very Heavy |
|---|---|---|---|
| Avg FPS | 1200+ | 900+ | 826 |
| Avg Frame Time | 0.83ms | 1.11ms | 1.21ms |
| Min Frame Time | 0.60ms | 0.75ms | 0.80ms |
| Max Frame Time | 1.50ms | 1.80ms | 2.30ms |
| Constraint Iterations | 4 | 4 | 4 |
- Physics update: Sub-millisecond per iteration
- Constraint solving: 4 passes per frame for stable simulation
- Memory usage: Efficient Float32Array and Uint16Array storage
- Scales linearly with particle and edge count
- Open
index.htmlin a web browser - Performance stats display in real-time on the right side
- Mouse drag: Cut the cloth by dragging across edges
- 1-4: Switch between test scenarios (Baseline, Heavy, Very Heavy, Multiple Cloths)
- R: Reset current scenario
Physics Engine: Verlet integration with Gauss-Seidel constraint solving (4 iterations/frame). Distance constraints maintain edge rest lengths. Pinned particles simulate cloth attachment.
Edge Splitting: On cut, two particles are created at the midpoint. Original edge replaced with two half-length edges. New particles disconnect from each other but maintain original connections, causing visible separation.
Performance: Baseline (40x20, 800 particles), Heavy (60x30, 1,800 particles), Very Heavy (80x40, 3,200 particles), Multiple Cloths (two separate systems).
index.html- Canvas and stats displaybenchmarkLoop.js- Main loop with performance monitoringgameLoop.js- Standard loop without benchmarkingphysicsScript.js- Verlet integration and constraintsrenderScript.js- Rendering and mesh generationtoolScript.js- Input handlingdataScript.js- Particle and edge data structures
Open for educational and personal use.