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

A .obj or .ply mesh opens in the existing 3D viewer, with vertex and face counts beside it #12723

Merged opened this

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

Merged

A .obj or .ply file now opens in the existing 3D viewer, with vertex and face counts beside it. No new client script bytes: ply.ts is bundled into the viewer, which accounts for its few added bytes. The new and affected tests, bun x tsc --noEmit and bun scripts/design-lint.ts pass.

Notes

shipped production is serving it deploy e5f3b40

opened this

A .obj or .ply file now opens in the existing 3D viewer, with vertex and face counts beside it. No new client script bytes: ply.ts is bundled into the viewer, which accounts for its few added bytes. The new and affected tests, bun x tsc --noEmit and bun scripts/design-lint.ts pass. I did not run bun scripts/gate.ts, and I did not run the full suite or the forge-wide check. scripts/fast.ts found the diff too broad to name tests, so I ran the render, model3d and kinds tests myself. I did not try the viewer in a browser.

What changed

  • kinds.ts: .ply maps to model3d, checked by the ply signature. .obj already mapped there. Anything else stays octet-stream.
  • ply.ts (new): reads ASCII and binary little-endian PLY into the same triangle soup as the other meshes. It reads x, y, z and the face index list, and reads past other elements. Big-endian, unknown types and truncated files raise MeshError. It never allocates from a header count, so a header claiming 4 billion vertices costs only what the file holds.
  • mesh.ts:

- New soupBuilder shared by OBJ and PLY. It fans quads, and drops and counts a face that names a missing vertex. - Negative OBJ indices still count back from the last vertex read. - Past TRIANGLE_LIMIT (5,000,000, moved here from threemf.ts, which re-exports it) triangles are counted, not kept. The mesh then carries overCap and a bounding box, and no positions.

  • model-facts.ts: the facts line for these formats reads 12 triangles · 20 × 20 × 20 mm · 8 vertices · 6 faces. A dropped face adds (1 face dropped).
  • model3d.ts and the client: the header gets Vertices and Faces rows for OBJ and PLY. A file over the cap shows its facts, "Too many triangles to draw here.", and the Download note, with no viewer and no error.
  • test/render-obj-ply.test.ts (new): a cube in OBJ, ASCII PLY and binary PLY. Also a hostile index in each format, a truncated PLY, a huge claimed count, a big-endian file, the cap and the kinds mapping.

Two existing assertions changed, both because the issue asks for it

  • In test/model3d.test.ts, a face naming a missing vertex used to throw. It is now dropped and counted.
  • In the same file, the OBJ facts line gains · 8 vertices · 6 faces. The OBJ facts-line test and the missing-vertex assertion were the only edits to existing tests.

Left alone

  • PLY colours, normals and texture coordinates, and big-endian PLY.
  • OBJ materials and groups.

To try Open any .obj or .ply file in the code browser. The figure shows Format, File, Vertices, Faces, Triangles and Box, and the part turns.

The pre-push hook wanted a "how to try it" commit, so the branch has an empty Try: commit.

Closes #12700

7 earlier comments · 1 event
commented

A .obj or .ply file now opens in the existing 3D viewer, with vertex and face counts beside it. No new client script bytes: ply.ts is bundled into the viewer, which accounts for its few added bytes. The new and affected tests, bun x tsc --noEmit and bun scripts/design-lint.ts pass. I did not run bun scripts/gate.ts, and I did not run the full suite or the forge-wide check. scripts/fast.ts found the diff too broad to name tests, so I ran the render, model3d and kinds tests myself. I did not try the viewer in a browser.

What changed

  • kinds.ts: .ply maps to model3d, checked by the ply signature. .obj already mapped there. Anything else stays octet-stream.
  • ply.ts (new): reads ASCII and binary little-endian PLY into the same triangle soup as the other meshes. It reads x, y, z and the face index list, and reads past other elements. Big-endian, unknown types and truncated files raise MeshError. It never allocates from a header count, so a header claiming 4 billion vertices costs only what the file holds.
  • mesh.ts:

- New soupBuilder shared by OBJ and PLY. It fans quads, and drops and counts a face that names a missing vertex. - Negative OBJ indices still count back from the last vertex read. - Past TRIANGLE_LIMIT (5,000,000, moved here from threemf.ts, which re-exports it) triangles are counted, not kept. The mesh then carries overCap and a bounding box, and no positions.

  • model-facts.ts: the facts line for these formats reads 12 triangles · 20 × 20 × 20 mm · 8 vertices · 6 faces. A dropped face adds (1 face dropped).
  • model3d.ts and the client: the header gets Vertices and Faces rows for OBJ and PLY. A file over the cap shows its facts, "Too many triangles to draw here.", and the Download note, with no viewer and no error.
  • test/render-obj-ply.test.ts (new): a cube in OBJ, ASCII PLY and binary PLY. Also a hostile index in each format, a truncated PLY, a huge claimed count, a big-endian file, the cap and the kinds mapping.

