Skip to content

Show a scale bar in the 3D view with the orthographic camera - #447

Merged
andeplane merged 2 commits into
mainfrom
claude/issue-77-scale-bar
Oct 16, 2026
Merged

andeplane merged 2 commits into
mainfrom
claude/issue-77-scale-bar

Conversation

@andeplane

@andeplane andeplane commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Requested by Anders Hafreager · project thread

Before: the 3D view gave no sense of how large molecules or the simulation box are.

After: with the orthographic camera and the new "Show scale bar (orthographic camera)" setting on, a bar in the bottom-right corner shows a round length (1, 2 or 5 × 10ⁿ) labelled with the script's length unit (Å for real/metal, σ for lj, and so on). It follows zoom, resize and camera switches, and is hidden in perspective mode or when the setting is off. The setting is off by default.

How: a pointer-transparent HTML overlay polls the active camera every animation frame and computes length per pixel as frustum height ÷ zoom ÷ viewport height. omovi has no public camera getter, so View.tsx reads visualizer["camera"] in one commented place. The unit comes from the unit style LAMMPS already reports (simulationStatus.unitStyle) via UNIT_SYSTEMS; until LAMMPS prints it, the label is just the number so it's never wrong. The overlay uses the shell's media-control design tokens like the other viewport controls. Unit tests cover the rounding and per-pixel math, the overlay, the show/hide rules, the unit label and the new setting. Checked in headless Chromium on the 2D LJ fluid example: the bar appears with the orthographic camera, read "2 σ" when zoomed in, rescales on zoom and resize, and disappears in perspective mode.

Closes #77

🤖 Generated with Claude Code

https://claude.ai/code/session_01HB39E3Y4jpon2ijSXT7emN

Add a "Show scale bar" render setting. With the orthographic camera on, an
overlay in the bottom-right corner of the viewport shows a bar of a round
length (1, 2, 5 x 10^n) labelled with the length unit of the script's
units style (Å, σ, nm, ...). It reads the camera every animation frame,
so it follows zoom, resize and camera changes. It is hidden in perspective
mode, where no single length scale applies, and the unit is left out
until LAMMPS has reported the unit style.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HB39E3Y4jpon2ijSXT7emN
@andeplane andeplane self-assigned this Oct 16, 2026
@andeplane
andeplane marked this pull request as ready for review October 16, 2026 06:59
Brings the scale bar PR up to date with main's refactors (EngineRegistry,
split store/screen modules, shared design tokens, prettier/ESLint in CI).

Conflicts:
- src/containers/View.tsx: main moved the simulation box/wall overlays
  into useSimulationBoxOverlays, dropped the styled Wrapper for a plain
  div and the THREE namespace import. Kept main's structure; re-added the
  unitStyle selector, the scale bar imports (OrthographicCamera as a named
  three import) and the <ScaleBar> overlay inside the new wrapper div. The
  visualizer now comes from the EngineRegistry via useEngineState.
- src/containers/View.test.tsx: kept main's EngineRegistry type import and
  dropped the unused Modifier import; kept the PR's UnitStyle import.

ScaleBar.tsx now styles the overlay with the shell's media tokens
(--media-control-bg, --media-control-border, --media-text, --radius)
instead of hard-coded colors, matching the other viewport controls.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HB39E3Y4jpon2ijSXT7emN
@andeplane
andeplane merged commit cfd9d12 into main Oct 16, 2026
3 checks passed
@andeplane
andeplane deleted the claude/issue-77-scale-bar branch October 16, 2026 13:54
andeplane pushed a commit that referenced this pull request Oct 16, 2026
Resolved the View.tsx import conflict by keeping both the pan remap and
the scale bar imports.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HB39E3Y4jpon2ijSXT7emN
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.

Show a scale bar in the 3D view

2 participants