forked from 1b-agent/opencadstudio-upstream
fix(hatch): clip fill with kernel mesh
Resolve boundary topology before rendering so corner-aligned pattern rows cannot flip shader parity. Chunk indexed geometry to device buffer limits and retain the texture compatibility transport. Refs #489
This commit is contained in:
1 parent
448869ac35
commit
5b9fffdfba
9 files changed
+259
-416
No files matched your search
@@ -1,8 +1,5 @@
|
||||
// HatchModel — CPU-side hatch fill data; rendered entirely on the GPU.
|
||||
//
|
||||
// The boundary is a closed polygon in world XY coordinates.
|
||||
// The GPU fragment shader performs point-in-polygon and hatch-line tests so
|
||||
// no line geometry is ever tessellated on the CPU.
|
||||
// CPU-side hatch fill data. The kernel triangulates the boundary and the GPU
|
||||
// evaluates the pattern inside that mesh.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -207,6 +204,40 @@ pub struct HatchModel {
|
||||
}
|
||||
|
||||
impl HatchModel {
|
||||
/// Indexed local-space fill mesh with even-odd loop containment.
|
||||
pub(crate) fn fill_mesh(&self) -> (Vec<[f32; 2]>, Vec<u32>) {
|
||||
let mut rings = Vec::new();
|
||||
let mut ring = Vec::new();
|
||||
for &[x, y] in self.boundary.iter() {
|
||||
if x.is_finite() && y.is_finite() {
|
||||
ring.push([x as f64, y as f64]);
|
||||
} else if ring.len() >= 3 {
|
||||
rings.push(std::mem::take(&mut ring));
|
||||
} else {
|
||||
ring.clear();
|
||||
}
|
||||
}
|
||||
if ring.len() >= 3 {
|
||||
rings.push(ring);
|
||||
}
|
||||
|
||||
let (points, triangles) = cadkernel::geom2d::triangulate_rings(&rings);
|
||||
let vertices = points
|
||||
.into_iter()
|
||||
.map(|[x, y]| [x as f32, y as f32])
|
||||
.collect();
|
||||
let mut indices = Vec::with_capacity(triangles.len() * 3);
|
||||
for triangle in triangles {
|
||||
for index in triangle {
|
||||
let Ok(index) = u32::try_from(index) else {
|
||||
return (Vec::new(), Vec::new());
|
||||
};
|
||||
indices.push(index);
|
||||
}
|
||||
}
|
||||
(vertices, indices)
|
||||
}
|
||||
|
||||
/// CPU-side rasteriser for `HatchPattern::Pattern` — produces the line
|
||||
/// segments inside the boundary so non-GPU consumers (PDF export,
|
||||
/// `paper_canvas`, print preview) can draw the actual pattern instead
|
||||
|
||||
Reference in new issue
Block a user