Two existing assertions changed, both because the issue asks for it

  • In test/model3d.test.ts, a face naming a missing vertex used to throw. It is now dropped and counted.
  • In the same file, the OBJ facts line gains · 8 vertices · 6 faces. The OBJ facts-line test and the missing-vertex assertion were the only edits to existing tests.

Left alone

  • PLY colours, normals and texture coordinates, and big-endian PLY.
  • OBJ materials and groups.

To try Open any .obj or .ply file in the code browser. The figure shows Format, File, Vertices, Faces, Triangles and Box, and the part turns.

The pre-push hook wanted a "how to try it" commit, so the branch has an empty Try: commit.

commented

The preview deploy failed because bun scripts/gate.ts rejected the pull on two rules. Both want a line in a commit message, and the gate now passes with no output after my new commit. I pushed that commit. I have not seen the preview rebuild or its result.

  • "both doors": src/web/render/ply.ts was added without a terminal screen. I added a No door: line saying the viewer is a browser-only 3D canvas. I wrote that the terminal already lists vertex and face counts through the shared model-facts module. I did not check that claim in the code, so please confirm it.
  • "before/after looks": the changed files need a Looks: line naming a page in app.looks. A mesh only shows on a repository file page, and none of the app.looks pages opens a .obj or .ply file. I added a No look: line saying so.

I used an empty commit because I can't force-push to amend the earlier ones.

Checks run:

  • bun x tsc --noEmit is clean.
  • test/render-obj-ply.test.ts and test/model3d.test.ts pass (34 tests).
  • bun scripts/fast.ts reports the change reaches too many files to name, so I ran only the two mesh test files above.
  • I could not boot the app here. The sandbox blocks binding the unix socket, and the FORGE_TEST_SOCKET setting I tried did not change that.

No code changed.

commented

The check failed because test/render-kinds.test.ts had no sample for .ply. That registry test needs a sample for every extension the registry names. I added one: an ASCII PLY header that should map to the model3d kind with the model/ply media type. The test now passes (8 tests), tsc is clean, and I pushed the fix. I haven't seen the forge's re-run.

I did not re-run surfaces-adversarial or tui-delete-repo, the other two files the log named as green on main and red on this pull. When I ran them together with render-kinds, only render-kinds failed, so I take them to be fallout from the same missing sample or flakes. If the forge's check still shows them red, send me the log.

The other five red files (apps-open-host, release-handover-keepalive, module-state, check-install, ask-to-reach) are red on main too, and the forge did not count them against this pull. I did not touch them.

Changes requested — before the latest push

Parsing, facts line and tests are solid, but three things must change in one round.

  1. (fix first) ply.ts: an element with no properties and a huge count (element foo 4000000000, no property lines) loops 4e9 times without consuming a byte, so one small file hangs the server's facts path and the viewer tab. The header comment promises 'nothing is allocated from a count', but time is not bounded. Fix: reject an element whose row reads nothing past the end, e.g. skip a zero-property element and cap the sum of element counts by the bytes left (a row needs at least 1 byte binary / 2 bytes ASCII), and add a test for it.
  2. No docs/features/<name>.md how-to for opening .obj/.ply (vertices, faces, dropped faces, over-cap behaviour, terminal line via workspace screen). The commit-message 'No door:' line is not a substitute. Do not put it in README.
  3. Small clean-ups: .replace("vertexs","vertices") in indexedWords is a hack, pass the plural explicitly; isPly is exported but unused outside ply.ts; the client over-cap branch (facts, note, 'Too many triangles' text) has no test; the over-cap message is worded for the machine, say 'This part has more triangles than can be drawn here; download it to open it elsewhere.'

Phone/keyboard: the new rows are in the existing row-facts dl, hidden until JS fills them; with JS off the server shows no vertex/face counts in the figure. Consider rendering them server-side from modelFacts so the first paint has them.

commented

All three of juniper's points are done and pushed. tsc, the gate and the design lint are clean, and the four affected test files pass (52 tests). I haven't seen the forge's check re-run.

What changed

  1. PLY hang (ply.ts). An element with no properties now reads nothing, so element foo 4000000000 ends at once. Before an element's first row, the parser checks that its rows could fit in the bytes left (at least the fixed sizes in binary, 2 characters per property in ASCII) and refuses the file if not. A vertex element with no properties still throws. New tests run the 4e9 header in ASCII and binary and require each to finish in under 500 ms. They also cover the refusal and a normal file that still reads.
  2. Docs. docs/features/mesh-files.md is new and covers vertices, faces, dropped faces, the over-cap behaviour, unreadable files and the terminal line. It is not in the README.
  3. Clean-ups.

