Skip to content

#729: import STL 3D models (binary and ASCII) - #735

Open
vangel76 wants to merge 1 commit into
storytold:mainfrom
vangel76:gap-stl-import
Open

vangel76 wants to merge 1 commit into
storytold:mainfrom
vangel76:gap-stl-import

Conversation

@vangel76

Copy link
Copy Markdown

Fixes #729.
Part of ranked gap #13 "3D model formats and materials" (docs/gaps.md).

Problem

After Effects 26 imports STL models (usdStl) besides glTF and OBJ. We refused .stl files, and neither the Media Browser nor the import dialog listed them as models.

Fix

  • New crates/model/src/stl.rs, a pure-Rust reader written from the public format description, with no new dependencies:
    • Binary: 80-byte header, u32 facet count, 50-byte facets. Bytes after the last facet are ignored.
    • ASCII: handles several solid blocks in one file and fan-triangulates loops with more than three vertices.
    • Format detection: an exact binary size wins over the solid keyword, because many binary headers also start with solid.
    • Colours: binary per-facet colours in both documented conventions (VisCAM/SolidView with bit 15 set; Materialise Magics COLOR= header with a part colour). Each colour becomes a plain dielectric material. Files without colour get no materials, so the renderer's default material applies, the same as OBJ without an MTL file.
    • Geometry: facets are flat-shaded, with the normal taken from the winding; the stored normal is used only when a facet is degenerate. Z-up (CAD/3D printing) is turned to the model's +Y-up with a proper rotation, so winding is kept.
    • Hostile input: truncated counts, empty files, files with no facets, non-finite coordinates and malformed ASCII vertices all return an error, never a panic. Allocation is bounded by the file size, and colour grouping uses a hash map, not a linear search.
  • .stl is wired in everywhere models are recognised: effectcraft_model::format_of/load, MODEL_EXTENSIONS (import and probe, codec STL (…)), the Media Browser model kind, the File ▸ Import dialog filter, the system report import list and the layer.newModel help.
  • docs/gaps.md row Unsaved changes: ask before closing a modified project; the modified mark follows undo #13 and docs/file-format-parity.md are updated (estimate unchanged).

Tests

  • effectcraft-model:
    • stl_binary_is_faceted_and_turned_y_up: binary file whose header starts with solid, Y-up turn, winding, trailing bytes.
    • stl_ascii_with_polygon_loops_and_several_solids
    • stl_binary_colours: VisCAM and Magics.
    • stl_hostile_input_is_an_error
  • effectcraft-media: stl_imports_as_a_model (is_importable plus probe as a model item). It fails without the change.

Gates

  • cargo fmt --check: passed.
  • cargo clippy -j 4 -p effectcraft-model -p effectcraft-media -p effectcraft-engine -p effectcraft-ui-egui --all-targets -- -D warnings: clean.
  • Full test suites, all targets, 0 failures:
    • cargo test -j 4 -p effectcraft-model
    • cargo test -j 4 -p effectcraft-media
    • cargo test -j 4 -p effectcraft-engine (523 passed)
    • cargo test -j 4 -p effectcraft-ui-egui (499 passed)
  • cargo xtask layers: ok.
  • cargo check -p effectcraft-model -p effectcraft-media -p effectcraft-engine --target wasm32-unknown-unknown: ok.
  • The full cargo xtask ci was not run locally because the machine is shared.

What remains

The rest of gap #13 is still open: FBX, USD/USDZ, and Substance 3D materials with mesh displacement. STL units are taken as-is, the same as OBJ, and scaled by Model Scale.

🤖 Generated with Claude Code

Problem: After Effects 26 imports STL models besides glTF and OBJ; we
refused .stl files, and the Media Browser and import dialog did not list
them as models.

Fix: a pure-Rust STL reader in effectcraft-model (binary and ASCII,
detected from the contents; several ASCII solids and polygon loops;
VisCAM/SolidView and Materialise Magics facet colours as plain
materials; Z-up turned to the model's Y-up; faceted normals from the
winding). Truncated, empty or non-finite input is an error, never a
crash. .stl is now a model extension for import, probing, the Media
Browser, the import dialog and the system report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Import STL 3D models (binary and ASCII) like After Effects

1 participant