Commit Graph
539 Commits
Author SHA1 Message Date
Hakan SevenandClaude Opus 4.8 e1c19d8af3 perf(snap): keep snap/hover responsive on block-heavy drawings
Snap and hover hit-testing scanned the whole model wire set every cursor move; a heavily block-instanced drawing explodes to millions of wires, so this stalled for over a second per move. Add a cached spatial grid (wire_grid) keyed on the geometry epoch and query only the cursor neighbourhood via Scene::hit_test_wires_near. Gate the O(in-range segments squared) intersection passes on the in-range POINT count, not the wire count — a handful of curved wires, each hundreds of tessellated points, blew the quadratic up while the wire count looked modest. Give zero-size entities away from the origin (POINTs) a real cullable AABB, and fall back to a block sub-wire's own world points when its entity bounding box is degenerate.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-09 01:00:51 +03:00
Hakan Seven 17f46968d8 Merge PR #322: perf — responsive large copy/paste + point picking
External contributor sLuCHa (sLuCHaa). Gates O(k²) snap intersection
passes, O(1) handle lookups in preview, bbox paste anchor/ghost,
count-only properties panel for huge selections, incremental paste mesh.
2026-07-08 23:38:37 +03:00
Hakan SevenandClaude Opus 4.8 b5106c82b5 feat(hatch): editable gradient colors + background color
Gradient Type (One/Two color), Color 1 and Color 2 editable via a generic field-keyed colour picker path. Background colour editable and stored as HATCHBACKGROUNDCOLOR extended data (group 1071 true colour), rendered in OCS as a solid backdrop drawn behind the pattern. Hide Origin X/Y for gradients (pattern-only concept) and drop the redundant gradient rows from the pattern branch.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-08 23:35:27 +03:00
Hakan SevenandClaude Opus 4.8 22059e138c feat(hatch): editable pattern props + origin grip
Merge duplicate Type into pattern_type; Type/Associative/Island detection as dropdown/toggle; Angle/Scale/Spacing/Origin X-Y editable; Color via picker. Reorder Pattern group, drop redundant Color/Transparency/Layer override and the Misc section. Wire the pattern origin (per-line base_point) into the render (x0/y0 relative to world_origin) so it affects dashed/offset patterns; add a circle origin grip at the hatch centroid (new GripShape::Circle).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-08 22:48:33 +03:00
Hakan SevenandClaude Opus 4.8 54a29409e7 fix(web): grow-only viewport textures to stop Windows-Firefox divider-drag freeze (#191)
Dragging a model-tile pane_grid divider changed each pane's pixel size
every frame, and `ensure_depth_texture` recreated the depth + 4×MSAA +
resolve textures on any size delta. On Windows Firefox (WebGL2 → ANGLE →
D3D11) this per-frame texture realloc hangs the D3D driver — the same
hang class as the native DX12 lock in #120. Linux Firefox (native GL) and
Chromium/Edge tolerate the churn, which is why the freeze is specific to
Windows Firefox.

Round the depth/MSAA/resolve allocation up to a 128px grid and only
recreate when the rounded size changes, so a live drag reallocates at
most once per 128px instead of every frame. Geometry passes still render
at the real size into the [0,0,render] corner of the larger texture, and
the blit UV is scaled by render/alloc so it samples exactly the filled
region — visually a no-op on every platform.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-08 18:20:27 +03:00
Hakan SevenandClaude Opus 4.8 b3c8c0a2f1 feat(properties): navigate polyline vertices from the panel
The Current Vertex row is now a ◀ / ▶ stepper (new PropValue::Stepper)
showing "i / N". Stepping it moves the panel's focus through the
polyline's vertices — Vertex X/Y and the per-vertex start/end widths show
and edit the focused vertex instead of always the first — and the focused
vertex's grip is drawn hot (filled) in the drawing so it's visible while
navigating. Focus wraps around and resets to the first vertex when the
selection changes. Adds Area and Length to the LwPolyline Geometry group
(Polyline2D already had them). Applies to LwPolyline and Polyline2D.

The focused vertex is threaded to the per-entity property builder/editor
through a dispatch thread-local (like the curve-tolerance override), so
the PropertyEditable trait signatures are unchanged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-08 17:53:05 +03:00
sLuCHa 30b907cdd6 perf(clipboard): keep large copy/paste responsive
Copying and pasting a whole drawing froze the app. Three synchronous,
main-thread hot spots scaled with the full document rather than the
selection:

- Copy centroid did a linear document scan per selected handle
  (wire_models_for / mirror_preview_parts), making copy O(H*N). Use the
  document's O(1) handle index instead.
- The paste ghost translated every point of every clipboard wire on each
  mouse move — O(points) per frame, which stalls placement of a huge
  selection. Above a point budget, rubber-band a single bounding-box
  outline instead (O(1) per frame).
- finalize_paste re-tessellated every solid in the document on each
  paste. add_entity already tessellates pasted solids, so switch to the
  incremental populate_missing_meshes_from_document.
2026-07-08 16:09:35 +02:00
Hakan SevenandClaude Opus 4.8 a4f7ee376f refactor(properties): drop Shadow display from 3D Visualization
Leaves just Material in the group. The shadow_flags entity field is
untouched (preserved on save); only the read-only panel row is removed.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-08 16:36:12 +03:00
Hakan SevenandClaude Opus 4.8 ee4e6cc91c refactor(properties): Color above Layer; drop the Invisible toggle
Reorder the General group so Color precedes Layer. Remove the "Invisible"
row: the entity visibility flag (DXF code 60) is driven by dynamic-block
visibility states, not a manual per-object toggle — setting it from the
panel hid the object with no easy way to reselect it. The flag itself is
unchanged (dynamic blocks still set it, render/save still honour it, and
it stays settable programmatically).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-08 16:31:37 +03:00
Hakan SevenandClaude Opus 4.8 910caa6f67 fix(polyline): render width bands for polylines inside blocks (#222)
Wide LwPolyline / Polyline2D fills only drew for entities directly in the
layout — the model-space loop skips block-internal ones, and the
block-explode fill pass handled hatches but not wide polylines. So a
polyline with a width nested in a block drew at zero width (its
centreline came from the wire path, the band fill never materialized).

Extend the block-explode fill walk (exploded_insert_hatch_models) to emit
wide-polyline bands at world position, gated by a new block_has_wide_poly
scan mirroring block_has_hatch, with a shared push_block_wide_fills helper
that resolves block-child colour inheritance and applies XCLIP.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-08 15:56:56 +03:00
Hakan SevenandClaude Opus 4.8 4df41cdf34 fix(hatch): render fills via the per-fragment in_polygon test again
The batched hatch path pre-triangulated every boundary on the CPU
(PR#300) with no cap on the resulting vertex buffer. A hatch-dense
drawing (13k solid-filled hatches) built a ~6.75 GB `hatch_batched.vertex`
buffer and panicked in `Device::create_buffer` (device max 256 MB), after
a long stall spent triangulating on load.

Drop the CPU triangulation and always draw each hatch as its AABB quad
(6 verts) with `poly_test = 1`, letting the shader resolve inside/outside
per fragment against the uploaded boundary — the path the shader always
kept as a fallback. The vertex buffer is now 6 verts/hatch regardless of
boundary complexity, so no drawing can overflow it. The interaction-LOD
flicker PR#300 addressed no longer occurs (OCS_HATCH_LOD defaults off).
Removes the now-unused hatch_tess triangulation module.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-08 13:30:49 +03:00
Hakan SevenandClaude Opus 4.8 492ad940eb perf(render): incremental wire tessellation for the resident model set
The main GPU render holds the resident (un-culled, camera-independent)
model wire set from `model_tile_wires_arc`, which called
`wires_for_block_culled` with `view_aabb = None` — the branch that bypassed
the per-entity tessellation memo. So every geometry edit re-tessellated
the whole model, even though `mark_entity_dirty` already drops just the
changed entity from the memo.

Give the resident set its own per-entity memo (`resident_tess_memo`),
separate from the camera-dependent `tess_memo` so the culled path can't
thrash it on zoom. Its guard depends only on annotation scale and
background (the resident set has no view cull or zoom LOD), so it survives
pan/zoom and a single-entity edit re-tessellates just that entity, reusing
every other entity's cached wires — on a large drawing, editing one object
now re-tessellates one object instead of the whole model.

Every `bump_geometry_no_blocks` site was audited to confirm it drops the
edited handle via `mark_entity_dirty` (or adds a new entity — a natural
memo miss); `bump_geometry` still clears both memos on structural change.
`OCS_NO_RESIDENT_MEMO` reverts to full re-tessellation as a kill-switch.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-08 12:06:26 +03:00
0964e97cfa fix(text): keep inline \C colours through block colour inheritance (SDF)
Ports PR #301 (by Kevin Griffin) to the SDF text renderer. Block-nested MTEXT
with inline colour codes (\C1;, \c…) collapsed to a single colour: the block
cache applies ByBlock / layer-0 colour inheritance per entity, so at emit time
every segment's colour was replaced with the inherited colour — including
segments carrying an explicit inline override.

- block_cache tessellate_sub_local: gate ByBlock / layer-0 colour inheritance
  on `wire_on_base_color` (a wire whose colour differs from the entity base
  carries an explicit override and keeps it) — #301's fix, still correct for
  the remaining stroke wires.
- block_cache emit_wire: the per-vertex analogue for SDF text — a glyph whose
  colour equals the wire's base inherits the resolved colour; a glyph with an
  inline \C / \c override keeps it. (Previously every block glyph was recoloured
  with final_color, collapsing colour-split MTEXT.)
- tests/text_font_rendering.rs: restore the block colour-split regression test
  (it had stopped compiling on main when expand_insert gained the InheritStyle
  param) and adapt it — and drawable_point_count — to SDF text_verts, since
  block MTEXT now renders as glyph quads, not colour-split stroke wires.

\C (ACI) / \c (true-colour) are parsed by acadrust (mtext_format
SpanProperties.color) → OCS InlineColor → the glyph's per-vertex colour.

Co-Authored-By: Kevin Griffin <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 22:17:27 +03:00
Hakan SevenandClaude Opus 4.8 8498b08abf Merge PR #303: paste copies dimensions correctly (#290)
External contribution by sLuCHa. A dimension draws from its baked *D block
(baked in absolute WCS); the in-drawing COPY re-points block_name to a
transformed copy (#161) but clipboard PASTE did not, so a pasted dimension
rendered at the source location (same drawing) or was missing (cross drawing).

Copy now snapshots each copied dimension's *D block into the clipboard
(dim_blocks); paste builds a fresh copy transformed by the paste offset and
re-points block_name — same- and cross-drawing alike, no orphan blocks.
Refactors out shared define_transformed_block / snapshot_block helpers
(behaviour-preserving).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 21:57:51 +03:00
Hakan SevenandClaude Opus 4.8 fe00bc30ba Merge PR #300: tessellate hatch fills so navigation no longer flickers (#258)
External contribution by sLuCHa. Triangulates each hatch boundary once
(lyon even-odd, cached with the batch build) and rasterizes the triangles
instead of the per-fragment point-in-polygon test, removing the screen-fill
overdraw + boundary raycast that forced the flicker-causing interaction LOD
(now default off behind OCS_HATCH_LOD). Precision preserved (triangles in the
same world_origin-relative frame + RTE path); untessellatable boundaries fall
back to the old AABB-quad + in_polygon path (poly_test=1).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 21:45:02 +03:00
Hakan SevenandClaude Opus 4.8 fa322991c6 fix(text): clip SDF text to xclip boundary; stop debug-assert crash on block fills
Two fixes for opening drawings with XCLIP'd blocks (crashed / mis-rendered
since SDF text became the default).

- block_cache emit_wire: the fill_tris/fill_tris_low length debug_assert
  panicked in debug builds on a legitimate case — a Leader/dimension arrowhead
  fill nested in a block carries fill_tris with an empty fill_tris_low (the
  WireModel contract's "all-zero low" form, which the code already handles via
  get().unwrap_or). Relax the assert to permit the empty case; a *partial* low
  half is still caught.
- xclip clip_wires: also clip the SDF glyph quads. Block-internal text was
  bleeding past the clip boundary (mixed batch) or vanishing (the tail retain
  dropped empty-points wires). Now each glyph quad is kept/dropped by its
  centroid vs the boundary (whole-glyph granularity), text_verts-carrying wires
  survive the retain, and the pick-box AABB is recomputed from the surviving
  glyphs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 21:32:17 +03:00
Hakan SevenandClaude Opus 4.8 5c15091e74 refactor(text): SDF for all text kinds; remove the legacy stroke text path
SDF is the only text renderer now — the stroke path and its LOD ladder are
gone, and the remaining text kinds render as SDF glyph quads too.

- ATTDEF / ATTRIB: carry a GlyphRun so single-line attribute text renders as
  SDF (multi-line already did via layout_mtext). Tolerance / complex-linetype
  text already SDF.
- Remove `sdf_text_enabled()` (the OCS_TEXT_SDF flag / kill switch) and take
  the SDF path unconditionally everywhere: tessellate Text arm (per-group by
  GlyphRun presence), hit_test fallbacks, render gather, complex_lt, table,
  mleader.
- Delete the text LOD ladder: tess.rs baseline/greek block and the
  block_cache greek/baseline path (emit_greeked_text / emit_text_baseline),
  plus the now-dead helpers text_baseline_points / text_greek_obb_tris /
  text_obb_corners_native / mtext_line_count and the LocalWire
  text_height_local / text_obb_local fields. All text is crisp at every zoom;
  text entities are exempt from the sub-pixel stub cull.
- Fix a latent bug: block-internal SDF text was culled because its LocalWire
  aabb_local was [0,0,0,0] (no points) — fold the glyph-quad extent into
  aabb_local and exempt text_verts-carrying wires from the sub-pixel cull.
- Clear the pre-existing dead-code warnings (TextPlacement.elevation, TabKind,
  MTextRunKind::Tab).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 21:07:00 +03:00
Hakan SevenandClaude Opus 4.8 67ce45d40b feat(text): SDF for synthesized-table cell text + guard table pick box
An in-app-created table (no baked *T### block) synthesised its cell text via
layout_mtext as stroke polylines — the last text path still rendering strokes
while SDF is the default (imported/baked tables already render SDF via the
recursive Text arm).

- tessellate_table: when SDF is on, build each cell's glyph quads from the
  run-carrying layout and collect them into one text-carrying wire (per-vertex
  cell colour, glyph-bounds AABB); the stroke/fill accumulation is the SDF-off
  fallback. Mirrors the MLEADER SDF branch.
- tess.rs synthesized-table path: guard the whole-table AABB clobber on
  (!points.is_empty() || !fill_tris.is_empty()) — matching the dim / mleader /
  baked-block paths — so the empty SDF-text wire keeps its tight glyph-box AABB
  and the pick box hugs the text instead of the whole table. Found by the
  adversarial review pass.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 18:37:17 +03:00
Hakan SevenandClaude Opus 4.8 d9a2c8245c feat(text): SDF for tolerance + complex-linetype text; per-group model; pick cycle
Extend SDF text to the remaining text kinds and make the Text arm decide SDF
per group instead of per entity type.

- Text arm: a stroke group renders as SDF glyph quads when it carries a
  GlyphRun (strokes suppressed); a run-less group keeps its strokes. TEXT /
  MTEXT / dim / block / mleader are unchanged (all run-groups). A composite
  Text object can now mix geometry + text: its run-less groups stay strokes and
  its run-groups become SDF. The glyph-bounds AABB is hoisted so both the
  bins-empty and bins-non-empty paths stamp it on the text wire.
- Tolerance: refactored to emit the feature-control frame (border, separators,
  dividers) as run-less stroke groups and each cell's text as a run-group, so
  the frame stays crisp geometry while the values/symbols render as SDF text.
- Complex linetypes: embedded LtSeg::Text renders as SDF glyph quads on an
  extra text wire (glyph-bounds AABB) instead of stroke polylines.
- click_hits_all: include SDF text boxes so selection cycling steps through
  text too, ranked after real geometry.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 18:22:08 +03:00
Hakan SevenandClaude Opus 4.8 96181563fb feat(text): make SDF text the default renderer
Flip `sdf_text_enabled()` to default ON: text renders as SDF glyph quads
(crisp at every zoom, no LOD, box-based snap/pick) for everyone. Set
`OCS_TEXT_SDF=0` to fall back to the legacy stroke path — a kill switch kept
in case a drawing or environment needs the old renderer. Off-screen text is
still view-culled per entity, so dropping the text LOD ladder stays bounded.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 17:47:06 +03:00
Hakan SevenandClaude Opus 4.8 cd7306f530 feat(text): MTEXT background fill / mask + text frame, editable in Properties
Render the MTEXT background (never drawn before — the flags were only shown
read-only in the panel) and make it editable.

- Text arm emits an opaque fill_tris rect behind the glyphs: flag 0x01 uses
  the entity background colour, 0x02 uses the canvas colour (a wipeout-style
  mask). Box = glyph bounds padded by (background_scale - 1) × text height.
- Text frame (flag 0x10) draws a closed rectangle in the text colour around
  the same box.
- Threaded `bg_color` into `tessellate()` (+ all callers and the
  MultiLeaderTess trait) so the mask can use the drawing-window colour.
- Properties: "Background mask" is a Off / Fill / Mask dropdown, "Background
  color" is its own colour picker (independent of the entity colour — new
  PropBgColor* messages; picking a colour switches to Fill mode), and "Text
  frame" is a checkbox toggle. Edits re-tessellate so the change shows live.

Renders via the face3d fill path, so the fill shows with FILLMODE on (same as
MLEADER background fill); the frame is a stroke and always shows.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 17:41:16 +03:00
Hakan SevenandClaude Opus 4.8 110683f419 refactor(text): per-entity SDF text — all text kinds, selection/hover highlight
Rearchitect SDF text from a document-wide collector to per-entity
production during tessellation, so each entity owns its glyph quads and
composite/nested text is covered for free (no re-explosion, no per-frame
document walk).

- WireModel gains `text_verts`: glyph quads ride on the wire, so they are
  cached by the tess memo, cloned on hit, and transformed by the block
  expand loop exactly like `points`.
- Text arm (tessellate.rs) builds the quads when SDF is on and suppresses
  the strokes; render gathers text_verts from the viewport wire set
  (`gather_text_verts`, cached on wire content id) — the old collector is
  removed. Covers model, dimension, table, block-internal and paper-sheet
  text uniformly.
- MLEADER text (lays out via layout_mtext, not the Text arm) gets its own
  SDF branch driven by the per-run GlyphRun.
- Pick box comes from the rendered glyph quads (true text extent), not
  entity_aabb which mis-places the box for MTEXT; composite paths no longer
  clobber the empty text wire's tight AABB (dim pick box hugs the text).
- Selection / hover highlight via a text-highlight overlay (upload_text_
  highlight, keyed on selection_generation) mirroring the selected-wire
  xray overlay; base glyphs stay neutral so a deselect leaves no stale tint.
- Debug: env OCS_TEXT_BOX draws each run's glyph-bounds rectangle.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 17:01:36 +03:00
sLuCHa c20f277e54 fix(clipboard): paste copies dimensions correctly (#290)
Copy-paste (CTRL+C / CTRL+V) dropped dimensions. A dimension draws from
its baked *D block, whose geometry is in absolute WCS coordinates, and
the clipboard paste path added the dimension entity but never gave it its
own transformed block — unlike the in-drawing COPY, which does (#161). So
the pasted dimension kept pointing at the source block and rendered at
the original location instead of the paste point (same drawing), or had
no block at all (cross-drawing).

Capture each copied dimension's *D block into the clipboard, and on paste
build a fresh transformed copy of it and re-point the dimension's
block_name — for same- and cross-drawing pastes alike. Factored the
block-building out of clone_transformed_block into a shared
define_transformed_block, and the block snapshotting out of
capture_blocks into snapshot_block.
2026-07-07 15:53:21 +02:00
sLuCHa b4152ae1fe perf(hatch): tessellate fills so navigation no longer flickers (#258)
The batched hatch pass drew a screen-covering AABB quad per hatch and,
for every fragment, ran a point-in-polygon ray-cast over the whole
boundary plus the pattern test, with a discard that disabled early-Z.
Zoomed into a hatch the quad covers the screen, so the shader re-ran
per pixel every frame — the cost the PR #273 interaction-LOD worked
around by suppressing hatches during navigation, which made fills
flicker on and off while zooming.

Triangulate each boundary once (lyon, even-odd — same coverage as the
old in_polygon, islands/holes included) and rasterize those triangles
instead: no screen-filling overdraw, no per-fragment boundary test. The
fragment shader keeps the boundary test only on a per-instance fallback
path (poly_test == 1) for boundaries that fail to tessellate.
Tessellation is cached with the batch build (geometry_epoch) in local
space, so the double-single relative-to-eye precision is preserved.

With the fast path the interaction-LOD is no longer needed; it is gated
behind OCS_HATCH_LOD (default off) as a safety net for now.
2026-07-07 15:23:54 +02:00
Hakan SevenandClaude Opus 4.8 fd0b8fc1d4 perf(text): cache SDF text vertices across frames
The SDF text collector re-laid out every glyph of every text entity on
each frame (pan/zoom included). Cache the vertex list on the Scene keyed
by (geometry_epoch, annotation-scale bits) — it only changes when geometry
or the scale changes — so pan/zoom reuses it. Glyph baking happens on the
cache-miss path only; the atlas is a persistent global and the texture
upload is already gated on the geometry epoch, so cache hits skip both the
layout and any re-upload. No behaviour change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 08:29:18 +03:00
Hakan SevenandClaude Opus 4.8 75ddab6da7 feat(text): bypass the greek/baseline LOD ladder for SDF text
With OCS_TEXT_SDF on, top-level text took the full path only at ≥5 px and
still drew greeked OBB rects / baseline lines when zoomed out — doubling
with the SDF glyphs. Force the text LOD height to None while SDF is on so
text always falls through to the full path, which is itself suppressed to
an empty snap-only wire; SDF then renders it crisply at every zoom.
(Block-internal text is unaffected — it is not collected for SDF, so its
wire/greek path stays.)

Verified in-app: zoomed-out SDF text stays crisp with no greek/baseline
double draw. Flag off: unchanged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 08:24:11 +03:00
Hakan SevenandClaude Opus 4.8 9f60470067 feat(text): suppress glyph strokes when SDF text is on
With OCS_TEXT_SDF set, text now renders only as SDF quads: the wire path
skips building glyph-stroke geometry (bins stays empty, so the existing
empty-wire branch still emits the insertion snap point). This removes the
double draw (strokes + SDF) and, as a side effect, fixes the long-standing
snap pollution (#276) — snapping near text no longer catches individual
glyph-stroke endpoints, only the insertion point.

Shared sdf_text_enabled() (cached env read) gates both the collector and
the stroke suppression so they stay in lock-step. Flag off: unchanged.

Verified in-app: TEXT/MTEXT/decorations render clean as single SDF, and
snap no longer hits glyph strokes. Click-pick on text is limited while the
flag is on (no stroke geometry) pending a text OBB pick box.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 08:18:08 +03:00
Hakan SevenandClaude Opus 4.8 a561b088d2 feat(text): draw SDF text decorations (underline/overline/strike)
The SDF glyph path skipped decoration toggles, so underline / overline /
strikethrough lines were missing from OCS_TEXT_SDF text. Reserve a small
solid (all-255) cell in the glyph atlas and expose solid_uv(); layout_glyph_quads
now tracks the decoration runs (mirroring the stroke tessellator's
UNDER/OVER/STRIKE positions) and emits a thin quad per run whose corners
all sample the solid cell — the SDF shader fills it solid in the run
colour, so decorations render through the same pass as glyphs, no extra
pipeline. Verified in-app; SDF text now covers glyphs, %% specials, and
decorations for both TEXT and MTEXT.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 01:11:05 +03:00
Hakan SevenandClaude Opus 4.8 d528a3e2a5 feat(text): parse TEXT via acadrust + extend SDF text to MTEXT
Two related steps for the text pipeline:

- TEXT parsing now goes through acadrust's parse_plain_text (like MTEXT
  uses parse_mtext). text::acad_text_encode parses the value's %% codes —
  including %%u/%%o underline/overline and %%nnn — and re-encodes to the
  stroke tessellator's \L/\O + resolved-Unicode grammar, so OCS no longer
  tokenizes TEXT %% codes itself. (ATTRIB/TOLERANCE/DIMENSION still use the
  local tokenizer for now.) Bumps the acadrust pin to the commit that
  completes the TEXT/MTEXT control-code set.

- SDF text (OCS_TEXT_SDF) now covers MTEXT and every text-producing
  entity, not just top-level TEXT. TextStroke carries a GlyphRun (layout
  params); the collector walks convert()'s TruckObject::Text runs and
  applies annotation scale exactly as tessellate does for strokes.
  layout_glyph_quads shares lff::tokenize_run so %% specials resolve and
  \L/\O decorations are skipped (decoration LINES in SDF are still TODO).

Verified: stroke rendering unchanged with the flag off; SDF glyphs render
correctly for TEXT and MTEXT with OCS_TEXT_SDF=1. 154 lib tests green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-07 00:53:19 +03:00
Hakan SevenandClaude Opus 4.8 896b6c385c feat(text): render TEXT as SDF quads behind OCS_TEXT_SDF flag
Wires the SDF glyph atlas into the render loop end-to-end for top-level
TEXT entities, gated by the OCS_TEXT_SDF env var so the default path is
unchanged. Verified rendering on a real drawing: glyph quads land exactly
over the existing stroke text (position, size, rotation), confirming the
atlas → shader → pipeline → screen path and the RTE / UV math.

- text::text_run_placement — extracted from to_truck (behaviour-preserved)
  so the stroke and SDF-quad paths compute an identical run placement.
- sdf_atlas::text_atlas — process-wide GlyphAtlas (Mutex/OnceLock), shared
  by the collector (bakes glyphs) and the GPU upload (reads texels).
- Scene::sdf_text_vertices — collects per-glyph TextVertex for the frame's
  TEXT entities via layout_glyph_quads + push_glyph_vertices. Empty unless
  OCS_TEXT_SDF is set.
- ViewportData.text_verts + Pipeline text_pipeline/atlas/vbuf, upload_text
  (rebuilds the R8 atlas texture when it grows), and a text render pass
  drawn over the wires.

Still additive over the stroke text; only top-level TEXT is wired (MTEXT,
attributes, and block-internal text are next), and the collector re-runs
per frame (vertex caching by geometry epoch is a follow-up).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-06 23:02:34 +03:00
Hakan SevenandClaude Opus 4.8 374cf7e89f feat(text): SDF glyph-atlas foundation for shader text rendering
Groundwork to render CAD text as per-glyph SDF quads (box-quad snap,
perf, no LOD) instead of stroke-polyline wires. CPU side fully tested;
GPU side compiles but is not yet wired into the render loop.

- scene::text::sdf_atlas — GlyphAtlas: shelf packer + R8 SDF tiles baked
  per (font, char). Unified field so one shader draws both kinds: TrueType
  = signed distance to the filled outline, LFF stroke = pen band. Uses only
  crates already in the tree (ttf-parser/lyon via the existing Glyph).
- scene::text::glyph_quads — layout_glyph_quads: lays a run out as per-glyph
  quads using the exact tessellate_text_run transform, so quads land where
  the strokes would. Per-char advance (TTF shaping is a follow-up).
- shaders/text.wgsl — SDF fragment shader (smoothstep over fwidth), RTE
  vertex path mirroring image.wgsl, per-vertex colour + draw-order bias.
- scene::pipeline::text_gpu — TextVertex + double-single vertex builder,
  R8 atlas texture upload, bind group, and the image-cloned pipeline.

13 unit tests across the three CPU stages, all green. Modules carry
#![allow(dead_code)] until the render-loop integration lands.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-06 22:03:36 +03:00
Hakan SevenandClaude Opus 4.8 cb41910f12 fix: address review findings on merged #293/#292 hatch+snap
Three defects found reviewing the just-merged PRs:

- PLOTWINDOW forced corner snap (#293) only ran in the on_tick preview
  path, so the marker highlighted an endpoint but the click committed a
  plain snap — with the global OSNAP master (or Endpoint mode) off the
  corner landed at the raw cursor, defeating the feature. Apply the same
  snap_forced_corners branch at the click-commit recompute.

- build_dxf_pattern (#292) wrote the pattern line's LOCAL step into the
  world-frame HatchPatternLine.offset. The new prebaked reader
  inverse-rotates offset assuming world frame, so app-created hatches
  (HATCH command) collapsed their spacing by cos(angle) — ANSI31 at 45deg
  rendered 2.245 instead of 3.175 on both viewport and PDF/plot export.
  Rotate the local step into world here so it round-trips and the stored
  offset is format-correct for other CAD apps.

- far_from_origin_pattern_hatch_still_fills placed its offset ALONG the
  45deg lines (projects to k~0), so it never exercised the span-cap fix and
  passed even with the old absolute-index clamp restored. Move the offset
  perpendicular to the lines so |k| >> the cap. Add
  app_created_hatch_roundtrips_catalog_spacing to guard the offset-frame
  fix (verified: fails at 2.245 without it, passes at 3.175 with it).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-06 20:23:59 +03:00
sLuCHa 1a45f6bd97 fix(plot): correct hatch rendering in PDF / plot export
Hatched content — especially fills nested inside a block INSERT, such as a
title-block logo — plotted incorrectly: missing, mis-spaced, or with phantom
bars. Five related fixes make the PDF/plot output match AutoCAD.

1. Export block-internal hatch fills.
   The export collected only hatches owned directly by the layout block, so a
   hatch nested in a block INSERT was dropped and printed as bare monochrome
   outlines. The insert-explosion the viewport already does is extracted into a
   shared `exploded_insert_hatch_models()` and called from both the viewport
   (`synced_hatch_models`) and the export (`paper_canvas_hatches`), so a plot
   draws block-internal hatches identically to the screen.

2. Honour the hatch's own stored pattern-line spacing.
   `hatch_model_from_dxf` re-derived pattern spacing from the name-matched
   catalog entry x pattern_scale, ignoring the resolved line geometry the DWG
   stores on the hatch. When a drawing was authored against a different base
   spacing (imperial 0.125 vs the catalog's metric 3.175 for ANSI31), lines
   came out up to ~25x too coarse and a dense fill collapsed to a few stray
   lines. When the hatch carries its own line geometry it is now used directly
   (identity scale/angle); the catalog path remains the fallback.

3. Fill far-from-origin pattern hatches.
   `pattern_segments` clamped the ABSOLUTE scan-line index to
   +/-MAX_LINES_PER_FAMILY. A fine-spaced hatch far from the pattern origin has
   large-magnitude indices at both ends but a small span, so the clamp inverted
   the range and emitted nothing — silently dropping the fill. Cap the line
   count (span) instead of the absolute index.

4. Skip TEXTBOX boundary paths.
   TEXTBOX boundary paths (flag bit 3) are text bounding-boxes AutoCAD derives
   for island detection; they are never drawn or filled. Treating one as a fill
   boundary painted its rectangle solid — a phantom bar. It is now skipped when
   building the fill boundary.

5. Print white/ACI-7 hatch fills black on paper.
   Hatch fills arrive adapted to the dark screen background, so a white/ACI-7
   fill would vanish white-on-white on the sheet. Mirror the wire pass:
   near-white/near-yellow -> black, near-cyan -> dark blue, matching AutoCAD's
   colour-7-on-white plotting. Wipeouts keep their paper-white mask.

Adds `tests/block_hatch_export.rs` covering: block-internal hatch reaches the
export set, stored-line spacing is honoured, far-from-origin fills are not
dropped, and TEXTBOX paths are not filled.
2026-07-06 12:24:10 +02:00
Hakan SevenandClaude Opus 4.8 b50921923f chore: post-merge cleanup for #287/#289
- Reword the two new explanatory comments to describe the behaviour on its
  own instead of citing another product.
- window_to_sheet: drop the unused window_min parameter (the caller already
  derives its coordinate offset from the returned min-corner position) and fix
  the doc comment to match what the function returns.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-06 01:22:10 +03:00
Hakan Seven 72233cd2fa Merge PR #289: exclude XLine/Ray display segments from ZOOM Extents (#284) 2026-07-06 01:16:52 +03:00
Kevin GriffinandClaude Fable 5 a3107d95e4 fix(view): exclude XLine/Ray display segments from ZOOM Extents (#284)
XLine/Ray tessellate as +/-1e6 display segments (entities/ray.rs), and
both fit_all outlier defenses miss them: the IQR reject passes because a
construction line through the drawing has its centroid at its base
point, inside the consensus cluster; and the per-point lim filter passes
because local_extent_max is computed once at document load and stays at
the 1e9 default for drawings created fresh in-app. The far endpoints
then poison the bounds and the view fits +/-1e6, shrinking real
geometry to a dot.

Exclude XLine/Ray wires from the extents up front (AutoCAD likewise
ignores infinite lines in ZOOM Extents), falling back to fitting their
base points when the drawing holds nothing else.

Regression tests verified to fail without the fix (camera distance
3,000,000) and pass with it.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-05 14:08:43 -07:00
Hakan SevenandClaude Opus 4.8 42e11b9250 fix(hatch): render user-defined hatches from angle + spacing
A user-defined hatch (angle + spacing + optional cross) carries the
placeholder pattern name "_USER", which isn't in the predefined catalog,
so it fell to a fallback that forced every one to flat horizontal lines
at the wrong spacing — ignoring the angle, the spacing and the double
flag.

Build base line families (angle 0, plus 90 when `is_double`) with unit
perpendicular spacing and let the HatchModel's existing angle_offset
(= pattern_angle) and scale (= pattern_scale) rotate and space them, the
same way predefined .PAT patterns are applied — so the angle/scale is
applied once, not doubled. Verified against the sample (0°/30°/90°-cross/
315°-cross at spacing 5/10).

Closes #278

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-05 11:58:44 +03:00
sLuCHa a55e1ac4f8 perf(render): skip hatch pass while navigating (interaction LOD)
The batched hatch pass evaluates its fill procedurally per fragment — a
point-in-polygon test over the whole boundary plus the pattern test, with a
`discard` that disables early-Z. When the view sits inside a hatch its quad
covers the screen, so panning / zooming re-runs that full-screen shader every
frame (~40 ms/frame on a hatch-heavy plan) even though the rest of the scene
is cheap — the wire pass and CPU prepare are negligible by comparison.

Suppress the hatch pass while the view is actively panning / zooming /
orbiting, detected from `camera_generation` plus a short settle timer
(`Scene::navigating_lod`), and fold that state into the render signature so
the moment the view settles it renders hatches once and the scene-render
cache holds that full-quality frame. A brief `is_settling` subscription keeps
requesting frames just past the settle point so the hatched frame renders
even when no input event would otherwise fire. Mirrors AutoCAD's adaptive
degradation. The paper sheet keeps its fills.
2026-07-05 09:48:49 +02:00
sLuCHa f99f1cd7a5 perf(render): cache rendered scene, skip re-raster on unchanged frames
Every cursor movement over the viewport re-rendered the entire GPU scene
(all wires, hatches, meshes) even when nothing visible changed: iced redraws
the whole window on each input message, and the shader's draw/prepare/render
runs every time. On large drawings one such redraw exceeds the frame budget,
so moving the mouse or panning stutters — and it gets worse the bigger the
drawing.

The pipeline already resolves each frame into a persistent, clip-sized
resolve texture and blits that to the surface. This hashes the inputs that
determine the rendered image (camera uniforms, geometry/selection
generations, wire content id, render-mode flags, clip size, live preview
coordinates) into a per-viewport signature. When a frame's signature matches
the previous one the image is pixel-identical, so `prepare` skips the buffer
uploads + per-frame scissor/LOD recompute and `render` skips passes 1-7 plus
the MSAA resolve, re-blitting the resolve texture instead. A pure cursor move
becomes a single fullscreen blit rather than an O(N) re-rasterization.

The ViewCube is excluded from the signature (it renders in its own always-on
pass) so cube hover still tracks while the scene is cached. Any real change —
edit (geometry_epoch), select/hover (selection_generation), camera move or
render-mode toggle — differs the signature and forces a full render, so
nothing goes stale. Navigation still renders every frame (the view genuinely
changes); this targets the wasted re-render on cursor-only movement.
2026-07-05 08:11:35 +02:00
Hakan SevenandClaude Opus 4.8 aa63634d95 fix(camera): orbit target in f64 to avoid extent-scale jitter
`orbit` revolved the target around the pivot as
`p + (delta * (self.target - p).as_vec3()).as_dvec3()`, casting the
target-to-pivot offset to f32. For a large model that offset is
extent-scale (the cursor can sit far from the view centre), so the f32
cast quantized it — nudging the whole view a fraction of a unit each orbit
step regardless of the drawing's origin. Do the revolve entirely in f64.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-05 03:26:07 +03:00
Hakan SevenandClaude Opus 4.8 626031de00 perf(render): reuse static wire set for model-space pick/snap
Every pan/rotate on a large drawing jerked once at the start of the
gesture. Instrumentation traced it to `paper_sheet_wires_arc` re-running a
full ~300 ms tessellation of the whole model block on the first hit-test
after each camera move.

`entity_wires_arc` (the pick/snap source in Model layout) delegated to the
camera_generation-keyed, view-culled `paper_sheet_wires_arc`. A camera
move bumps `camera_generation`, so the next hit-test cold-missed that cache
and re-tessellated every visible entity — O(visible), which is why the
jump grew with on-screen object count and shrank when zoomed in. The GPU
render was unaffected (it holds the separate camera-independent
`model_static_wires`), so only that one CPU frame stalled and the
accumulated mouse motion applied at once, reading as a jump.

Point the Model pick path at the same resident static set the render holds
(keyed on geometry_epoch only). Pick wants every entity, not a view-culled
subset, so this is also more correct — off-screen entities stay pickable —
and it never re-tessellates on a camera move.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-05 03:26:07 +03:00
Hakan SevenandClaude Opus 4.8 845194e05b refactor(render): reuse block_has_hatch in synced_hatch_models
The hatch-free-block skip added in the previous commit duplicated the
existing `block_has_hatch` helper (already used by
`insert_hatches_for_click`). Drop the parallel `block_contains_hatch` and
call the shared, memoised helper instead — same result, one implementation.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-05 02:10:56 +03:00
Hakan SevenandClaude Opus 4.8 0ce918da68 perf(render): skip exploding hatch-free blocks in hatch build
Opening an xref-heavy drawing froze for ~22s before the first frame.
`synced_hatch_models` walked every INSERT and called
`explode_from_document()` to scan the result for hatch fills — but explode
CLONES every child of the block, including 3D solids that each carry tens
of KB of SAB geometry. Clinic.dwg's five xref INSERTs each reference a
discipline block of thousands of solids and no hatch, so this materialized
~25000 solid clones (~1 GB) on every open just to find zero hatches.

Add a memoized `block_contains_hatch`: a read-only scan of the block's
entity types (recursing nested INSERTs, cycle-guarded) that skips the
explode for blocks containing no hatch, transitively. Blocks that do hold
a hatch still explode exactly as before, so the hatch set is unchanged.

Hatch build for Clinic.dwg drops from ~21.7s to ~0.02s, cutting the total
open-to-first-frame time from ~25s to ~5s.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-05 02:03:16 +03:00
Hakan SevenandClaude Opus 4.8 13de968ee9 perf(xref): fix O(n²) AcDs parse and skip host re-tessellation
Opening a drawing that xrefs several 3D-heavy DWGs (e.g. Clinic.dwg with
5 discipline files) took ~137s, effectively all of it inside the DWG
parser's AcDs SAB blob extraction.

Bump the acadrust pin to ceef045, which bounds the AcDs end-marker search
so a missing marker family no longer scans the whole buffer per record.
Total xref resolve for Clinic.dwg drops from ~97s to ~4s.

Also make the post-xref mesh pass incremental: the host solids were
already tessellated by the background loader and the merge assigns fresh
handles to every imported entity, so `populate_missing_meshes_from_document`
keeps the cached host meshes and tessellates only the merged xref solids
instead of clearing and rebuilding the whole document.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-05 00:38:38 +03:00
Hakan SevenandClaude Opus 4.8 cbf454979d chore(solid): drop needless mut on full_circle
`full_circle` from `angular_range` is only read, never reassigned — clears
the unused-mut warning.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-04 23:47:00 +03:00
Hakan SevenandClaude Opus 4.8 2bbd3cfcd2 feat(pick): select mesh entities by clicking their shaded faces
Mesh entities (PolyfaceMesh / PolygonMesh / SubD Mesh) could only be picked
on their thin edges — click_hit tested wire segments, and the solid face pick
only covers ACIS solids. When no edge is close, click_hit now also tests the
mesh's fill_tris with the same projected-triangle containment mesh_click_hit
uses for solids, so clicking a mesh's surface selects it, front-most first.
Edge proximity still takes priority.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-04 23:11:47 +03:00
Hakan SevenandClaude Opus 4.8 62680883cd fix(pick): don't XY-cull the pick wire set in tilted 3D views
view_world_aabb built a world-XY cull rectangle from the camera target and
ortho size without checking the view angle, so in a tilted / 3D view it
produced a top-down box that does not bound the on-screen footprint. That
box culls the pick wire set (while the render holds the full set via the
static hold), so a mesh running partially off-screen fell outside the box
and became unselectable — by edge or by face — even though it still
rendered. Top views were unaffected (the box is correct there), and 3D
solids pick through their mesh AABBs (not this wire set) so they never
showed it.

Return None for tilted views (fwd.z.abs() < 0.999), matching view_cull_aabb,
so no world-XY cull is applied and the pick reaches every on-screen wire.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-04 22:13:37 +03:00
Hakan SevenandClaude Opus 4.8 17077ba8bf fix(render): don't apply the draw-order z-bias to 3D mesh outline edges
Mesh (PolyfaceMesh / PolygonMesh) outline edges are drawn through the wire
pipeline, whose shader pulls each wire toward the camera by
draw_depth * DRAW_ORDER_BIAS (0.001) for 2-D draw-order layering. Every
entity gets a draw_depth in [-1, 1], so a mesh's edges were pulled forward
too — and when the mesh's depth extent projects to less than the bias (a
small or distant mesh), its hidden back-face edges peeked through its own
shaded fill. Solid feature edges use the mesh shader, which has no such
bias, which is why only meshes showed it and why adjusting the fill's depth
bias had no effect.

3-D mesh outline edges are real geometry occluded by true depth, so force
their draw_depth to 0 (they are already grouped as `mesh_edge` in
upload_wires). They now occlude exactly like solid edges.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-04 21:04:37 +03:00
Hakan SevenandClaude Opus 4.8 f8ceddd303 fix(solid): read rational NURBS spline-surface control points with weights
An ACIS spline-surface stored as `nurbs` (rational) carries a weight on each
control point, so the control net is a stream of x, y, z, w tuples. The
parser read plain x, y, z triples, shifting every control point by one float
and scrambling the whole net — the surface, and the solid it bounds,
rendered badly deformed. Non-rational `nubs` surfaces were unaffected, which
is why only some solids (rational lofts/sweeps with varying weights) broke.

Detect `nurbs` vs `nubs`; for rational surfaces read the fourth weight
component and build a truck `NurbsSurface` from homogeneous (xw, yw, zw, w)
control points so the weights actually shape the surface. Both the truck
B-rep path and the bespoke fallback share this parser.

Verified on VillaSavoye_MartinHedin2.dwg solid 0x24A1EE (handle 2400750): the
tessellated surface now stays within the solid's true extent instead of
flying outside it.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-04 20:15:17 +03:00
Hakan SevenandClaude Opus 4.8 e6a961be6c feat(render): draw 3D mesh outline edges black in filled modes
Extends the solid feature-edge behaviour to mesh entities (PolyfaceMesh /
PolygonMesh): their triangulation outline edges now render black when a
filled-with-edges mode is active, and keep the entity colour in the
lines-only modes (wireframe / hidden-line).

A mesh entity emits its face fill and its outline edges as separate
WireModels sharing the entity handle: the fill carries fill_tris plus a
non-empty fill_tris_low (real 3D depth), the edge carries points. The old
is_3d_mesh_edge flag keyed on `!fill_tris.is_empty()`, which tagged the
points-less fill wire rather than the edge wire, so the edges were never
recognised. upload_wires now collects the handles of real 3D fill wires and
flags any points-wire sharing one as the mesh edge (text greek, whose fill
has an empty fill_tris_low, is excluded — matching the face3d test). The
wire draw loop then routes flagged edges through a new black wire pipeline
(fs_black) in filled-with-edges modes.

fs_black lives in wire_indexed.wgsl (the native shader) and wire.wgsl (the
wasm shader).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-04 18:28:27 +03:00