#include <stdio.h>
#include <maya/MObject.h>
#include <maya/MFStream.h>
#include <maya/M3dView.h>
#include <maya/MFnPlugin.h>
#include <maya/MString.h>
#include <maya/MArgList.h>
#include <maya/MPxCommand.h>
#include <maya/MSyntax.h>
#include <maya/MArgDatabase.h>
#include <maya/MAnimControl.h>
#include <maya/MGlobal.h>
#include <maya/MImage.h>
#include <maya/MIOStream.h>
#include <maya/MViewport2Renderer.h>
#include <maya/MDrawContext.h>
#include <maya/MRenderTargetManager.h>
#include <maya/MRenderUtilities.h>
#define kFilenameFlag "-f"
#define kFilenameFlagLong "-filename"
#define kStartFrameFlag "-sf"
#define kStartFrameFlagLong "-startFrame"
#define kEndFrameFlag "-ef"
#define kEndFrameFlagLong "-endFrame"
#define kImageSizeFlag "-is"
#define kImageSizeFlagLong "-imageSize"
#define commandName "blast2"
{
public:
blast2Cmd();
virtual ~blast2Cmd();
static void* creator();
private:
unsigned int mWidth;
unsigned int mHeight;
MString mPostRenderNotificationName;
MString mPostRenderNotificationSemantic;
bool mDebugTraceNotifications;
MString mPreRenderNotificationName;
MString mPreRenderNotificationSemantic;
MString mPreSceneRenderNotificationName;
MString mPreSceneRenderNotificationSemantic;
MString mPostSceneRenderNotificationName;
MString mPostSceneRenderNotificationSemantic;
};
blast2Cmd::blast2Cmd()
: mPreRenderNotificationName("blast2CmdPreRender")
, mPreRenderNotificationSemantic(
MHWRender::MPassContext::kBeginRenderSemantic)
, mPostRenderNotificationName("blas2CmdPostRender")
, mPostRenderNotificationSemantic(
MHWRender::MPassContext::kEndRenderSemantic)
, mPreSceneRenderNotificationName("blast2CmdPreSceneRender")
, mPreSceneRenderNotificationSemantic(
MHWRender::MPassContext::kBeginSceneRenderSemantic)
, mPostSceneRenderNotificationName("blast2CmdPostSceneRender")
, mPostSceneRenderNotificationSemantic(
MHWRender::MPassContext::kEndSceneRenderSemantic)
, mWidth(0)
, mHeight(0)
, mDebugTraceNotifications(false)
{
}
blast2Cmd::~blast2Cmd()
{
}
void* blast2Cmd::creator()
{
return (void *)(new blast2Cmd);
}
{
return syntax;
}
{
mStart = 0.0;
mEnd = 1.0;
mWidth = 0;
mHeight = 0;
if (argData.isFlagSet(kFilenameFlag))
{
status = argData.getFlagArgument(kFilenameFlag, 0, mFilename);
}
else
{
}
if (argData.isFlagSet(kStartFrameFlag))
{
argData.getFlagArgument(kStartFrameFlag, 0, mStart);
}
if (argData.isFlagSet(kEndFrameFlag))
{
argData.getFlagArgument(kEndFrameFlag, 0, mEnd);
}
if (argData.isFlagSet(kImageSizeFlag))
{
argData.getFlagArgument(kImageSizeFlag, 0, mWidth);
argData.getFlagArgument(kImageSizeFlag, 1, mHeight);
}
return status;
}
{
if (!mDebugTraceNotifications)
return;
printf(
"\tPass Identifier = %s\n", passId.
asChar());
for (
unsigned int i=0; i<passSem.
length(); i++)
{
printf("\tPass semantic: %s\n", passSem[i].asChar());
}
}
{
blast2Cmd *cmd = (blast2Cmd *)clientData;
if (!cmd)
return;
cmd->printPassInformation(context);
}
{
blast2Cmd *cmd = (blast2Cmd *)clientData;
if (!cmd)
return;
cmd->printPassInformation(context);
}
{
blast2Cmd *cmd = (blast2Cmd *)clientData;
if (!cmd)
return;
cmd->printPassInformation(context);
}
{
blast2Cmd *cmd = (blast2Cmd *)clientData;
if (!cmd)
return;
cmd->printPassInformation(context);
if (!renderer)
return;
frameName += ".";
frameName += cmd->mCurrentTime.value();
bool saved = false;
if (colorTarget)
{
switch (format)
{
frameExtension = ".exr";
break;
case MHWRender::kA8B8G8R8:
frameExtension = ".iff";
break;
default:
frameExtension = "";
break;
};
if (frameExtension.
length() == 0)
return;
frameName += frameExtension;
if (colorTexture)
{
}
}
char msgBuffer[256];
if (!saved)
{
sprintf(msgBuffer, "Failed to color render target to %s.", frameName.asChar());
}
else
{
sprintf(msgBuffer, "Captured color render target to %s.",
frameName.asChar());
}
}
{
if (!renderer)
{
return status;
}
status = parseArgs ( args );
if ( !status )
{
char msgBuffer[256];
sprintf( msgBuffer, "Failed to parse args for %s command.\n", commandName );
return status;
}
if ( !status )
{
return status;
}
renderer->
addNotification(captureCallback, mPostRenderNotificationName, mPostRenderNotificationSemantic,
(void *)this );
if (mDebugTraceNotifications)
{
renderer->
addNotification(preFrameCallback, mPreRenderNotificationName, mPreRenderNotificationSemantic, (
void *)
this);
renderer->
addNotification(preSceneCallback, mPreSceneRenderNotificationName, mPreSceneRenderNotificationSemantic, (
void *)
this);
renderer->
addNotification(postSceneCallback, mPostSceneRenderNotificationName, mPostSceneRenderNotificationSemantic, (
void *)
this );
}
bool setOverride = (mWidth > 0 && mHeight > 0);
if (setOverride)
{
}
for ( mCurrentTime = mStart; mCurrentTime <= mEnd; mCurrentTime++ )
{
}
renderer->
removeNotification(mPostRenderNotificationName, mPostRenderNotificationSemantic);
if (mDebugTraceNotifications)
{
renderer->
removeNotification(mPreSceneRenderNotificationName, mPreSceneRenderNotificationSemantic);
renderer->
removeNotification(mPostSceneRenderNotificationName, mPostSceneRenderNotificationSemantic);
}
return status;
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"1.0",
"Any");
status = plugin.registerCommand( commandName,
blast2Cmd::creator,
blast2Cmd::newSyntax);
if (!status) {
status.
perror(
"registerCommand");
return status;
}
return status;
}
{
status = plugin.deregisterCommand( commandName );
if (!status) {
status.
perror(
"deregisterCommand");
return status;
}
return status;
}