Wave 283/509: STEP import: an edge through a face's pole is split there (and 3 more)
4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. - 0694fd4e8 jyviko: STEP import: an edge through a face's pole is split there - 1d70ac267 jyviko: tess: a face whose boundary still crosses itself after untangling is filled leniently, not the whole body refused - 77bd85cab jyviko: cli: snapshot --quality coarse|normal|fine|ultra meshes the bodies at that display quality - 1404bc1f5 jyviko: STEP import: a spline face's edges are measured on their pcurves only, not by nearest point first Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
@@ -458,10 +458,23 @@ impl<'b, 'a> Builder<'b, 'a> {
|
||||
/// and the edge's tolerance covers it. A spline face's gaps are measured on the pcurves its
|
||||
/// kernel makes (`raise_edges`): an iterative nearest point may settle elsewhere on it.
|
||||
fn measure_edges(&mut self, surface: &BSurface, edge_loops: &[Vec<(u32, bool)>]) -> R<()> {
|
||||
// Only where the nearest point is in closed form: on a spline the search may settle on
|
||||
// another part of the surface, or on its boundary for a point a hair past it, and report a
|
||||
// gap the edge does not have (2.9 mm on Poppy Humanoid's leg shells, whose edges lie within
|
||||
// 0.003 mm), widening tolerances past what SMLib takes. A spline face's gaps are measured
|
||||
// on the pcurves its kernel makes (`raise_edges`).
|
||||
if !matches!(
|
||||
surface,
|
||||
BSurface::Plane { .. }
|
||||
| BSurface::PlaneThrough { .. }
|
||||
| BSurface::Cylinder { .. }
|
||||
| BSurface::Cone { .. }
|
||||
| BSurface::Sphere { .. }
|
||||
| BSurface::Torus { .. }
|
||||
) {
|
||||
return Ok(());
|
||||
}
|
||||
let on = SurfaceEval::new(surface).map_err(|m| m.to_string())?;
|
||||
// One search grid for all of the face's points, each searched from the whole grid: a
|
||||
// nearest point carried on as the next one's start can settle on another part of a
|
||||
// closed spline.
|
||||
let starts = solidcraft_geom::tess::uv::Starts::default();
|
||||
for l in edge_loops {
|
||||
for &(e, _) in l {
|
||||
@@ -794,6 +807,10 @@ impl<'b, 'a> Builder<'b, 'a> {
|
||||
fn finish(mut self, item: u64, name: String, shells: Vec<Vec<(u32, bool)>>, kind: Kind) -> R<Solid> {
|
||||
let _span = solidcraft_profile::span("import", "step.solid_record");
|
||||
let mut notes = Vec::new();
|
||||
let at_poles = self.split_at_poles()?;
|
||||
if at_poles > 0 {
|
||||
notes.push(format!("{at_poles} edges split where they pass through a face's pole"));
|
||||
}
|
||||
let seams = self.add_seams()?;
|
||||
if seams > 0 {
|
||||
notes.push(format!("{seams} seam edges added to faces that wind around their surface"));
|
||||
|
||||
@@ -207,6 +207,69 @@ impl Builder<'_, '_> {
|
||||
Ok(added)
|
||||
}
|
||||
|
||||
/// Split every edge that passes through a pole of a face it bounds (a sphere's, a revolved
|
||||
/// face's on its axis) inside its interval: a great circle from the equator over the pole to a
|
||||
/// vertex just past it. On the face's parameters the pole is a line, along which the edge's
|
||||
/// pcurve would have to jump half a turn; split there, the jump is at a vertex on the pole,
|
||||
/// where a loop may run along the pole's line. Returns how many edges were split.
|
||||
pub(super) fn split_at_poles(&mut self) -> R<usize> {
|
||||
let mut splits = 0;
|
||||
for fi in 0..self.faces.len() {
|
||||
let Some(face) = self.faces.get(fi) else { continue };
|
||||
let Some(ax) = axis(&face.surface) else { continue };
|
||||
let poles: Vec<Vec3> = ax.poles.iter().flatten().copied().collect();
|
||||
if poles.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mut edges: Vec<u32> =
|
||||
face.loops.iter().filter_map(|l| if let LoopB::Edges(es) = l { Some(es) } else { None }).flatten().map(|u| u.0).collect();
|
||||
edges.sort_unstable();
|
||||
edges.dedup();
|
||||
for e in edges {
|
||||
for pole in &poles {
|
||||
let Some(t) = self.through_at(e, *pole)? else { continue };
|
||||
splits += 1;
|
||||
if splits > MAX_SPLITS {
|
||||
return Err(format!("more than {MAX_SPLITS} edges split at poles"));
|
||||
}
|
||||
let v = self.split_edge(e, t)?;
|
||||
// The new vertex is the pole, as the face's parameters have it.
|
||||
if let Some(x) = self.vertices.get_mut(v as usize) {
|
||||
let gap = Vec3::from(x.point).dist(*pole);
|
||||
x.point = arr(*pole);
|
||||
x.tolerance = x.tolerance.max(1.5 * gap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(splits)
|
||||
}
|
||||
|
||||
/// Where edge `e` passes through `pole` inside its interval (within the tolerance, away from
|
||||
/// its ends), if it does: its nearest point to the pole, refined by golden-section search.
|
||||
fn through_at(&self, e: u32, pole: Vec3) -> R<Option<f64>> {
|
||||
let edge = self.edges.get(e as usize).ok_or("edge reference")?;
|
||||
let c = CurveEval::new(&edge.curve).map_err(|m| m.to_string())?;
|
||||
let [lo, hi] = edge.interval;
|
||||
let reach = self.tol.max(edge.tolerance);
|
||||
let d = |t: f64| c.point(t).map_or(f64::INFINITY, |p| p.dist(pole));
|
||||
let step = (hi - lo) / SAMPLES as f64;
|
||||
let k = (0..=SAMPLES).min_by(|&i, &j| d(lo + step * i as f64).total_cmp(&d(lo + step * j as f64))).unwrap_or(0);
|
||||
let (mut a, mut b) = (lo + step * k.saturating_sub(1) as f64, (lo + step * (k + 1) as f64).min(hi));
|
||||
let g = 0.5 * (5f64.sqrt() - 1.0);
|
||||
for _ in 0..100 {
|
||||
let (x, y) = (b - g * (b - a), a + g * (b - a));
|
||||
if d(x) < d(y) {
|
||||
b = y;
|
||||
} else {
|
||||
a = x;
|
||||
}
|
||||
}
|
||||
let t = 0.5 * (a + b);
|
||||
let ends = [lo, hi].map(|s| c.point(s).map_or(0.0, |p| p.dist(pole)));
|
||||
Ok((d(t) <= reach && ends.iter().all(|x| *x > reach) && t > lo && t < hi).then_some(t))
|
||||
}
|
||||
|
||||
/// Turns (in u, in v) a loop makes around a periodic surface.
|
||||
fn winding(&self, eval: &SurfaceEval, es: &[(u32, bool)], periods: [Option<f64>; 2]) -> R<[i64; 2]> {
|
||||
let mut last: Option<[f64; 2]> = None;
|
||||
|
||||
Reference in New Issue
Block a user