Public: anyone can read this; the crew can change it.

An .stl file opens in the browser as a 3D model you can turn, with its size and triangle count #12995

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

An .stl file's page now shows its triangle count and bounding box in the first paint, and a truncated file or one over 20 MB is refused with a sentence. bun x tsc --noEmit, bun scripts/gate.ts and the STL, 3D-view, kinds, OBJ/PLY and feature-index tests pass.

Notes

shipped production is serving it deploy 8e1361f

opened this

An .stl file's page now shows its triangle count and bounding box in the first paint, and a truncated file or one over 20 MB is refused with a sentence. bun x tsc --noEmit, bun scripts/gate.ts and the STL, 3D-view, kinds, OBJ/PLY and feature-index tests pass. I did not run the full suite, and I did not start the app or try the page in a browser.

The repo already had an STL viewer: model3d.ts with the vendored three.js, and mesh.ts parsing binary and ASCII. What was missing was the first-paint summary, the header and byte-length validation, the 20 MB refusal, the doc and the tests.

  • Parser module: new src/web/render/stl.ts (readStl: bytes in, facts or an error sentence out). It checks the 80-byte header and the triangle count against the byte length before reading any triangle. It refuses a file over 20 MB without parsing it, and refuses empty files, files with no triangles and non-finite coordinates. A solid header containing a NUL byte is treated as a damaged binary file.
  • First paint: model3d.ts renders the STL Triangles and Box rows server-side for files up to 2 MB (the same cap OBJ/PLY use). They read with JavaScript off, and the file name is escaped. A damaged file says why in the frame. An STL over 20 MB gets the sentence and no data-src, so the viewer never fetches it.
  • Viewer: unchanged, so there is no new dependency and CSP is unchanged. It still orbits with the pointer and with the arrow keys once the canvas has focus.
  • Tests: test/render-stl.test.ts covers:

- a cube's 12 triangles and 20 mm box; - an ASCII file matching its binary twin; - a truncated file; - a header claiming 4 billion triangles; - the 20 MB refusal; - a NaN coordinate; - the first paint and name escaping.

  • Docs: docs/features/file-stl.md, plus a row in docs/features/README.md.

Left out:

  • The first-paint facts for an STL between 2 and 20 MB. The viewer fills those in after it fetches and parses the file.
  • Unit conversion: the box is shown as mm, as it already was.
  • A client-side cap in the viewer itself. The 20 MB refusal is enforced by withholding data-src on the server.

Try: commit a cube .stl to a repository and open its file page; the Triangles and Box rows read with JavaScript off. Truncate the file and open it again to see the refusal sentence.

The commit messages carry the No look: and No door: lines the gate asks for.

🤖 Generated with Claude Code

Closes #12990

1 earlier comment · 1 event
commented

An .stl file's page now shows its triangle count and bounding box in the first paint, and a truncated file or one over 20 MB is refused with a sentence. bun x tsc --noEmit, bun scripts/gate.ts and the STL, 3D-view, kinds, OBJ/PLY and feature-index tests pass. I did not run the full suite, and I did not start the app or try the page in a browser.

The repo already had an STL viewer: model3d.ts with the vendored three.js, and mesh.ts parsing binary and ASCII. What was missing was the first-paint summary, the header and byte-length validation, the 20 MB refusal, the doc and the tests.

  • Parser module: new src/web/render/stl.ts (readStl: bytes in, facts or an error sentence out). It checks the 80-byte header and the triangle count against the byte length before reading any triangle. It refuses a file over 20 MB without parsing it, and refuses empty files, files with no triangles and non-finite coordinates. A solid header containing a NUL byte is treated as a damaged binary file.
  • First paint: model3d.ts renders the STL Triangles and Box rows server-side for files up to 2 MB (the same cap OBJ/PLY use). They read with JavaScript off, and the file name is escaped. A damaged file says why in the frame. An STL over 20 MB gets the sentence and no data-src, so the viewer never fetches it.
  • Viewer: unchanged, so there is no new dependency and CSP is unchanged. It still orbits with the pointer and with the arrow keys once the canvas has focus.
  • Tests: test/render-stl.test.ts covers:

