Can't get hou.SimpleDrawable to display in SOP context.

   1353   4   0
User Avatar
Member
28 posts
Joined: Nov. 2016
Offline
Hi,
I'm trying to simply display a hou.SimpleDrawable in an otherwise empty asset on SOP level, basicly following the documentation example here [www.sidefx.com].

So all I have is this code in the Viewer State of an asset with a Null inside labeled "GET_INPUT" connected to the first input and nothing connected to the output.


class State(object):
    def __init__(self, state_name, scene_viewer):
        self.state_name = state_name
        self.scene_viewer = scene_viewer

    
    def onDraw(self, kwargs):
        """ Called for rendering a state e.g. required for 
        hou.AdvancedDrawable objects
        """
        draw_handle = kwargs["draw_handle"]
        
        geo = kwargs["node"].node("GET_INPUT").geometry()
        
        drawable = hou.SimpleDrawable(self.scene_viewer, geo, "drawable")
        drawable.setDisplayMode(hou.drawableDisplayMode.WireframeMode)
        drawable.setWireframeColor(hou.Color(1.0,0.0,0.0))
        drawable.enable(True)
        drawable.show(True)


def createViewerStateTemplate():
    """ Mandatory entry point to create and return the viewer state 
        template to register. """

    state_typename = kwargs["type"].definition().sections()["DefaultState"].contents()
    state_label = "SimpleDrawable test"
    state_cat = hou.sopNodeTypeCategory()

    template = hou.ViewerStateTemplate(state_typename, state_label, state_cat)
    template.bindFactory(State)
    template.bindIcon(kwargs["type"].icon())

    return template

I would expect to see the geometry connected to the first input of the asset to be displayed as a wireframe when I select the node and press enter in the viewport, but nothing shows up.

Could someone shed some light on what else I need to be doing with the SimpleDrawable to display correctly?
Edited by gorrod - May 24, 2021 15:05:22
User Avatar
Staff
396 posts
Joined: Feb. 2018
Offline
onDraw is normally used for drawing advanced drawables (e.g. hou.GeometryDrawable). hou.SimpleDrawable is rendered by the viewer, there is no need for an onDraw callback. For instance, you could create your simple drawable in the __init__ method, enable it in onEnter, disable it in onInterrupt, re-enable it in onResume and so on.

Check out the simple_drawable.hip demo scene which provides a more detailed scene setup.
User Avatar
Member
28 posts
Joined: Nov. 2016
Offline
Thanks a lot, that does the trick already.

I will certainly take a look into the demo scene!
User Avatar
Member
53 posts
Joined: Sept. 2018
Offline
Could you point me, where I can find this simple_drawable.hip demo scene?
User Avatar
Staff
396 posts
Joined: Feb. 2018
Offline
wolskikrzys
Could you point me, where I can find this simple_drawable.hip demo scene?
In H19, you can load the examples from the Viewer State Browser file menu and load the scene from the Demo Viewer States shelf or load the scene from $HH/viewer_states/examples if you're in H18.5 or previous versions.
  • Quick Links