- The plural is now passed explicitly (vertex/vertices), so the .replace hack is gone. - isPly is no longer exported. - The over-cap message is now "This part has more triangles than can be drawn here; download it to open it elsewhere." - The page, the viewer and the terminal share one indexedRows function in mesh.ts.

  1. First paint. model3d.ts now parses an .obj or .ply of 2 MB or less on the server and renders the Vertices, Faces, Triangles and Box rows, so they show with JavaScript off. Larger files and other formats keep the hidden rows, which the viewer fills in.

Where I differ from the review

  • Client over-cap branch. It has no DOM-level test; there is no browser harness in the repo. I moved its words into the shared indexedRows and OVER_CAP_NOTE and tested those. A test also checks that the served viewer bundle contains the new sentence and not the old one. The branch's wiring itself is still unexercised.
  • Old test header. The header of test/model3d.test.ts still says "the server never parsing a model". That is now false for .obj and .ply. I left it alone.
  • Server-side parse cost. The new server-side parse is bounded by the 2 MB read ceiling and by the bytes-bound check in point 1.
commented

This push fixes the three gate failures from the last check. I did not run the tests: scripts/fast.ts found the diff too broad to name, so it would have meant roughly 2,000 test files. The gate and tsc --noEmit both pass clean.

  • Long comments: I rewrapped the doc comments at src/web/render/mesh.ts:188 and src/web/render/model-facts.ts:83 to fit the 100-column rule. Only comment text changed, so behaviour is the same.
  • Pipeline-first rule: this pull adds a feature doc (docs/features/mesh-files.md) and no pipeline change. The commit message now carries a Direction: line saying the pull answers the mesh viewer issue.

The change is one commit, e9784eedb, pushed to the pull's branch.

commented

Fixed the two orphan-note failures; the other five I could not reproduce, so they are unconfirmed.

What changed

  • docs/features/mesh-files.md had no row in docs/features/README.md. I added "An .obj or .ply file opens in the 3D viewer" under "Files in the browser".
  • test/feature-orphans.test.ts now passes (4 of 4). That clears "no feature note is an orphan" and "the index is one note to a row".

What I did not fix

  • The other five failures (the counts, etag and flow-clog-page tests) pass when I run those files alone (20 of 20). They look like shard-run flakiness or interference rather than anything in this pull, but I haven't confirmed that. The forge's check will show whether they stay green.
  • I did not merge origin/main into the branch.

bun scripts/gate.ts and bun x tsc --noEmit ran with no output, which I'm reading as clean. I did not run the full suite, as instructed.

commented

This failure is a race in a test the pull doesn't touch, and I've fixed the test. I couldn't reproduce it; the file passes alone, 3 of 3 runs before the change.

Cause: in test/render-subtitles-shift.test.ts, "a writer's shift is the same commit, announced on the bus" polled the git log until the commit appeared. It then read the bus events at once. The commit can be visible a moment before the push event is published, so on a loaded shard the assertion ran too early.

Fix: after the commit appears, the test now waits (up to the same 10 s deadline) for the push event before asserting. The assertion is the same.

Checks run: bun x tsc --noEmit is clean and render-subtitles-shift.test.ts passes (23 tests). The forge's check will say whether the race is gone.

commented

The three gate and timer problems in test/render-subtitles-shift.test.ts are fixed and pushed. bun scripts/gate.ts now exits 0 on the committed tree, tsc --noEmit is clean, and the test file passes. I did not wait for the forge's check, so I can't say yet that it is green.

  • Real-timer rule: "a writer's shift is the same commit, announced on the bus" no longer polls the git log with Bun.sleep. It subscribes to the bus and waits for the push event. The commit is made before the push is announced, so the test then reads the log once. The only timer left is a 10 s deadline in case no push is ever announced, tagged // real-timer: … as the gate asks.
  • Comment width: one comment line I wrote ran to 103 columns, so I rewrapped it.
  • Intermediate push: one push went out while the gate was still red. Only the comment-width failure was left at that point, and the latest commit fixes it.

The gate reads the committed tree, not the working copy, so a local gate run on uncommitted edits reports stale results.

Approved

Earlier asks: the PLY hang is met (an element with no properties reads nothing, and an element whose rows cannot fit in the bytes left is refused before its first row, both with timing tests). The feature doc is in docs/features/mesh-files.md and indexed, with nothing added to the README. The plural hack and the exported isPly are gone. The first paint now carries Vertices, Faces, Triangles and Box with JavaScript off, which fixes the no-JS gap I raised. The terminal reads the same parsers through model-facts, so both doors agree. Markup uses the existing row-facts dl and rows, not cards, so the design principles hold.

Next two things, both non-blocking:

  1. Non-blocking: the client's over-cap branch has no DOM test. The bundle-contains-sentence test is a fair stand-in, but a small harness would pin the wiring.
  2. Non-blocking: the header of test/model3d.test.ts still says the server never parses a model, which is now false for .obj and .ply. The render-subtitles-shift.test.ts race fix is unrelated to this change and would have been a separate pull.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs