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

Files render in the browser: STL (and OBJ/GLB) as an interactive 3D view #7391

Parked opened this in answer to
Closed without merging

Every .stl (ASCII or binary), .obj, .glb and .gltf file page now shows the part in 3D: it fits the camera to the part, sits it on a ground grid in one neutral material, and you can turn it. The header gives the triangle count and the bounding box in mm, and Wireframe and Axes toggles sit beside them.

Notes

stopped parked by the crew deploy 5f172b7

opened this

Every .stl (ASCII or binary), .obj, .glb and .gltf file page now shows the part in 3D: it fits the camera to the part, sits it on a ground grid in one neutral material, and you can turn it. The header gives the triangle count and the bounding box in mm, and Wireframe and Axes toggles sit beside them. The server only renders the frame; the browser fetches the bytes from the #7330 media route and parses them.

What moved where

  • src/web/render/model3d.ts: the renderer, registered in RENDERERS. It renders a <figure class="card model3d"> with data-src (the media URL), data-format and data-module (the viewer bundle). Until the viewer draws, the figure holds a 4:3 stage with a note and a Download button. That note is what stays without JavaScript or WebGL, or when a file fails to parse; in that last case the header says why. The same file builds /assets/model3d-<hash>.js, once per process, with Bun.build. The address is a hash of the sources, so the page doesn't wait for a build to know it.
  • src/web/render/model3d-client.ts: the browser entry. It fetches the file, draws only when something changes (no render loop), and lets go of the WebGL context when the code browser swaps the file out. glTF is read as metres and shown in mm.
  • src/web/render/mesh.ts: our own STL and OBJ parsers, plain data in and out. A binary STL is recognised by its exact length, so one whose header starts with solid still reads as binary. OBJ faces of more than three corners are split into triangles, and negative indices work.
  • src/web/render/vendor/three/: three.js 0.186.1, byte-for-byte as published, with its MIT licence and a README listing each file's hash. The build maps three onto these files, so they are not edited. vendor/three.d.ts types the part we use; the type checker runs without the DOM library, so page elements are typed loosely there.
  • render/renderers.ts gains rendererFor(). A file too large for the page to read is now drawn only by a kind that fetches its own bytes (just model3d), up to its 100 MB cap; over the cap the page offers Download. repo.ts is a net shrink: it now calls this function.
  • kinds.ts reads .obj as model3d and adds kindByName().
  • client.ts (the shell): a small loader that adds a <script type="module"> with the shell's own nonce, once per bundle and only when a figure asks for one. It runs on the first paint and when the code browser swaps a file in. The page's CSP is unchanged.
  • server.ts serves the bundle immutable. The bundle is 648 KB, 166 KB gzipped.
  • The styles sit in model3dCss, named in docs/design/areas/model3d.md. User docs are in docs/features/file-media.md under "3D models".

What to look at

  • I couldn't see it run. Chromium can't start in this sandbox (it needs a unix socket), so the drawing itself is unchecked. Please look at the preview on a phone (390 px) and on a desktop, in both themes.
  • The grid colour comes from the theme when the part is drawn, so switching theme while a part is open leaves the grid in the old colour until reload.
  • On the /origins/… remote-browse pages there is no media route. The 3D view there will say "the file answered 404", the same gap the Download button already has since #7330. I didn't fix it here.
  • glTF buffers or textures embedded as data: or blob: addresses are refused by the page's CSP. Every part wears the neutral material anyway, so textures aren't shown either way.
  • Vendoring adds about 2.3 MB of source to the repository.

Tests

  • test/model3d.test.ts:
    • ASCII and binary cube fixtures give 12 triangles and a 20×20×20 box, and the OBJ cube gives the same.
    • Bad files raise an error instead of drawing nonsense.
    • It checks which files and sizes get the 3D view.
    • The frame's HTML carries the module and media URL, with no inline script.
    • On a real forge, the blob page carries the module, the media URL, Source and Download.
    • A broken STL gets the same frame, which shows the server never parses models.
    • The bundle is served immutable with the parser inside.
  • render-kinds.test.ts gained an .obj sample.
  • Ran 26 related test files (279 pass, none fail), tsc (clean), scripts/design-lint.ts and scripts/gate.ts (both clean).

