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 <noreply@anthropic.com>
This commit is contained in:
parent
a8aece1909
commit
b3016ca892
48 changed files with 322 additions and 7 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue