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 <[email protected]>
This commit is contained in:
1 parent
fd0b8fc1d4
commit
110683f419
47 files changed
+529
-143
No files matched your search
@@ -183,6 +183,7 @@ impl CadCommand for AlignedDimensionCommand {
|
||||
}
|
||||
};
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "dimaligned_preview".into(),
|
||||
points: vec![[p1.x, p1.y, p1.z], [p2.x, p2.y, p2.z]],
|
||||
points_low: Vec::new(),
|
||||
@@ -224,6 +225,7 @@ fn preview_aligned(p1: Vec3, p2: Vec3, dim_pt: Vec3) -> WireModel {
|
||||
// Show ext lines + dim line.
|
||||
let (d1, d2) = dim_line_endpoints(p1, p2, dim_pt);
|
||||
WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "dimaligned_preview".into(),
|
||||
points: vec![
|
||||
[p1.x, p1.y, p1.z],
|
||||
|
||||
@@ -124,6 +124,7 @@ fn v3(pt: Vec3) -> Vector3 {
|
||||
|
||||
fn preview_wire(points: Vec<Vec3>) -> WireModel {
|
||||
WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "dimangular_preview".to_string(),
|
||||
points: points.into_iter().map(|p| [p.x, p.y, p.z]).collect(),
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -179,6 +179,7 @@ fn v3(p: Vec3) -> Vector3 {
|
||||
|
||||
fn preview_line(a: Vec3, b: Vec3) -> WireModel {
|
||||
WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "dimdia_preview".into(),
|
||||
points: vec![[a.x, a.y, a.z], [b.x, b.y, b.z]],
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -169,6 +169,7 @@ impl CadCommand for DimBaselineCommand {
|
||||
let p1 = self.base_p1;
|
||||
let (dim_line_pt, dim_line_pt2) = self.dim_line_pts(pt);
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "dimbase_preview".into(),
|
||||
points: vec![
|
||||
[p1.x, p1.y, p1.z],
|
||||
|
||||
@@ -149,6 +149,7 @@ impl CadCommand for DimContinueCommand {
|
||||
let dim_line_pt = p1 + self.perp * (self.dim_line_perp - p1.dot(self.perp));
|
||||
let dim_line_pt2 = pt + self.perp * (self.dim_line_perp - pt.dot(self.perp));
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "dimcont_preview".into(),
|
||||
points: vec![
|
||||
[p1.x, p1.y, p1.z],
|
||||
|
||||
@@ -85,6 +85,7 @@ impl CadCommand for DimJogLineCommand {
|
||||
}
|
||||
let d = 0.3_f32;
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "dimjog_preview".into(),
|
||||
// Jog zigzag in the XY drawing plane (Z is elevation, ~0). The old
|
||||
// marker varied Z, so in the top-down view it collapsed to a flat
|
||||
|
||||
@@ -101,6 +101,7 @@ impl CadCommand for DimTeditCommand {
|
||||
}
|
||||
let d = 0.2_f32;
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "dimtedit_preview".into(),
|
||||
// Marker box in the XY drawing plane (Z is elevation, ~0). The old
|
||||
// box varied Z, so in the top-down view it collapsed to a flat line
|
||||
|
||||
@@ -163,6 +163,7 @@ fn preview_wire(pts: &[Vec3]) -> WireModel {
|
||||
points.push([w2.x, w2.y, w2.z]);
|
||||
}
|
||||
WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "leader_preview".into(),
|
||||
points,
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -218,6 +218,7 @@ fn v3(pt: Vec3) -> Vector3 {
|
||||
|
||||
fn preview_wire(points: Vec<Vec3>) -> WireModel {
|
||||
WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "dimlinear_preview".to_string(),
|
||||
points: points.into_iter().map(|p| [p.x, p.y, p.z]).collect(),
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -149,6 +149,7 @@ fn preview_wire(pts: &[Vec3]) -> WireModel {
|
||||
points.push([w2.x, w2.y, w2.z]);
|
||||
}
|
||||
WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "mleader_preview".into(),
|
||||
points,
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -456,6 +456,7 @@ impl CadCommand for MLeaderCollectCommand {
|
||||
|
||||
fn preview_wire(pts: &[Vec3]) -> WireModel {
|
||||
WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "mleader_edit_preview".into(),
|
||||
points: pts.iter().map(|p| [p.x, p.y, p.z]).collect(),
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -116,6 +116,7 @@ fn ordinate_elbow(feature: Vec3, leader: Vec3, is_x: bool) -> Vec3 {
|
||||
|
||||
fn preview_wire(points: Vec<Vec3>) -> WireModel {
|
||||
WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "dimordinate_preview".into(),
|
||||
points: points.into_iter().map(|p| [p.x, p.y, p.z]).collect(),
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -88,6 +88,7 @@ impl CadCommand for QdimCommand {
|
||||
}
|
||||
let d = 0.5_f32;
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "qdim_preview".into(),
|
||||
points: vec![[pt.x - d * 3.0, pt.y, pt.z], [pt.x + d * 3.0, pt.y, pt.z]],
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -184,6 +184,7 @@ fn v3(pt: Vec3) -> Vector3 {
|
||||
|
||||
fn preview_wire(points: Vec<Vec3>) -> WireModel {
|
||||
WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "dimradius_preview".to_string(),
|
||||
points: points.into_iter().map(|p| [p.x, p.y, p.z]).collect(),
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -139,6 +139,7 @@ impl CadCommand for TableCommand {
|
||||
let y = pt.y;
|
||||
let z = pt.z;
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "table_preview".into(),
|
||||
points: vec![
|
||||
[x, y, z],
|
||||
|
||||
@@ -84,6 +84,7 @@ impl CadCommand for ToleranceCommand {
|
||||
}
|
||||
let d = 0.15_f32;
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "tolerance_preview".into(),
|
||||
points: vec![
|
||||
[pt.x - d, pt.y, pt.z],
|
||||
|
||||
@@ -160,6 +160,7 @@ impl CadCommand for AttdefCommand {
|
||||
// Show a small cross at the insertion point.
|
||||
let d = 0.15_f32;
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "attdef_preview".into(),
|
||||
points: vec![
|
||||
[pt.x - d, pt.y, pt.z],
|
||||
|
||||
@@ -131,6 +131,7 @@ impl CadCommand for MlineCommand {
|
||||
let mut pts: Vec<[f32; 3]> = self.points.iter().map(|p| [p.x, p.y, p.z]).collect();
|
||||
pts.push([pt.x, pt.y, pt.z]);
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "mline_preview".into(),
|
||||
points: pts,
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -108,6 +108,7 @@ impl CadCommand for ImageCommand {
|
||||
let p3 = [origin.x, origin.y + world_height, origin.z];
|
||||
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "image_preview".into(),
|
||||
points: vec![p0, p1, p2, p3, p0],
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -74,6 +74,7 @@ impl CadCommand for RayCommand {
|
||||
let dir = (pt - base).normalize_or_zero();
|
||||
let far = base + dir * DISPLAY_EXTENT;
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "ray_preview".into(),
|
||||
points: vec![[base.x, base.y, base.z], [far.x, far.y, far.z]],
|
||||
points_low: Vec::new(),
|
||||
@@ -154,6 +155,7 @@ impl CadCommand for XLineCommand {
|
||||
let far_pos = base + dir * DISPLAY_EXTENT;
|
||||
let far_neg = base - dir * DISPLAY_EXTENT;
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "xline_preview".into(),
|
||||
points: vec![
|
||||
[far_neg.x, far_neg.y, far_neg.z],
|
||||
|
||||
@@ -80,6 +80,7 @@ impl CadCommand for RevCloudCommand {
|
||||
preview_pts.push([pt.x, pt.y, pt.z]);
|
||||
preview_pts.push([self.points[0].x, self.points[0].y, self.points[0].z]);
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "revcloud_preview".into(),
|
||||
points: preview_pts,
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -114,6 +114,7 @@ impl CadCommand for WipeoutCommand {
|
||||
let min = p1.min(pt);
|
||||
let max = p1.max(pt);
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "wipeout_preview".into(),
|
||||
points: vec![
|
||||
[min.x, min.y, min.z],
|
||||
@@ -148,6 +149,7 @@ impl CadCommand for WipeoutCommand {
|
||||
pts.push([pt.x, pt.y, pt.z]);
|
||||
pts.push([self.poly_pts[0].x, self.poly_pts[0].y, self.poly_pts[0].z]);
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "wipeout_poly_preview".into(),
|
||||
points: pts,
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -69,6 +69,7 @@ impl CadCommand for AreaCommand {
|
||||
pts.push(f(pt));
|
||||
pts.push(f(self.points[0]));
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "area_preview".into(),
|
||||
points: pts,
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -63,6 +63,7 @@ impl CadCommand for DistCommand {
|
||||
let p1 = self.first?;
|
||||
// The preview wire is purely visual, so f32 vertices are fine here.
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "dist_preview".into(),
|
||||
points: vec![
|
||||
[p1.x as f32, p1.y as f32, p1.z as f32],
|
||||
|
||||
@@ -67,6 +67,7 @@ impl MeasureGeomCommand {
|
||||
/// Build a cyan preview wire connecting the picked points and the cursor.
|
||||
fn preview_wire(name: &str, pts: Vec<[f32; 3]>) -> WireModel {
|
||||
WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: name.to_string(),
|
||||
points: pts,
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -80,6 +80,7 @@ impl CadCommand for MviewCommand {
|
||||
fn on_mouse_move(&mut self, pt: DVec3) -> Option<WireModel> { let pt = pt.as_vec3();
|
||||
let c1 = self.corner1?;
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "mview_preview".to_string(),
|
||||
points: vec![
|
||||
[c1.x, c1.y, c1.z],
|
||||
|
||||
@@ -74,6 +74,7 @@ impl CadCommand for MviewCommand {
|
||||
fn on_mouse_move(&mut self, pt: Vec3) -> Option<WireModel> {
|
||||
let c1 = self.corner1?;
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "mview_preview".to_string(),
|
||||
points: vec![
|
||||
[c1.x, c1.y, c1.z],
|
||||
|
||||
@@ -305,6 +305,7 @@ inventory::submit!(crate::command::CommandRegistration {
|
||||
|
||||
fn wire(name: &str, points: Vec<[f32; 3]>) -> WireModel {
|
||||
WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: name.into(),
|
||||
points,
|
||||
points_low: Vec::new(),
|
||||
|
||||
@@ -48,6 +48,7 @@ impl CadCommand for PlotWindowCommand {
|
||||
let p1 = self.p1?;
|
||||
// Draw the selection rectangle.
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "plotwindow_preview".into(),
|
||||
points: vec![
|
||||
[p1.x, p1.y, p1.z],
|
||||
|
||||
@@ -65,6 +65,7 @@ impl CadCommand for ZoomWindowCommand {
|
||||
let max = p1.max(pt);
|
||||
// Draw a rectangle preview
|
||||
Some(WireModel {
|
||||
text_verts: Vec::new(),
|
||||
name: "zoom_window_preview".into(),
|
||||
points: vec![
|
||||
[min.x, min.y, 0.0],
|
||||
|
||||
Reference in new issue
Block a user