Viewport 2.0 issue with readColorBuff

262 views
Skip to first unread message

Bay

unread,
Nov 4, 2014, 5:44:41 PM11/4/14
to python_in...@googlegroups.com
Hi guys, 
              running into a strange issue with viewport 2.0 that I was wondering if there's a solution to. I often use this script to take a screenshot of the active viewport to make a thumbnail:

         view = api_ui.M3dView.active3dView()
        mimage = api.MImage()
        view.readColorBuffer(mimage, True)
        mimage.writeToFile(self.screenshot_path, 'jpg') 

And I sometimes get a grey flat image with nothing else in it. I've tried setting readColorBuffer to False and I get a brown colored image instead.

I don't run into this issue with the Legacy viewports so I'm wondering if this is something only Maya2015 has. I'm using OSX 10.9.5 if that information helps. 

Thank you for any assistance rendered : ) 

Thank you
Gann Boon Bay
Message has been deleted

Janos Hunyadi

unread,
Nov 7, 2014, 9:45:32 AM11/7/14
to python_in...@googlegroups.com
Btw.I'm not sure if you can do it in python in VP 2.0. It's possible that its only implemented as C++ atm.

tomp_blue

unread,
Jan 20, 2015, 11:31:06 AM1/20/15
to python_in...@googlegroups.com
I m running into this issue with a pose library also. cmds.ogsRender seems to still work. I had tried getting the QWidget from PySide but this always came out garbled.

TomP

twitter.com/blue_zoo | facebook.com/bluezooanimation | vimeo.com/bluezoo

Blue Zoo Animation   |   385 Euston Road, London NW1 3AU   |   t. 020 7434 4111

Bay

unread,
Feb 23, 2015, 7:59:43 PM2/23/15
to python_in...@googlegroups.com
Well after reading the documentations it appears that writecolorbuffer is obsolete and it is advised that rendertarget should be used to obtain the information. This is the solution you just need to substitute the path variable with your output. 

    def create_viewport_render(self, path):
        """
        Function that calls the OpenMaya Renderer module to screenshot the viewport and save it
        """
        renderer = apiOMR.MRenderer
        tgt_mgm = renderer.getRenderTargetManager()
        texture_mgm = renderer.getTextureManager()

        target = tgt_mgm.acquireRenderTargetFromScreen('MTextureTest')

        target_desc = target.targetDescription()
        target_data = target.rawData()
        # Render Target must be released in order to avoid causing buffer issues
        tgt_mgm.releaseRenderTarget(target)

        # Setting parameters of the file to be output.
        texture_desc = apiOMR.MTextureDescription()
        texture_desc.fWidth = target_desc.width()
        texture_desc.fHeight = target_desc.height()
        texture_desc.fDepth = 1
        texture_desc.fBytesPerRow = target_data[1]
        texture_desc.fBytesPerSlice = target_data[2]
        texture_desc.fMipmaps = 1
        texture_desc.fArraySlices = target_desc.arraySliceCount()
        texture_desc.fFormat = target_desc.rasterFormat()
        texture_desc.fTextureType = 2
        texture_desc.fEnvMapType = 0

        texture = texture_mgm.acquireTexture('MTextureTest', texture_desc, target_data[0])
        texture_mgm.saveTexture(texture, path)
        # Texture must be release to avoid causing buffer issues.
        texture_mgm.releaseTexture(texture)

David Moulder

unread,
Feb 25, 2015, 6:13:05 AM2/25/15
to python_inside_maya
What version of Maya is this?

renderer = apiOMR.MRenderer

I don't have MRenderer in the Python API?

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/52bbc7a9-68c6-4a78-8b1a-756e6b53c16d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Bay

unread,
Feb 25, 2015, 2:19:20 PM2/25/15
to python_in...@googlegroups.com
Maya 2015.

It's maya python api 2.0 though 
So try this:
 import maya.api.OpenMayaRender as apiOMR
Reply all
Reply to author
Forward
0 new messages