forked from 1b-agent/opencadstudio-upstream
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
fd0b8fc1d4
commit
110683f419
47 files changed
+529
-143
No files matched your search
@@ -134,7 +134,48 @@ pub fn click_hit<'a>(
|
||||
}
|
||||
}
|
||||
}
|
||||
best_fill.map(|(_, n)| n)
|
||||
if let Some((_, n)) = best_fill {
|
||||
return Some(n);
|
||||
}
|
||||
|
||||
// SDF text renders as glyph quads, not strokes — its only pick target is
|
||||
// the empty wire that carries the quads (`text_verts`) and the text's own
|
||||
// tight AABB. Fall back to AABB containment so such text stays click-
|
||||
// selectable, and use `text_verts` as the exact discriminator so only real
|
||||
// text boxes qualify (never some other empty wire). Lowest priority — real
|
||||
// edges and fills above always win. Prefer the tightest box so a click over
|
||||
// overlapping text picks the smallest.
|
||||
if crate::scene::text::sdf_atlas::sdf_text_enabled() {
|
||||
let mut best_area = f32::MAX;
|
||||
let mut best_box: Option<&str> = None;
|
||||
for wire in wires {
|
||||
if wire.text_verts.is_empty()
|
||||
|| !wire.points.is_empty()
|
||||
|| !wire.fill_tris.is_empty()
|
||||
|| wire.aabb == WireModel::UNBOUNDED_AABB
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let [minx, miny, maxx, maxy] = wire.aabb;
|
||||
let (mut sx0, mut sy0, mut sx1, mut sy1) = (f32::MAX, f32::MAX, f32::MIN, f32::MIN);
|
||||
for (cx, cy) in [(minx, miny), (maxx, miny), (maxx, maxy), (minx, maxy)] {
|
||||
let s = world_to_screen(glam::DVec3::new(cx as f64, cy as f64, 0.0), view_rot, eye, bounds);
|
||||
sx0 = sx0.min(s.x);
|
||||
sx1 = sx1.max(s.x);
|
||||
sy0 = sy0.min(s.y);
|
||||
sy1 = sy1.max(s.y);
|
||||
}
|
||||
if cursor.x >= sx0 && cursor.x <= sx1 && cursor.y >= sy0 && cursor.y <= sy1 {
|
||||
let area = (sx1 - sx0) * (sy1 - sy0);
|
||||
if area < best_area {
|
||||
best_area = area;
|
||||
best_box = Some(wire.name.as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
return best_box;
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Like `click_hit` but returns every wire within the click threshold,
|
||||
|
||||
@@ -610,6 +610,7 @@ mod tests {
|
||||
|
||||
// A polyline half inside, half outside the 0..10 square.
|
||||
let mut wires = vec![WireModel {
|
||||
text_verts: Vec::new(),
|
||||
points: vec![[5.0, 5.0, 0.0], [15.0, 5.0, 0.0]],
|
||||
..Default::default()
|
||||
}];
|
||||
|
||||
Reference in new issue
Block a user