Jump to content

MSS State attached to an OBJ_Node?


Recommended Posts

Hi, 

I'm trying to attach an MSS_SingleOpBaseState to an OBJ HDA, I know I can attach to an SOP HDA without trouble but the OBJ isn't working. 

I have PI_NETMASK_OBJ set for the Pi_Template and it does attach but it doesn't call mouseEvent or keyEvent etc.. 

It looks like MSS classes are more aimed for SOPs, Do i need to inherit from a BM_State in order to get the mouse events? 

Thanks

Link to comment
Share on other sites

Yeah that was my thought, it attached, but had same issue.  But that's seems to be uncharted territory from an outsiders perspective, so I'll have to study the headers and see if I can find any clues as to what it wants.

 

Attaching to a SOP as a workaround shouldn't make any difference, even if I'm working with OBJ_Nodes, at least I don't see how it could.  Well I'll find out shortly.

 

 

Thanks, it s nice to know I'm not just being stupid for once.

Edited by captain
Link to comment
Share on other sites

Okay, shot in the dark here, so please correct me if I'm wrong but manipulating OBJs will probably work but the MSS state won't call doRender unless, the Sop changes?

 

Is there way to force it, or like mark it dirty?

 

Or would it be better to use a RenderHook?

 

 Edit: Using a RenderHook seems to have the same flaw.  There has to be some way to force rendering right?

 

Okay, attaching the MSS to a faux SOP and forcing it to cook solved the problem :)

Edited by captain
Link to comment
Share on other sites

Er, what exactly is the thing that you're trying to accomplish with this object tool? Changing a node won't cause doRender() to be called unless the viewport needs to redraw. And the viewport typically only needs to redraw for objects when their world transform changes AND its displaying some type of geometry.

Link to comment
Share on other sites

Well if you must know :)

 

This is in particular applies to a bone drawing tool, that raycasts at the character so I can get the exact placement the first time.  So I need to draw a manipulator and update it with the mouse.  

 

As well as a slew of other tools, I've been working on for an animation and rigging plug in, and an API I designed that basically allows me to attach an event loop to an HDA and make it interactive, with interchangeable mouse events, a UI that renders in the view port and attempts to handles all the issues that come from non procedural editing of geometry in Houdini.

 

The MSS stuff is admittedly less then ideal, but inheriting from a BM_State seems to be pretty complicated without a sample or anything.

Link to comment
Share on other sites

How do you mean?

 

Inherit from BM_State directly, register with a PI_StateTemplate and then just call WantsLocates()?  Would it be that simple to get an event loop?  I haven't tried that.

 

Or call BM_State::wantLocates because MSS overrides it?  I did try that just now and it doesn't call doRender() that way.

 

Attaching an MSS to a subnet SOP doesn't seem to create any side effect though.  

 

The only other issue I do have is getting unfiltered keyboard input, I know I can override it through the interface or python, I forget how I've done it.  But I can't seem to figure out what I need to call through the HDK.  I can live without it or use looks and feels if I really needed typed input, but I would love to know how to do it.

Edited by captain
Link to comment
Share on other sites

No, I was thinking of inheriting from BM_SingleOpState, and then having it set wantLocates(true) so that you get mouse move events in your handleMouseEvent() override. Now, you can call redrawScene() (inherited from BM_SimpleState) to cause the viewport to redraw whenever the mouse moves.

 

PS. Make sure you read the comments in the header source itself, and not just look at it from the doxygen docs.

Link to comment
Share on other sites

That was the first thing I tried when you suggested it, it still didn't allow me to attach to OBJs,, at least it still didn't get mouse events.  I even checked hasLocates() and it was setting it to true but it wouldn't call handleMouseEvent.

 

My thought is either PI_State needs more then just PI_NETMASK_OBJ, or getType.. something or another, the pure virtual function in BM_SingleOpState.  I returned "MSS" I realized this was not correct, but I would have no idea what the OBJ analogue of MSS what be called, or even if its actually using it that way, which didn't seem likely.

 

However I'm hopefully ~two weeks from having a working version of the API and the prototyped plug in, so I'm likely going to wait on this.  Probably until I attempt to create python binding for the code that defines the event loops, so I could create tool states directly in Houdini with Python, but still have it run native code.  

 

 

Yup, I pretty much only use the doxygen pages for searching now, it sounds like I may need to reopen some older issues.

 

 

Thank you for your help, I really appreciate it  

 

 

redrawScene() was exactly what I needed for the rendering, it's mentioned like six times in my code too, silly, silly.

Edited by captain
Link to comment
Share on other sites

Did you name your state the same as your object type's name? I believe that's how the default behaviour of matchesNode() works. You should override it and make sure that it's being called and that the base class is returning what you want/expect. As for the getChosenOp() virtual, here's a sample implementation:

OP_Node *
MyObjState::getChosenOp() const
{
    OP_Network	*network = (OP_Network*)viewer().getNetwork();
    OP_Node	*node = NULL;

    UT_ASSERT(network->getChildTypeID() == OBJ_OPTYPE_ID);
    if (network)
	node = network->getCurrentNodePtr();

    // If we don't have a current node pointer for this network, then fall back
    // on the last selected object.
    if (!node)
    {
	node = OPgetDirector()->getLastPickedNode();
	if (node && node->getOpTypeID() != OBJ_OPTYPE_ID)
	    node = NULL;
    }

    return node;
}
Link to comment
Share on other sites

Sorry, I was referring to  virtual const char *getPresetTypeName() const { return "MSS"; } Which is a pure virtual in BM_ParmState.

 

And yes your right, I didn't have the class itself named the same, I forgot about that, however ::myConstructor did return the name of the Node I want to attach to, and with SOP nodes I never had an issue. The OBJ code may have enforce this where the SOP didn't. The OBJ state code did attach though, perhaps some where, some one is rejecting me before the mouseEvent gets called because the name wasn't set right.

 

I'm going to try this now.

Edited by captain
Link to comment
Share on other sites

In your implementation of getChoosenOp where is "viewer()" coming from?

 

I think I would have to implement that myself.   I'm not sure about the differences with BM_OpView and JEDI_View neither seem to be documented. Will it convert implicitly? Apparently not.

 

Well this works now :) 

 

Thank you very much for your time :)

Edited by captain
Link to comment
Share on other sites

Okay wait hang on a second here, this is a bit above my pay grade, but BM_OpView isn't exposed to me so/and I can't include it or compile any usage of it.  But without it, it looks like I have no access to what I assume is some pretty important data inside.  I would assume that's where I could get the view port camera matrices?  But I should be able to get them through some other means?  Outside of OP_Director I wouldn't know where to look, and I didn't see it there.

Edited by captain
Link to comment
Share on other sites

Hmm ... In that case, you could try skipping that part and just use getLastPickedNode() and/or getLastPickedNode()->getParent(). It'll probably work most of the time.

Another hacky workaround might be to override BM_State::handleOpNetChange() and/or handleOpNetClear() to see if you can catch which network is being used. Make sure you also delegate to the base class.

Link to comment
Share on other sites

Just getting the network isn't too bad, I already found an okay work around for that.

 

But in order to do integrate this with my code, I need the camera matrices, so I can project my cursor into the scene, mapToWorld is an MSS function.

 

Maybe I'm just missing it but outside of the HOM lib, I don't see them anywhere.

 

It looks to me that getting the active view port "camera" is not exposed to the HDK in any way, that being said, I don't believe my profile picture could be any more apt then it is right now.  

Edited by captain
Link to comment
Share on other sites

Yeah, I had been kinda thinking the same thing, but I was planning on sticking with MSS_SingleOpState for a bit.  It kinda seemed like it wouldn't work, but i guess as long as the PI_State_Template gets empty string arguments there shouldn't be a problem, maybe.     Nevermind, as long as I don't register it, it makes no difference.

 

But actually that would be ideal, I get the all the MSS functionality but I'm no longer bound to it.  

 

I'm going to see if I can get it to construct.

Edited by captain
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...