forked from 1b-agent/opencadstudio-upstream
feat(lwpolyline): render the wide-polyline band via the wire shader
A wide polyline's flat band was drawn by the hatch pipeline: a solid fill with only draw-order depth. It ignored the entity linetype (the width "crushed" the dash pattern) and showed through 3-D geometry in a tilted view. Draw the band from the polyline's own centre-line wire instead. A new `WireModel.world_width` (drawing units) makes the wire vertex shader expand the quad by `world_half_width / world_per_pixel` (clamped to a hairline), so the band is sized in world units and tracks zoom. Because it is now a wire: - the GPU dash shader dashes the band by arc-length — the linetype applies; - it is depth-tested at the polyline elevation — no draw-order see-through; - no CPU band triangles or per-dash geometry are generated. `world_half_width` rides in `WireConst` (native, replacing a pad) and the web `WireInstance` (loc 14); both wire shaders branch on it. The tessellator sets `world_width` from the LwPolyline width on the Contour / SegmentedLines arms, and the model-space fill loop no longer emits a hatch band for any LwPolyline. Pick still uses the band polygon (`pick_tris`). Blocks keep the hatch band: `LocalWire` carries no `world_width` (finalize zeroes it), so a scaled insert still scales its band correctly. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
3d37e1f8d8
commit
bd1a5affd7
44 files changed
+158
-17
No files matched your search
Vendored
+7
@@ -325,6 +325,12 @@ fn build_defn(
|
||||
subs.push(LocalSub::Nested(build_nested_ref(nested_ins, doc, bg_color)));
|
||||
}
|
||||
_ => {
|
||||
// A wide polyline inside a block keeps its thin centre-line
|
||||
// here (`LocalWire` carries no `world_width`, and `finalize`
|
||||
// rebuilds every block wire with `world_width: 0.0`); its band
|
||||
// is drawn by the hatch pipeline (`push_block_wide_fills`),
|
||||
// which transforms with the block instance so the band scales
|
||||
// correctly. The shader band is a top-level-entity path only.
|
||||
for lw in tessellate_sub_local(doc, entity, anno_scale, bg_color) {
|
||||
subs.push(LocalSub::Wire(lw));
|
||||
}
|
||||
@@ -848,6 +854,7 @@ impl Batches {
|
||||
// the cached defn.
|
||||
let color = crate::scene::view::render::adapt_to_bg(b.color, bg_color);
|
||||
WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: b.pick_tris,
|
||||
pick_tris_low: b.pick_tris_low,
|
||||
|
||||
@@ -650,6 +650,7 @@ pub(crate) fn tessellate_entity(
|
||||
(ins.insert_point.z) as f32,
|
||||
);
|
||||
let marker = WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -1029,6 +1030,7 @@ fn lod_stub_wire(
|
||||
// LOD boundary. #19.
|
||||
let stored_color = if selected { WireModel::SELECTED } else { color };
|
||||
WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -1115,6 +1117,7 @@ fn lod_stub_wire_3d(
|
||||
}
|
||||
let stored_color = if selected { WireModel::SELECTED } else { color };
|
||||
WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
|
||||
@@ -370,6 +370,7 @@ pub fn tessellate(
|
||||
None
|
||||
};
|
||||
elem_wires.push(WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -660,6 +661,7 @@ pub fn tessellate(
|
||||
ftl.push(lo);
|
||||
}
|
||||
wires.push(WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -697,6 +699,7 @@ pub fn tessellate(
|
||||
fpl.push(lo);
|
||||
}
|
||||
wires.push(WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -741,6 +744,7 @@ pub fn tessellate(
|
||||
low.push(ll);
|
||||
}
|
||||
wires.push(WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -766,6 +770,7 @@ pub fn tessellate(
|
||||
});
|
||||
}
|
||||
wires.push(WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -821,6 +826,7 @@ pub fn tessellate(
|
||||
(Vec::new(), Vec::new(), Vec::new())
|
||||
};
|
||||
out.push(WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -858,6 +864,7 @@ pub fn tessellate(
|
||||
(Vec::new(), Vec::new(), Vec::new())
|
||||
};
|
||||
out.push(WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -892,6 +899,7 @@ pub fn tessellate(
|
||||
// are empty → the early-return path above).
|
||||
if !sdf_verts.is_empty() {
|
||||
out.push(WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -919,6 +927,7 @@ pub fn tessellate(
|
||||
|
||||
if out.is_empty() {
|
||||
out.push(WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -968,6 +977,7 @@ pub fn tessellate(
|
||||
.map(|[kx, ky, kz]| [kx, ky, kz])
|
||||
.collect();
|
||||
return vec![WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -1016,6 +1026,7 @@ pub fn tessellate(
|
||||
.map(|[x, y, z]| [x, y, z])
|
||||
.collect();
|
||||
return vec![WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -1052,9 +1063,12 @@ pub fn tessellate(
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [x, y, z])
|
||||
.collect();
|
||||
// A wide polyline arrives here: its band is pick geometry.
|
||||
// A wide polyline arrives here: the shader expands this
|
||||
// centre-line to `world_width` so the band IS the wire (the
|
||||
// linetype dashes it); the band also backs pick.
|
||||
let (pick_tris, pick_tris_low) = points_to_ds(te.pick_tris);
|
||||
return vec![WireModel {
|
||||
world_width: lwpolyline_band_width(entity),
|
||||
fill_is_3d: false,
|
||||
pick_tris,
|
||||
pick_tris_low,
|
||||
@@ -1140,6 +1154,7 @@ pub fn tessellate(
|
||||
(Vec::new(), Vec::new(), Vec::new())
|
||||
};
|
||||
out.push(WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris,
|
||||
pick_tris_low,
|
||||
@@ -1176,6 +1191,7 @@ pub fn tessellate(
|
||||
(Vec::new(), Vec::new(), Vec::new())
|
||||
};
|
||||
out.push(WireModel {
|
||||
world_width: 0.0,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
dash_from_start: false,
|
||||
@@ -1203,6 +1219,7 @@ pub fn tessellate(
|
||||
|
||||
if out.is_empty() {
|
||||
out.push(WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -1239,9 +1256,11 @@ pub fn tessellate(
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [x, y, z])
|
||||
.collect();
|
||||
// A wide polyline with PLINEGEN=0 arrives here.
|
||||
// A wide polyline with PLINEGEN=0 arrives here: same shader-band
|
||||
// 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 {
|
||||
world_width: lwpolyline_band_width(entity),
|
||||
fill_is_3d: false,
|
||||
pick_tris,
|
||||
pick_tris_low,
|
||||
@@ -1310,6 +1329,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 {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -1489,6 +1509,29 @@ pub(crate) fn entity_z(entity: &EntityType) -> f32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Band width (drawing units) of a wide LwPolyline whose flat band is drawn by
|
||||
/// expanding its centre-line wire in the shader. `0.0` = a zero-width polyline
|
||||
/// or a non-LwPolyline (a normal screen-pixel wire). A thickness-extruded
|
||||
/// polyline is excluded: its band becomes a 3-D tube (`thick_wide_band`), not a
|
||||
/// flat shader band. A tapering polyline (per-vertex start/end widths) collapses
|
||||
/// to its widest edge — the shader carries one width per wire.
|
||||
fn lwpolyline_band_width(entity: &EntityType) -> f32 {
|
||||
match entity {
|
||||
EntityType::LwPolyline(p) if p.thickness.abs() <= 1e-10 => {
|
||||
let mut w = p.constant_width;
|
||||
for v in &p.vertices {
|
||||
w = w.max(v.start_width).max(v.end_width);
|
||||
}
|
||||
if w > 1e-9 {
|
||||
w as f32
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
}
|
||||
_ => 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
// ── Fallback geometry (Viewport, Insert, Hatch outline, Ole2Frame) ───────
|
||||
//
|
||||
// Per-entity blocks have moved to their respective `entities/*.rs` files
|
||||
|
||||
+8
-9
@@ -691,15 +691,14 @@ impl Scene {
|
||||
// Wide LWPolyline and Polyline2D fills
|
||||
for entity in self.document.entities() {
|
||||
let (common, fill_origin, fills) = match entity {
|
||||
// A thickened wide LwPolyline becomes a 3-D tube: its bottom cap
|
||||
// is drawn as a real depth-tested surface by the tessellator, not
|
||||
// as this flat 2-D band (which, having only draw-order depth,
|
||||
// would show through the tube walls in a 3-D view).
|
||||
EntityType::LwPolyline(pl) if pl.thickness.abs() > 1e-10 => continue,
|
||||
EntityType::LwPolyline(pl) => {
|
||||
let (o, f) = crate::entities::lwpolyline::wide_fills(pl);
|
||||
(&pl.common, o, f)
|
||||
}
|
||||
// A wide LwPolyline no longer draws its band here: the shader
|
||||
// expands the centre-line wire to `world_width` (a real
|
||||
// depth-tested band that also carries the linetype dash), so a
|
||||
// second flat 2-D band with only draw-order depth would double
|
||||
// it and show through 3-D geometry. A thickened one is likewise
|
||||
// a 3-D tube built by the tessellator. Its band still backs pick
|
||||
// (`pick_tris`), just not this fill.
|
||||
EntityType::LwPolyline(_) => continue,
|
||||
EntityType::Polyline2D(pl) => {
|
||||
let (o, f) = crate::entities::polyline::wide_fills(pl);
|
||||
(&pl.common, o, f)
|
||||
|
||||
@@ -54,6 +54,12 @@ pub struct WireModel {
|
||||
pub pattern: [f32; 8],
|
||||
/// Rendered line width in screen pixels (half-width = line_weight_px / 2).
|
||||
pub line_weight_px: f32,
|
||||
/// World-space band width (drawing units). `0.0` = a normal wire whose
|
||||
/// width comes from `line_weight_px` (screen pixels). Non-zero = a wide
|
||||
/// polyline: the shader expands this centre-line to `world_width` world
|
||||
/// 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,
|
||||
/// 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).
|
||||
@@ -173,6 +179,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 {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -394,6 +401,7 @@ impl Default for WireModel {
|
||||
pattern_length: 0.0,
|
||||
pattern: [0.0; 8],
|
||||
line_weight_px: 1.0,
|
||||
world_width: 0.0,
|
||||
aci: 0,
|
||||
snap_pts: Vec::new(),
|
||||
tangent_geoms: Vec::new(),
|
||||
|
||||
@@ -119,7 +119,11 @@ pub struct WireConst {
|
||||
pub draw_depth: f32,
|
||||
pub align_end: f32,
|
||||
pub align_total: f32,
|
||||
pub _pad0: f32,
|
||||
/// World-space half-width for a wide-polyline band. `0.0` = a normal wire
|
||||
/// (uses `half_width`, screen pixels). Non-zero = the vertex shader expands
|
||||
/// the quad by `world_half_width / world_per_pixel` so the band tracks zoom
|
||||
/// in drawing units.
|
||||
pub world_half_width: f32,
|
||||
pub _pad1: f32,
|
||||
pub _pad2: f32,
|
||||
}
|
||||
@@ -171,6 +175,9 @@ pub struct WireInstance {
|
||||
/// and the total wire length. `align_total == 0.0` = not aligned.
|
||||
pub align_end: f32,
|
||||
pub align_total: f32,
|
||||
/// 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,
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
@@ -194,6 +201,7 @@ impl WireInstance {
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(WireInstance, pos_b_low) as u64, shader_location: 11, format: wgpu::VertexFormat::Float32x3 },
|
||||
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::VertexBufferLayout {
|
||||
array_stride: std::mem::size_of::<WireInstance>() as u64,
|
||||
@@ -403,6 +411,7 @@ fn emit_wire_instances(wire: &WireModel, color: [f32; 4], draw_depth: f32) -> Ve
|
||||
draw_depth,
|
||||
align_end,
|
||||
align_total,
|
||||
world_half_width: wire.world_width * 0.5,
|
||||
});
|
||||
}
|
||||
instances
|
||||
@@ -427,7 +436,7 @@ pub(crate) fn emit_wire_native(
|
||||
draw_depth,
|
||||
align_end,
|
||||
align_total,
|
||||
_pad0: 0.0,
|
||||
world_half_width: wire.world_width * 0.5,
|
||||
_pad1: 0.0,
|
||||
_pad2: 0.0,
|
||||
};
|
||||
|
||||
@@ -305,6 +305,7 @@ pub fn apply_along(
|
||||
.into_iter()
|
||||
.filter(|s| s.len() >= 2)
|
||||
.map(|pts| WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
@@ -344,6 +345,7 @@ pub fn apply_along(
|
||||
xy = xy.max(y);
|
||||
}
|
||||
out.push(WireModel {
|
||||
world_width: 0.0,
|
||||
fill_is_3d: false,
|
||||
pick_tris: Vec::new(),
|
||||
pick_tris_low: Vec::new(),
|
||||
|
||||
Reference in new issue
Block a user