Viewer State geo intersection in 18.5

   3289   4   0
User Avatar
Member
122 posts
Joined: June 2019
Offline
I saw this in what's new section:
States can now find primitives/points under the mouse much more efficiently than doing a ray intersection.

Is it something new from sopGeometryIntersection in stateutils or it's just this function is more optimized now?
User Avatar
Staff
397 posts
Joined: Feb. 2018
Offline
You can use the new hou.GadgetDrawable for locating primitives such as polygons and points instead of intersecting the geometry for a specific prim type.

Checkout $HFS/houdini/viewer_states/examples/state_gadget_demo.hip
Edited by mabelzile - Nov. 2, 2020 10:24:22
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
Am I missing anything or both methods, the old hou.geometry().intersect() and the new hou.GadgetDrawable, return only 1 primitive under the mouse cursor?
I'd like to have a list of all the prims instead.
Only workaround I can think of is a convoluted implementation of a vex wrangle with the intersect_all() function.
User Avatar
Member
122 posts
Joined: June 2019
Offline
Yeah, afaik there is no hom equivalent of intersect_all and gadgets are high level structure with the main use case of picking and dragging (so it's not designed to get intersection info).

Docs on hou.Geometry.intersect suggested this one to get all hits:

hit_positions = []
prev_dist = 0.01
while geometry.intersect(origin, direction, position, normal, uvw,
                         min_hit=prev_dist):
    # Make sure to store a *copy* of the position, not the object
    # that is being modified in each iteration of the loop
    hit_positions.append(hou.Vector3(position))
    prev_dist = origin.distanceTo(position) + 0.01

You can also use hou.GeometryRayCache for that (just note that in docs signature isn't correct and missed the first argument which is geometry). Though I'm not sure if it's better in terms of performance.

Anyway this approach is probably is the same as intersect_all with 0.01 tolerance.
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
oh I missed that bit of code, thanks.
My use case is a 2D top view, with coplanar overlapping prims.
I guess I'll have to offset them in the Y according to min_hit.
Edited by Andr - March 15, 2021 08:37:07
  • Quick Links