I was working on our pose library a bit today, and ran into some issues with generating icons for use with the pose file:

  • You can render an image, but then you are subject to render issues like bad lights and missing textures. You also have to worry about setting and restoring the users render settings
  • You can playblast a single frame to an image file, but then you have to deal with the pose changing if the rig has animation on it (Playblast evaluates the current frames animation first)
  • You can screengrab, but then you have to crop out the parts of Maya you don’t want to see, and have occlusion issues with other floating windows/offscreen

This code will grab the frame buffer from the active viewport (You could also change it to be a specified viewport with little work) and write it to any format that MImage supports:

#Import api modules
import maya.OpenMaya as api
import maya.OpenMayaUI as apiUI

#Grab the last active 3d viewport
view = apiUI.M3dView.active3dView()

#read the color buffer from the view, and save the MImage to disk
image = api.MImage()
view.readColorBuffer(image, True)
image.writeToFile('C:/test.jpg', 'jpg')

Something to note: Since the hud, and all tools/manipulators are also part of the openGL framebuffer, they also show up in the image. This could be good or bad depending on your needs. In my case I’m already hiding all that stuff before I render my pose anyways, so it’s not an issue.

Our old pose image code was doing render() and then writing the icon file using renderWindowEditor(). This was pretty unreliable since the renderWindowPanel tends to get renamed, or not exist at all. Also of note: sometimes the call to renderWindowEditor(writeImage=path) seems to be non-blocking, causing the image to be written after the script tries to work with it, and finds it missing.

  1. sweeeeeeeeeeeeeeet !!!!

You must be logged in to post a comment.