Custom Clickable Objects

Hi, I am writing a plugin that involves the generation of various objects. They are displayed via conduit and not added to the Rhino document. I am wondering if it is possible to make them clickable to run an event of my own.

I tested the MouseCallback class with the idea of doing a raycast from the viewport to my collection of geometry. I however am unsure how best to handle any objects in the Rhino document that are visibly obstructing. Do I need to implement something for that or am I missing a better method?

Hi @YCoCg,

Your approach is right — MouseCallback plus your own picking is exactly how you’d handle geometry that only lives in a conduit. Nothing needs to go into the document; you just have to do two things yourself: hit-test your geometry, and decide whether a real document object is in front of it. Those are two separate jobs, and there’s a good tool for each.

Hit-testing your geometry — use PickContext. Rather than rolling your own raycast, construct a Rhino.Input.Custom.PickContext in your mouse handler, feed it the viewport’s pick line, and call PickFrustumTest(...) against your meshes/curves/points. It uses the same pick math as Rhino’s own selection, returns a depth value so you can order hits front-to-back, and — importantly — it honors the pick aperture (the few-pixel screen tolerance). That means clicking near a curve or point registers, which a raw ray intersection won’t give you. There are overloads for Mesh, NurbsCurve, Point3d, PointCloud, and more.

– Dale