Skip to main content

Module pick

Module pick 

Source
Expand description

Ray-based hit testing (“picking”) against a Model, for interactive selection in a viewer: cast a ray from the camera through the cursor, ask for the nearest vertex/edge/face/solid it hits, and get back its id — which a caller turns into the entity’s stable name to put into a program step.

Built entirely on a RasterizedModel the caller passes in — the same sampled points/polylines/triangles its viewer draws — rather than re-deriving triangulation or curve sampling here, so a pick can never disagree with what the viewer actually shows. Sketches likewise, through SketchTargets. Rasterizing once per build and picking against that also makes a pick cheap enough to run on every pointer move, to show what a click would pick.

Generic over the model’s own Scalar, using the crate’s existing Vector3 linear algebra (add/sub/prod_dot/prod_cross/norm) throughout rather than a second, ad hoc vector-math implementation. tolerance (how close a click has to land to count, for PickFilter::Vertex/PickFilter::Edge) is the one deliberate exception, staying a plain f64: it is a UI fuzziness knob derived from screen pixels, not a geometric quantity the kernel reasons about, so it is compared against Scalar::to_f64 rather than folded into interval arithmetic.

Structs§

PickHit
Ray
A pickable ray, in world space. dir need not be unit length; t in PickHit is in units of dir, i.e. the hit point is origin + dir * t.
SketchHit
A sketch a ray hit, where it hit its plane.
SketchTarget
One sketch as something to click on and to draw: its plane, the outlines of its closed regions, and every curve as a polyline — all in sketch coordinates.
SketchTargets
Every sketch of a part, outlined once — finding a sketch’s regions is the expensive part of picking it — for picking with pick_sketch and for drawing.

Enums§

PickFilter
What a pick query is looking for.
PickKind
Which kind of entity a pick found (or was asked to look for).

Functions§

pick
Cast ray against model, as rasterized samples it, and return the nearest entity matching filter within tolerance (world-space distance; only meaningful for PickFilter::Vertex/PickFilter::Edge — face/solid hits are exact ray/triangle intersections and ignore it).
pick_sketch
The sketch nearest along ray that it hits (see [hit_sketch]), with tolerance the world-space distance within which a click counts as on a curve.
solid_of_face
The solid that owns face_id, if it can be found (a face is always part of exactly one shell, and a shell of exactly one solid).