Egg Belt Simulator
Live: https://bherbruck.github.io/eggsim/ · original 2D prototype: https://bherbruck.github.io/eggsim/2d/
Synthetic overhead camera feed of eggs on a conveyor, with physics (Three.js + Rapier) and pixel-accurate
ground truth for detection, rotated-box, segmentation and tracking models. The original 2D canvas prototype
is in legacy-2d/.
npm install
npm run dev # live app at http://localhost:5173
npm run build # dist/index.html, a single self-contained file
npm run artifact # also writes dist/artifact.html for claude.ai publishing
Export a dataset
npm run build
node scripts/export.mjs --frames 500 --preset jam --format seg --out data/jam
node scripts/export.mjs --frames 300 --settings my-profile.json --format obb --gpu
--format detect | obb | seg picks the YOLO label layout. data.yaml is written for Ultralytics.
--settings takes the JSON from Copy settings JSON in the app; --set k=v,... overrides single values.
--sequences K renders K runs with different seeds; the last one becomes the val split.
- Every frame also gets
json/<seq>/<frame>.json (bbox, rotated box, all polygons, egg size, velocity,
rolling, stacked) and mot/<seq>/gt/gt.txt for tracker evaluation.
- Labels come from an ID render, so they cover only the visible part of each object. Dirt patches are
separate
dirt objects with a parent egg id.
--profiles a.json,b.json cycles sequences through several saved profiles.
--randomize draws belt, flock, camera and lighting settings per sequence (and exposure, gain and noise
per frame) from built-in ranges; pass a spec file to use your own (scripts/lib/randomize.mjs documents
the format, and "extend": true merges it over the defaults). What each sequence drew is saved in
sessions.json.
--workers N renders N sequences at once; --jpg saves JPEG instead of PNG.
- Speed: software rendering manages about 1.5 frames per second per worker plus a few seconds of warm-up per
sequence. With a GPU (
--gpu) it should be far faster.
# 1000 randomized frames, 50 sequences of 20, 8 at a time
node scripts/export.mjs --randomize --frames 1000 --sequences 50 --workers 8 --jpg --gpu --out data/random
# 1000 frames from your own saved profiles
node scripts/export.mjs --profiles flockA.json,flockB.json --frames 1000 --sequences 20 --workers 8 --out data/mine
Install as a Claude Code plugin
/plugin marketplace add bherbruck/eggsim
/plugin install eggsim@eggsim
or from a shell: claude plugin marketplace add bherbruck/eggsim && claude plugin install eggsim@eggsim.
That adds the eggsim MCP server. It needs only Node 18+: on the first capture it installs
playwright-core and a headless Chromium (about 110 MB) into the plugin's data folder, which takes a minute
once. It loads the published simulator from GitHub Pages. Set EGGSIM_GPU=1 in your environment to render on
the GPU.
Agents and programmatic access
Three ways in, all producing the same labels:
- MCP server for Claude and other agents: install the plugin above, or
claude mcp add eggsim -- node /path/to/eggsim/mcp/server.mjs (a single bundled file; rebuild it with
npm run build:mcp after changing scripts/). Tools: list_presets, describe_settings,
start_session, set_settings, step, capture_frame, export_dataset, end_session.
capture_frame returns a downscaled preview inline, or writes full-resolution PNG, JSON, instance mask
and YOLO txt with save_dir.
- Export CLI:
node scripts/export.mjs (above).
- In-page API at
window.eggsim.api (version 1) for browser automation:
startSession({preset, settings, seed}), set(settings), step(seconds),
capture({image, labels, mask, ids, shapes, imageScale, imageFormat}), presets(), schema().
The page loaded is dist/index.html if built, otherwise the GitHub Pages copy; set EGGSIM_URL to override
and EGGSIM_GPU=1 to render on the GPU.
What a capture contains
session_id (new per session) and frame_index.
- Per object:
class, class_id, track_id (stable for the session), instance_id (1..N in this frame,
equal to the value in the instance mask), global_track_id (session_id:track_id), bbox_xywh,
obb_xy, polygons, area_px, truncated, visible_fraction, and egg size, velocity, rolling and
stacked flags. Dirt patches carry parent_track_id and parent_instance_id. ids: false drops the ids.
- Instance mask PNG: red + 256 × green =
instance_id, 0 = background.
Visible only