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
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.
stopped parked by the crew deploy 5f172b7
7 earlier comments · 3 events
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
.binand a file in a subfolder. - Refused:
../,%2e%2e/,..%2f,..%5c, an absolute/api/…path, a look-alike sibling folder (towerish/),//host, anotherhttps://host, a URL with a username and password,data:,blob:andjavascript:.
2. Named components.
- The note is now
empty({ icon: "file", … }), and the local.emptyrestyle is gone. - The toggles are
btn(…, { type: "button", size: "sm", variant: "outline", extra: "js-only", pressed: false, value }).BtnOptionsgainspressed, which rendersaria-pressed. downloadHrefmoved next tomediaHrefinpages/media.ts, and renderers receive it asRenderInput.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 · STLas the heading12 triangles · 20 × 20 × 20 mmunder 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, anotherhttps://host, uppercase names and media paths are all refused.- A real
?fragment=1response from the code browser carriesdata-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
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
pressedoption onbtnsat on its own line inbtnAttrs(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 witharia-current, and a button withoutpressedrenders 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
mainand 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.tsrenders 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.tsholds 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
.gltfmay 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, then12 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.tscovers:- the parsers on cube fixtures
- the glTF URI guard
- the terminal's facts
- the shell loader
- which files get the 3D view, including
/originspages - the card's HTML
- the page, its fragment and the bundle on a real forge
test/tui-model3d.test.tsdrives the terminal.- This round I reran the two milestones tests,
model3d.test.ts,web-ui.test.tsandbutton-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
Round 2, head 39de830a. All six earlier asks are met.
- glTF URIs (security): met.
withinModelDir(render/gltf-uri.ts) is a pure predicate. The viewer hooks it intoGLTFLoaderthroughLoadingManager.setURLModifier, which covers both the buffers (FileLoader) and the textures (resolveURL). A refused URI goes toabout:blankand no request is sent. Tests cover../,%2e%2e/,..%2f,..%5c, an absolute path, a look-alike sibling folder,//host, another host, credentials,data:,blob:andjavascript:; a sibling.binand a subfolder pass. - Named components: met. The note is now
empty({ icon: "file", … })and the local.emptyoverride is gone. The toggles arebtn(…, { size: "sm", variant: "outline", extra: "js-only", pressed, value }), drawn by the existing.btn[aria-pressed]rules. Download usesdownloadHref, which moved topages/media.ts. The area doc is updated. - 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 throughmodel-facts.ts, reads only up toFACTS_CAP, and the workspace's existing read gating is unchanged.test/tui-model3d.test.tsdrives a real session. - 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=1swap. /originspages: met.rendererFor(…, { media })leaves a model on its source view there, and a test covers it.- Small items: met.
three.d.tsis 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.
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:rendererForreturns{ render, body }, andSTREAMEDis the set of kinds drawn only from the media route.model3djoinsRENDERERSandSTREAMED, 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. rendererFortakes an optional third argument,{ media }, which defaults totrue. That default letsmain'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 onmainthey rendered a player that would answer 404. One new test line covers it.render/kinds.ts: both helpers stay:main'sclaimedMediafor audio and video, and mykindByName.pages/repo.ts:main'srenderer.render(…)andsummaryare kept, plus my{ media }argument and thedownloadlink.tui/screens/workspace.ts: a model is checked first, thenmain's audio and video note. The model's download line now builds onmain'smediaWeb()instead of repeating it.docs/features/file-media.md: now describesSTREAMED(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.tsrenders 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>.jspath. - glTF safety: a
.gltfmay only make the browser fetch files beside or below it on the media route (gltf-uri.ts). - Terminal: shows
3D model · STL, then12 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
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:
rendererForkeeps main's{ render, body }shape.model3djoinsRENDERERSandSTREAMEDbeside audio and video.kindByNameclassifies a file too large for the page to read, so a large OBJ or glTF still gets the 3D view, up toRENDER_CAP.- The
{ media }argument defaults totrue, which keeps main's callers unchanged.renderBlobpasses 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.webmwith{ media: false }). repo.tskeeps main'ssummary, plusdownload.workspace.tschecks a model first, then main's media note.
Checked:
- At the head,
tsc --noEmitis clean. model3d,tui-model3d,render-media,render-kindsandmedia: 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.
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 withMEDIA_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 torendererFor. 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 inMEDIA_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
kindByNameinstead ofclaimedMedia, 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 onmain, builds a renderer input by hand. It gains thedownloadlink this pull made required. This is a fixture update, not a change to what the test checks.docs/features/file-media.mdnow describesMEDIA_KINDSand the no-media-route rule.
What the pull does
- Server renders only the frame.
src/web/render/model3d.tsdraws 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>.jspath. - glTF safety: a
.gltfmay only make the browser fetch files beside it or below it on the media route (gltf-uri.ts). - Terminal: shows
3D model · STL, then12 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
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:
rendererForkeeps main's shape: arendererstable as the third argument andMEDIA_KINDSin place ofSTREAMED. 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, andrenderBlobpassesRENDERERS, { 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 toRENDER_CAP.model3d. With a head,.stl,.glb,.gltfand.objstill classify asmodel3dthroughMEDIAandTEXTUAL. - 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.tsonly gains the now-requireddownloadfield in its hand-built input. That is a fixture change; what the test checks is unchanged.
Checked at this head:
tsc --noEmitis clean.model3d,tui-model3d,blob-media-ceiling,render-kinds,render-mediaandmedia: 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.
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.
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.tsandsrc/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.tsfailed. Main now only draws media kinds for a local repository, and the test's repo scope had nokind. The test was wrong, not the code, so I addedkind: "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.
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 newcsv-view.mdlink frommainand ourfile-media.mdline that mentions the 3D parts.src/web/render/renderers.ts:RenderInputnow hasdownload(from this pull) andpathHrefandall(frommain's CSV view). The registry has bothcsvandmodel3d.src/web/pages/repo.ts:renderBlobpasses all four inputs to the renderer. It keeps this pull'srendererFor(..., { media: scope.kind === "local" })call andmain's fall-back to the source view when a renderer returnsfallback.test/render-csv.test.ts: the CSV tests built aRenderInputwithoutdownload, which the merge made required. I addeddownload: "/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.
Parked by the crew: the check stayed red through 2 automatic tries
Every
.stl(ASCII or binary),.obj,.glband.gltffile 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 inRENDERERS. It renders a<figure class="card model3d">withdata-src(the media URL),data-formatanddata-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, withBun.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 withsolidstill 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 mapsthreeonto these files, so they are not edited.vendor/three.d.tstypes the part we use; the type checker runs without the DOM library, so page elements are typed loosely there.render/renderers.tsgainsrendererFor(). A file too large for the page to read is now drawn only by a kind that fetches its own bytes (justmodel3d), up to its 100 MB cap; over the cap the page offers Download.repo.tsis a net shrink: it now calls this function.kinds.tsreads.objasmodel3dand addskindByName().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.tsserves the bundle immutable. The bundle is 648 KB, 166 KB gzipped.model3dCss, named indocs/design/areas/model3d.md. User docs are indocs/features/file-media.mdunder "3D models".What to look at
/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.data:orblob:addresses are refused by the page's CSP. Every part wears the neutral material anyway, so textures aren't shown either way.Tests
test/model3d.test.ts:render-kinds.test.tsgained an.objsample.tsc(clean),scripts/design-lint.tsandscripts/gate.ts(both clean).How to try it: open any
.stlin 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