Skip to content

Add StlDef FileDef subclass for .stl 3D meshes - #5627

Closed
FadhlanR wants to merge 2 commits into
mainfrom
cs-12053-stl-file-def
Closed

Add StlDef FileDef subclass for .stl 3D meshes#5627
FadhlanR wants to merge 2 commits into
mainfrom
cs-12053-stl-file-def

Conversation

@FadhlanR

Copy link
Copy Markdown
Contributor

Resolves CS-12053.

Registers .stl (3D-print mesh) as a first-class file type, the way every other file extension already is.

What changed

  • packages/base/stl-file-def.gtsStlDef extends FileDef: cube icon, '3D Model (STL)' display name, isolated/embedded/fitted/atom formats, and a single format field (binary | ascii).
  • packages/base/stl-meta-extractor.tsextractStlFormat(bytes, contentSize). Classifies the encoding from the first 84 bytes plus the file size: the binary size identity 84 + 50·count === contentSize, else an ASCII solid … header. Non-STL bytes throw FileContentMismatchError so a mislabeled/truncated file indexes as a bare FileDef instead of erroring the row. Isolated from the component for unit testing, mirroring mp3-meta-extractor.ts.
  • packages/runtime-common/file-def-code-ref.ts — maps .stl → StlDef, so urlNamesFile() / resolveFileDefCodeRef() route a linksTo a .stl through the file-meta MIME path rather than mis-dispatching it as a card.
  • packages/runtime-common/infer-content-type.tsisBinaryFilename() now treats model/stl (and legacy application/vnd.ms-pki.stl) as binary. .stl matched no MIME prefix before, so binary STL was read as UTF-8 text and its bytes mangled in boxel-cli push/pull/read.

Extract scope

Only format is stored. The extractor reads the header triangle count internally to run the binary/ASCII sniff but does not persist it — triangleCount isn't a real search key and carries no display value on its own. extractAttributes runs per-file on the indexing hot path, so the read is bounded to an 84-byte readFirstBytes (like mp3-audio-def); a full-mesh parse (bounding box, volume) is deliberately deferred off the index path.

Tests

  • packages/host/tests/integration/components/stl-file-def-test.gtsextractStlFormat (binary / ASCII / whitespace-ASCII / non-STL) and StlDef.extractAttributes (format stamping, inherited base fields, extension guard).
  • packages/host/tests/acceptance/stl-file-def-test.gts — drives the file-extract render route for binary + ASCII fixtures, the mismatch fallback, and the indexing → file-meta path resolving to StlDef (mirrors csv-file-def-test.gts).
  • packages/host/tests/unit/file-def-code-ref-test.ts — extends isFileDefCodeRef coverage for StlDef.

Follow-ups (out of scope)

  • Interactive 3D viewer (needs a WebGL/model-viewer dep; the isolated format also renders during prerender).
  • Bounding-box dimensions for size-range filtering — deferrable behind an opt-in flag or a lazy viewer path, off the index hot path.
  • Text-search value from 3D content is a 3MF story, tracked separately.

🤖 Generated with Claude Code

Register `.stl` as a first-class file type:

- StlDef (packages/base/stl-file-def.gts) with a cube icon, the four
  display formats, and a `format` field (binary vs ASCII).
- stl-meta-extractor.ts classifies the encoding from the first 84 bytes
  plus the file size (the `84 + 50*count == size` binary identity, else
  an ASCII `solid` header), guarding non-STL bytes with
  FileContentMismatchError so a bad file indexes as a bare FileDef.
- file-def-code-ref maps `.stl -> StlDef`, so urlNamesFile()/resolveFileDefCodeRef()
  route a `.stl` link through the file-meta path instead of mis-dispatching it
  as a card.
- isBinaryFilename() now treats model/stl (and the legacy
  application/vnd.ms-pki.stl) as binary; otherwise binary STL was read as
  UTF-8 text and its bytes mangled in boxel-cli push/pull/read.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Preview deployments

Host Test Results

    1 files  ±0      1 suites  ±0   2h 31m 41s ⏱️ +51s
3 727 tests ±0  3 713 ✅ ±0  14 💤 ±0  0 ❌ ±0 
3 746 runs  ±0  3 732 ✅ ±0  14 💤 ±0  0 ❌ ±0 

Results for commit a78e47d. ± Comparison against earlier commit 7856763.

Realm Server Test Results

    1 files  ±0      1 suites  ±0   14m 19s ⏱️ -25s
2 017 tests ±0  2 011 ✅  - 6  0 💤 ±0  6 ❌ +6 
2 096 runs  ±0  2 090 ✅  - 6  0 💤 ±0  6 ❌ +6 

Results for commit a78e47d. ± Comparison against earlier commit 7856763.

For more details on these errors, see this check.

Adopts the metadata + rendering from the file-experience prototype onto the
current FileDef subclass, keeping expensive work off the indexing hot path.

Metadata (cheap, index path):
- extractStlMetadata also returns the binary triangle count (already read for
  the format sniff, so free) and the ASCII `solid <name>` label.
- StlDef stores `triangleCount` and `solidName` alongside `format`.

Rendering (interactive card view):
- ThreeModelViewer (base) mounts a three.js WebGL viewer in the StlDef isolated
  view; reusable for a future 3MF def via the same component.
- three.js is loaded with a runtime CDN dynamic import inside the component (the
  approach from the prototype), so it resolves natively in the Boxel card
  runtime with no host build wiring. Bytes are fetched with credentials.
- Ported the prototype's scene setup: hemisphere + directional lights, ACES
  tone mapping, vertex-normal repair, STL Z-up→Y-up, geometry-centered camera
  framing, orbit controls with damping, double-click reset, full GPU teardown.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@FadhlanR

Copy link
Copy Markdown
Contributor Author

[Claude Code 🤖] Superseded by #5658, which unifies StlDef (CS-12053) and ThreeMfDef (CS-12054) under a shared ModelDef base. Closing in favor of that combined PR.

@FadhlanR FadhlanR closed this Jul 31, 2026
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.

1 participant