Python/Hscript Select Visible Geometry only

   112   4   0
User Avatar
Member
16 posts
Joined: April 2012
Offline
I want to select visible geometry only in an automated fashion. Thanks!

I am able to select the visible geometry in the viewport manually by enabling ‘Area Select Visible Geometry only’ and selecting on the scene.

I was wondering if it's possible to achieve this via script (HScript or Python). I know Maya has a script that does this so was hoping to find a similar option in Houdini too.
User Avatar
Member
402 posts
Joined: Dec. 2006
Offline
scene_viewer = hou.ui.paneTabOfType(hou.paneTabType.SceneViewer)
scene_viewer.setPickingVisibleGeometry(True)
https://www.patreon.com/user?u=14076972 [www.patreon.com]
https://vimeo.com/user43923185 [vimeo.com]
https://gumroad.com/alexeyvanzhula [gumroad.com]
User Avatar
Member
16 posts
Joined: April 2012
Offline
Thanks for the input.

Unfortunatelly, I got that far and that is setting the toggle on only.

What I am after is a script to do the actual selection of the visible faces only.

This may not be entirely possible in Houdini yet, but it would be nice.
User Avatar
Member
402 posts
Joined: Dec. 2006
Offline
ant_5555
Thanks for the input.

Unfortunatelly, I got that far and that is setting the toggle on only.

What I am after is a script to do the actual selection of the visible faces only.

This may not be entirely possible in Houdini yet, but it would be nice.

Shelf script:
scene_viewer = hou.ui.paneTabOfType(hou.paneTabType.SceneViewer)
pwd = scene_viewer.pwd()
if pwd.childTypeCategory() == hou.sopNodeTypeCategory():
    sop = pwd.displayNode()
    if sop is not None:
        sop = sop.createOutputNode('groupexpression')
        view_normal = hou.Vector3(0, 0, 1) * scene_viewer.curViewport().viewTransform().transposed().inverted()
        sop.parm('groupname1').set('viewprims')
        sop.parm('snippet1').set('dot(prim_normal(0, @elemnum, 0.5, 0.5), {%f, %f, %f}) > 0' % (view_normal[0], view_normal[1], view_normal[2]))
        sop.setCurrent(True, True)
        sop.setDisplayFlag(True)
        sop.setRenderFlag(True)
        sop.setHighlightFlag(True)
        scene_viewer.enterCurrentNodeState()
https://www.patreon.com/user?u=14076972 [www.patreon.com]
https://vimeo.com/user43923185 [vimeo.com]
https://gumroad.com/alexeyvanzhula [gumroad.com]
User Avatar
Member
16 posts
Joined: April 2012
Offline
Thanks again for your script. However, not quite there yet

I'm away from my computer right now so I can't quite test it so forgive me if I'm wrong, but if I look at your code… It seems to me you are just selecting front-facing faces, regardless of whether they are visible or occluded.

Again, my intent is to get visible primitives only. I want to make a script that has the same behaviour as enabling ‘Area Select Visible Geometry only’ and then manually selecting everything in the view.

This selects all visible faces, but ignores the occluded ones.
  • Quick Links