Skip to content

About

Multi-camera, multi-controller 3D WLED mapping and spatial effect studio (Ternary ECC, sparse BA, Android/macOS fleet, Rust DDP). Built by dotfun.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

24 Commits

Folders and files

Repository files navigation

dotfun

MIT License Built by dotfun WLED DDP

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 still end up with one controller that refuses to line up with the rest of the room.

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 sparse bundle adjustment, 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:

  1. Every LED flashes pure R, G, or B in ~2 seconds. A systematic linear code over $\mathrm{GF}(3)$ with minimum Hamming distance $d_{\min} \ge 3$ corrects single-frame errors and keeps ~33/33/33% RGB balance across every frame so unlocked cameras don't pump exposure. For up to 727 LEDs, that's 9 frames; for ~59,000 LEDs, that's 13 frames.
  2. Decode first, localize second. Instead of guessing blob centroids first and losing overlapping LEDs, the host calibrates a 3×3 camera color-crosstalk matrix, discards ambient lamps and lit walls with a temporal chromatic-swing mask, decodes every active pixel in one vectorized pass, and unmixes tight multi-LED overlaps with bounded NNLS.
  3. Walk around with any phone to close gaps. Fixed cameras handle the backbone. Walk around with an iPhone (zero-install Safari Web Cam or native ios-cam) or Android phone, tap SCAN ROUND right on the phone, and add new angles. All connected phones lock out controls during a scan and announce start/completion with audio cues so nobody moves a tripod mid-capture. The solver enforces scale-adaptive baseline and parallax guards (min(0.25, max(0.03, 0.04 * cam_span)) + min_parallax_deg >= 5°), stitches overlapping rooms with robust RANSAC Sim(3) consensus, and lets you click any solved camera cone in 3D to delete a bad shot and re-solve cleanly.
  4. Auto-level and paint the blind spots. iPhones and Android phones stream hardware gravity vectors so the 3D scene lands upright instead of tilted. Hit Paint Unmapped (P) and every mapped LED switches OFF while every unmapped LED lights up bright RED (held continuously over DDP so WLED never times out)—making missed spots obvious in the dark.
  5. Drive every WLED controller in lockstep as one 3D canvas. Studio runs a dedicated real-time DDP thread (ddp-rt) with a continuous integrated speed clock (no phase jumps when dragging Speed), Best-Effort UDP (IP_TOS = 0x00) with paced pre-load, Auto-Sync FPS matched to your slowest controller's WS2812B bus, and WS2812B bus-latch phase alignment so short and long strips update at the same millisecond. Built-in 1-click tools optimize WLED /json/cfg, trim oversized ghost LEDs per GPIO pin (losslessly remapping saved scan rounds), and export non-locking 2D /ledmap.json fallbacks. Custom Python shaders hot-reload from host/effects_custom/, and a standalone Rust binary (ledmap-rt) blasts zero-jitter DDP frames at ~0.32 ms per 2,000-LED frame.
  6. Multi-scene ready & live-synced across browsers. Switch, cycle, create, rename, or delete saved venues from the Top HUD Scene Picker. Active scene, per-scene shader/speed/brightness/FPS, and shared UI settings persist across browser refreshes and server restarts, syncing live across every open browser window over /ws with zero-re-render binary WebSocket 3D previews.

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 WLED mDNS discovery, diagnostics/optimizer/pin-trimmer, latch-aligned UDP DDP (:4048) streamer, auto-HTTPS (:8443) Safari Web Cam server, camera fleet manager, ternary ECC scanner, multi-round 3D solver + sparse BA, real-time 3D effect engine
web/ Vite, React, TypeScript, Three.js Full-bleed 3D Studio UI, Top HUD Scene Picker, multi-browser live settings sync, binary WS 3D preview, WLED optimizer & 1-click Trim Pins modal, camera fleet PIP tray, QR onboarding modal, 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, 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, field remote with busy lock & voice alerts, and OTA .ipa support
macos-cam/ Swift, AVFoundation Native HTTP camera bridge (:8781) 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

Start the macOS camera bridge (:8781), FastAPI backend (:8780 HTTP + :8443 self-signed HTTPS for iPhone Safari Web Cam), and Three.js Studio UI (:5173) in one shot:

./scripts/dev.sh

Then open http://localhost:5173 (or http://<host-lan-ip>:8780 from any other laptop, tablet, or phone—all open UIs stay live-synced). Studio auto-discovers WLED controllers over mDNS, local macOS cameras over :8781, and phone cameras over mDNS (_ledcam._tcp), UDP broadcast (:8089), USB ADB, or HTTPS Web Cam (/cam).

Prefer running each piece by hand?

(cd macos-cam && swift build -c release)
(cd host && uv sync && uv run uvicorn ledmap.api.server:app --host 0.0.0.0 --port 8780)
(cd web && npm install && npm run dev -- --host)

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://<host-ip>:8443/cam). Accept the local self-signed cert once in Safari, 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 Wi-Fi /install QR 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, open ios-cam/LEDMapCam.xcodeproj in 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 in red), 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 LAN or Tailnet:

./scripts/deploy-macos-cam.sh <remote-mac> 8781

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, and click Allow. After authorizationStatus == 3, deploy-macos-cam.sh launches headless automatically.


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 them current):

  • docs/targeting-and-3d-solver.md—Ternary ECC codebook, Decode-First NNLS unmixing, multi-round 3D pose solver, Strip Viterbi DP, robust Sim(3) cross-zone stitching, sparse BA, and auto-leveling.
  • docs/hardware-and-fleet.md—Camera HTTP/MJPEG protocol, discovery transports, Android Camera2, native ios-cam & Safari HTTPS Web Cam, macos-cam, latch-aligned WLED DDP streaming, WLED optimizer & pin trimming, and ledmap-rt.
  • docs/api-and-ui.md—FastAPI REST/WebSocket contract, multi-scene storage & persistent settings, custom Python shaders, and the Three.js Studio UI.

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.

About

Multi-camera, multi-controller 3D WLED mapping and spatial effect studio (Ternary ECC, sparse BA, Android/macOS fleet, Rust DDP). Built by dotfun.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages