Maya Viewport Render

Overview

In this step by step guide I will show you how I created a viewport rendering tool combining native maya commands with python. In the end you will have your own viewport rendering tool and a very strong knowledge of python scripting and maya UI customization.

We start by creating an interactive tool with maya c++ api, using miscrosoft visual studio to compile the plugin. We just reuse some code from maya devkit, so don’t worry if you are not familiar with the c++ API. The main focus will be the python script that will do all the work. Users that have little experience with scripting will find it easy to follow and more advanced users will also benefit from this guide, using python maya commands in a “not-so-obvious” way. Maya 2014 win x64 is the maya version used in this guide, but should work with any version of maya from 2011 up.

In your download you will find all the source code so you can use as reference and of course a pdf guide will all the necessary steps to make your own viewport render tool in maya.

You can buy this detailed tutorial using paypal for only 25$.

UPDATED vray and mental ray support. If you already have this tutorial, download again using the same link.

buy now


  • Adam Cheshire

    Is this for Arnold only or can it be used for other render packages? For example Vray

    • therenderblog

      Hi Adam, thanks for the input.

      In the tutorial I will use arnold render but this can be used within any render package. Instead of “cmds.arnoldrender()” you replace it with the vray render command “cmds.vrend()”. If you have any trouble finding the right commands for your render engine I can help you on that.

      But since this uses native maya commands and the maya renderview it will always be compatible with any render package.

      • Adam Cheshire

        Looks great, thanks for the reply – And thanks for the tut, i’ll be getting it.

      • Jorge Miranda

        Hi! thanks for the tool ! looks cool ! I tried to replace it with cmds.vrend() but gives me this error: # ImportError: No module named mtoa.utils #
        Do you know what shoud I do next ?

        • therenderblog

          That’s the arnold imports. Remove the line in the beginning “import mtoa” or any imports related to arnold render.

  • Pingback: Maya | Create an Interactive Viewport Rendering Tool Using Native Commands and Python

  • Davide Alidosi

    Hi, if I buy the tutorial I can use the surce directly like a script in my installation of Maya 2014/Arnold 1.0 on Win and Mac?

    • therenderblog

      Hi Davide, I only tested this on windows environment. It works fine with any version of arnold. You will find all the source files in the download but you will need to compile the maya plugin yourself (just copy/paste the cpp code and compile). Let me know if you have any other question.

      • Davide Alidosi

        How I can compile CPP? I never do it.

        • therenderblog

          With microsoft visual studio. In the tutorial you have step by step instructions and if you have any question you can always email us. Don’t worry if you never compiled plugins for maya, this tutorial focus on the python script, the cpp part is just resuing some code from the maya devkit so we can have a tool in maya that can draw the rectangle marque (visual feedback).

          • Davide Alidosi

            Ok, what release of visual studio you suggest? And in case you can send already compiled plug-in for Win 64?

          • therenderblog

            I used 2012, but previous versions will work fine. And yes I can send you a compiled version for win 64 if you need ;)

          • Davide Alidosi

            Very good tool and tutorial, tnx a lot!

  • Stu

    Utterly fantastic! I bought the training straight away as I’ve been wanting this feature in Maya ever since I saw it working so well in Softimage (aside from the problem of having to change frames in order for the image to update, that’s a pain). Very creative use of appropriating an existing Maya tool for a new purpose, and while I found a lot of the code hard to follow (I’m pretty new to scripting) I’ll be revisiting it often to gain a better understanding of how it’s put together.

    I’ve already made a small change.. instead of displaying an error when the render region is too small, I run a slightly modified dropTool function instead (it switches back to the select tool at the end). This way you can just click outside the render window and quickly get back to working in the scene. The next thing to figure out is how to switch quickly between different versions of the code in order for it to work across the different renderers- mental ray, vray, etc.

    Thanks again- I’m really loving this!

    Stu Tozer
    http://materialism-blog.blogspot.com/

    • therenderblog

      Thanks a lot for the feedback. :)

      More than a viewport render tool you will eventually find it a great reference for future tools/scripts you may want to build.

      To switch between renders you can do a basic test like so:

      currentRender = cmds.getAttr(‘defaultRenderGlobals.currentRenderer’)

      #later in the script

      if currentRender == ‘arnold’:
      # arnold render command
      elif currentRender == ‘vray’:
      # vray render command
      elif currentRender == ‘mentalRay’:
      # mr render command
      else:
      cmds.warning( ‘render engine not supported’ )

      If you find any code that you can’t fully understand send an email and I will explain more in detail.

      Cheers

      • Stu

        Ah great, yep that should be pretty straight forward, thanks very much for the help :)

        There’s just one other small niggle I’m trying to figure out right now, and that’s getting rid of the text which displays at the bottom of the render once it’s completed. In your code you’ve set ‘-cap’ and ‘-pca’ flags for the renderWindowEditor-

        “cmds.renderWindowEditor( renderViews, e=True, rs=True, cap=0, pca=0)”

        …but the problem is that they seem to reset to display once the render is done, so they don’t actually work. I’m not sure if there’s a way around this problem or not, but it would be nice to find a way. That small niggle aside, this is hands down going to be my favourite Maya tool for a long time. :) :)

        Cheers :)

        • therenderblog

          Yeh, you are using the correct aproach, but the problem is that in the “background” arnold is forcing the display of custom caps (pca flag). I have found 2 ways of dealing with it.

          - Use a “post render frame mel” with the “cleaning” code. You can setup this in the viewport script, with the setAttr(‘defaultRenderGlobals.postRenderMel’, melCode). This will only execute the command after the render is done.

          But, arnold should have a scriptJob working on the background, So sometimes it will still display the text.

          - The other option is to use a scriptJob, but scriptJobs are a bit unstable and sometimes crashes maya. But even this will make the text blink 2/3 times :D

          Again, it’s an arnold thing, in other renders the code you posted in the post render mel should work fine.

          In the end you may want to add more controls to the viewport render window, like a clean button with that code.

          Thanks for the feedback Stu.

      • http://www.ghurtahstudios.com Albert Du Plessis

        Hi

        I am trying to add support for redshift 3d renerer this is the info I recieved from the developer. I cant get it to work on my own, some help is needed thanks.

        The command to render a single frame with Redshift is:

        rsRender -render -camera
        e.g. rsRender -render -camera persp

        For IPR there are a few different commands.
        To query whether IPR is running, run:
        rsRender -q -ipr

        To start IPR:
        rsRender -render -ipr -camera

        To stop IPR:
        rsRender -render -stopIpr;

        When starting a render, the resolution/region info is taken from the
        standard attributes (also used by Mental Ray and most other renderers).

        • therenderblog

          I will reply by email and help you on that, should be simple since it’s similar to mental ray aproach.

      • LeoJ4y

        Hey TB,I can’t pay for the viewport render cuz my country network (china ,you know it),

        But i’d very like to try your aws tool,can you do me a favour?

        if U do
        please send me an email as 28596301@qq.com

        Very Glad to hear u!

    • Davide Alidosi

      Hi Stu could you post here the code of your mod? TNX

      • Stu

        Hi Davide- sure. Basically all that’s needed is to find the line in the ‘getRegion’ function which says: “cmds.warning(‘Region is too small’)”

        delete that line (or comment it out) and replace it with the next couple of lines…

        dropTool()
        mel.eval(‘global string $gSelect; setToolTo $gSelect;’)

        That second line runs a mel command to switch to the select tool. When you click outside the render window you’re in effect making a very small region selection, which now runs the DropTool function and mel command instead. Hope this helps, cheers

        • therenderblog

          Very nice Stu :)

          You can also use the python command:

          cmds.setToolTo(‘selectSuperContext’)

          To find the the tool context you can query in the script editor:

          cmds.currentCtx() #selectSuperContext

  • therenderblog

    If you want to start the tool in IPR mode use:

    #current code
    #cmds.arnoldRender(cam=camera1, w=resoX, h=resoY)

    cmds.arnoldIpr(cam=camera1, w=resoX, h=resoY, mode=’start’)
    cmds.arnoldIpr(mode=’refresh’)

    • http://www.silent-house.com David S. Perkins

      Where is this inserted, in viewportRender.py, or somewhere else?

      • therenderblog

        Exactly, in the python file :)

        In line #223 you should have: cmds.arnoldRender(cam=camera1)

        Replace that code with the one in the previous comment (cmds.arnoldIpr…)

  • Suren Verdiyan

    Thank you

  • Davide Alidosi

    Hi anyone know how or can compile the plugin for OSX?

  • Pingback: Ptex workflow with arnold and mari | The Render Blog

  • Alan Lam

    Just bought this tutorial. Thanks for your sharing. Love to have it…^_^

    *Off topic question*
    Does you know whether Arnold(mtoa) has similar function like mib_roundcorner in Mental Ray?
    I found the patent – “Computer graphics methods and systems for generating images with rounded corners” http://www.google.com/patents/US8049753. I am trying to write my own. The progress is slow since I am not shader writer.

    • therenderblog

      Thanks for that Alan.

      About your question. arnold has no similar shader yet, I am no shader writer as well, but I will ask a friend if he could give it a try. I will let you know. ;) Cheers

      • Alan Lam

        Appreciate your kind help.
        Cheers~

  • Vincent Vega

    Great Tool !! Thanks a bunch. Well worth the 25. It works great with arnold set to ipr mode. I compiled for maya 2014 sp3 with VS 2013 and it works well. Since XSI is getting Axed and lots of XSI users are going to migrate to Maya. It would be awesome to have this convenient render region in maya. The render region tool saves space because you dont have to have an extra window with the renderer open to see the render also when rendering happens away from the 3d viewport it feel disconnected. I included a diagram of few areas that would still benefit from improvement. What do you guys think ?

  • http://www.silent-house.com David S. Perkins

    Really Fantastic Tool!
    Feature requests for the future:
    It’d awesome to allow orbit/pan/zoom of the current camera inside the active region, rather than panning/zooming the image inside the region. Perhaps wireframe mode could be re-enabled until the orbit/pan/zoom is completed, and then begin rendering buckets when mouse is released.
    One other cosmetic issue, if you draw a new region over an existing window, the marquee has a scaling issue as you move your mouse through the current region, and doesn’t continue the marquee preview on the second corner.
    Otherwise, Love this!

  • Arvid Schneider

    Hey guys, I have just bought and tested the viewport render, I am having a hard time compiling the code for Maya build earlier than 2014.
    Could someone please help me out, and create compiled versions for Maya 2012, 2013 and send them to me?
    Arvid

  • Mohsen

    Hi,

    Just bought the tutorial, and I think it’s great.
    One thing which is really needed is the ability to keep images while rendering and compare them like Softimage,
    Not sure if it’s so hard to add or not, I hope it’s not…

    Any Idea?

    Best Regards…

  • Mohsen

    ust bought the tutorial, and I think it’s great.
    One thing which is really needed is the ability to keep images while rendering and compare them like Softimage,
    Not sure if it’s so hard to add or not, I hope it’s not…

    Any Idea?

    Best Regards…

    • therenderblog

      Hey, you can add extra buttons with the “keep image” command. Try yourself, check the scripteditor output when you use the renderview “keep image”, copy that code and use it in your new buttons. Let me know. Cheers

  • Brandon Harris

    Does this show how to override Maya’s default IPR, possibly to create a better frame buffer with IPR in it?

    • therenderblog

      This uses default rendering features, no rendering overrides, only manipulates the default features to fit in a viewport region window. Not sure if I fully understand your question, let me know.

      • Brandon Harris

        I’m working to find a way of writing a much more awesome frame buffer for maya/arnold. One with a catalog and stored settings and such. I think this tutorial may give me some insight into how that can be done.