forked from 1b-agent/opencadstudio-upstream
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:
1 parent
a8aece1909
commit
b3016ca892
48 files changed
+322
-7
No files matched your search
Vendored
+1
@@ -864,6 +864,7 @@ impl Batches {
|
||||
// the cached defn.
|
||||
let color = crate::scene::view::render::adapt_to_bg(b.color, bg_color);
|
||||
WireModel {
|
||||
taper_widths: Vec::new(),
|
||||
world_width: b.world_width,
|
||||
fill_is_3d: false,
|
||||
pick_tris: b.pick_tris,
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -60,6 +60,11 @@ pub struct WireModel {
|
||||
/// units (scaling with zoom) so the band IS the wire — the linetype dash
|
||||
/// pattern then applies to the band instead of a separate hatch fill.
|
||||
pub world_width: f32,
|
||||
/// Per-point full band width (drawing units), aligned index-for-index with
|
||||
/// [`points`], for a polyline whose width VARIES (a taper). Empty = a
|
||||
/// constant band of `world_width`. The wire shader reads the two endpoint
|
||||
/// widths of each segment and interpolates, so the band tapers smoothly.
|
||||
pub taper_widths: Vec<f32>,
|
||||
/// ACI color index (1-255). 0 means true-color or unknown (no CTB lookup).
|
||||
pub aci: u8,
|
||||
/// Pre-baked snap candidates (Center, Node, Quadrant, Insertion).
|
||||
@@ -179,6 +184,7 @@ impl WireModel {
|
||||
/// Create a solid wire (no dash pattern, 1px weight).
|
||||
pub fn solid(name: String, points: Vec<[f32; 3]>, color: [f32; 4], selected: bool) -> Self {
|
||||
Self {
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
@@ -402,6 +408,7 @@ impl Default for WireModel {
|
||||
pattern: [0.0; 8],
|
||||
line_weight_px: 1.0,
|
||||
world_width: 0.0,
|
||||
taper_widths: Vec::new(),
|
||||
aci: 0,
|
||||
snap_pts: Vec::new(),
|
||||
tangent_geoms: Vec::new(),
|
||||
|
||||
@@ -189,6 +189,8 @@ fn blank_instance() -> WireInstance {
|
||||
distance_a: 0.0,
|
||||
distance_b: 0.0,
|
||||
wire_id: 0,
|
||||
world_hw_a: 0.0,
|
||||
world_hw_b: 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,6 +80,11 @@ pub struct WireInstance {
|
||||
pub distance_b: f32,
|
||||
/// Index into the per-wire `WireConst` storage buffer (group 1).
|
||||
pub wire_id: u32,
|
||||
/// World-space half-width at each endpoint for a TAPERED band. `0.0` =
|
||||
/// use the per-wire constant (`WireConst.world_half_width`). The shader
|
||||
/// interpolates between the two so the band tapers across the segment.
|
||||
pub world_hw_a: f32,
|
||||
pub world_hw_b: f32,
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@@ -94,6 +99,8 @@ impl WireInstance {
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(WireInstance, distance_a) as u64, shader_location: 4, format: wgpu::VertexFormat::Float32 },
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(WireInstance, distance_b) as u64, shader_location: 5, format: wgpu::VertexFormat::Float32 },
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(WireInstance, wire_id) as u64, shader_location: 6, format: wgpu::VertexFormat::Uint32 },
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(WireInstance, world_hw_a) as u64, shader_location: 7, format: wgpu::VertexFormat::Float32 },
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(WireInstance, world_hw_b) as u64, shader_location: 8, format: wgpu::VertexFormat::Float32 },
|
||||
];
|
||||
wgpu::VertexBufferLayout {
|
||||
array_stride: std::mem::size_of::<WireInstance>() as u64,
|
||||
@@ -178,6 +185,10 @@ pub struct WireInstance {
|
||||
/// World-space half-width for a wide-polyline band (see `WireConst`). `0.0`
|
||||
/// = a normal wire (uses `half_width`, screen pixels).
|
||||
pub world_half_width: f32,
|
||||
/// Per-endpoint world half-width for a tapered band (0 = use the constant
|
||||
/// `world_half_width`). The shader interpolates across the segment.
|
||||
pub world_hw_a: f32,
|
||||
pub world_hw_b: f32,
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
@@ -202,6 +213,8 @@ impl WireInstance {
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(WireInstance, align_end) as u64, shader_location: 12, format: wgpu::VertexFormat::Float32 },
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(WireInstance, align_total) as u64, shader_location: 13, format: wgpu::VertexFormat::Float32 },
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(WireInstance, world_half_width) as u64, shader_location: 14, format: wgpu::VertexFormat::Float32 },
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(WireInstance, world_hw_a) as u64, shader_location: 15, format: wgpu::VertexFormat::Float32 },
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(WireInstance, world_hw_b) as u64, shader_location: 16, format: wgpu::VertexFormat::Float32 },
|
||||
];
|
||||
wgpu::VertexBufferLayout {
|
||||
array_stride: std::mem::size_of::<WireInstance>() as u64,
|
||||
@@ -389,6 +402,7 @@ fn emit_wire_instances(wire: &WireModel, color: [f32; 4], draw_depth: f32) -> Ve
|
||||
}
|
||||
let (dists, align_end, align_total) = wire_distances(wire);
|
||||
let low = |i: usize| -> [f32; 3] { wire.points_low.get(i).copied().unwrap_or([0.0; 3]) };
|
||||
let tw = |i: usize| -> f32 { wire.taper_widths.get(i).copied().unwrap_or(0.0) * 0.5 };
|
||||
let mut instances: Vec<WireInstance> = Vec::with_capacity(seg_count);
|
||||
for i in 0..seg_count {
|
||||
let a = wire.points[i];
|
||||
@@ -412,6 +426,8 @@ fn emit_wire_instances(wire: &WireModel, color: [f32; 4], draw_depth: f32) -> Ve
|
||||
align_end,
|
||||
align_total,
|
||||
world_half_width: wire.world_width * 0.5,
|
||||
world_hw_a: tw(i),
|
||||
world_hw_b: tw(i + 1),
|
||||
});
|
||||
}
|
||||
instances
|
||||
@@ -446,6 +462,9 @@ pub(crate) fn emit_wire_native(
|
||||
return (Vec::new(), cst);
|
||||
}
|
||||
let low = |i: usize| -> [f32; 3] { wire.points_low.get(i).copied().unwrap_or([0.0; 3]) };
|
||||
// Per-point half-width for a tapered band (empty ⇒ 0 ⇒ shader uses the
|
||||
// per-wire constant width).
|
||||
let tw = |i: usize| -> f32 { wire.taper_widths.get(i).copied().unwrap_or(0.0) * 0.5 };
|
||||
let mut instances: Vec<WireInstance> = Vec::with_capacity(seg_count);
|
||||
for i in 0..seg_count {
|
||||
let a = wire.points[i];
|
||||
@@ -461,6 +480,8 @@ pub(crate) fn emit_wire_native(
|
||||
distance_a: dists[i],
|
||||
distance_b: dists[i + 1],
|
||||
wire_id,
|
||||
world_hw_a: tw(i),
|
||||
world_hw_b: tw(i + 1),
|
||||
});
|
||||
}
|
||||
(instances, cst)
|
||||
|
||||
@@ -305,6 +305,7 @@ pub fn apply_along(
|
||||
.into_iter()
|
||||
.filter(|s| s.len() >= 2)
|
||||
.map(|pts| WireModel {
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
@@ -345,6 +346,7 @@ pub fn apply_along(
|
||||
xy = xy.max(y);
|
||||
}
|
||||
out.push(WireModel {
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
|
||||
Reference in new issue
Block a user