Skip to content

feat: center of gravity marker for every object - #828

Open
samuelcomeau6 wants to merge 1 commit into
Snapmaker:mainfrom
samuelcomeau6:per-object-cog
Open

samuelcomeau6 wants to merge 1 commit into
Snapmaker:mainfrom
samuelcomeau6:per-object-cog

Conversation

@samuelcomeau6

Copy link
Copy Markdown

Description

Adds a per-object center of gravity marker to the sliced preview, as a preview option in the legend which is hidden by default.

Screenshots/Recordings/Graphs

image image

Tests

No unit tests: the change is a rendering pass over an in-memory G-code result
plus a legend row, neither of which is reachable from the libslic3r test suite.

Verification

  • Build: GitHub Actions Build all green on windows-2022, macos-14 (arm64),
    ubuntu-24.04 and both Flatpak targets.
  • Placement sanity: symmetric cube — marker sits at the XY center of the
    object and near half height. L-shaped part — marker sits toward the heavy leg,
    outside the bounding-box center.
  • Infill test: CoG responds to differences in infill density between two otherwise identical objects (white and red cones in screenshot)
  • Per object: plate with three objects and a two-instance object — four markers,
    one per printed instance.
  • Supports excluded: same object sliced with and without supports — marker does
    not move.
  • Toggle: appears in the options list of both Line Type and Filament views;
    off on a fresh config; survives restart via show_objects_cog.
  • Themes: legend glyph and the 3D marker read correctly in light and dark.

Adds a per-object center of gravity marker to the sliced preview, as a
preview option in the legend which is hidden by default.

- GCodeViewer::ObjectsCoG walks the G-code moves once, attributes every
  extrusion to the printable object instance whose 2D convex hull it falls
  into, and accumulates a mass weighted centroid. Mass uses mm3_per_mm and
  the per filament density, so multi material objects get a correct center
  of gravity. The Z of a segment is taken half a layer below the nozzle,
  where the material actually sits.
- Nothing is computed while slicing or while the preview loads. The markers
  are built on the first frame after the user switches them on, so the pass
  stays off the memory peak of slicing and costs nothing for the users who
  never turn it on. A new preview only discards the old markers. The update
  stands down while m_loading is armed, since load() pumps the event loop
  while holding the non-recursive gcode result lock.
- Skirt, brim, support material, the prime tower and custom G-code are left
  out, so a marker matches the part that comes off the plate.
- A standalone G-code file (no print objects) falls back to a single marker
  for the whole plate.
- The marker is the standard center of gravity symbol: a quartered black and
  white disc, turned to face the camera so it reads the same from any angle
  and drawn on top of the toolpaths, since the center of gravity is inside
  the object. Its size in pixels stays constant while zooming.
- 'Center of Gravity' sits with the other preview options, in the Line Type
  view and in the Filament view, with the same eye toggle. The legend row
  draws the symbol itself through a new EItemType::CoG, so it reads as the
  glyph rather than a flat swatch. Off by default, remembered in the
  application config as show_objects_cog.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GVXhqDzbHafBk96nYK2xKS
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