How to try it: open any .stl in a repository's code view on the preview, drag to turn it, and press Wireframe and Axes. Then switch to Source and back.

🤖 Generated with Claude Code

Closes #7335

8 earlier comments · 4 events
commented

Every .stl (ASCII or binary), .obj, .glb and .gltf file page now shows the part in 3D: it fits the camera to the part, sits it on a ground grid in one neutral material, and you can turn it. The header gives the triangle count and the bounding box in mm, and Wireframe and Axes toggles sit beside them. The server only renders the frame; the browser fetches the bytes from the #7330 media route and parses them.

What moved where

  • src/web/render/model3d.ts: the renderer, registered in RENDERERS. It renders a <figure class="card model3d"> with data-src (the media URL), data-format and data-module (the viewer bundle). Until the viewer draws, the figure holds a 4:3 stage with a note and a Download button. That note is what stays without JavaScript or WebGL, or when a file fails to parse; in that last case the header says why. The same file builds /assets/model3d-<hash>.js, once per process, with Bun.build. The address is a hash of the sources, so the page doesn't wait for a build to know it.
  • src/web/render/model3d-client.ts: the browser entry. It fetches the file, draws only when something changes (no render loop), and lets go of the WebGL context when the code browser swaps the file out. glTF is read as metres and shown in mm.
  • src/web/render/mesh.ts: our own STL and OBJ parsers, plain data in and out. A binary STL is recognised by its exact length, so one whose header starts with solid still reads as binary. OBJ faces of more than three corners are split into triangles, and negative indices work.
  • src/web/render/vendor/three/: three.js 0.186.1, byte-for-byte as published, with its MIT licence and a README listing each file's hash. The build maps three onto these files, so they are not edited. vendor/three.d.ts types the part we use; the type checker runs without the DOM library, so page elements are typed loosely there.
  • render/renderers.ts gains rendererFor(). A file too large for the page to read is now drawn only by a kind that fetches its own bytes (just model3d), up to its 100 MB cap; over the cap the page offers Download. repo.ts is a net shrink: it now calls this function.
  • kinds.ts reads .obj as model3d and adds kindByName().
  • client.ts (the shell): a small loader that adds a <script type="module"> with the shell's own nonce, once per bundle and only when a figure asks for one. It runs on the first paint and when the code browser swaps a file in. The page's CSP is unchanged.
  • server.ts serves the bundle immutable. The bundle is 648 KB, 166 KB gzipped.
  • The styles sit in model3dCss, named in docs/design/areas/model3d.md. User docs are in docs/features/file-media.md under "3D models".

What to look at

  • I couldn't see it run. Chromium can't start in this sandbox (it needs a unix socket), so the drawing itself is unchecked. Please look at the preview on a phone (390 px) and on a desktop, in both themes.
  • The grid colour comes from the theme when the part is drawn, so switching theme while a part is open leaves the grid in the old colour until reload.
  • On the /origins/… remote-browse pages there is no media route. The 3D view there will say "the file answered 404", the same gap the Download button already has since #7330. I didn't fix it here.
  • glTF buffers or textures embedded as data: or blob: addresses are refused by the page's CSP. Every part wears the neutral material anyway, so textures aren't shown either way.
  • Vendoring adds about 2.3 MB of source to the repository.

Tests

  • test/model3d.test.ts:
    • ASCII and binary cube fixtures give 12 triangles and a 20×20×20 box, and the OBJ cube gives the same.
    • Bad files raise an error instead of drawing nonsense.
    • It checks which files and sizes get the 3D view.
    • The frame's HTML carries the module and media URL, with no inline script.
    • On a real forge, the blob page carries the module, the media URL, Source and Download.
    • A broken STL gets the same frame, which shows the server never parses models.
    • The bundle is served immutable with the parser inside.
  • render-kinds.test.ts gained an .obj sample.
  • Ran 26 related test files (279 pass, none fail), tsc (clean), scripts/design-lint.ts and scripts/gate.ts (both clean).

How to try it: open any .stl in a repository's code view on the preview, drag to turn it, and press Wireframe and Axes. Then switch to Source and back.

🤖 Generated with Claude Code

Changes requested — before the latest push

The shape is good. The server renders only the frame and never parses a model. STL and OBJ get our own pure parsers with real fixtures, three.js is vendored unedited with its licence and hashes, and the bundle is lazy and immutable. On the preview, /assets/model3d-1c4a683cdd34ae0b.js answers 200, text/javascript, immutable, 648 KB (164 KB gzipped), under the unchanged nonce CSP. The preview has no repository with a model in it, and the pull says the drawing was never seen running. So nobody has watched a part turn yet, and the fixes below should come back with a look (phone and desktop, both themes).

What to change, in order:

  1. Fix first (security): keep a glTF's external URIs inside its own directory on the media route. model3d-client.ts:104 passes the media directory as the loader's base, but nothing confines what a .gltf names. A public file with "buffers":[{"uri":"../../../../../settings/tokens"}] or "/api/v1/..." makes every reader's browser send credentialed same-origin GETs to whatever the file author chose. connect-src 'self' stops exfiltration but not the requests. Give the GLTFLoader a LoadingManager whose setURLModifier refuses any URL that, resolved against location, is not same-origin with a pathname under base. Put that predicate in a pure function and test it: ../, %2e%2e/, an absolute path, //host and https:// must all be refused, and a sibling .bin must pass.
  2. Design system: use the named components, not hand-rolled markup (model3d.ts:57-68, :80).
    • The note is <div class="empty"> plus a CSS override that strips its border and background. Use empty({ icon, title, note, action }). If it must sit borderless inside the card, name that variant in docs/design/areas/model3d.md rather than restyling .empty locally.
    • The two toggles are hand-written <button class="btn" data-size="sm">. Render them with btn("Wireframe", { type: "button", size: "sm", variant: "outline", extra: "js-only" }). DESIGN §8 item 10 says a script-only control carries js-only; hidden alone is not the contract.
    • Use downloadHref(base, ref, path) for the note's Download, as the binary and too-large states do, not a hand-built ?download=1.
    • The eye icon on a 3D model reads as "preview". Pick the file icon the binary state uses, or name a new one.
  3. Both doors. The page now tells a person what the part is: triangles and box size. In the terminal (src/tui/screens/workspace.ts:671-678) a binary STL or a GLB is still "Binary file, N KB." mesh.ts is plain data and runs server-side as is. Have the terminal's file view of a model say 3D model · STL · 12 triangles · 20 × 20 × 20 mm under a modest cap, plus where to download it. Say so in docs/features/file-media.md, and test it.
  4. Tests for the shell loader. client.ts gains loadModules and its code:swap hook. No test proves that a fragment swapped in by the code browser carries data-module, or that the loader refuses a data-module that is not a first-party asset. Tighten that check to /^\/assets\/[a-z0-9-]+\.js$/ (indexOf('/assets/') === 0 lets /assets/../… through) and cover it.
  5. /origins/… pages. You noted that the frame there says "the file answered 404". Don't render a viewer that cannot work: when the scope has no media route, rendererFor should leave a model on the source or binary view. A one-line test would hold it.
  6. Small items:
    • three.d.ts declares members nothing uses (Group aside: sub, isEmpty, near/far, LineSegments beyond the helpers). Trim it to what the viewer calls.
    • The grid colour going stale on a theme switch is fine to leave, but open an issue for it.

On direction: this is a feature while the pipeline work is first. It continues the file-render series whose part 1 already landed, so I am not blocking on that. Keep the next round to the points above and nothing more.

commented

The 3D view now draws STL, OBJ, GLB and glTF files, and all six review points are addressed and pushed. But nobody has watched a part turn yet. Chromium can't start in this sandbox (it needs a unix socket), and I have no account on the preview to commit a model there. A look needs someone to push an .stl to a repository on the preview and open it on a phone (390 px) and a desktop, in both themes.

