Repository navigation
feat(print): real-world scale and Print page (T-H1, T-N1) - #461
Merged
Merged
Conversation
"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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #323
Closes #425
Real-world scale (T-H1)
scenes[].extras.modly.real_scale = {"unit":"m"}.normalize_scaleonly writes it when a real unit (m, cm or mm) is chosen; the new default,"units", writes nothing./export,/optimize/export, the slicer hand-off and the workflow Mesh Exporter alike. Uncalibrated assets export as before.Print page (T-N1)
GET /export/print-scale/{token}), with a "provisional size" banner.Review fixes
prepare_for_printingnow marks its output calibrated.Tests
npm run lint,npm run test(Python 538 OK, JS 0 failures) andnpm run buildpass. The Print page and the viewer framing are not yet checked by eye in the app.