Maya 2017 and VP 2.0 - Post Render Callback Drawing


#1

Hi there!
It’s all about Maya’s new viewport and developed in python.
The task:
I need a viewport post render callback to draw some stuff over everything in the viewport. For now I managed to do it using the “old” methods via MGLFunctionTable and glBegin(MGL_POINTS) etc.

the way it’s working for now:

  1. register python procedure as post render viewport callback with MUiMessage.add3dViewPostRenderMsgCallback() <- no worries here
  2. get the renderer and draw directly via OpenGL:

    glRenderer = omr.MHardwareRenderer.theRenderer()
    glFT = glRenderer.glFunctionTable()
    view.beginGL()
    glFT.glBegin(omr.MGL_POINTS)
    
    { Draw geometry ....
        glFT.glColor3f(r,g,b)
        glFT.glVertex3f(x,y,z)
    .... }
    
    glFT.glEnd()            
    view.endGL()

and all this is working like a charm… in legacy mode.

I’ve been reading trough the new api 2.0, but can’t figure out how to do something similar for VP 2.
I begin to doubt if this is even doable without writing some sort of a plugin.
Any suggestions? Thanks.


#2

VP2.0 has Python API 2.0 support so you can write this all in Python.

If you grab the devkit, a good plug-in sample you want to look at is:

\devkit\plug-ins\scripted\pyViewRenderOverride.py

That one demonstrates how to create your own multi-pass system. You could simply render the scene, its UIs and then add your “post render” pass at the end. If you’re comfortable reading C++, you can look at the other viewRender* devkit samples and mentally convert their implementations into the Python API 2.0. They won’t translate 100%, but should get you most of the way. Some of those are simpler than the viewRenderOverride so they could help you get your bearings.

But yes, at the end, this will be a plug-in - but it can still be written in Python!