
Flit Physics
io.github.brashler由 GitHub 账号 brashler 发布v0.2.2更新于 Oct 24, 2026
Tiny sphere-physics engine for three.js games: spawn, step, raycast, InstancedMesh-ready positions
概览
本地 MCP 服务器,封装面向 three.js 游戏的轻量球体物理引擎 Flit,让助手生成粒子、推进模拟并进行射线检测。
- 可以做什么
- 查看引擎信息并重置世界参数,如重力、弹性、地面、边界、静止速度与高度场地形,支持雨滴、爆炸、网格、喷泉等生成预设,也可手动添加粒子。按固定步长推进模拟,并读回适合 InstancedMesh 同步的扁平 xyz 位置及已静止数量。在广相网格与地形上投射射线以查找命中。
- 适用场景
- 适合在构建或原型化需要球体碰撞、重力、地形或射线检测的小型 three.js 游戏或演示时使用,让助手直接驱动模拟并查看粒子状态,而无需先编写集成代码。
- 运行要求
- 作为本地 stdio 进程在桌面运行,通过 npx 配合 vite-node 启动仓库中的 mcp/server.ts,因此需要本地存在 Flit 仓库,并安装 Node.js 及其依赖。未声明认证、环境变量或请求头。
安装
在 SourceWeft 中
- 打开 控制台中的 Flit Physics,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
Flit
Flit is a tiny little physics engine for 3js. It doesn't do much yet! but I believe!
Spheres, collisions, raycasts, gravity, and a spatial-hash broadphase — nothing more, on purpose.
All simulation state lives in flat Float32Arrays (structure-of-arrays), so
the CPU path doubles as the reference implementation for a future WebGPU
compute backend: same buffers, same kernels, no re-architecting.
What's in the box
World— point-sphere particles, semi-implicit Euler integration, impulse + positional-correction contact solver, infinite ground plane. Bodies that stay quiet SETTLE (per-body sleep driven by a stiction threshold), so resting piles cost ~nothing; a fast-enough impact wakes them, a slow push is held by static friction.Heightfield— 2.5D terrain as a grid of height posts, no meshing: bilinear height + central-difference normals sampled directly for collision, and a 2D Amanatides-Woo DDA for raycasts (index: -1).- Raycast — Amanatides-Woo voxel walk over the broadphase grid; candidates from the 3x3x3 block around the walked path so corner clips are never missed. Differential-tested against a brute-force oracle.
SpatialHash— uniform grid broadphase keyed by Morton (Z-order) cell codes. This is the Euclidean cousin in the LSH family: MinHash buckets documents by Jaccard similarity; this buckets positions so nearby points collide in the same bucket. Morton keys are bijective (no hash-collision pair bloat), invertible (no side table), and locality-ordered for a future sorted-array GPU backend.- Distance & bit utilities — squared Euclidean/L1/Minkowski/L∞/Hellinger/
chi-square/KL distances (ported from FLANN), Morton (Z-order) keys,
float bit-flips for radix sorting, octagonal approximate distance.
See
THIRD_PARTY_NOTICES.mdfor provenance and licenses.
For agents
Building a little three.js game or demo? Two ways in:
- Skill:
skills/flit/SKILL.md— copy theskills/flit/directory into your agent's skills path (e.g..claude/skills/,~/.code_puppy/skills/). It carries the 30-second integration recipe, the MCP option, measured performance envelope, and contributor rules. - MCP server (no code needed):
npm run mcp, or point your client at it:
Tools: flit_info, flit_reset (gravity/restitution/ground/bounds/
settleSpeed/heightfield), flit_spawn (rain/explosion/grid/fountain
presets), flit_add_particles, flit_step, flit_state, flit_raycast
— step/state return flat xyz positions shaped for InstancedMesh syncing
plus settledCount, so you can watch a pile go quiet.
Usage
Terrain and sleep are one option each:
Develop
Benchmarks
Deterministic seeds; numbers from a local dev machine, recorded at commit time (see commit messages for the full series, including rejected designs).
bench/broadphase.bench.ts— broadphase only, N=4096: xor-hash 3.4–3.7 ms (444 pairs, ~90% collision bloat) → Morton keys with ordered probing 3.5–3.7 ms (234 pairs, exact).bench/world.bench.ts— fullWorld.step, N=1024: xor-hash 0.85 ms/step → Morton ordered-probing 0.83 ms/step → 0.93 ms/step with the sequential-impulse velocity solver (4 iterations + LUT friction). Exact keys, real contacts, +11%.bench/scaling.bench.ts— two regimes. Fixed box (density rises): pairs scale ~N² from crowding physics. Scaled box (constant spawn density): flat O(N) ≈ 1.2 ms per 1000 through N=8000 while bodies are scattered. With gravity on, everything rains into a dense floor pile over ~2-4s (WARMUP=240to reproduce) — and since 0.3.0 the pile SETTLES: 34.2 → 9.2 ms/step at N=8000 (3.7x, inside the 60fps budget) as bodies fall asleep bottom-up. Settled bodies are skipped by integration, planes, and mutual contacts until a >1 m/s impact wakes them. (docs/issues/001— resolved; brief kept for the analysis and the remaining ideas: warm starting, adaptive iterations.)bench/raycast.bench.ts— 2000 seeded rays at N=4096: 63–68 µs/ray (vs ~160 µs for a brute-force O(N) oracle at the same density; the grid walk pulls further ahead as N grows).bench/morton-libs.bench.ts— codec bake-off vs npm libs (npm run bench:libs): ours 3.8 ns/encode, fast-morton MB 26.1, fast-morton LUT 43.8, @thi.ng/morton 539.9. In-house wins; the libs stay as devDependencies purely so the bake-off stays runnable.bench/threaded.bench.ts— WorkerWorld over a real worker thread (SAB ping-pong):kick()costs 0.014 ms on the main thread; with a 4 ms render workload a frame costs 8.84 ms pipelined vs 14.96 ms serial at N=8192 (113 fps vs 67). At N=1024 the 0.8 ms step hides entirely behind render (4.03 vs 4.80 ms).- Rejected on measurement (see commits): 63-bit BigInt keys (13× alloc regression); sorted-array + binary-search broadphase (1.4× slower than Map probing in JS — negative result recorded).
Roadmap
Morton-ordered broadphase cells— done, measured, shippedthree.js demo scene—npm run demo, 220 balls in a box (?terrainfor heightfield hills,?n=8000for load testing)Worker-threaded stepping—WorkerWorld: kick/waitForUpdate, SAB ping-pong zero-copy renderingSettled-pile solver cost— per-body sleep shipped (34.2 → 9.2 ms at N=8000); issue brief kept for the remaining ideas (warm starting, adaptive iterations)Heightfield terrain— shipped, no meshing; hooks left for more collider shapes- Raycast coarse occupancy filter (skip empty space faster) if
ray-heavy workloads show up — see commit
3173a6ffor the analysis - WebGPU compute backend once the CPU reference settles
License
MIT — see LICENSE. Third-party portions and their licenses are listed in
THIRD_PARTY_NOTICES.md.
来源:README.md,提交 754e05f
工具
0版本历史
1- v0.2.2最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分