Dot-Fun/led-mapping
关于
Multi-camera, multi-controller 3D WLED mapping and spatial effect studio (Ternary ECC, sparse BA, Android/macOS fleet, Rust DDP). Built by dotfun.
人工智能与机器学习实测星标增长
- 24小时
- 0
- 7天
- 正在收集历史
- 15天
- 正在收集历史
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文3D Multi-Camera WLED Mapping Studio
Mapping randomly strung LEDs in 3D usually turns into a weekend of pain. You light one pixel at a time, wait ten minutes per camera angle, lose half the string to window reflections, and start over from scratch the first time a strand shifts or you plug in another box.
This repo skips all of that. Point whatever cameras you already own—iPhones, Android phones, MacBooks, USB 4K webcams—at any number of stock ESP32 WLED controllers on your network. Each scan round encodes every LED in ~2 seconds using a DC-balanced ternary error-correcting code over $\mathrm{GF}(3)$, strips out reflections with Strip Viterbi DP, solves true 3D coordinates with hardened multi-round bundle adjustment, patches living scenes in seconds without disturbing untouched lights, and drives every controller in lockstep as one 3D canvas over UDP DDP (:4048).
We built it at dotfun to map living rooms, staircases, whole houses, and trees in the woods without buying proprietary hardware or flashing custom WLED firmware.
How It Actually Works
Most optical mappers flash binary on/off codes that pump camera auto-exposure, or they scan one LED at a time until your battery dies. We took a different call:
- DC-balanced ternary ECC + Decode-First NNLS unmixing. Every LED flashes pure R, G, or B in ~2 seconds using a systematic linear code over $\mathrm{GF}(3)$ with minimum Hamming distance $d_{\min} \ge 3$ (9 frames up to 727 LEDs; 13 frames up to ~59,000 LEDs) that holds ~33/33/33% RGB balance across every frame so unlocked cameras don't pump exposure. The host calibrates a 3×3 color-crosstalk matrix, rejects static lamps and lit walls with a temporal chromatic-swing mask, decodes every active pixel in one vectorized pass, unmixes tight overlapping LEDs with bounded NNLS, and automatically runs strided recovery passes when milky silicone neon or dense COB strips blend together.
- Multi-round 3D solver with post-merge hardening & gravity auto-leveling. Walk around with any phone and tap SCAN ROUND to add angles. The solver enforces scale-adaptive baseline and parallax guards (
min(0.25, max(0.03, 0.04 * cam_span))+min_parallax_deg >= 5°), rejects mirror/glass ghost detections with Strip Viterbi DP, stitches separate rooms with robust RANSACSim(3)consensus (with optional movable Temp Bridge controllers), and runs post-merge per-bus jump-spike pruning plus a multi-round isolated 2-view singleton guard so bad cross-room rays never survive. Hardware IMU gravity vectors from Android and iOS—plus 1-click RANSAC vertical-plane auto-leveling—land every zone upright instead of tilted. Click any solved camera frustum in 3D to delete a bad shot and re-solve cleanly. - Paint Unmapped (
P) & 3D Coverage Mode. Hit Paint Unmapped (P) and Studio takes over the physical strings over DDP (held continuously via a0.8 skeepalive so WLED's live timeout never reverts it): unmapped LEDs glow bright RED, interpolated LEDs glow bright BLUE, and measured + temporary bridge LEDs switch OFF. The 3D Coverage view mirrors that ground truth in real time (green = measured, blue = interpolated), making missed corners obvious in the dark. - Living-scene updates (
Update / Patch Scene). Real installations change. Switch scan mode to Update / Patch Scene (patch_update) ordelta_ternaryand the fast anchored patch solver (~1–2 s) freezes all untouched measured LEDs in place while automatically detecting newly added LEDs and fallen or moved strings (> 15 pxacross 2+ views with>= 5°parallax). At scan start, Studio also refreshes live WLED gossip and hardware lengths—backing upproject.jsonbefore shrinking, compacting shrunken tails, growing expanded pins, and appending newly selected boxes atmax(global_id) + 1. Need to redo or retire a box? Use 1-clickRe-mapon a single controller (untouched boxes stay frozen) orRemoveto drop a retired/offline controller cleanly with zero scans. - Multi-scene picker, scene lock & duplicate. Switch, create, rename, duplicate, lock, or delete saved venues from the Top HUD Scene Picker. Locking a scene protects it with
423 Lockedagainst accidental scans, round edits, controller removals, or deletion—while still allowing 3D playback, Paint Unmapped, Duplicate, and Re-Solve. Active scene, per-scene shader/speed/brightness/FPS, and shared UI settings persist across refreshes and restarts, syncing live across all open browsers over/wswith zero-re-render binary WebSocket 3D previews. - Performant, lock-aware talking WLED monitor. Studio continuously watches your LAN whenever the active scene is unlocked using passive mDNS (
_wled._tcp+_http._tcp), dynamic WLED/json/nodesgossip (~1 seed GET per/24subnet every 5 s), and a lightweight 10 s heartbeat with 90 s offline debounce, MAC deduplication, anduptime-drop reboot detection. When a WLED controller is power-cycled (even briefly), changes IP, or comes back online, Studio automatically resyncs the liveEffectEngineso DDP resumes immediately without manual resync. When a new or reconnected WLED joins, Studio pushes a live/wstoast and speaks"<name> online."; when an active WLED drops off the network, Studio speaks"<name> offline.", pushes an offline alert, and highlights that controller's mapped LEDs in bright RED on the 3D canvas (even during live playback) until it returns. Speech uses local Qwen3-TTS (terran-advisor+ optional chime + pitch-preservingffmpeg atempoovertts-player, configurable viaLEDMAP_TTS_*, withafplayand opt-in system speech fallbacks andLEDMAP_MUTE_TTS=1mute override). Lock the active scene and the watcher stops completely (0% CPU, 0 background packets)—resuming immediately when you unlock. - Lockstep 3D DDP engine, LED Groups & Draggable Parallel Planes, per-scene custom modes & WLED hardware tools. A dedicated real-time thread (
ddp-rt) drives all controllers over Best-Effort UDP (IP_TOS = 0x00) with a continuous integrated speed clock (no phase jumps while dragging Speed),float32temporal error-diffusion dithering (silky slow fades with zero 8-bit stair-stepping), Auto-Sync FPS matched to your slowest WS2812B bus, and WS2812B bus-latch phase alignment so short and long strips update at the same millisecond. LED Groups & Parallel Planes Studio lets you assign LEDs into named groups (e.g., Tree, Sidewalk, Bushes, Inside) using a Polygon Lasso, 3D Paint/Erase Brush, or 1-click Controller & individual GPIO Pin strand chips—keeping the 3D viewport completely uncluttered with zero wireframe boxes. Toggle each group independently ON/OFF, assign any Parallel Planes animation, built-in 3D shader (including 3D Rainbow Vortex with live Reverse Direction toggle), custom per-scene Python effect, or saved Plane Preset to each group simultaneously (Multi-Group Show), and drag/tilt isolated Cyan/Coral parallel ceiling & floor planes per group with live physical preview on the real LEDs—automatically hiding & locking the planes whenever you aren't editing a group so you never bump them accidentally. Built-in 1-click tools optimize WLED/json/cfg(wifi.sleep, FPS cap,hw.led.ld, liveno-gc&maxbri, auto-rebooting if LED outputs need RMT re-init), trim oversized ghost LEDs per GPIO pin (losslessly remapping saved scan rounds,map_3d, and group LED IDs in place with zero re-solve drift), and export non-locking 2D/ledmap.jsonfallbacks. Deployment-specific Python shaders hot-reload within0.5 sfromprojects/<scene>/effects/(and global custom shaders fromhost/effects_custom/), receiving optionalEffectContext(xyz, controller masks, strandled_indices,bus_lengths,groups, and persistentstate) plus auto-generated live sliders and boolean toggles, and the standalone Rust binary (ledmap-rt) blasts zero-jitter DDP frames at ~0.32 ms per 2,000-LED frame.
Stated limits: Every camera needs to see a few LEDs in common with at least one other view (>= 8 shared LEDs, fallback 5) to land in the same 3D zone; disjoint rooms or distant trees solve as separate components until you capture a bridging round (or place a temporary Temp Bridge light between them). Reflections on mirrors or glass still need real parallax across at least two physical camera positions to reject cleanly.
What's in This Repo
| Directory | Stack | What it owns |
|---|---|---|
host/ |
Python 3.11+ (uv), FastAPI, OpenCV, SciPy |
Lock-aware 3-tier WLED discovery & voice announcer, diagnostics/optimizer/pin-trimmer, latch-aligned UDP DDP (:4048) streamer, auto-HTTPS (:8443) Safari Web Cam server, camera fleet manager, ternary ECC scanner, hardened multi-round & anchored-patch 3D solver, real-time 3D effect engine |
web/ |
Vite, React, TypeScript, Three.js | Full-bleed 3D Studio UI, Top HUD Scene Picker with lock & duplicate, multi-browser live settings sync, binary WS 3D preview, WLED watch pill / discovery toasts / 1-click Re-map, Remove, optimizer & Trim Pins modal, camera fleet PIP tray, QR onboarding modal, toggleable (C) & click-to-delete 3D camera frustums |
android-cam/ |
Kotlin, Camera2 (minSdk 24) |
Android camera node with manual AE/ISO/focus lock (plus EV+AE-lock fallback for older tablets), hardware gravity sensor, isolated HTTP server (zero CORS, 403 on browser Origin), on-phone field remote with busy lock & voice alerts, and 1-tap Wi-Fi self-updater |
ios-cam/ |
Swift, UIKit, AVFoundation, CoreMotion |
Native iOS 15+ camera companion with manual exposure/focus lock, hardware intrinsics, gravity vector, isolated HTTP server (zero CORS, 403 on browser Origin), field remote with busy lock & voice alerts, and OTA .ipa support |
macos-cam/ |
Swift, AVFoundation, AppKit |
Native HTTP camera bridge (:8781) + live desktop/web viewfinder for local and remote Macs; tolerates external camera locks (EMEET STUDIO) without dropping frames |
rust-engine/ |
Rust, rayon (ledmap-rt) |
Standalone zero-jitter 3D DDP player and Rayon parallel benchmark |
Quick Start & Security Posture
Start the macOS camera bridge (:8781), FastAPI backend (:8780 + :8443), and Three.js Studio UI (:5173) in one shot:
./scripts/dev.sh
Then open http://localhost:5173. Studio auto-discovers WLED controllers (passive mDNS + /json/nodes gossip), local macOS cameras over :8781, and phone cameras over mDNS (_ledcam._tcp), UDP broadcast (:8089), USB ADB, or HTTPS Web Cam (/cam).
macOS Dock Launcher & Start-on-Boot Service
Install the native macOS Dock launcher (~/Applications/LED Mapping Studio.app) and background launchd service (co.dotfun.led-mapping-studio, start-on-boot enabled):
./scripts/install-macos-launcher.sh
Clicking the Dock icon probes localhost, your local Wi-Fi/LAN (via Bonjour _ledmap._tcp.local.), and online Tailnet peers for any running Studio server—if one is already live on your network, it pops a native Server Picker letting you connect to it, enter a custom URL, or start a local server here (with an optional Remember this server checkbox and Dock right-click Switch Server...). When running locally, it manages the single background server via ./scripts/run-server.sh (Tailnet HTTPS + --lan-cam when Tailscale is connected, loopback fallback otherwise), restores the last active scene and playing effect automatically on boot, and opens Studio in a chromeless Chrome app window that auto-reloads whenever the server restarts or updates. Pass --no-dock, --no-boot, --open-mode=browser, or --remote-url=https://<studio-host> (pin directly to a remote server with zero local backend) to customize.
Security & Private Tailnet HTTPS
Studio is locked down by default and designed to run either locally on loopback or behind Tailscale HTTPS:
- Loopback-only by default: FastAPI, Vite, and the local
macos-cambridge bind to127.0.0.1. - Same-origin browser guard: Cross-origin HTTP writes are rejected with
403, cross-origin WebSocket upgrades are closed with1008, and forwardedX-Forwarded-Proto/X-Forwarded-Hostheaders are strictly validated (400on malformed values). - Private Tailnet HTTPS (recommended for multi-device use): Connect Tailscale and run:
The backend stays on loopback (./scripts/serve-tailnet.sh127.0.0.1), disables the self-signed:8443sidecar, exportsLEDMAP_PUBLIC_ORIGIN=https://<machine>.<tailnet>.ts.netfor QR codes andX-Studio-Hostphone callbacks, and lets Tailscale Serve terminate trusted HTTPS—your Tailnet grants decide who can connect. - Tailnet + Wi-Fi LAN Instant Web Cam (non-Tailnet phones on your Wi-Fi): Pass
--lan-cam(orLEDMAP_LAN_CAM=1):
Keeps the main HTTP server loopback-only (./scripts/serve-tailnet.sh --lan-cam127.0.0.1:8780) behind Tailscale Serve while enabling the companion self-signed HTTPS:8443sidecar (LEDMAP_HTTPS_BIND_HOST=0.0.0.0), so the Add Phone modal shows both the Tailnet HTTPS QR and a Wi-Fi LAN HTTPS (https://<server-lan-ip>:8443/cam) QR for guest/non-Tailnet phones on the same network. - Isolated mobile camera servers: Android and iOS camera nodes emit zero CORS headers, reject any request carrying a browser
Originheader with403 Forbidden, and validateX-Studio-HostURLs strictly. - Opt-in trusted LAN dev mode: On an isolated trusted LAN without Tailscale, explicitly opt in to non-loopback binding:
LEDMAP_BIND_HOST=0.0.0.0 ./scripts/dev.sh
Voice Monitor Configuration
When the active scene is unlocked, newly discovered or reconnected WLED controllers are announced aloud via WLEDAnnouncer. Tune or disable speech with environment variables:
| Variable | Default | Purpose |
|---|---|---|
LEDMAP_TTS_URL |
http://127.0.0.1:5002/v1/text-to-speech/terran-advisor/stream?speed=1.6&format=wav |
Local Qwen3-TTS WAV stream synthesis endpoint (pitch-preserved via ffmpeg atempo when installed) |
LEDMAP_TTS_BLEEP_PATH |
~/.claude/custom/sounds/terran_advisor_bleep.mp3 |
Optional chime played before spoken announcements |
LEDMAP_TTS_PLAYER_SOCK |
~/.claude/custom/tts-player/player.sock |
Optional serialized tts-player Unix socket (falls back to afplay / paplay / aplay) |
LEDMAP_TTS_RATE |
1.5 |
Pitch-preserving speech playback speed multiplier |
LEDMAP_TTS_VOLUME |
0.33 |
Announcement and chime volume multiplier |
LEDMAP_TTS_SYSTEM_FALLBACK |
0 when LEDMAP_TTS_URL is set |
Set to 1 to allow fallback to system say / spd-say / espeak-ng if local TTS is unreachable |
LEDMAP_MUTE_TTS |
(unset; auto-muted in pytest) | Set to 1 to silence host voice alerts while keeping live UI toasts active |
Prefer running each service by hand?
(cd macos-cam && swift build -c release)
(cd host && uv sync && uv run uvicorn ledmap.api.server:app --host 127.0.0.1 --port 8780)
(cd web && npm install && npm run dev)
Offline Simulation Mode & Sharing Modes
Develop and preview new 3D modes on any Mac or Linux laptop with zero WLED controllers or cameras on the network:
- Export a shareable scene bundle: In Studio, open Scenes → Export to download a compact
<scene>.ledscene.zip(~300 KB; strips raw 2D scan rounds by default while keeping the 3D map, controllers, LED groups, plane presets, custom.pymodes, and an auto-generatedMODE_GUIDE.mdwith your venue's exact geometry and shader API). - Launch Simulation Mode on another computer:
Starts Studio in zero-UDP Simulation Mode (./scripts/sim.sh path/to/scene.ledscene.zipLEDMAP_SIMULATION=1), skips macOS camera builds, treats saved controllers as virtually online, and streams a smooth 30 FPS 3D preview. You can also toggle SIM MODE anytime in the top HUD or drag-and-drop a.ledscene.ziponto the 3D canvas. - Develop & preview modes live:
- Click + New Mode in the 3D FX drawer to scaffold a custom Python shader and edit it directly in Studio's built-in Code Editor (
⌘Shot-reloads live with inline syntax/runtime tracebacks), or open the.pyfile in your IDE / AI coding assistant alongsideMODE_GUIDE.md. - Use the 3D Preview controls for Night mode (true-dark background & off-LED floor), Bulb size, Pause / Step / t=0, and ● Rec 6s to save a
.webmpreview clip.
- Click + New Mode in the 3D FX drawer to scaffold a custom Python shader and edit it directly in Studio's built-in Code Editor (
- Share back to the live venue: Click Copy, ↓ .py, or Export Pack (
.ledmodes.zipwith modes + LED groups + plane presets). On the live venue Studio, drag-and-drop the.pyor.ledmodes.ziponto the 3D canvas to hot-load and run it on your real WLEDs immediately.
Phone Fleet & Field Workflow
You shouldn't have to sprint back to a laptop between camera angles.
- Instant iPhone / Any-Phone Web Cam (zero install): Click Add Phone in Studio's bottom dock and scan the Instant Web Cam (HTTPS) QR code (
https://<machine>.<tailnet>.ts.net/camover Tailscale Serve, orhttps://<host-ip>:8443/camin opt-in LAN mode). Tap Start Camera and your phone joins the fleet immediately with live preview, gravity sensing, and field scan buttons. - Android APK over Wi-Fi or USB: Scan the
/installQR code to download and install the native Camera2 APK, or plug in phones with USB debugging and run./scripts/install-android.sh. Rebuilding the APK lights up an amber Update button on connected Android phones for 1-tap Wi-Fi self-updates. - Native iOS App (
ios-cam/): For manual exposure/ISO/focus lock on iPhones, openios-cam/LEDMapCam.xcodeprojin Xcode (or run./scripts/install-ios.sh --team <TEAM_ID>). - Trigger scans from the field: Every phone (Safari Web Cam, Android, and iOS) exposes SCAN ROUND, MAP (holds unmapped LEDs RED, interpolated BLUE, measured OFF), Undo, and FX toggle—automatically locking controls across all phones while Studio is busy and playing start/complete voice cues.
Adding Remote Macs
Deploy macos-cam to another Mac on your Tailnet or trusted LAN:
./scripts/deploy-macos-cam.sh <remote-mac> 8781
When launched on a remote Mac with an active desktop session, deploy-macos-cam.sh binds explicitly to the remote Mac's detected Tailscale (or LAN) IPv4 address, starts the camera bridge on :8781, and automatically opens a live Camera View window on that Mac's screen (with camera switcher, exact FOV framing grid/crosshair, mirror toggle, and always-on-top pin) so you can aim the camera directly from the remote Mac. Pass --headless to skip the desktop window, or open http://<remote-mac>:8781/ in any browser for the built-in web viewfinder.
One macOS catch: headless SSH cannot pop the macOS camera permission prompt. On a brand-new remote Mac, open Terminal once on that Mac's desktop, run ~/ledmap-macos-cam --port 8781 --bind <remote-ip>, and click Allow—the live Camera View window opens automatically. When deploy-macos-cam.sh is re-run later, it keeps an existing desktop bridge's permission intact (or starts the bridge automatically once SSH authorizationStatus == 3) and launches the desktop viewfinder as a separate Aqua --viewer process.
High-Speed Rust Player (ledmap-rt)
Once a project is mapped, you can close Python and run effects straight from compiled Rust:
cd rust-engine && cargo build --release
# Drive all mapped WLED controllers in a saved project at 60 FPS
./target/release/ledmap-rt play ../projects/<project>/project.json plasma_3d 60 0.8
# Run the Rayon 3D shader + ternary decoder benchmark
./target/release/ledmap-rt bench
Built-in ledmap-rt effects: plasma_3d, expanding_sphere, helix_vortex, axis_test, and sweep_plane.
Deep Docs & Verification
Every subsystem has one owning reference doc under docs/ (and AGENTS.md enforces keeping both those docs and this README current):
docs/targeting-and-3d-solver.md—Ternary ECC codebook, Decode-First NNLS unmixing, multi-round 3D pose solver, Strip Viterbi DP, robustSim(3)cross-zone stitching, post-merge spike/singleton filtering, anchored patch solver, sparse BA, and auto-leveling.docs/hardware-and-fleet.md—Camera HTTP/MJPEG protocol & origin hardening, discovery transports, Android Camera2, nativeios-cam& Safari HTTPS Web Cam,macos-cam, 3-tier lock-aware WLED discovery & voice announcer, latch-aligned WLED DDP streaming, WLED optimizer & pin trimming, andledmap-rt.docs/api-and-ui.md—FastAPI REST/WebSocket contract, scene locking/duplication/patching, multi-scene storage & persistent settings, Tailscale grants authorization boundary, custom Python shaders, and the Three.js Studio UI..agents/skills/wled-remap-and-trim/SKILL.md—Reusable, venue-agnostic agent skill for onboarding a new WLED box or split strand (1000/pin probe →patch_update+ Paint Unmapped RED loop → human-gated exact physical pin trim).
Verify every component you touch:
(cd host && uv run --extra dev pytest -v)
(cd web && npm run build)
(cd android-cam && ./gradlew assembleDebug)
(cd ios-cam && xcodegen generate && xcodebuild -project LEDMapCam.xcodeproj -scheme LEDMapCam -sdk iphoneos -configuration Debug CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY="" build)
(cd macos-cam && swift build -c release)
(cd rust-engine && cargo build --release)
License & No-Babysitting Disclaimer
Released under the MIT License.
Use this at your own risk. We aren't in charge of your rig, and we aren't responsible for what happens when you run it. This software comes strictly "AS IS" with zero warranty and zero liability. If you overload a 5V power supply, drop a phone off a ladder, point a tripod into a puddle in the woods, or blast 2,000 LEDs at 100% white into your neighbor's bedroom at midnight—that's on you.
Built with curiosity and too many ESP32s by dotfun—Run Good · Look Good · Feel Good.
No Smoke, No Mirrors. Fluff Free, Fun Forward.
探索相关项目
加载中…