388 Commits
Author SHA1 Message Date
Hakan SevenandClaude Opus 4.7 a997490814 chore: release v0.2.8
Co-Authored-By: Claude Opus 4.7 <[email protected]>
v0.2.8
2026-05-15 23:39:19 +03:00
Hakan SevenandClaude Opus 4.7 41cf2ffe11 docs(rendering): drop completed roadmap phases (1.4 / 3.3 / 3.4)
Phase 1.4 (hatch/image scissor), Phase 3.3 (hatch LOD), and Phase 3.4
(mesh LOD) landed in commits fbbac42, e7675be, and 8c08ae1. Removed
their roadmap sections and pruned the Implementation Order / Key Files
/ Success Metrics tables to reflect what's still outstanding (Phase 2
spatial index, Phase 4 GPU compute cull + Hi-Z).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 23:34:42 +03:00
Hakan SevenandClaude Opus 4.7 8c08ae104a perf(scene): multi-resolution mesh LOD (Phase 3.4)
ACIS SAT entities (Solid3D / Region / Body) were tessellated at one
fixed sampling density (CIRC_SEGS=48, GRID_U=32, GRID_V=16) regardless
of how far they were from the camera. Distant solids paid the full
triangle bill for fragments that mostly resolved to sub-pixel size.

Generate three pre-built LODs per entity at load time:

  * LOD 0 (HIGH)  — 48/32/16 segments. Use above 200 px projected diag.
  * LOD 1 (MID)   — 24/16/8.  Use 50–200 px.
  * LOD 2 (LOW)   — 12/8/4.   Use below 50 px.

Tessellation cost is paid 3× on load (cheap — typical files have few
solids). Render picks per-frame via `compute_mesh_lod` from each mesh's
`world_aabb` projected diagonal. When a level is missing (e.g. a solid
entity that only emits LOD 0), the selector walks down to the nearest
available slot.

API ripples:
  * New `LodConfig` (HIGH/MID/LOW) drives `tess_sat`, `tess_cone_face`,
    `tess_sphere_face`, `tess_torus_face`.
  * `tessellate_solid3d / _region / _body` now return `MeshLodSet`.
  * `MeshLodSet { lods: Vec<MeshModel>, world_aabb }` + `from_single`
    constructor so interactive truck-based commands (BOX/CYLINDER/etc.)
    that only generate one tessellation stay one-line.
  * GPU side gets `MeshLodGpu { lods: Vec<MeshGpu>, world_aabb }` and
    a `mesh_lod_levels` per-frame index vector.
  * STL/STEP export pulls slot 0 explicitly so the on-disk geometry
    isn't downgraded by the view-dependent ladder.

Background-thread lazy generation (per the roadmap) is deferred — the
synchronous eager build is fine for typical CAD files. Switch to a
queue + background tessellator when files with hundreds of solids
become a load-time bottleneck.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 23:30:13 +03:00
Hakan SevenandClaude Opus 4.7 e7675be0bc perf(scene): hatch LOD — solid-fill substitute + sub-pixel skip (Phase 3.3)
Hatch fills drew the full per-family pattern loop every frame regardless
of zoom. Two LOD tiers, neither of which existed:

  * **Shader-side solid substitute.** When the densest line family's
    spacing × scale projects to less than 2 px, individual lines blur
    into a solid color and the per-fragment family loop is wasted ALU
    (and produces moiré). Pass `world_per_pixel` through Uniforms; the
    hatch fragment shader now returns `h.color` directly in that case.
  * **CPU-side sub-pixel skip.** When the entire hatch AABB projects
    to less than 2 px, drop the draw call. Adds `world_aabb` to
    HatchGpu plus a per-frame `compute_hatch_lod` pass (mirrors the
    existing scissor pass) and `hatch_skip_flags`. The render pass
    skips flagged hatches.

Factored a shared `aabb_below_pixel` helper for future LOD callers.

The Uniforms layout is unchanged in size (96 B) — the trailing
`_pad: vec2<f32>` becomes `world_per_pixel: f32, _pad: f32`, so wgsl
modules that don't read the new field keep working with their old
`_pad: vec2<f32>` declarations.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 23:18:21 +03:00
Hakan SevenandClaude Opus 4.7 fbbac423d4 perf(scene): extend viewport scissor to hatch / image / wipeout passes (Phase 1.4)
Wire pass already uses `WireModel.vp_scissor` to clip viewport-projected
geometry to its paper-space viewport rect; hatch / image / wipeout
passes drew across the whole canvas. When a future paper-space path
projects fills/images into a viewport, they would bleed past the
viewport frame.

Add `vp_scissor: Option<[f32; 4]>` to HatchModel and ImageModel
(mirroring WireModel), forward it through HatchGpu / ImageGpu, and add
per-pass `compute_*_scissors` / `set_scissor_rect` machinery. Factored
the wire-side scissor-projection math into a shared `project_scissor`
helper. Field defaults to None at every constructor site — no producer
sets it yet, so this is plumbing for the paper-viewport fill projection
that Phase 1.4 unblocks without changing current visual output.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 23:13:16 +03:00
Hakan SevenandClaude Opus 4.7 9a4531bd8e fix(scene): use median of MSPACE entity centroids for world_offset
Min/max midpoint is wrecked by a single bogus entity at WCS distance
from the real drawing — a Ray with a bad direction, an orphan block-
defn entity at WCS x = -510k while real geometry sits at WCS x = +510k.
Header EXTMIN/EXTMAX bakes the same min/max midpoint, and the entity
scan we added in 59da4f3 reproduced it: both lined up perfectly on the
broken midpoint (drift = 0.000 in tracing) and parked world_offset
508 km from the dense cluster. Wires then rendered at f32 magnitudes
~5e5 — 6 cm precision on a drawing where the user is editing at mm.

Switch the entity scan to per-entity centroids and take the **median**
of x and y. Median is immune to a single far outlier regardless of how
far it sits, so the same file that previously parked world_offset at
(1445, 4277904) — halfway between the real drawing and a stray entity
512 km away — now resolves to (509099, 4274221), within 1 km of the
actual drawing. Wire magnitudes drop from ~5e5 to ~4e3, restoring
precision from 6 cm to ~0.5 mm (~120× improvement).

local_extent_max also derives from the centroid spread (95th-percentile
distance from the median × 2) rather than the raw min/max span, so the
fit_all clamp rejects the same outliers that were previously inflating
it. The header EXTMIN/EXTMAX path remains as a fallback for the case
where the entity scan found nothing (truly empty MSPACE).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 22:58:32 +03:00
Hakan SevenandClaude Opus 4.7 7ee93f6aea fix(scene): align compute_world_offset filter with belongs_to_visible_block
compute_world_offset rejected any entity whose owner_handle didn't
equal model_block, but belongs_to_visible_block (the render-time
filter) treats owner_handle = null as a legitimate MSPACE entity
whenever block_record.entity_handles is empty and the file enumerates
no block contents anywhere. DXF writers commonly omit group-code 330,
so on those files the render path drew the entities while the offset
scan missed them — direct WCS-coordinate wires then drove world_offset
to the header (sentinel → [0,0,0]) and f32 precision collapsed for
UTM-authored content.

Replicate belongs_to_visible_block's decision exactly:

  * If model_block's BlockRecord enumerates entity_handles, use that
    set as the authoritative MSPACE membership list.
  * Otherwise: owner==model_block always counts; owner==null counts
    only when no other block_record enumerated either (legacy DXF
    without 330 codes anywhere); a non-null owner pointing elsewhere
    or an entity enumerated by some other block is always rejected.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 22:08:09 +03:00
Hakan SevenandClaude Opus 4.7 59da4f35a9 fix(scene): cross-check world_offset against MSPACE entity AABB, not just DXF header
world_offset (the precision-preserving translation subtracted from every
f32 wire point) came purely from the DXF $EXTMIN/$EXTMAX header. Three
real-world failure modes drove geometry far from the local origin and
killed f32 precision on MSPACE wires:

  * Sentinel header (1e20 / -1e20) when the writer never computed
    extents → world_offset = [0,0,0] → UTM-authored drawings render at
    WCS 4M with single-pixel jitter.
  * Stale header — drawing was edited but extents weren't refreshed →
    offset center sits well outside the actual entity centroid.
  * Civil-3D-style header that reports only a single Insert footprint,
    leaving direct MSPACE Line/Polyline/Hatch geometry far from the
    chosen offset.

Block defns already self-correct via `block_cache::build_defn`'s
per-defn bbox scan; top-level had no equivalent and was the inconsistent
half of the system. Add `compute_world_offset()` that scans MSPACE
entity bounding boxes (same `bounding_box()` API + SANE_EXTENT and
zero-placeholder filters that `build_defn` uses) and:

  * Header invalid + entity scan ok → use entity scan.
  * Header ok + entity scan empty → keep header (truly empty file).
  * Both ok → cross-check: if the header center drifts more than 10×
    its own half-span from the entity centroid, the header is stale —
    trust the entity scan.
  * Both unavailable → ([0,0,0], 1e9) sentinel.

`compute_and_set_world_offset` now delegates to the same helper so the
load path and any later recompute path can't diverge.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 21:56:19 +03:00
Hakan SevenandClaude Opus 4.7 2716bcbbd8 fix(scene): drop unknown-owner entities when the file enumerates ownership elsewhere
belongs_to_visible_block's reverse-map fallback returned `true` on a
map miss, which let block-defn entities with a null owner_handle leak
into model space whenever their owning BlockRecord also had an empty
entity_handles list. The visible symptom was a stray HATCH (and
formerly BLOCK / BLOCKEND) selectable far from the drawing.

The legacy permissive default existed because some DXF files omit
group-code 330 everywhere, and dropping unknown-owner entities would
empty MSPACE. Detect that case explicitly: if the entity_block_map is
empty, no BlockRecord enumerated its contents — keep the legacy
permissive behavior. If the map has at least one entry, the file is
capable of declaring ownership, so an unknown-owner entity is an
orphan and must not leak into the queried block.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 21:09:56 +03:00
Hakan SevenandClaude Opus 4.7 708fdec941 fix(scene): IQR outlier reject in fit_all so one orphan wire can't poison bbox
The absolute `local_extent_max` filter degrades to 1e9 whenever EXTMIN/
EXTMAX are the DXF "no geometry" sentinel (1e20 / -1e20), which lets a
single orphan wire — a stray hatch boundary at WCS origin, a Ray with a
bogus direction, a block-defn entity that leaked into MSPACE — drag
fit_all's bounding box across the world and collapse the real drawing
to sub-pixel size on ZOOM EXTENTS.

Compute a per-wire centroid first, then reject any wire whose centroid
sits more than 10× the inter-quartile span outside the X/Y consensus
cluster. The IQR pass only runs when there are ≥8 wires (so the
quartiles are meaningful); below that the legacy absolute-magnitude
gate is the only filter. The point-level `lim` check is preserved as a
final per-point guard.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 21:08:49 +03:00
Hakan SevenandClaude Opus 4.7 f592c5f1a2 fix(scene): skip Block/BlockEnd sentinels in wires_for_block filter
Block and BlockEnd are block-defn markers, not drawable geometry.
wires_for_block did not filter them, so they fell through to
legacy_geometry's `_` arm and emitted a 1-unit phantom horizontal
segment at world_offset. The phantom was invisible on a real drawing
but selectable and — worse — its points poisoned fit_all, contributing
to the "ZOOM EXTENTS shrinks the model" symptom on files with weak
EXTMIN/EXTMAX or with block-defn entities leaking into MSPACE.

Same skip already exists in commands.rs:5364 and block_cache.rs:271 —
the render path was the missing one.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 21:07:01 +03:00
HakanandClaude Opus 4.7 f4ae0e7773 fix(scene): per-line text greek honors word-wrap subline count
`text_obb_corners_native` derived MText line count from explicit `\n`
matches in `m.value`, so any MText that relied on `\P`/`\N` breaks or
word-wrap (rectangle_width-driven) reported a single line. The greek
emitter then split the OBB into one row and the user saw a single box
on top of a 5-line wrapped paragraph.

  - text_support: new `mtext_line_count` — strip codes, split on
    \n/\P/\N, word-wrap each paragraph against `rectangle_width`,
    sum. Same line splitting the MText/MultiLeader renderers already
    perform; centralized for reuse.
  - text_obb_corners_native: takes `mtext_lines_override: Option<usize>`.
    When supplied, OBB height = h_world × n × line_spacing_factor; this
    also overrides a possibly stale `rectangle_height` on resaved DWGs.
  - Top-level greek paths (scene/mod.rs) compute the line count via
    `mtext_line_count` and pass it through to baseline / rect emission.
  - block_cache: tessellate_sub_local computes the count at defn build
    so the stored `text_obb_local` is wrap-aware; emit_text_baseline
    and emit_greeked_text recover n_lines from `ulen / h_local` as
    before and now produce the correct per-row split inside Inserts.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 17:41:56 +03:00
HakanandClaude Opus 4.7 ddd0a2de16 fix(scene): greek text rect renders filled at the text's own color
Greek rects rendered through fill_tris went through the face3d 0.45
dim path; the pre-boost (color × 1/0.45) compensated only until clamp
hit at 1.0, leaving bright user colors washed out. The earlier outline
workaround dodged the dim but lost the filled box visual that AutoCAD
uses for "text lives here".

  - face3d pipeline now skips the 0.45 dim when `wire.points` is
    empty. PolyfaceMesh / PolygonMesh keep their dim (both points and
    fill_tris populated); greek and MultiLeader background-fill emit
    `points: vec![]` so they render at the literal color.
  - All three greek paths (top-level, block-defn, MultiLeader) emit a
    2-triangle filled rect instead of an outline / boosted fill.
  - Greek rects are clamped to single-line height so 5-line MText
    doesn't blow the box up to the full text-block height. MultiLeader
    emits one rect per line — keeps the per-row visual hint.
  - BatchEntry/StyleKey gain an `is_fill_only` discriminator so greek
    batches never collide with regular wire batches; otherwise the
    finalized WireModel could carry both points and fill_tris and
    defeat the pipeline-side empty-points check.

Xref fade still applies to the resolved color via the existing
`fade_toward_bg` path, so xref greek stays faded as expected.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 16:32:27 +03:00
HakanandClaude Opus 4.7 1f1aa80f17 perf(scene): apply text LOD ladder to MultiLeader text content
MultiLeader's text strokes go through cxf::tessellate_text_ex per-glyph
regardless of zoom — same waste the top-level Text/MText path used to
have. Mirror the 1/5 px ladder here:

  h_px < 1   → top-line baseline (skipped if its own length is < 2 px)
  1 ≤ h < 5  → greek rect at the tight text bbox, color pre-boosted for
               the face3d 0.45 fill_tris dim
  h_px ≥ 5   → full per-glyph stroke (existing path, untouched)

Frame and background-fill rects keep rendering at every LOD — only the
glyph payload is collapsed.

Plain Leader entities don't bake their own text (annotation lives in a
separate linked MText), so they already inherit the top-level Text/MText
ladder; no change there.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 14:22:05 +03:00
HakanandClaude Opus 4.7 26271b8c63 perf(scene): zoom-adaptive curve tolerance for top-level wires (Phase 3.2)
Edge tessellation used a fixed 0.005 world-unit chord-height tolerance
regardless of zoom — a 1000 m radius arc viewed at 50 mm/px still emitted
hundreds of segments that all collapsed onto the same screen pixel.

`truck_tess` now reads tolerance from a process-wide AtomicU64 override.
`Scene::wires_for_block` sets the override to ~0.5 px chord height
(world_per_pixel × 0.5) before the par_iter, then a Drop guard clears it
back to the default. Floor stays at the original CURVE_TOL so extreme
zoom-in keeps full quality. Block-cache rebuilds and off-render paths
(snap, hit-test) always see the default — the override is bracketed to
the render call only.

Roadmap entry for Phase 3.2 removed; Implementation Order / Key Files
tables updated.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 14:07:28 +03:00
HakanandClaude Opus 4.7 0584e3c862 perf(scene): text LOD ladder 1/5 px with baseline-line tier
Replaces the 2/4 drop/greek/full ladder with 1/5 baseline/greek/full so
zoomed-out text still leaves a visual hint instead of disappearing:

  h_px < 1   → OBB baseline line in the text color
  1 ≤ h < 5  → greeked OBB rect
  h_px ≥ 5   → full per-glyph stroke

Extra guard: in the baseline tier, the line itself is dropped when its
projected length is under 2 px (single-char text seen edge-on would
otherwise emit a sub-pixel segment).

Text/MText is exempted from the generic 5 px AABB cull (top-level and
block-defn paths) so it can reach this ladder even when its bounding
box projects below the threshold.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 13:19:43 +03:00
HakanandClaude Opus 4.7 5344d0d6d6 docs(rendering): drop completed roadmap phases
Phase 1.1 (entity AABB), 1.2 (ViewVolume), 1.3 (CPU cull), 3.1 (sub-pixel
cull), and 3.5 (text simplification) are all live in tree — remove them
from the roadmap. Implementation Order and Key Files tables trimmed to
the still-pending work. TEMPORARY Insert sub-entity guard section now
notes which "proper fix" already landed (per-block cache, def72e4) and
which is still open.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 13:19:35 +03:00
HakanandClaude Opus 4.7 4d58a905e0 chore: release v0.2.7
Co-Authored-By: Claude Opus 4.7 <[email protected]>
v0.2.7
2026-05-15 09:46:47 +03:00
HakanandClaude Opus 4.7 6cc2323905 fix(scene): skip pixel-size LOD in paper space
PaperCanvas (Iced 2-D canvas) never feeds set_render_pixel_scale, so
last_world_per_pixel held either zero or a stale model-world value.
Paper-space entity AABBs (mm) tested against model-scale wpp all
projected below the 5 px threshold and got culled — leaving only
Viewports and Inserts (which bypass the cull). world_per_pixel() now
returns None in paper space, mirroring view_world_aabb()'s existing
skip with the same reasoning: the paper canvas is small enough that
LOD culling buys nothing.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 09:45:48 +03:00
HakanandClaude Opus 4.7 f738a20457 feat(properties): label xref Insert as "External Reference"
Match AutoCAD properties panel — Insert whose block_record carries
is_xref/is_xref_overlay now shows "External Reference" instead of
"Block Reference". Silence dead_code warning on XrefStatus::Unloaded
(intentional, awaiting on-disk Unload-bit detection).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 09:19:57 +03:00
Hakan SevenandClaude Opus 4.7 f713354de1 fix(block_cache): drop zero-bbox placeholders from defn LO scan
`Entity::bounding_box()` for empty / vertex-less entities (Polyline,
LwPolyline, Hatch, etc.) returns `BoundingBox3D::from_point(Vector3::ZERO)` —
the (0, 0, 0)→(0, 0, 0) placeholder. Including those in the LO centroid
scan dragged it toward the origin even for UTM-authored blocks, defeating
the precision-preservation: stored f32 then sat at UTM-minus-near-zero,
losing precision before tessellate even returned. Reject the zero
placeholder so only real geometry contributes.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-15 06:30:52 +03:00
Hakan SevenandClaude Opus 4.7 0d543e8c88 fix(block_cache): harden defn local_offset against NaN + bad-extent poison
Two latent traps in the first-pass centroid scan:

- A bbox where x/y were finite but z was NaN would skip the z update;
  if NO entity contributed a finite z, `min[2]` stayed at `INFINITY` and
  `max[2]` at `NEG_INFINITY`. `(INF + NEG_INF) * 0.5 = NaN`, so the defn's
  `local_offset.z` was NaN, propagating to every cast point in the defn.
  Track `have` per axis and default missing axes to 0.

- A single corrupt entity at parser-garbage coords (1e15+) silently
  dragged the centroid out of the real geometry's neighbourhood. Reject
  per-axis values above `SANE_EXTENT` so one bad bbox doesn't ruin the
  whole defn.

Also include `Insert::insert_point` as a contributing sample so a
composite block (only nested Inserts, no direct wires) still gets a
non-zero offset — useful for the nested-defn AABB transforms even
though no direct LocalWire stores against it.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-14 21:56:27 +03:00
Hakan SevenandClaude Opus 4.7 2f0220b1a0 feat(xref+block): bind xref tables, fade rendered geometry, per-defn precision offset
Xref work:
- merge_xref_into_block now copies the xref's layer / linetype / nested
  block_record tables into the host under `{xref}|{name}` prefixes and
  remaps entity references, so ByLayer/ByBlock resolution lands on the
  right entry instead of falling back to WHITE + 1 px.
- expand_insert (and the explode fallback) detect xref BlockRecords by
  flag and apply `fade_toward_bg(color, bg, 0.5)` to every emitted final
  color (selection bypasses the fade). ExpandCtx propagates `is_xref` +
  `bg_color` through nested expansions.

Block precision groundwork:
- BlockDefn gains `local_offset: [f64; 3]` set in build_defn from the
  AABB centre of the defn's direct entities. tessellate_sub_local now
  passes that offset to tessellate(), so LocalWire.points / fill_tris /
  aabb_local / text_obb_local are stored in offset-frame f32 and don't
  lose precision for distant content.
- emit_wire / emit_greeked_text / transform_tangent take the defn offset
  and re-add it in f64 before composing with accum_xform. defn_aabb_
  recursive transforms nested children from their offset frame into the
  parent's. transform_offset_aabb_xy replaces transform_aabb_xy.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-14 21:45:37 +03:00
Hakan SevenandClaude Opus 4.7 ea87b3db76 fix(scene): greek text OBB honors attachment point, propagates into blocks
Top-level OBB used insertion_point as anchor and hardcoded MText anchor to
bottom-left, so greeked rects landed on the opposite side of the actual
text whenever MText used a non-default attachment_point or TEXT used a
non-Left/Baseline alignment. Block-defn subs never set or read
`text_obb_local`, so greeked text inside Inserts fell back to the
axis-aligned AABB and ignored entity rotation entirely.

- Share OBB corner computation via `text_obb_corners_native`.
- Map all 9 MText AttachmentPoint variants to (h_anchor, v_anchor).
- For TEXT, anchor on `alignment_point` (DXF 11) when alignment != Left+Baseline.
- Populate `LocalWire.text_obb_local` in `tessellate_sub_local`.
- `emit_greeked_text` transforms OBB corners by `accum_xform`, falls back
  to AABB only when no OBB was precomputed.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-14 20:49:33 +03:00
Hakan ab69203414 feat(scene): enhance text LOD handling and add OBB support for Text/MText 2026-05-14 15:21:35 +03:00
Hakan e043e54f7e perf(block_cache): apply text LOD ladder inside block defns
Text greeking previously only fired for top-level Text/MText — text
that was baked into a block defn at cache build time still ran the
full glyph stroke path on every expand, so cadastral parcel labels
(typically inside xrefed blocks) saw none of the LOD benefit.

  - `LocalWire` now records `text_height_local` for Text / MText subs.
  - `expand_defn`'s wire arm applies the same 5 / 10 px ladder: cull
    below 5 px (after scaling the local glyph height by the accumulated
    transform's Y-scale), greek between 5 and 10, full glyphs above.
  - `emit_greeked_text` reuses the batch infrastructure so multiple
    greeked rects in the same style still collapse into one buffer.
2026-05-14 15:01:51 +03:00
Hakan 84621a2fab tune(scene): text LOD ladder 5/10 px (cull / greek / full)
Per real-world feedback the previous greeking threshold (4 px → full)
left a lot of unreadable text still going through the glyph path
without any visible payoff. Sharper ladder now:

  - h < 5 px   → drop (illegible, not worth even a rect)
  - 5–10 px    → greeked rect in text color
  - h ≥ 10 px  → full per-glyph tessellation
2026-05-14 14:56:12 +03:00
HakanandClaude Opus 4.7 242e8870c3 perf(scene): greek top-level Text/MText below 4px height
When a Text/MText entity's anno-scaled glyph height projects to fewer
than 4 screen pixels, drop the per-glyph stroke tessellation and emit
a single filled rectangle in the text's color instead. The user still
sees "text lives here" at the original color and footprint, but the
expensive font-stroke generation is skipped for thousands of unreadable
labels at fit-all / zoom-out views.

Pre-boosts the fill color to compensate for the 0.45 ambient-occlusion
dim the face3d pipeline applies (it's meant for 3D-shaded mesh solids,
not 2D text greeking).

Note: applies only to top-level entities; Text/MText *inside* block
defs is already tessellated into the block cache at build time, so
greeking those would require either a cache rebuild on zoom or a
parallel "low-detail" cache. Left for later if real-world test
suggests it's needed.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-14 14:49:59 +03:00
HakanandClaude Opus 4.7 c5ed83c752 perf(scene): pixel-size LOD cull at zoom-out
Frustum culling only helps at zoom-in (offscreen geometry); zoom-out
still tessellated and uploaded every wire even when an entire entity
projected to a single pixel. Now we also drop wires whose world AABB
projects smaller than 0.5px in the active view — a fit-all view of a
city plan skips sub-pixel symbols, lines, and curves before they ever
hit the GPU.

  - `Scene` captures `world_per_pixel` each render from camera ortho_size
    / widget height.
  - `expand_insert` / `tessellate_entity` take an optional
    `world_per_pixel`; per-LocalWire / per-nested / whole-Insert /
    top-level entity AABB → pixel-size test → skip if < MIN_PIXEL_SIZE.
  - One-off paths (hit-test, viewport pane) pass `None` so they still
    see full geometry regardless of zoom.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-14 14:22:39 +03:00
HakanandClaude Opus 4.7 0996b75bdd Revert: stop honoring BlockRecord.is_loaded for xref skip decision
Empirically the DWG \"loaded\" bit doesn't track AutoCAD's XREF Manager
\"Loaded\"/\"Unloaded\" state reliably:

  - File A: manager \"Loaded\", on-disk is_loaded = Some(true)
  - File B: manager \"Loaded\", on-disk is_loaded = Some(false)

Same UI state, opposite bit values, so we were incorrectly skipping
xrefs the user wants loaded. Drop the `is_loaded == Some(false)` skip
and auto-resolve every xref again. The OOM problem this was meant to
mitigate is now addressed by the frustum culler, so loading more
xrefs no longer threatens the GPU budget.

The `BlockRecord::is_loaded` field + acadrust patch stay in place so
we can revisit once we identify the actual on-disk representation of
XREF→Unload (likely an XREF dependency record or
ACAD_XREF_PANEL_DATA xrecord).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-14 14:14:07 +03:00
HakanandClaude Opus 4.7 8d5ecdef51 fix(scene): correct view_world_aabb space + guard initial render
Two bugs in the new frustum culler that left the GUI rendering nothing
on file open:

1. `cam.target` is already in **local** f32 space — `fit_to_bounds`
   populates it from local wire coords — so subtracting `world_offset`
   again pushed the view rect to the negated centroid, with the actual
   geometry far outside.
2. The first call to `entity_wires()` after open comes from `fit_all()`
   itself, while `camera_generation` is still 0 and the camera is at
   its default origin. Culling against that rect discarded every wire
   → fit_all saw an empty list → camera never moved → the user-visible
   render stayed empty forever.

`view_world_aabb` now returns `None` until `camera_generation > 0`
(letting fit_all collect a real extent), then derives the view rect
directly from `cam.target` in local space.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-14 14:02:48 +03:00
HakanandClaude Opus 4.7 78cbb5570e perf(scene): frustum-cull wires using camera view AABB
Block defns and top-level entities now know their world-space XY
AABB, and `tessellate_entity` / `expand_insert` early-out for anything
that doesn't intersect the camera's view rect. Tested commit-only on
time_open (correct subset emitted with default camera); GUI run
pending user verification.

Cache plumbing:
  - `LocalWire` / `BlockDefn` carry `aabb_local` (post-build recursive
    union over nested defns).
  - `Scene::view_world_aabb()` derives a 25%-margined world rect from
    the active camera + last-seen render aspect.
  - `wire_cache` / `paper_sheet_cache` keys widen to
    `(geometry_epoch, camera_generation)` so pan/zoom invalidates the
    cached wire list — and pipeline `cached_epoch` widens to match
    so the GPU re-uploads on view change.
  - `XrefStatus::Unloaded` ack already shipped — orthogonal to this.

Also adds `examples/xref_states.rs` to dump per-block_record xref
metadata for diagnosing the is_loaded / unloaded distinction.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-14 13:52:04 +03:00
HakanandClaude Opus 4.7 e88a946176 feat(xref): honor BlockRecord is_loaded — skip Unloaded xrefs
When the host DWG marks an xref as Unloaded (via XREF→Unload in
AutoCAD), the user explicitly chose NOT to load that reference. We
were ignoring that and pulling the external file in anyway, which
on large drawings could push GPU memory past the device budget.

Bump the acadrust dep to the branch that exposes
`BlockRecord::is_loaded`, then short-circuit `resolve_xrefs` for
any entry with `is_loaded == Some(false)`. New `XrefStatus::Unloaded`
surfaces this in the command-line log so the user can see which
references were skipped (and can re-load them via the XREF dialog).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-14 11:20:11 +03:00
HakanandClaude Opus 4.7 def72e435e perf(scene): cache block defns + batch wires by style
Tessellates each block_record once into local-coord LocalWires; Insert
references transform-copy + ByBlock-resolve the cache rather than
explode+re-tessellate per reference. Same-style wires inside one Insert
are NaN-batched into a single WireModel to keep wgpu buffer counts
sane — large blocks that previously bailed to a marker now render in
a handful of buffers each.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-14 11:12:08 +03:00
Hakan SevenandClaude Opus 4.7 03555ce8bd chore: expose lib target + open-path profiling examples
Examples can't import from a bin-only crate, so add a thin lib.rs that
re-exports the existing modules. Used by the new examples that helped
diagnose the freeze fixed in the previous commit.

- examples/time_open: times parse / purge / cache / first-wires phases
- examples/inspect_insert: lists Insert blocks with sub-entity counts
- examples/find_raster: dumps RasterImage path + dimensions

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-13 23:02:54 +03:00
Hakan SevenandClaude Opus 4.7 c61d648dc7 fix(scene): unfreeze open on huge xref Inserts
A real DWG with an xref containing ~74k sub-entities froze on the first
render: Insert tessellation exploded the block, style-resolved every sub
serially, and one bad sub could hang the loop forever.

- Insert short-circuits to an insertion marker when the referenced block
  has more than INSERT_SUB_LIMIT (5_000) sub-entities. Documented as
  temporary in RENDERING_OPTIMIZATION.md.
- Re-run purge_corrupt_entities after resolve_xrefs so parser-garbage
  inside xref content is caught (initial purge runs before xref load).
- build_derived_caches: single pass over entities collecting handles
  per kind; tessellation reads via doc.get_entity instead of cloning
  every EntityType. Image decode now parallel too.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-13 23:02:48 +03:00
HakanandClaude Opus 4.7 2e985fdc9c chore: release v0.2.6
Co-Authored-By: Claude Opus 4.7 <[email protected]>
v0.2.6
2026-05-13 17:34:21 +03:00
HakanandClaude Opus 4.7 9b6d5437fa revert: drop wire segment caps that silently truncated geometry
Remove MAX_SEGS_PER_WIRE = 100_000 and MAX_TOTAL_SEGS = 3_000_000.
These were stop-gap GPU-memory guards that mutated visible output:
single complex entities were cut mid-geometry, and entire wires past
the 3M total were dropped by arrival order with no spatial awareness.
Either is worse than honestly drawing whatever the file contains —
truncated arcs and missing road segments look like bugs to the user,
not "we ran out of GPU memory."

The matching "Temporary Workarounds" section in
RENDERING_OPTIMIZATION.md goes with them. Per-entity LOD and
viewport culling (Phase 1 + 3.2 in the same doc) remain the right
long-term answer; until they land, prefer correctness over a soft
crash on pathological files.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-13 10:11:54 +03:00
HakanandClaude Opus 4.7 2f751c08f4 fix(scene): drop Z gate in fit_all so high-elevation entities show
Civil 3D files can legitimately carry profile geometry at huge Z
(10^6+ units) inside an otherwise small XY footprint — long-section
polylines on a road, for example. fit_all's outlier gate previously
filtered any point whose |x|, |y|, or |z| exceeded 10× the header
extent half-size, which dropped those polylines and made ZOOM
EXTENTS center on the main drawing only, leaving the profile
geometry permanently invisible.

The gate exists to reject origin-stuck entities and Ray/XLine far
points, both of which manifest as large XY excursions after
world_offset subtraction. Z-axis outliers are not a known garbage
pattern, so the gate now only checks XY.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-13 10:05:38 +03:00
HakanandClaude Opus 4.7 b2588e1790 feat(io): drop parser-garbage entities at load time
acadrust's DWG reader occasionally desynchronises on certain files
(observed on render.dwg: 1519 of 1763 LwPolylines arrived with non-unit
normals in the 1e200+ range and 100k phantom vertices). Tessellating
those entities allocates gigabytes and produces NaN-laden wires,
freezing the UI.

Add a pre-tessellation guard that scans freshly loaded documents and
drops any entity failing a cheap sanity check: non-unit normal,
non-finite or absurd coordinate, or vertex count above 100k. Count of
dropped entities is threaded through DerivedCaches and surfaced as a
warning in the command line so the user knows the file was patched up
on the way in.

Same file in DXF form parses cleanly (0 corrupt), so this is strictly
a DWG-path workaround until the upstream parser bug is fixed.

The new examples/inspect_polyline.rs is a one-off diagnostic that dumps
LwPolyline/Polyline2D/Polyline3D fields plus a corrupt-entity count;
useful for narrowing down the acadrust bug.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-13 10:00:16 +03:00
HakanandClaude Opus 4.7 586df77b2c feat(io): show loading overlay while opening CAD files
Big DWG/DXF files block the UI for seconds during parse + cache build,
leaving the user wondering whether the app froze. Split the file-open
flow into pick → load and show a modal overlay during the load: file
name, size, phase label (Reading / Parsing / Building caches /
Finalizing), animated indeterminate bar, and Cancel button.

Phase is tracked via a shared AtomicU8 written by the loader thread
and read by the overlay each frame. Cancel hides the overlay and
discards the result; the parser thread runs to completion in the
background since acadrust has no interrupt hook.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-13 09:59:07 +03:00
Hakan Seven 288ccff95a fix(render): preserve f64 precision until world_offset subtraction
Entity converters were casting WCS coordinates to f32 before the renderer
subtracted world_offset, which destroyed sub-unit precision on drawings
sitting at large coordinates (typical UTM-style CAD files). The multileader
case made it visible — glyphs warped under rotation — but every entity
that emits TruckObject::Lines/SegmentedLines/key_vertices/fill_tris was
affected.

Type changes (in src/scene/acad_to_truck.rs):
- TruckObject::Lines / SegmentedLines: Vec<[f32; 3]> → Vec<[f64; 3]>
- TruckEntity::key_vertices / fill_tris: f32 → f64

All ~17 producer files updated to keep WCS coordinates in f64 right up to
the TruckEntity boundary. The consumer in scene/tessellate.rs now performs
`(x - ox) as f32` (f64 subtract, then cast) for points, key_vertices, and
fill_tris — preserving precision near the camera origin even when the
drawing sits at million-unit coordinates.

catmull_rom_pts (multileader spline) is now f64; the scene path widens its
offset-relative f32 ctrl points to f64 around the call and narrows back at
the output.

Notes:
- Table layout still uses glam::Vec3 (f32) internally; widened to f64 only
  at the TruckEntity boundary for type compatibility. Separate cleanup to
  switch its internal math to f64 is tracked.
- snap_pts and tangent_geoms remain f32 — they are UI feedback (snap
  candidates, tangent hints) and the precision is sufficient there.
2026-05-12 23:47:40 +03:00
Hakan Seven 8bfa5088c4 fix(multileader): render text properly — strip MText codes, honor full layout
Multileader text was emitted as a single literal stroke pass with no MText
code handling, no rotation, no attachment, no line breaks, no per-piece
color and bad f32 precision under world_offset. Two separate render paths
both had the same bug, and one was masking the fix in the other.

This rewrite, applied to both paths:

- Strips MText format codes (`{\fArial Black|b0|i0|c162|p34;...}`) so the
  rendered text is the actual content, not the markup.
- Honors text_rotation (preferring text_direction so transforms survive),
  text_attachment_point (Left/Center/Right horizontal anchor), and
  text_left_attachment for vertical alignment via a shared
  v_offset_for_attachment helper.
- Splits on \P/\n/\N and word-wraps to text_width.
- Applies line_spacing_factor with the same 5/3 × height convention as
  MText.
- Resolves the text style via text_style_handle (fallback STANDARD).
- Applies ml.scale_factor everywhere (arrow size, dogleg length, text
  height, text width). anno_scale is now only applied when
  enable_annotation_scale is set.
- Splits the scene-level output into separate WireModels so leader,
  text, frame and background fill each carry their own colour
  (ctx.text_color, ml.text_frame, ctx.background_fill_color).
- Mirrors text_direction, base_direction and root.direction in
  apply_transform so a mirrored multileader's text follows the geometry
  instead of staying at its original rotation.
- Computes the text origin and frame corners in offset-relative f32
  space — drawings sit at large absolute coordinates and casting to f32
  before subtracting world_offset was wrecking the rotated sub-glyph
  precision.
2026-05-12 23:27:53 +03:00
Hakan Seven 2600ae1815 chore: release v0.2.5 v0.2.5 2026-05-12 22:29:22 +03:00
Hakan Seven ef57a629c0 Update image in README.md 2026-05-12 22:26:34 +03:00
Hakan Seven 406e04f2f0 chore: repin acadrust to 622729f on clean HakanSeven12 fork
Old fork was deleted and re-forked from upstream; the mirror-handedness fix
is now isolated on fix/mirrored-arc-handedness with no other diverging work.
2026-05-12 22:18:23 +03:00
Hakan Seven 200f10fd25 fix(explode): correct arc/ellipse direction in mirrored INSERT blocks
Mirrored INSERTs reverse OCS handedness, but acadrust's explode used to
keep the original normal — making CCW-around-normal arcs and ellipses
sweep the wrong way. The fix lives in acadrust 7c711e9, which flips the
new normal when det < 0 and reprojects center/major_axis/angles into the
new OCS. H7CAD's fix_mirrored_arc workaround is no longer needed.
2026-05-12 22:04:12 +03:00
Hakan Seven 04b898106c chore: release v0.2.4 v0.2.4 2026-05-12 20:54:03 +03:00
HakanandClaude Sonnet 4.6 a3efad9caf fix(hatch): align EllipticArc angle logic with CircularArc
Use reflection (TAU - sa, TAU - ea) for CW arcs and span.abs() for
segment count, consistent with the CircularArc pattern in both
hatch boundary (mod.rs) and tessellate (tessellate.rs).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-05-12 17:47:54 +03:00
HakanandClaude Sonnet 4.6 4b5f4c7ee8 fix(hatch): sync color from entity in synced_hatch_models
Color was read from the stale HatchModel cache instead of the live
entity, so property-panel color changes appeared on boundaries (wire)
but not on the hatch fill pattern.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-05-12 17:33:16 +03:00