feat(polyline): smooth per-segment taper for varying-width wide polylines

A wide polyline with per-vertex varying widths rendered at its widest edge
(uniform-width ones were already exact). Draw the true taper instead.

`WireModel.taper_widths` carries a per-point full band width. The wire
instance (native slim + web fat) gains per-endpoint `world_hw_a/b`, and both
wire shaders interpolate `mix(hw_a, hw_b, which_end)` so each segment's band
narrows/widens linearly — depth-tested, and the linetype dash still applies.

Alignment (widths must match the tessellated points) is solved by building
both together: a new `TruckObject::TaperedLines(points, widths)`, filled by
`common::tapered_band_points` (straight = endpoints, arc = 16 samples with the
width lerped along it). to_truck routes a varying-width polyline here —
LwPolyline before the PLINEGEN split, Polyline2D at its return — while a
uniform-width one keeps the constant-band Contour path unchanged. `world_width`
stays the widest edge as the PDF-stroke + zoom-floor fallback.

Blocks fall back to the constant-widest band (`LocalWire` carries no
taper_widths).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 4.8 committed 2026-07-20 16:36:06 +03:00
1 parent a8aece1909
commit b3016ca892
48 files changed
+322 -7

No files matched your search

+5
View File
@@ -56,6 +56,11 @@ pub enum TruckObject {
Lines(Vec<[f64; 3]>),
/// Like Lines but linetype pattern restarts at each NaN-separated segment (plinegen=false).
SegmentedLines(Vec<[f64; 3]>),
/// A wide polyline whose band width VARIES (a taper): a continuous WCS point
/// list paired index-for-index with a per-point full band width. The wire
/// shader interpolates the two endpoint widths of each segment so the band
/// tapers smoothly. Points hold no NaN breaks (one continuous band).
TaperedLines(Vec<[f64; 3]>, Vec<f32>),
Volume(Solid),
}
+3
View File
@@ -650,6 +650,7 @@ pub(crate) fn tessellate_entity(
(ins.insert_point.z) as f32,
);
let marker = WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
@@ -1030,6 +1031,7 @@ fn lod_stub_wire(
// LOD boundary. #19.
let stored_color = if selected { WireModel::SELECTED } else { color };
WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
@@ -1117,6 +1119,7 @@ fn lod_stub_wire_3d(
}
let stored_color = if selected { WireModel::SELECTED } else { color };
WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
+60
View File
@@ -370,6 +370,7 @@ pub fn tessellate(
None
};
elem_wires.push(WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
@@ -661,6 +662,7 @@ pub fn tessellate(
ftl.push(lo);
}
wires.push(WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
@@ -699,6 +701,7 @@ pub fn tessellate(
fpl.push(lo);
}
wires.push(WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
@@ -744,6 +747,7 @@ pub fn tessellate(
low.push(ll);
}
wires.push(WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
@@ -770,6 +774,7 @@ pub fn tessellate(
});
}
wires.push(WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
@@ -826,6 +831,7 @@ pub fn tessellate(
(Vec::new(), Vec::new(), Vec::new())
};
out.push(WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
@@ -864,6 +870,7 @@ pub fn tessellate(
(Vec::new(), Vec::new(), Vec::new())
};
out.push(WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
@@ -899,6 +906,7 @@ pub fn tessellate(
// are empty → the early-return path above).
if !sdf_verts.is_empty() {
out.push(WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
@@ -927,6 +935,7 @@ pub fn tessellate(
if out.is_empty() {
out.push(WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
@@ -977,6 +986,7 @@ pub fn tessellate(
.map(|[kx, ky, kz]| [kx, ky, kz])
.collect();
return vec![WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
@@ -1026,6 +1036,7 @@ pub fn tessellate(
.map(|[x, y, z]| [x, y, z])
.collect();
return vec![WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
@@ -1068,6 +1079,7 @@ pub fn tessellate(
// linetype dashes it); the band also backs pick.
let (pick_tris, pick_tris_low) = points_to_ds(te.pick_tris);
return vec![WireModel {
taper_widths: Vec::new(),
world_width: polyline_band_width(entity),
fill_is_3d: false,
pick_tris,
@@ -1159,6 +1171,7 @@ pub fn tessellate(
(Vec::new(), Vec::new(), Vec::new())
};
out.push(WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris,
@@ -1196,6 +1209,7 @@ pub fn tessellate(
(Vec::new(), Vec::new(), Vec::new())
};
out.push(WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
pick_tris: Vec::new(),
pick_tris_low: Vec::new(),
@@ -1224,6 +1238,7 @@ pub fn tessellate(
if out.is_empty() {
out.push(WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),
@@ -1265,6 +1280,7 @@ pub fn tessellate(
// treatment as the Contour arm, restarting the dash per segment.
let (pick_tris, pick_tris_low) = points_to_ds(te.pick_tris);
return vec![WireModel {
taper_widths: Vec::new(),
world_width: polyline_band_width(entity),
fill_is_3d: false,
pick_tris,
@@ -1291,6 +1307,49 @@ pub fn tessellate(
}];
}
TruckObject::TaperedLines(points, widths) => {
// A wide polyline whose width varies: one continuous band wire
// carrying a per-point width; the shader interpolates each
// segment's two endpoint widths. `world_width` (the widest edge)
// stays as the constant fallback for PDF export + a hairline
// floor when zoomed out.
let (local_pts, local_pts_low) = points_to_ds(points);
let snap_pts = te.snap_pts;
let key_vertices: Vec<[f64; 3]> = te
.key_vertices
.into_iter()
.map(|[x, y, z]| [x, y, z])
.collect();
let (pick_tris, pick_tris_low) = points_to_ds(te.pick_tris);
let world_width = widths.iter().copied().fold(0.0f32, f32::max);
return vec![WireModel {
taper_widths: widths,
world_width,
fill_is_3d: false,
pick_tris,
pick_tris_low,
dash_from_start: false,
dash_align_end: None,
text_verts: Vec::new(),
name,
points: local_pts,
points_low: local_pts_low,
color,
selected,
pattern_length,
pattern,
line_weight_px,
snap_pts,
tangent_geoms: te.tangent_geoms,
aci: 0,
key_vertices,
plinegen: true,
aabb: WireModel::UNBOUNDED_AABB,
fill_tris: vec![],
fill_tris_low: Vec::new(),
}];
}
TruckObject::Volume(_) => {
// Solid3D / Region / Body → mesh tessellation lives in
// `solid3d_tess`. As a wire fallback, render the pre-computed
@@ -1334,6 +1393,7 @@ pub fn tessellate(
let snap_pts: Vec<(glam::DVec3, SnapHint)> =
snap_pts.into_iter().map(|(p, h)| (p.as_dvec3(), h)).collect();
vec![WireModel {
taper_widths: Vec::new(),
world_width: 0.0,
fill_is_3d: false,
pick_tris: Vec::new(),