Skip to content

Web app: 3D mouse navigation through the Gamepad API (#1336) - #1473

Merged
bherbruck merged 4 commits into
tangency-labs:mainfrom
CamWight:web-spacemouse
Oct 15, 2026
Merged

bherbruck merged 4 commits into
tangency-labs:mainfrom
CamWight:web-spacemouse

Conversation

@CamWight

@CamWight CamWight commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1336.

Change

The web app read no 3D mouse at all. All it got was 3DxWare's mouse-wheel emulation for browsers: a small, jerky zoom and nothing else.

It now reads the cap through the browser's Gamepad API and moves the view the way the desktop app does.

  • Shared code. The platform-independent part of the desktop's 3D mouse code moves to crates/ui-egui/src/space_mouse.rs, with its tests:

    • the axes, the 3DxWare axis mapping and the dead zone;
    • navigate_frame, which is the old per-frame tick body. That covers the preferences, the start page, the speed, begin_external_navigation and the repaint, plus the open-file-picker check the desktop made at its call site. It hands the frame's motion to the page that shows the camera.
    • DriverMapping::apply now uses get_mut, because the mapping's fields are public now.
    • The desktop keeps its HID readers, the report decoding and the 3DxWare profile, and calls the shared code. Its behaviour is unchanged.
  • Through the shared navigation (from the review): navigation::device, which handle calls for its page, applies the motion with the page's NavCaps and the page's own height.

    • The cap pans and zooms every page.
    • It turns the view only where the page may orbit (never on a flat page), and not while a sketch is edited.
    • hand_rolled_camera_input_is_rejected no longer exempts space_mouse.rs, and it scans the web app too. It also reads CRLF checkouts as LF, so the split before a file's own tests works on Windows.
  • The web app (apps/solidcraft-web/src/space_mouse.rs):

    • Each frame it reads navigator.getGamepads() and takes a 3Dconnexion device if one is listed, else 3DxWare's virtual joystick.
    • It recognises 3Dconnexion devices by vendor and product, in both id formats: Chromium's Name (Vendor: 046d Product: c62b) and Firefox's 046d-c62b-Name.
      • Vendor 256f (3Dconnexion) counts with any product: the browser lists only its 3D mice as gamepads.
      • Vendor 046d (Logitech) counts only with 3Dconnexion's products from usb.ids. Logitech gamepads and wheels share that vendor id, and a pedal resting at -1 would spin the view forever.
      • beef:046d is 3DxWare's virtual joystick.
    • The browser's -1..1 is the device's ±350. The axes come in the device's own order and signs (measured below), so they go through 3DxWare's object-mode mapping, which is what the Linux app uses without a profile (Linux: SpaceMouse roll and spin swapped when no 3DxWare profile exists (follow-up to #198) #1172).
  • 3DxWare's emulated wheel is dropped while the cap moves and for 150 ms after. Pinch zoom (Zoom events) is dropped the same way.

    • This happens before the app's own input hook, so the control channel's events are never touched.
    • A wheel turn with the cap at rest is kept.
  • Waking from idle. The browser sends no event when a gamepad moves.

    • A gamepadconnected listener redraws once the cap is first moved on the page.
    • A 50 ms timer, started once a 3D mouse is listed, redraws when the cap starts moving.
    • With navigation switched off, neither runs and the Gamepad API isn't called.
  • The preference row read "3D mouse (Windows)" (Linux has worked since 3D mouse on Linux (hidraw) and devices that report all six axes in report 1 #343). It now reads "3D mouse" in every catalog that has the message, under the same id, as docs/localization.md asks.

  • Docs. Getting started gains "3D mouse in the browser", covering:

    • Edge and Chrome;
    • the first firm push a browser needs before it lists a gamepad;
    • Firefox.

    The README points there.

Firefox lists only joysticks and gamepads, not 3D mice (Mozilla bug 1226575). Its Windows backend accepts only the HID usages Joystick and Game Pad (kUsagePages in dom/gamepad/windows/WindowsGamepad.cpp), and a SpaceMouse is a Multi-axis Controller. It does list 3DxWare's virtual joystick, and a 3DxWare profile for Firefox can route the six axes there. The docs give that profile. It also stops the emulated wheel in Firefox.

Validation

Measured with a real device (Windows 11, SpaceMouse Pro 046d:c62b, 3DxWare 10.9.8, Edge 155, Firefox 157):

  • Axes: a direction test page recorded each motion's strongest axis and sign. Edge, reading the device, and Firefox, reading 3DxWare's joystick through the profile, agree on all six: right X+, push forward Y−, lift Z−, tilt forward Rx−, tilt right Ry−, twist clockwise Rz+. These are the raw HID signs Linux: SpaceMouse roll and spin swapped when no 3DxWare profile exists (follow-up to #198) #1172 measured on Linux. Hence 3DxWare's object-mode mapping, which is what the Linux app uses without a profile.
  • The emulated wheel: in Edge, 3DxWare sent 33 wheel events while the cap moved. Every one came with an axis at 119 or more (of 350): none at or under the dead zone of 20, and none after release. Their deltas (±100) are the same as a real wheel's, so only the cap's motion tells them apart. The real wheel sent 68 events, all with the cap at exactly 0. In Firefox with the profile, 3DxWare sends no wheel events at all.
  • The web app, in Edge, Chrome and Firefox (with the profile): all six motions move the view as the cap does. The browser lists the cap only after a firm push, so that first push can still zoom a little (documented). Firefox feels slightly more sensitive, because 3DxWare scales its joystick output.

Tests:

  • crates/ui-egui/src/space_mouse.rs (10): the desktop's moved tests unchanged, plus:
    • object-mode signs;
    • the dead zone;
    • a mapping can't reach past the six axes;
    • a frame moves the view and keeps the next frame coming;
    • a long gap moves no further than 50 ms;
    • a non-finite step;
    • navigation off, the start page and an open file picker leave the view alone;
    • speed clamped to 0.1–5×.
  • crates/ui-egui/src/navigation.rs (2 new):
    • through handle, the cap pans and zooms a flat page and never turns it, and turns the model and render pages;
    • the cap never turns a sketch being edited.
  • apps/solidcraft-web/src/space_mouse.rs (6):
    • both browsers' id formats;
    • gamepads and other Logitech devices aren't 3D mice;
    • 20,000 random ids never panic, and every one recognised has a 3D-mouse id;
    • gamepad values to raw units, including NaN, infinities and fewer than six axes;
    • a device is read before the virtual joystick;
    • the wheel guard keeps the user's wheel and drops 3DxWare's, including after a clock that goes back.
  • apps/solidcraft/src/space_mouse.rs (12): the desktop's decode and profile tests, plus a new one: each frame moves the view through the loaded 3DxWare mapping.

Planted faults: 21, all caught after two test fixes. The first run caught 16 of 18. The two that survived (the speed clamp, and the desktop's frame ignoring the loaded mapping) led to the new speed test and the desktop frame test, and they're caught now, along with two more clamp variants. Six more faults went into the navigation change from the review, and all six were caught.

Desktop: behaviour unchanged. The Windows mapping when there's no 3DxWare profile is the same before and after; it's wrong on main too (#1380).

wasm: the web crate builds for wasm32-unknown-unknown and is clean under clippy -D warnings there.

Gate: cargo xtask ci's steps on Windows, on main at 2bfec25.

  • fmt, assets, licences, layers, clippy -D warnings (workspace and ui-egui), wasm and the web offline test pass.
  • Every test crate passes except for tests that fail the same way on main on this PC:
    • control_render_export_respects_upstream_file_scope: this PC's %TEMP% is an 8.3 path (NAME~1).
    • startup_steps_survive_a_rebase_and_running_ends_startup: checked on main's build.
    • fillet_beside_a_modelled_thread_finishes: a timing test under full load; it passes on its own.
    • The four robustness_goldens: they give the same values on main here.
  • After rebasing onto e8e2ccc: fmt passes again, and so do the catalog, preference and 3D mouse tests of all three crates (63 + 6 + 12).
  • After the review change:

Screenshots of the behavior (when observable)

A still can't show the cap moving the view: the measurements above stand in for that. Preferences › Navigation in the web app, with the row that now reads "3D mouse":

Preferences › Navigation in the web app built from this branch: the row reads "3D mouse"

Integration status

main is merged in up to 843c548, with one conflict in navigation.rs (the new middle_double_click signature, kept). Before the PR opened, it was rebased after #1233 merged. The two conflicts, in the web app's Cargo.toml features and main.rs modules, keep both sides: MediaQueryList and Gamepad, mod install and mod space_mouse. Nothing was force-pushed.

Open PRs that touch the same files without touching these lines:

#1380 (the desktop's mapping on Windows without a profile, and 3DxWare's wheel on the desktop) builds on the shared module here and follows in its own PR.

🤖 Generated with Claude Code

)

The web app now reads a 3Dconnexion device through navigator.getGamepads()
and moves the view the way the desktop app does. The platform-independent
navigation moves to crates/ui-egui/src/space_mouse.rs, shared by both apps.
3DxWare's emulated mouse wheel is dropped while the cap moves. The
preference row reads "3D mouse" now that Linux and the browser have it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bherbruck

Copy link
Copy Markdown
Collaborator

Thanks, @CamWight, this is great work, and the measurements with a real SpaceMouse in Edge and Firefox (with the virtual-joystick profile) are exactly what I needed to trust it. Moving the device-independent part into ui-egui so the desktop and web apps share it is the right shape.

One thing before I merge: since #1462, every page's camera input goes through the shared navigation::handle in crates/ui-egui/src/navigation.rs, with the page's NavCaps. Now that the 3D mouse is shared code rather than a desktop-only driver, I'd like it to go through there too instead of moving app.cam itself in space_mouse::navigate_frame:

  • hand the frame's Motion to the navigation module (for example an entry point next to handle that handle also uses, taking the page's NavCaps), so a flat page with orbit: false pans and zooms with the cap but never turns, the same as the mouse does there;
  • keep space_mouse.rs to reading the axes, the mapping, the dead zone and the wheel suppression, and take it out of the allowed list in hand_rolled_camera_input_is_rejected;
  • add apps/solidcraft-web/src to that test's scanned dirs, so the web app's input hook is checked as well.

A test that the cap leaves the view unturned on the flat pattern page would cover the NavCaps part. The rest (device matching, the emulated-wheel filter, the docs) looks good to me as it is.

CamWight and others added 3 commits October 15, 2026 19:31
…NavCaps (tangency-labs#1336)

The 3D mouse now only reads the device, maps the axes, applies the dead zone
and drops the emulated wheel; navigate_frame hands the frame's motion to the
page showing the camera. navigation::device, which handle calls for its
page, applies it with the page's NavCaps and height: the cap pans and zooms
every page and turns the view only where the page may orbit, and not while a
sketch is edited. hand_rolled_camera_input_is_rejected no longer exempts
space_mouse.rs, scans the web app too, and reads CRLF checkouts as LF.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	crates/ui-egui/src/navigation.rs
@CamWight

Copy link
Copy Markdown
Contributor Author

Thanks, good call. Done in eb6bc35:

  • space_mouse::navigate_frame now only hands over the frame's motion (app.viewport.device_motion). navigation::device, next to handle and called by it, applies that motion with the page's NavCaps and the page's own height.
    • The cap pans and zooms every page.
    • It turns the view only where the page may orbit, and not while a sketch is being edited, as before.
    • The camera maths (device_camera) moved into navigation.rs.
  • space_mouse.rs is down to the axes, the mapping, the dead zone and the wheel suppression, and it's off the allowed list in hand_rolled_camera_input_is_rejected. That test now scans apps/solidcraft-web/src too.
  • New tests:
    • the_3d_mouse_pans_and_zooms_a_flat_page_but_never_turns_it drives handle with the flat, model and render caps.
    • the_3d_mouse_never_turns_a_sketch_being_edited checks the sketch case through device.
    • Six faults planted in the new code were all caught.
  • One more fix in that test: it now reads files with Windows line endings. On a CRLF checkout its split before the in-file tests never matched, so it flagged a camera set-up in prefs.rs's tests.
  • I merged main in, with no conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Spacemouse doesn't work properly on Web

2 participants