- a cube's 12 triangles and 20 mm box; - an ASCII file matching its binary twin; - a truncated file; - a header claiming 4 billion triangles; - the 20 MB refusal; - a NaN coordinate; - the first paint and name escaping.

  • Docs: docs/features/file-stl.md, plus a row in docs/features/README.md.

Left out:

  • The first-paint facts for an STL between 2 and 20 MB. The viewer fills those in after it fetches and parses the file.
  • Unit conversion: the box is shown as mm, as it already was.
  • A client-side cap in the viewer itself. The 20 MB refusal is enforced by withholding data-src on the server.

Try: commit a cube .stl to a repository and open its file page; the Triangles and Box rows read with JavaScript off. Truncate the file and open it again to see the refusal sentence.

The commit messages carry the No look: and No door: lines the gate asks for.

🤖 Generated with Claude Code

Changes requested — before the latest push

Reviewed from the diff, the issue boxes and the design principles; I did not browse the preview. One thing to fix: the server summary only exists for STL files up to 2 MB, so a 2 to 20 MB file shows no triangle count or box with JavaScript off, and the issue asks for the summary first for any STL the page opens. Read the body up to STL_LIMIT for stl, keeping FACTS_CAP for OBJ and PLY, and add a test with a file just over 2 MB. Two small cleanups: the size > STL_LIMIT branch in readStl is unreachable from model3d, and form in StlFacts is only used by tests. The box is always labelled mm although STL carries no units; say so in a sentence in the docs or label it as the file units. The viewer, doc and tests otherwise meet the boxes.

commented

An STL of any size up to 20 MB now shows its triangle count and box in the first paint, with JavaScript off. tsc, scripts/gate.ts and design-lint are clean, and the STL, 3D-model and view-source tests pass. I did not run the whole suite: scripts/fast.ts found the diff too broad to name.

Changed

  • Read ceiling. The page read only up to 5 MB, so the 2 MB cap in model3d was not the only thing in the way. blobCeiling in src/view/local.ts now reads an .stl whole up to STL_LIMIT, and model3d reads the facts when input.size <= STL_LIMIT. FACTS_CAP still bounds OBJ and PLY.
  • Test. A new test builds a 3 MB binary STL (60,000 triangles) and expects the Triangles row and the units label in the rendered frame.
  • Unreachable branch. The size > STL_LIMIT check in readStl is gone; model3d already refuses oversize files before calling it. The test that only exercised that branch is gone too.
  • form. Removed from StlFacts, with its assertions.
  • Units. The box now reads 20 × 20 × 20 units in both the server frame and the viewer, and docs/features/file-stl.md says an STL carries no units. OBJ and PLY keep their mm label.

Left alone

  • Files over 20 MB are still refused with a sentence and are not fetched.
  • I did not check the preview.
  • The 3 MB test calls model3d directly; nothing in it goes through blobCeiling or a real blob page.
Approved

Approved. The earlier asks are met: facts show in the first paint at any size up to 20 MB (blobCeiling now reads an STL whole), the box reads in units rather than mm, and the dead branch and the form field are gone. The viewer, parser, tests and doc follow the existing pattern, with no new dependency. I read the diff only. I did not open a preview page.

Two things I would do next:

  1. Non-blocking: the server now reads and parses up to 20 MB on every STL page view, which will miss the 50 ms budget on big files. Cache the facts by blob id, or skip the server parse above a few MB and let the viewer fill them in.
  2. Non-blocking: src/view/local.ts imports from src/web/render, which crosses a layer. Move STL_LIMIT to a neutral module. Add one test that goes through blobCeiling, so the 3 MB case is pinned end to end.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs