Mesh export: the faces of an edge share its points exactly (#1753)
Thanks @SychPL.
This commit is contained in:
1 parent
a8a3cea1d0
commit
74ce904142
3 files changed
+130
-1
No files matched your search
Vendored
+9
@@ -154,6 +154,15 @@ Changes:
|
||||
p11`, across that plane, at the middle). A bilinear patch equals the blend of its corners the
|
||||
division compared against, so a twisted ruled face (a loft between polylines) went out as two
|
||||
triangles per face (#1666); a flat cell such as a cone's trapezoid between rulings is not split.
|
||||
- `tessellation/triangulation.rs`: a shell's face meshes share their edges' points exactly. A
|
||||
face's mesh puts each point at its parameters on the face's own surface, so a point of an edge
|
||||
that lies off a surface within tolerance (an intersection-curve sample whose projection did not
|
||||
converge, an imported edge) came out in a different place on each of the edge's faces, and the
|
||||
exported mesh had a crack there. In display and export meshes (`Deflection::rulings`), a
|
||||
vertex at a point of a face's boundary loops that is farther than `TOLERANCE` from the nearest
|
||||
point of the face's edges now goes to that point, when it is within the chord tolerance
|
||||
(`onto_edges`). Points within `TOLERANCE` stay on the surface, so exact geometry meshes as
|
||||
before. The meshes Boolean operations intersect keep truck's points.
|
||||
|
||||
## matext4cgmath 0.1.0 (Apache-2.0, © RICOS Co. Ltd., https://github.com/ricosjp/matext4cgmath)
|
||||
|
||||
|
||||
+44
-1
@@ -389,7 +389,14 @@ fn shell_create_polygon<S: PreMeshableSurface>(
|
||||
.collect::<Option<Vec<_>>>();
|
||||
let polygon: Option<PolygonMesh> = (|| {
|
||||
let boundary = PolyBoundary::new(preboundary?, &surface, tol);
|
||||
Some(trimming_tessellation(surface, &boundary, tol, cap))
|
||||
let mut mesh = trimming_tessellation(surface, &boundary, tol, cap);
|
||||
// Display and export meshes only, as the ruling grid lines: the meshes Boolean
|
||||
// operations intersect keep truck's points.
|
||||
if tol.rulings {
|
||||
let points: Vec<Point3> = wires.iter().flat_map(Wire::edge_iter).flat_map(|e| e.curve().0).collect();
|
||||
onto_edges(&mut mesh, &boundary, &points, tol.chord);
|
||||
}
|
||||
Some(mesh)
|
||||
})();
|
||||
// SolidCraft: faces with seam edges (a loop running along an edge both ways, as STEP
|
||||
// writes cylinders) are valid here; `debug_new` asserts simple loops in debug builds.
|
||||
@@ -400,6 +407,42 @@ fn shell_create_polygon<S: PreMeshableSurface>(
|
||||
new_face
|
||||
}
|
||||
|
||||
/// SolidCraft: a face's mesh puts every point where its own surface passes the point's
|
||||
/// parameters, and a boundary point's parameters are those its edge point projects to. An edge
|
||||
/// that lies on a surface only within tolerance (a sample of an intersection curve whose
|
||||
/// projection did not converge, an imported edge) then puts the point it shares with the next
|
||||
/// face in a different place on each face, and the shell's mesh cracks there. Each vertex at a
|
||||
/// point of the boundary loops (the same parameters, as the triangulation got them) that is
|
||||
/// farther than `TOLERANCE` from the nearest point of the face's edges goes to that point, when
|
||||
/// it is within `tol`, so the faces of an edge have the very same points along it. Within
|
||||
/// `TOLERANCE` the points are already the same, and a face keeps them on its surface: grid
|
||||
/// points can lie on a boundary between its points (the ruling lines of a plane), and moving
|
||||
/// only the boundary points would bend the boundary there.
|
||||
fn onto_edges(mesh: &mut PolygonMesh, boundary: &PolyBoundary, points: &[Point3], tol: f64) {
|
||||
let key = |x: f64, y: f64| [spade_round(x).to_bits(), spade_round(y).to_bits()];
|
||||
let loops: rustc_hash::FxHashSet<[u64; 2]> = boundary.0.iter().flatten().map(|p| key(p.x, p.y)).collect();
|
||||
let on_loops: Vec<bool> = mesh.uv_coords().iter().map(|uv| loops.contains(&key(uv.x, uv.y))).collect();
|
||||
let cell = |p: Point3| [p.x, p.y, p.z].map(|x| (x / tol).floor() as i64);
|
||||
let mut grid: HashMap<[i64; 3], Vec<Point3>> = HashMap::default();
|
||||
points.iter().for_each(|p| grid.entry(cell(*p)).or_default().push(*p));
|
||||
for (p, _) in mesh.positions_mut().iter_mut().zip(on_loops).filter(|(_, on)| *on) {
|
||||
let c = cell(*p);
|
||||
let mut best = (tol * tol, None);
|
||||
for d in (0..27).map(|k| [k % 3 - 1, k / 3 % 3 - 1, k / 9 - 1]) {
|
||||
let near = [c[0].saturating_add(d[0]), c[1].saturating_add(d[1]), c[2].saturating_add(d[2])];
|
||||
for q in grid.get(&near).into_iter().flatten() {
|
||||
let d2 = q.distance2(*p);
|
||||
if d2 <= best.0 {
|
||||
best = (d2, Some(*q));
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(q) = best.1.filter(|_| best.0 > TOLERANCE2) {
|
||||
*p = q;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
struct PolyBoundaryPiece(Vec<Point2>);
|
||||
|
||||
|
||||
Reference in new issue
Block a user