Alice12
Hello i wonder if i can create something similar like render texture ? would be useful for creating CCTV-like animation in Maya.

for now, i'm only use maya hardware 2.0 viewport renderer. Thanks.
Reply 0 0
pshipkov
Yes, certainly.
I can think of few different approaches.

The simplest, almost codeless option is to playblast the viewport at a given frame, or render it. Both will produce files on disk.
Then you have a read texture node that picks it up and passes to a shading network.
After that you produce the final frame - in viewport, or by using your offline renderer of choice (vray, arnold, etc).
This can be driven by a simple script that consists of few lines only.
 
A slightly more involving approach is to use the OpenMayaUI (https://download.autodesk.com/us/maya/2009help/API/class_m3d_view.html) - the native CPP, or the Python version of it. You will need something like this (typing blindly):
#include <maya/MImage.h>
#include <maya/M3dView.h>
// create image buffer
auto img = MImage();
img.create(...);
// get viewport of interest and capture it
auto vp = M3dView::active3dView(); // or ::get3dView(...) - for specific viewport.
vp.readColorBuffer(img);
// do something with the buffer, for example get the pixels from it
img.convertPixelFormat(...)
This can be exposed as CPP Maya command, Python routine, or what i think will be most useful - put it inside a custom viewportToTexture shading node that writes out the texture data itself. This node can feed a shading network that is used in a material assigned to an object of interest.
 
Now, this goes by working with the graphics APIs of Maya's viewport system.
If you want to use fully rendered image by your offline renderer of choice, you have 3 options:
Most renderers already integrate with the viewport system. From the "renderer" dropdown menu of a viewport choose the renderer and then everything will conform to what i mentioned above.
Option two is to work with the renderer API and see if you can capture the output before it is written to file on disk - this will be faster since it will avoid the file operations. Depends on how the API is you can:
- directly capture the in-memory representation of the frame. 
- most renderers don't directly write to file, but pipe the data through a network socket that gets read by a write-to-file plugin of sort, so you can capture the bytestream on that socket (it is actually simpler than it sounds).
Option 3 is to simply use the very first technique i mentioned above, but instead of viewport playblast you use a full blown renderer.
 
Hope this makes sense.
Reply 0 0
Reply