The viewport's picker took the nearest face along the ray whatever the section removed. Over a cut it hovered the cut-away face in front of the plane (the outer wall of a sectioned hub, say); the shader clipped that face's tint, but its outline, drawn dimmed where the model hides it, ran behind the cap and showed through it. While orbiting with the pointer on the model the hovered face changed from frame to frame, so lines and patches of the far side came and went over the hatch. The picker now does what view.pick already does: faces, edges and corners on the removed side are skipped (the ray walks past them), and where the plane crosses a body nearer than any kept face, the cap hides the faces, edges and corners behind it and nothing is hovered there. The walk that tells whether the plane is inside a body moves into view_pick::body_cut_at so both pickers share it. Test: view_pick_tests::the_mouse_picker_stops_at_a_section_cap (a box with a pocket, cut through the pocket: over the cut material nothing is picked, over the pocket its floor, and with the section cleared the top face). It fails on main, which picks the removed top face. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4f2c133d01
commit
e1d99ef0ce
3 files changed
+96
-7
No files matched your search
@@ -32,7 +32,7 @@ const DEFAULT_MODEL_H: f64 = 600.0;
|
||||
|
||||
/// How far past the section plane a face point may lie and still count as kept (the renderer
|
||||
/// clips at `n·p <= n·o`; this is the same hairline `clip_segment` allows).
|
||||
const SECTION_EPS: f64 = 1e-6;
|
||||
pub(crate) const SECTION_EPS: f64 = 1e-6;
|
||||
|
||||
/// Crossings one body may contribute before the section-cap walk gives up on it.
|
||||
const MAX_CROSSINGS: usize = 64;
|
||||
@@ -307,6 +307,26 @@ fn section_cap(
|
||||
if !(t_cap > 0.0) || t_cap >= first_kept.unwrap_or(f64::INFINITY) {
|
||||
return None;
|
||||
}
|
||||
let body = body_cut_at(app, st, bounds, input.o, input.d, t_cap, include_ghosted, replaced, active_bodies)?;
|
||||
Some((t_cap, body, sn))
|
||||
}
|
||||
|
||||
/// The body the ray `o + d·t` is inside of at `t_cap` (where it crosses the section plane): an
|
||||
/// odd number of mesh crossings before it. The walk re-raycasts each body past every crossing
|
||||
/// it finds, bounded per body. The viewport's picker asks the same, so a cut cap hides what lies
|
||||
/// behind it there too.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn body_cut_at(
|
||||
app: &SolveApp,
|
||||
st: &solidcraft_engine::doc::ModelState,
|
||||
bounds: &[(String, solidcraft_engine::geom::Aabb3)],
|
||||
o: Vec3,
|
||||
d: Vec3,
|
||||
t_cap: f64,
|
||||
include_ghosted: bool,
|
||||
replaced: &[String],
|
||||
active_bodies: &Option<Vec<String>>,
|
||||
) -> Option<String> {
|
||||
let walk_eps = 1e-6 * (1.0 + crate::viewport::scene_radius(app));
|
||||
for (i, b) in st.bodies.iter().enumerate() {
|
||||
if !app.session.body_visible(&b.name) || replaced.contains(&b.name) {
|
||||
@@ -317,7 +337,7 @@ fn section_cap(
|
||||
}
|
||||
if let Some((_, bb)) = bounds.get(i) {
|
||||
let pad = bb.diagonal() * 1e-6 + 1e-9;
|
||||
match crate::viewport::ray_box(input.o, input.d, bb, pad) {
|
||||
match crate::viewport::ray_box(o, d, bb, pad) {
|
||||
None => continue,
|
||||
Some(t0) if t0 > t_cap => continue,
|
||||
_ => {}
|
||||
@@ -326,7 +346,7 @@ fn section_cap(
|
||||
let (m, place) = b.mesh_in_place();
|
||||
let index = app.viewport.pick_index.of(&m);
|
||||
let (mut t, mut crossings) = (0.0f64, 0usize);
|
||||
while let Some((lo, ld)) = crate::viewport::local_ray(&place, input.o + input.d * t, input.d) {
|
||||
while let Some((lo, ld)) = crate::viewport::local_ray(&place, o + d * t, d) {
|
||||
let Some((dt, _)) = crate::pick_index::raycast(index.as_deref(), &m, lo, ld) else { break };
|
||||
let tt = t + dt;
|
||||
if tt >= t_cap - SECTION_EPS {
|
||||
@@ -339,7 +359,7 @@ fn section_cap(
|
||||
}
|
||||
}
|
||||
if crossings % 2 == 1 {
|
||||
return Some((t_cap, b.name.clone(), sn));
|
||||
return Some(b.name.clone());
|
||||
}
|
||||
}
|
||||
None
|
||||
|
||||
@@ -201,3 +201,39 @@ fn all_lists_the_faces_along_the_ray_and_the_cap_is_enforced() {
|
||||
assert_eq!(v["ok"], false);
|
||||
assert!(v["error"].as_str().is_some_and(|e| e.contains("1024")), "{v}");
|
||||
}
|
||||
|
||||
/// The pointer over a section's cap picks nothing behind it (#6328): hovering the cut used to
|
||||
/// pick the removed top face, whose highlighted outline then showed dimmed through the cap
|
||||
/// wherever it ran behind it, so the cut looked see-through. Through the pocket the cut opens,
|
||||
/// the pointer still finds the pocket's floor.
|
||||
#[test]
|
||||
fn the_mouse_picker_stops_at_a_section_cap() {
|
||||
use crate::viewport::{Hit, pick, pick_all, projection};
|
||||
let mut h = top_view();
|
||||
h.call(
|
||||
"engine.execute",
|
||||
json!({"command": "solid.box", "params": {"length": 4, "width": 4, "height": 4, "corner": [3, 3, 6], "operation": "cut"}}),
|
||||
);
|
||||
h.call("engine.execute", json!({"command": "inspect.section", "params": {"plane": {"origin": [0, 0, 8], "normal": [0, 0, 1]}}}));
|
||||
let rect = egui::Rect::from_min_size(egui::pos2(0.0, 0.0), egui::vec2(600.0, 600.0));
|
||||
let proj = projection(&h.app, rect);
|
||||
let faces = |hits: &[Hit]| hits.iter().filter(|x| matches!(x, Hit::Face { .. })).cloned().collect::<Vec<_>>();
|
||||
// Over the cut material, between the pocket and the box's side: no face, and no edge or
|
||||
// corner behind the cap.
|
||||
let solid = proj.to_screen(Vec3::new(1.5, 5.0, 8.0)).unwrap();
|
||||
let hits = pick(&h.app, &proj, solid);
|
||||
assert!(hits.iter().all(|x| !matches!(x, Hit::Face { .. } | Hit::Edge { .. } | Hit::Vertex { .. })), "{hits:?}");
|
||||
assert!(faces(&pick_all(&h.app, &proj, solid)).is_empty());
|
||||
// Over the pocket: its floor at z = 6, below the cut.
|
||||
let pocket = proj.to_screen(Vec3::new(5.0, 5.0, 8.0)).unwrap();
|
||||
match faces(&pick(&h.app, &proj, pocket)).first() {
|
||||
Some(Hit::Face { point, .. }) => assert!((point.z - 6.0).abs() < 1e-6, "{point:?}"),
|
||||
other => panic!("the pocket's floor: {other:?}"),
|
||||
}
|
||||
// Without the section, the box's top face answers there.
|
||||
h.call("engine.execute", json!({"command": "inspect.section", "params": {"clear": true}}));
|
||||
match faces(&pick(&h.app, &proj, solid)).first() {
|
||||
Some(Hit::Face { point, .. }) => assert!((point.z - 10.0).abs() < 1e-6, "{point:?}"),
|
||||
other => panic!("the top face: {other:?}"),
|
||||
}
|
||||
}
|
||||
@@ -1706,6 +1706,11 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,
|
||||
}
|
||||
}
|
||||
hits.extend(bestc.hits());
|
||||
// A section hides the material its normal points at: nothing there is picked, and where the
|
||||
// plane crosses a body its cap hides what lies behind it (#6328), as `view.pick` answers.
|
||||
let section = section_plane(app);
|
||||
let kept = |p: Vec3| section.is_none_or(|(so, sn)| sn.dot(p) <= sn.dot(so) + crate::view_pick::SECTION_EPS);
|
||||
let walk_eps = 1e-6 * (1.0 + scene_radius(app));
|
||||
// Nearest face along the ray (hides what is behind it); with `all`, every body's nearest.
|
||||
let mut bestf: Option<(f64, Hit)> = None;
|
||||
let mut faces = Near::new(all);
|
||||
@@ -1727,8 +1732,21 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,
|
||||
// A placed part is picked in its own frame, from its shared mesh and index: the ray is
|
||||
// moved there (a rigid move keeps distances along it), so no moved copy is made.
|
||||
let (m, place) = b.mesh_in_place();
|
||||
let Some((lo, ld)) = local_ray(&place, o, d) else { continue };
|
||||
if let Some((t, ti)) = crate::pick_index::raycast(app.viewport.pick_index.of(&m).as_deref(), &m, lo, ld) {
|
||||
let index = app.viewport.pick_index.of(&m);
|
||||
// The nearest kept face: past any the section removes (a bounded walk along the ray).
|
||||
let mut nearest = None;
|
||||
let mut from = 0.0f64;
|
||||
for _ in 0..64 {
|
||||
let Some((lo, ld)) = local_ray(&place, o + d * from, d) else { break };
|
||||
let Some((dt, ti)) = crate::pick_index::raycast(index.as_deref(), &m, lo, ld) else { break };
|
||||
let t = from + dt;
|
||||
if kept(o + d * t) {
|
||||
nearest = Some((t, ti));
|
||||
break;
|
||||
}
|
||||
from = t + walk_eps;
|
||||
}
|
||||
if let Some((t, ti)) = nearest {
|
||||
let fi = m.tri_face.get(ti).copied().unwrap_or(0) as usize;
|
||||
let hit = Hit::Face { body: b.name.clone(), index: fi, point: o + d * t };
|
||||
if bestf.as_ref().is_none_or(|(bt, _)| t < *bt) {
|
||||
@@ -1739,10 +1757,25 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,
|
||||
}
|
||||
}
|
||||
}
|
||||
// The cut cap, where the plane crosses a body nearer than any kept face: it hides that face
|
||||
// and everything behind it, and is no face itself.
|
||||
let cap = section.and_then(|(so, sn)| {
|
||||
let den = sn.dot(d);
|
||||
let t_cap = (sn.dot(so) - sn.dot(o)) / den;
|
||||
let nearer = den.abs() > 1e-12 && t_cap > 0.0 && bestf.as_ref().is_none_or(|(t, _)| t_cap < *t);
|
||||
let replaced = app.preview.effective_replaced();
|
||||
let shown_bodies = &None;
|
||||
(nearer && crate::view_pick::body_cut_at(app, &st, &bounds, o, d, t_cap, true, replaced, shown_bodies).is_some()).then_some(t_cap)
|
||||
});
|
||||
if let Some(t_cap) = cap {
|
||||
bestf = None;
|
||||
faces.v.retain(|(t, _)| *t < t_cap);
|
||||
}
|
||||
let hidden_from = cap.or(bestf.as_ref().map(|(t, _)| *t));
|
||||
let slack = scene_radius(app) * 0.02;
|
||||
// Wireframe draws no faces, so nothing hides an edge or a vertex.
|
||||
let wireframe = app.ui.visual_style == 2;
|
||||
let visible = |p: Vec3| wireframe || bestf.as_ref().is_none_or(|(t, _)| (p - o).dot(d) <= *t + slack);
|
||||
let visible = |p: Vec3| kept(p) && (wireframe || hidden_from.is_none_or(|t| (p - o).dot(d) <= t + slack));
|
||||
// Vertices (edge end points) and edges, within 7 and 6 points of the cursor.
|
||||
let reach = crate::pick_index::reach(proj, pos, 8.0);
|
||||
let mut bestv = Near::new(all);
|
||||
|
||||
Reference in new issue
Block a user