1. glTF URIs stay beside the model. The new pure function withinModelDir in src/web/render/gltf-uri.ts decides what a .gltf may make the browser fetch. The viewer's GLTFLoader gets a LoadingManager whose URL hook sends any refused URI to about:blank#refused, so no request is sent. A URI is allowed only if it is http(s), same-origin, carries no username or password, has no encoded dot, slash or backslash, and its path is strictly below the model's own media directory. Tests:

  • Allowed: a sibling .bin and a file in a subfolder.
  • Refused: ../, %2e%2e/, ..%2f, ..%5c, an absolute /api/… path, a look-alike sibling folder (towerish/), //host, another https:// host, a URL with a username and password, data:, blob: and javascript:.

2. Named components.

  • The note is now empty({ icon: "file", … }), and the local .empty restyle is gone.
  • The toggles are btn(…, { type: "button", size: "sm", variant: "outline", extra: "js-only", pressed: false, value }). BtnOptions gains pressed, which renders aria-pressed.
  • downloadHref moved next to mediaHref in pages/media.ts, and renderers receive it as RenderInput.download.

3. The terminal. The new render/model-facts.ts uses the same parsers as the browser. A glTF is read from its JSON: vertex counts, and position bounds before node transforms. In the file view, a binary or too-large model shows:

  • 3D model · STL as the heading
  • 12 triangles · 20 × 20 × 20 mm under it (files over 2 MB are only named and sized)
  • Download: <forge>/<owner>/<repo>/media/<ref>/<path>?download=1, or "Download it from its web page." when the forge has no address or the repository is on another forge

emptyState gains an optional full-width detail line for that address. An ASCII STL or OBJ is text, so it still opens as its source, the same as the web's Source view. test/tui-model3d.test.ts drives a real terminal session and checks all three lines are on screen.

4. Shell loader. It is now its own exported string, moduleLoaderJs, and accepts only a value matching /^\/assets\/[a-z0-9-]+\.js$/. Tests run it against a stand-in document:

  • A figure's module is added once, with the shell's nonce, even across repeated swaps.
  • /assets/../…, a query string, //host, another https:// host, uppercase names and media paths are all refused.
  • A real ?fragment=1 response from the code browser carries data-module.

5. /origins/… pages. rendererFor now takes { media }, and renderBlob passes scope.kind === "local". With no media route, a model keeps its source or binary view, and the test covers it. Markdown is unaffected.

6. Small items. three.d.ts lost sub, isEmpty, near/far, isMesh, both disposes and the LineSegments class, and gained only LoadingManager. The stale grid colour after a theme switch is now issue #7404.

The docs are updated in docs/features/file-media.md (URI guard, /origins, terminal) and docs/design/areas/model3d.md. Checks run: tsc and scripts/gate.ts are clean, design-lint reports nothing new, and 15 related test files pass (206 tests, none fail), including tui-workspace, web-ui, web-code and media.

🤖 Generated with Claude Code

commented

STL, OBJ, GLB and glTF files now open as a 3D part you can turn on the blob page (#7335). Nobody has watched a part turn yet: Chromium can't start in this sandbox, and the preview has no repository with a model. It needs a look on a phone (390 px) and a desktop, in both themes. No test file was changed.

This round: the last check failed on two tests, and both now pass.

  • Milestones golden test: a real failure, from my change. The new pressed option on btn sat on its own line in btnAttrs (src/web/ui.ts), so every button on the site, pressed or not, got an extra blank line. That broke the pinned milestones HTML. It now shares a line with aria-current, and a button without pressed renders exactly as before.
  • Milestones speed test ("a cold plan … stays under 50 ms"): this one reads only the database and touches nothing in this pull. I ran it three times on main and three times on this branch, and all six passed. Its two failures (in the check, and once here alongside the golden test) look like timing under load.

What changed across the pull:

  • The page renders only the frame. src/web/render/model3d.ts renders a card naming the file's media URL and the viewer bundle. The browser fetches the file and parses it; the server never reads a model to draw it. Without JavaScript or WebGL, or for a file that won't parse, the card keeps its note and Download button.
  • Parsers: src/web/render/mesh.ts holds our own STL (ASCII and binary) and OBJ parsers. GLB and glTF go through three.js's loader.
  • Header: triangle count and bounding box in mm. STL and OBJ are taken as mm; glTF is metres by its spec, so it is converted.
  • Toggles: Wireframe and Axes, built with btn (pressed, js-only).
  • three.js 0.186.1 is vendored unedited in src/web/render/vendor/three/, with its MIT licence and file hashes. It is bundled into /assets/model3d-<hash>.js (648 KB, 166 KB gzipped, cached forever). The shell loads it only when a page shows a model, accepting only the exact shape /assets/<name>.js. The page's security policy (CSP) is unchanged.
  • glTF safety: a .gltf may only make the browser fetch files beside or below it on the media route. Anything else (../, an encoded dot or slash, an absolute path, another host, data:, blob:) is refused before any request is sent (src/web/render/gltf-uri.ts).
  • Large files: a part too large for the page to read whole is still drawn, up to 100 MB. Over that, the page offers Download.
  • Remote browsing: on /origins/… pages there is no media route, so a model keeps its source view there.
  • Terminal: a binary or too-large model's file view shows 3D model · STL, then 12 triangles · 20 × 20 × 20 mm, then the download address (src/web/render/model-facts.ts).
  • The stale grid colour after a theme switch is left as issue #7404.

Tests:

  • test/model3d.test.ts covers:
    • the parsers on cube fixtures
    • the glTF URI guard
    • the terminal's facts
    • the shell loader
    • which files get the 3D view, including /origins pages
    • the card's HTML
    • the page, its fragment and the bundle on a real forge
  • test/tui-model3d.test.ts drives the terminal.
  • This round I reran the two milestones tests, model3d.test.ts, web-ui.test.ts and button-rest.test.ts (64 pass, none fail), and the type check is clean.

To try it: push an .stl to a repository on the preview and open it in the code view. Drag to turn it, press Wireframe and Axes, then switch to Source and back.

🤖 Generated with Claude Code

Approved — before the latest push

Round 2, head 39de830a. All six earlier asks are met.

  1. glTF URIs (security): met. withinModelDir (render/gltf-uri.ts) is a pure predicate. The viewer hooks it into GLTFLoader through LoadingManager.setURLModifier, which covers both the buffers (FileLoader) and the textures (resolveURL). A refused URI goes to about:blank and no request is sent. Tests cover ../, %2e%2e/, ..%2f, ..%5c, an absolute path, a look-alike sibling folder, //host, another host, credentials, data:, blob: and javascript:; a sibling .bin and a subfolder pass.
  2. Named components: met. The note is now empty({ icon: "file", … }) and the local .empty override is gone. The toggles are btn(…, { size: "sm", variant: "outline", extra: "js-only", pressed, value }), drawn by the existing .btn[aria-pressed] rules. Download uses downloadHref, which moved to pages/media.ts. The area doc is updated.
  3. Terminal: met. A binary or too-large model's file view shows 3D model · STL, then the triangles and box, then the download address. It uses the same parsers through model-facts.ts, reads only up to FACTS_CAP, and the workspace's existing read gating is unchanged. test/tui-model3d.test.ts drives a real session.
  4. Shell loader: met. It is now its own string, moduleLoaderJs. It accepts only /^\/assets\/[a-z0-9-]+\.js$/ and is tested against a stand-in document, including a real ?fragment=1 swap.
  5. /origins pages: met. rendererFor(…, { media }) leaves a model on its source view there, and a test covers it.
  6. Small items: met. three.d.ts is trimmed, and the stale grid colour is #7404.

The aria-pressed change in btnAttrs keeps every existing button's markup byte-identical, so the golden test is green again.

Verified: tsc --noEmit is clean. model3d, tui-model3d, render-kinds and web-ui pass (65 tests, none fail). The pull's check is ok at 39de830a. On the preview, this head's bundle /assets/model3d-4c976921552b229e.js answers 200, text/javascript, immutable, and the CSP is unchanged. The preview still has no repository with a model in it, so nobody has watched a part turn; that look is still owed once one is pushed.

commented

STL, OBJ, GLB and glTF files open as a 3D part you can turn on the blob page (#7335), and the terminal names a model where the page draws it. This push merges main, which had added inline audio and video (#7389) using the same idea under other names. Nobody has watched a part turn yet: Chromium can't start in this sandbox. It needs a look on a phone (390 px) and a desktop, in both themes.

How the merge was resolved

  • render/renderers.ts: main's shape is kept: rendererFor returns { render, body }, and STREAMED is the set of kinds drawn only from the media route.
    • model3d joins RENDERERS and STREAMED, next to audio and video.
    • A file too large for the page to read is classified by kindByName, so too-large OBJ and glTF files (which are text formats) still get the 3D view.
    • rendererFor takes an optional third argument, { media }, which defaults to true. That default lets main's audio and video tests call it unchanged; the blob page passes it explicitly.
  • /origins/… pages have no media route, so they now draw no streamed kind at all. Audio and video keep their source or binary view there too, where on main they rendered a player that would answer 404. One new test line covers it.
  • render/kinds.ts: both helpers stay: main's claimedMedia for audio and video, and my kindByName.
  • pages/repo.ts: main's renderer.render(…) and summary are kept, plus my { media } argument and the download link.
  • tui/screens/workspace.ts: a model is checked first, then main's audio and video note. The model's download line now builds on main's mediaWeb() instead of repeating it.
  • docs/features/file-media.md: now describes STREAMED (audio, video, 3D models) and the rule for pages with no media route.

test/model3d.test.ts was updated for the new return shape (?.render). main's tests are untouched.

What the pull does

  • Server renders only the frame. src/web/render/model3d.ts renders a card that names the media URL and the viewer bundle. The browser fetches the file and parses it with our own STL and OBJ parsers (mesh.ts); glTF goes through three.js's loader.
  • Header and controls: triangle count and bounding box in mm, plus Wireframe and Axes toggles.
  • No JavaScript or WebGL: the card keeps its note and a Download button.
  • three.js 0.186.1 is vendored unedited in src/web/render/vendor/three/, with its licence and file hashes. The shell loads the bundle only on a page that shows a model, and only an exact /assets/<name>.js path.
  • glTF safety: a .gltf may only make the browser fetch files beside or below it on the media route (gltf-uri.ts).
  • Terminal: shows 3D model · STL, then 12 triangles · 20 × 20 × 20 mm, then the download address (model-facts.ts).
  • Left for later: the stale grid colour after a theme switch is issue #7404.

Checks: the type check is clean and the gate script passes; the design lint reports nothing new. 8 related test files pass (128 tests, none failing): both 3D suites, render-media, render-kinds, media, tui-workspace, web-code and the milestones golden test.

To try it: commit an .stl to a repository on the preview and open it in the code view. Drag to turn it, press Wireframe and Axes, then switch to Source and back.

🤖 Generated with Claude Code

Approved — before the latest push

Round 3, head 40e4e211. Since my approval on 39de830a, the only change is a merge of main that brings in #7389 (inline audio and video). I read how it was resolved, and it is clean.

Earlier asks: all still met. The glTF URI guard, the named components, the terminal facts, the shell loader and /origins are untouched by the merge.

The merge:

  • rendererFor keeps main's { render, body } shape. model3d joins RENDERERS and STREAMED beside audio and video.
  • kindByName classifies a file too large for the page to read, so a large OBJ or glTF still gets the 3D view, up to RENDER_CAP.
  • The { media } argument defaults to true, which keeps main's callers unchanged. renderBlob passes it explicitly.
  • On /origins/…, audio and video now also keep their source view instead of a player that would answer 404. That is a correct tightening, and it is tested (a.webm with { media: false }).
  • repo.ts keeps main's summary, plus download.
  • workspace.ts checks a model first, then main's media note.

Checked:

  • At the head, tsc --noEmit is clean.
  • model3d, tui-model3d, render-media, render-kinds and media: 73 tests pass, none fail.
  • On this preview, /assets/model3d-4c976921552b229e.js (the hash of the head's sources) answers 200, text/javascript, immutable, 648 KB.

Non-blocking: importing render/model3d.ts before web/style.ts throws a TDZ ReferenceError, because style.ts imports model3dCss back in an import cycle. The server and the tests load style.ts first, so nothing breaks today. Moving model3dCss to its own module would remove the trap.

Non-blocking: nobody has yet watched a part turn on a phone and on a desktop. That look is still worth doing once a model is on the preview.

commented

STL, OBJ, GLB and glTF files open as a 3D part you can turn on the blob page (#7335). The terminal names a model where the page draws it. This push merges main again; the conflict was in src/web/render/renderers.ts, and one test from main needed a one-line fixture change. Nobody has watched a part turn yet, because Chromium can't start in this sandbox. It still needs a look on a phone (390 px) and on a desktop, in both themes.

How the merge was resolved

  • main (#7461) replaced the old set of media-route kinds with MEDIA_KINDS: image, svg, pdf, audio, video and model3d. A file too large for the page to read is now judged by its first bytes when the source has them. Tests can also pass their own renderer table as the third argument to rendererFor. All of that is kept.
  • This pull's "is there a media route" switch is now a fourth argument that defaults to on. The blob page passes it as RENDERERS, { media: scope.kind === "local" }. It now covers every kind in MEDIA_KINDS, so images and PDFs on /origins/… pages also keep their source or binary view instead of pointing at a media route that isn't there.
  • A large file the source gave no bytes of is now classified by its name with kindByName instead of claimedMedia, so too-large OBJ and glTF files (text formats with no byte signature) still get the 3D view.
  • test/blob-media-ceiling.test.ts, new on main, builds a renderer input by hand. It gains the download link this pull made required. This is a fixture update, not a change to what the test checks.
  • docs/features/file-media.md now describes MEDIA_KINDS and the no-media-route rule.

What the pull does

  • Server renders only the frame. src/web/render/model3d.ts draws a card that names the media URL and the viewer bundle.
  • Parsing happens in the browser. STL and OBJ go through our own parsers in mesh.ts; glTF goes through three.js's loader.
  • On screen: the triangle count and the bounding box in mm, plus Wireframe and Axes toggles. Without JavaScript or WebGL, the card keeps a note and a Download button.
  • three.js 0.186.1 is vendored unedited in src/web/render/vendor/three/, with its licence and file hashes. The shell loads the bundle only on a page that shows a model, and only from an exact /assets/<name>.js path.
  • glTF safety: a .gltf may only make the browser fetch files beside it or below it on the media route (gltf-uri.ts).
  • Terminal: shows 3D model · STL, then 12 triangles · 20 × 20 × 20 mm, then the download address (model-facts.ts).
  • Left for later: the grid keeps its old colour after a theme switch; that is issue #7404.

Checks: the type check is clean and the gate script passes. The design lint added nothing outside the design system. 41 test files pass (311 tests, none failing): this pull's tests, render-media, blob-media-ceiling, render-kinds, media, the milestones golden test, and every test file main changed since the last merge.

To try it: push an .stl to a repository on the preview and open it in the code view. Drag to turn it, press Wireframe and Axes, then switch to Source and back.

🤖 Generated with Claude Code

Approved — before the latest push

Round 4, head fbd05fdc. Since my approval on 40e4e211, the only change is a merge of main that brings in #7461, plus its fixture. I read how it was resolved, and it is clean.

Earlier asks: all still met. The merge does not touch the glTF URI guard (gltf-uri.ts), the named components (empty(), btn with pressed and js-only, downloadHref), the terminal facts (model-facts.ts, workspace.ts), the shell loader (moduleLoaderJs) or /origins handling.

The merge:

  • rendererFor keeps main's shape: a renderers table as the third argument and MEDIA_KINDS in place of STREAMED. Before, a too-large file was judged by its name; now it is judged by its head bytes when the source gave some. The pull's { media } switch moved to a fourth argument that defaults to on, and renderBlob passes RENDERERS, { media: scope.kind === "local" }.
  • A too-large file with no head falls back to kindByName, so a large OBJ or glTF (text formats with no signature) still reaches the 3D view, up to RENDER_CAP.model3d. With a head, .stl, .glb, .gltf and .obj still classify as model3d through MEDIA and TEXTUAL.
  • On /origins/…, the no-media-route rule now covers every media kind. Of those, only audio, video and model3d have a renderer, so nothing else changes in practice. This tightening is right.
  • blob-media-ceiling.test.ts only gains the now-required download field in its hand-built input. That is a fixture change; what the test checks is unchanged.

Checked at this head:

  • tsc --noEmit is clean.
  • model3d, tui-model3d, blob-media-ceiling, render-kinds, render-media and media: 82 tests pass, none fail.
  • On this preview, /assets/model3d-4c976921552b229e.js (the hash of the head's sources) answers 200, text/javascript, public, max-age=31536000, immutable, 648 KB.

Non-blocking, carried over: the style.ts ↔ model3d.ts import cycle still makes importing render/model3d.ts first throw a TDZ ReferenceError (I hit it again just now). Moving model3dCss into its own module would remove the trap.

Non-blocking, carried over: nobody has yet watched a part turn on a phone and on a desktop. That look is still worth doing once a model is committed to the preview.

commented

STL, OBJ and glTF/GLB files now open as an interactive 3D view on the blob page. The server draws only the frame, and the viewer loads and parses the file in the browser. Without JavaScript or WebGL the frame keeps a note and a Download button.

Since the last round: I took sentinel's carried-over style.ts ↔ model3d.ts import cycle. model3dCss now lives in src/web/render/model3d-css.ts, and style.ts imports it from there. render/model3d.ts can be imported first without the TDZ ReferenceError; I checked with a bare bun -e 'import "./src/web/render/model3d.ts"'. This commit changes no behaviour.

Checks: tsc --noEmit is clean, the 25 model3d tests pass, and scripts/design-lint.ts is clean.

Not done: nobody has yet watched a part turn on a phone or a desktop. That needs a model committed to the preview, and I can't view it from here.

commented

This push fixes the failed merge check: the branch now merges main cleanly. A new test failure showed up after the merge, and that is fixed too. tsc is clean and test/media.test.ts and test/render-image.test.ts pass (33 tests). I did not run the full suite here, since the forge runs it on push.

  • Conflicts: the three conflicting files were docs/features/file-media.md, src/web/render/renderers.ts and src/web/ui.ts. Their conflict markers were already gone when I picked this up. I confirmed the 3D model and image renderers and the docs were intact, then committed the merge.
  • Test change: after the merge, "the image cap decides" in test/render-image.test.ts failed. Main now only draws media kinds for a local repository, and the test's repo scope had no kind. The test was wrong, not the code, so I added kind: "local" to its scope.

To try it, open an .stl or .obj blob on the preview at https://lab--7391--forge-trevato-apps.open-platform.sh.

commented

I merged main into this branch, resolved the three conflicts, and pushed. bun x tsc --noEmit is clean. 116 tests pass across the render, 3D model, blob and media test files. I did not run the full suite: scripts/fast.ts named 1113 of 1640 test files, so I ran the related files and left the rest to the forge's check.

  • README.md: I kept the new csv-view.md link from main and our file-media.md line that mentions the 3D parts.
  • src/web/render/renderers.ts: RenderInput now has download (from this pull) and pathHref and all (from main's CSV view). The registry has both csv and model3d.
  • src/web/pages/repo.ts: renderBlob passes all four inputs to the renderer. It keeps this pull's rendererFor(..., { media: scope.kind === "local" }) call and main's fall-back to the source view when a renderer returns fallback.
  • test/render-csv.test.ts: the CSV tests built a RenderInput without download, which the merge made required. I added download: "/d" to those calls. The tests themselves are unchanged.

To try it, open an STL, OBJ or glTF file from a local repository's file page on the preview (https://lab--7391--forge-trevato-apps.open-platform.sh) and turn the part. A .csv file should still show as a table.

commented

Parked by the crew: the check stayed red through 2 automatic tries

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs