Skip to content

feat(print): real-world scale and Print page (T-H1, T-N1) - #461

Merged
lightningpixel merged 8 commits into
devfrom
feat/print-page
Nov 17, 2026
Merged

lightningpixel merged 8 commits into
devfrom
feat/print-page

Conversation

@lightningpixel

Copy link
Copy Markdown
Owner

Closes #323
Closes #425

Real-world scale (T-H1)

  • A new Set Real Size op (mesh ops, the Edit panel and an agent tool) scales a mesh to a given size in mm, cm or m and bakes the scale into the vertices. The file is then marked calibrated with scenes[].extras.modly.real_scale = {"unit":"m"}.
  • The marker survives other mesh ops and Library round-trips. normalize_scale only writes it when a real unit (m, cm or mm) is chosen; the new default, "units", writes nothing.
  • A calibrated asset exports in mm as STL, OBJ and PLY, from /export, /optimize/export, the slicer hand-off and the workflow Mesh Exporter alike. Uncalibrated assets export as before.
  • Imported STL/OBJ/PLY files are converted from mm and Z-up to metres and Y-up, and marked calibrated. The viewer frames models far from one unit in size.

Print page (T-N1)

  • A new page in the Create group: a build-plate view in mm with a 10 mm grid and the build-volume outline. There are 6 printer presets plus a custom volume. The model's size is shown, and a model too large for the printer is flagged.
  • An uncalibrated model is shown at the size the slicer route would send (one shared rule, GET /export/print-scale/{token}), with a "provisional size" banner.

Review fixes

  • Scale stored in node matrices was ignored by the STL export and by Repair and Smooth, so files came out up to 6.7× too large. It is now baked into the vertices and read in world space.
  • prepare_for_printing now marks its output calibrated.
  • The Print page no longer keeps a stale load error, and no longer races when two models are picked quickly.
  • The marker is read from the GLB header only, and the viewer's cleanup and centring helpers are shared.

Tests

npm run lint, npm run test (Python 538 OK, JS 0 failures) and npm run build pass. The Print page and the viewer framing are not yet checked by eye in the app.

"This object is 30 cm": the new set_real_scale op rescales the mesh with
normalize_scale and marks the GLB as calibrated, in the default scene's
extras (modly.real_scale = {unit: "m"}). The declaration travels with the
file, and the registry carries it over to the output of any later op that
rebuilds the mesh.

Exports use it: a calibrated asset's STL is written in millimetres, and
the slicer hand-off sends its real size instead of the 50 mm default.

Closes #323
A new Print page (Create, after Workflows) shows a model on a printer's
build plate at its real size:
- the model is Generate's current mesh or any mesh from the Library
- printer presets (Bambu Lab, Prusa, Creality, Voron) or a custom
  volume, remembered between sessions; the default is 256 x 256 x 256 mm
- the model is read in metres (glTF), drawn in millimetres, centred on
  the plate and resting on it; its size is shown in mm
- a model larger than the build volume is flagged, side by side, and
  the volume outline turns red
- a model without a declared real size (set_real_scale) says so and
  points to Set Real Size

Closes #425
trimesh's Scene.apply_transform only moves the scene's base frame, so
set_real_scale stored the new size in a node matrix and left the
vertices as they were. Readers that join the geometry without the
nodes then saw the old size: a 2 x 1 x 0.5 mesh declared as 30 cm
exported as a 2000 mm STL, and repair and smooth wrote it back at its
original size, still marked calibrated.

- The transform ops bake the node transforms into the vertices, so the
  stored geometry is what the scene shows.
- The STL/OBJ/PLY exports and the repair and smooth ops read the mesh
  in world space, whatever GLB they get.
- normalize_scale, and so prepare_for_printing and prepare_for_game,
  declare the real size too: the slicer no longer resizes a print
  prepared at 100 mm to the 50 mm default.
- read_real_scale reads only the GLB header and JSON chunk.

Each case has a test that runs the op end to end on a real file.
- A load error belongs to the model it was about: it is no longer shown
  once another model is on the plate.
- A Library asset that finishes opening after a newer choice is
  ignored, instead of replacing it.
- MM_PER_M comes from printBed, and the Print page shares mesh disposal
  and ground placement with the Generate viewer (shared/three/meshScene).
…cale

- GET /export/print-scale/{token} says how the slicer hand-off sizes a
  mesh (millimetres per unit, calibrated or not). print_mm_per_unit is
  the one rule behind both: the slicer route uses it, and the Print page
  will read it instead of guessing.
- STL, OBJ and PLY imports are millimetres and Z-up by convention: they
  are now converted to a glTF in metres and Y-up, marked at real size,
  and registered as glTF so the slicer route rotates them back.
- A calibrated asset's OBJ and PLY exports are in millimetres too, like
  STL and the slicer route. Uncalibrated assets do not change.
- normalize_scale marks the mesh as real-sized only for a real unit.
  Its unit defaults to the new "units" (model units, no real size), so
  the Edit panel's default and an agent call without a unit no longer
  mark it; prepare_for_printing (mm) and prepare_for_game (m) still do.
The Print page asks the backend how the slicer hand-off would size the
model (GET /export/print-scale) and shows it at exactly that size, so
the plate and OrcaSlicer never disagree: about 50 mm for unit-sized AI
output, its real size once calibrated. The fit check uses the same
size, and a "Provisional size" banner says how to set a real one.
An imported 30 mm STL is now 0.03 m, a speck under the default camera,
and a model of several metres swallowed it. When the model's longest
side leaves the 0.25-10 range, Generate's viewer scales its camera,
clipping planes, zoom limits and grid to it; generated, unit-sized
meshes keep the default view and the user's camera.
…rter

The Mesh Exporter node reads the real-scale marker of its input GLB and,
for a calibrated asset, writes STL, OBJ and PLY in millimetres, like the
API's exports and the slicer hand-off. GLB output and uncalibrated
assets are unchanged.
@lightningpixel
lightningpixel merged commit 45b0639 into dev Nov 17, 2026
5 checks passed
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