Changing StrokeCursor geometry in python viewer states

   965   3   0
User Avatar
Member
4 posts
Joined: 4月 2019
Offline
Hello! I've just started dabbling in Python viewer states for some custom tools but I've run into a roadblock with a feature I want to get in although I'm unable to do so, which makes me feel like I am missing something?

I writing a custom StrokeState viewer state however I want to change the color of the cursor geometry to the current value the user is painting, instead of the default red. I'm able to change the StrokeCursor.COLOR value in the __init__ of my viewer state before I call self.cursor.init_brushlist which sets the color correctly however I can't seem to change it dynamically?

I've set up a callback to be notified when my stroke parameter changes with
node.addEventCallback([hou.nodeEventType.ParmTupleChanged], self.onParmChanged)

but I can't seem to change anything in the cursor's brush list and have it reflected in the viewport? I get that the brush list is an array of SimpleDrawables with read only geometry. So I've tried reconstructing new geometry the same way StrokeCursor::init_brushlist does, however calling setGeometry() on the brush doesn't seem to do anything. I've also tried enabling / disabling the brush and telling the viewport to draw although those didn't seem to have an effect either.

Is there something I am missing after setting the new geometry? Do I need to tell something to cook somewhere? I'm a little confused on where these SimpleDrawable geometries actually "live" since there is no sop node associated with them.
Edited by quentinsking - 2024年3月5日 00:24:41

Attachments:
hindie.steam_juowKKDHcl.png (610.1 KB)

User Avatar
スタッフ
445 posts
Joined: 2月 2018
Offline
Ideally we should have a state parameter to let you know when a new cursor has been changed. Try overloading StrokeState.onMenuAction instead to set the cursor color.

e.g.
def onMenuAction(self, kwargs):
    super().onMenuAction(kwargs)

    menu_item = kwargs['menu_item']
    node = kwargs['node']
    if menu_item == 'cycle_brushes':
        self.cursor.brush.setWireframeColor(hou.Color(0,1,0))
User Avatar
Member
4 posts
Joined: 4月 2019
Offline
Thanks for the reply!

Unfortunately even in that case I don't see the wireframe changing. (In fact I can't find any event / scenario where self.cursor.brush.setWireframeColor() works)

I set up a simple example that doesn't seem to work:
class State(StrokeState):
    def __init__(self, **kwargs):
        super(State, self).__init__(**kwargs)

        self.cursor.brushes = []
        self.cursor.init_brushlist([('sphere', {}), ('tube', {})])


    def onMenuAction(self, kwargs):
        super().onMenuAction(kwargs)
        self.log("onMenuAction")
        self.cursor.brush.setWireframeColor(hou.Color(0.0, 0.0, 1.0))
        self.cursor.show()
        self.cursor.brush.show(True)



I can see that my menu actions get triggered, but the wireframe or brush geometry never updates. From my experience it seems like after the brushlist is initialized, there's no way to change the underlying geometry it's using. I've had some success by clearing out the brushlist, and calling init_brushlist with new attributes and then calling self.cursor.select(0), but I don't really want to be recreating everything all the time, and even then I still have some issues where the viewport won't update until the next mouse event even after calling draw() in the scene viewer.

I'm leaning more to just ditching this idea and using default cursors since I've already spent more effort than I care for on this lol. Just wanted to raise it in case there's an underlying bug here or that I'm just getting something wrong with viewer states (which is also totally possible LOL)

Attachments:
hindie.steam_nVHwdchIrF.png (782.4 KB)

User Avatar
スタッフ
445 posts
Joined: 2月 2018
Offline
Seems like there are 2 issues, one with the ability to customized the stroke cursor and a second one which seems related to an drawable update bug. Please log a bug.
  • Quick Links