aboutsummaryrefslogtreecommitdiff
path: root/mayaPlug/shaveMaya.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mayaPlug/shaveMaya.cpp')
-rw-r--r--mayaPlug/shaveMaya.cpp321
1 files changed, 321 insertions, 0 deletions
diff --git a/mayaPlug/shaveMaya.cpp b/mayaPlug/shaveMaya.cpp
new file mode 100644
index 0000000..630b571
--- /dev/null
+++ b/mayaPlug/shaveMaya.cpp
@@ -0,0 +1,321 @@
+// Shave and a Haircut
+// (c) 2019 Epic Games
+// US Patent 6720962
+
+#include <maya/MAnimControl.h>
+#include <maya/MFnDependencyNode.h>
+#include <maya/MGlobal.h>
+#include <maya/MObject.h>
+#include <maya/MPlug.h>
+#include <maya/MPlugArray.h>
+#include <maya/MSelectionList.h>
+#include <maya/MStatus.h>
+#include <maya/MTime.h>
+
+#include "shaveMaya.h"
+#include "shaveRender.h"
+
+#define USE_GLOBALS 0
+
+MString shaveMaya::outFormat;
+MString shaveMaya::outFormatString;
+MString shaveMaya::outExt;
+
+bool shaveMaya::animation;
+MString shaveMaya::animExt;
+MString shaveMaya::baseFileName;
+float shaveMaya::deviceAspectRatio;
+bool shaveMaya::deviceAspectRatioLocked;
+int shaveMaya::doCameraMotion;
+int shaveMaya::doDef;
+short shaveMaya::doExtensionPadding;
+bool shaveMaya::doMotionBlur;
+int shaveMaya::doSingleFile;
+MString shaveMaya::extension;
+double shaveMaya::fov_ratio;
+int shaveMaya::frameFirst;
+int shaveMaya::frameLast;
+unsigned int shaveMaya::frameBy;
+bool shaveMaya::ignoreFilmGate;
+unsigned int shaveMaya::imageDepth;
+unsigned int shaveMaya::imageHeight;
+unsigned int shaveMaya::imageWidth;
+MString shaveMaya::imageName;
+
+short shaveMaya::outPadding;
+short shaveMaya::outFormatControl;
+
+int shaveMaya::pixelSamples;
+double shaveMaya::motionBlurByFrame;
+bool shaveMaya::renderAllCameras;
+
+
+int shaveMaya::mb2smoothValue;
+double shaveMaya::mb2blurSharpness;
+double shaveMaya::mb2blurLength;
+bool shaveMaya::motionBlurType;
+bool shaveMaya::useFrameExt;
+
+
+//
+// Get MAYA's render globals information
+//
+MStatus shaveMaya::getRenderGlobals()
+{
+ MStatus status = MS::kSuccess;
+
+ doMotionBlur = false;
+ imageWidth = 0;
+ imageHeight = 0;
+
+ //
+ // Get the render globals node
+ //
+ MSelectionList renderGlobalsList;
+ renderGlobalsList.add("defaultRenderGlobals");
+
+ if (renderGlobalsList.length() < 1) return MS::kFailure;
+
+ MObject renderGlobalsNode;
+
+ renderGlobalsList.getDependNode(0, renderGlobalsNode);
+
+ MFnDependencyNode fnRenderGlobals(renderGlobalsNode);
+
+ //
+ // Get its resolution node.
+ //
+ MPlugArray connectedPlugs;
+ MPlug resPlug = fnRenderGlobals.findPlug("resolution");
+
+ resPlug.connectedTo(
+ connectedPlugs,
+ true, // asDestination
+ false, // asSource
+ &status
+ );
+
+ if (!status || (connectedPlugs.length() != 1)) return MS::kFailure;
+
+ MObject resNode = connectedPlugs[0].node(&status);
+
+ if (!status) return status;
+
+ MFnDependencyNode fnRes(resNode);
+
+ //
+ // If we're doing an interactive render, then the width and height
+ // of the output image are determined by the test resolution,
+ // otherwise they're determined by the resolution node.
+ //
+ if (MGlobal::mayaState() == MGlobal::kInteractive)
+ {
+ MIntArray res;
+ MGlobal::executeCommand("shave_getTestResolution", res);
+
+ if (res.length() == 2)
+ {
+ imageWidth = res[0];
+ imageHeight = res[1];
+ }
+ else
+ status = MS::kFailure;
+ }
+ else
+ {
+ short res_width;
+ short res_height;
+
+ fnRes.findPlug("width").getValue(res_width);
+ fnRes.findPlug("height").getValue(res_height);
+
+ imageWidth = (unsigned int)res_width;
+ imageHeight = (unsigned int)res_height;
+ }
+
+ //
+ // Determine the output image format
+ //
+ enum
+ {
+ kGIF = 0,
+ kSoftimage = 1,
+ kRLA = 2,
+ kTiff = 3,
+ kTiff16 = 4,
+ kSGI = 5,
+ kAlias = 6,
+ kMaya = 7,
+ kJPEG = 8,
+ kEPS = 9,
+ kMaya16 = 10,
+ kCineon = 11
+ };
+
+ short outputId;
+ fnRenderGlobals.findPlug("imageFormat").getValue(outputId);
+
+ switch (outputId)
+ {
+ case kSGI:
+ outFormat = "sgif";
+ outExt = "sgi";
+ break;
+
+ case kAlias:
+ outFormat = "alias";
+ outExt = "als";
+ break;
+
+ case kEPS:
+ outFormat = "cpostscript";
+ outExt = "ps";
+ break;
+
+ case kCineon:
+ outFormat = "cineon";
+ outExt = "cin";
+ break;
+
+ default:
+ outFormat = "tiff";
+ outExt = "tif";
+ break;
+ }
+
+ // Whether "outExt" is to be included in file name
+ fnRenderGlobals.findPlug("outFormatControl").getValue(outFormatControl);
+
+ if (outFormatControl == 2)
+ {
+ fnRenderGlobals.findPlug("outFormatExt").getValue(outFormatString);
+ }
+
+ //
+ // Get MOBLURS STUFF
+ //
+ fnRenderGlobals.findPlug("motionBlur").getValue(doMotionBlur);
+ fnRenderGlobals.findPlug("motionBlurByFrame").getValue(motionBlurByFrame);
+ fnRenderGlobals.findPlug("blurLength").getValue(mb2blurLength);
+ fnRenderGlobals.findPlug("blurSharpness").getValue(mb2blurSharpness);
+ fnRenderGlobals.findPlug("smoothValue").getValue(mb2smoothValue);
+ fnRenderGlobals.findPlug("motionBlurType").getValue(motionBlurType);
+
+ //
+ // Get own blur setting for Vray -- vlad|15Apr2010
+ //
+ if (shaveRender::rendererIsVray())
+ {
+ renderGlobalsList.clear();
+ renderGlobalsList.add("vraySettings");
+
+ if (renderGlobalsList.length() > 0)
+ {
+ MObject vraySettingsNode;
+ renderGlobalsList.getDependNode(0, vraySettingsNode);
+
+ MFnDependencyNode depFn(vraySettingsNode);
+
+ int mbOn = 0;
+ MPlug mbOnPlug = depFn.findPlug("cam_mbOn");
+ if(!mbOnPlug.isNull())
+ mbOnPlug.getValue(mbOn);
+ else
+ MGlobal::displayError("shave: can not find vraySettings.cam_mbOn plug.");
+
+ doMotionBlur = (mbOn != 0);
+ }
+ else
+ MGlobal::displayError("shave: can not get V-Ray settings.");
+ }
+ //
+ // Check if there is animation
+ //
+ fnRenderGlobals.findPlug("animation").getValue(animation);
+
+ MTime startFrame;
+ MTime endFrame;
+ float byFrame;
+
+ if (animation)
+ {
+ // Check if the time-slider or renderGlobals is used for
+ // the frame range
+ //
+ short animRange;
+ fnRenderGlobals.findPlug("animationRange").getValue(animRange);
+
+ if (USE_GLOBALS == animRange)
+ {
+ fnRenderGlobals.findPlug("startFrame").getValue(startFrame);
+ fnRenderGlobals.findPlug("endFrame").getValue(endFrame);
+ fnRenderGlobals.findPlug("byFrameStep").getValue(byFrame);
+
+ frameFirst = (int)startFrame.as(MTime::uiUnit());
+ frameLast = (int)endFrame.as(MTime::uiUnit());
+ frameBy = (unsigned int)byFrame;
+ }
+ else // USE_TIMESLIDER
+ {
+ startFrame = MAnimControl::minTime();
+ endFrame = MAnimControl::maxTime();
+
+ frameFirst = (int)startFrame.as(MTime::uiUnit());
+ frameLast = (int)endFrame.as(MTime::uiUnit());
+ }
+
+ // Check if motionBlur is turned on.
+ // (This is matrix motion blur)
+ // BIJAN
+ }
+ else // No animation
+ {
+ frameFirst = (int)MAnimControl::currentTime().as(MTime::uiUnit());
+ frameLast = (int)MAnimControl::currentTime().as(MTime::uiUnit());
+ frameBy = 1;
+ //doMotionBlur = false; // BIJAN
+
+ // Whether the frame number is to be incded in the file name
+ fnRenderGlobals.findPlug("useFrameExt").getValue(useFrameExt);
+ }
+
+ fnRenderGlobals.findPlug("extensionPadding").getValue(outPadding);
+
+ if (outPadding > 99) outPadding = 99;
+
+ //
+ // If a film gate is used this tells us whether the image is
+ // blacked out in regions outside the film-fit region.
+ // In our case we crop the image to the size of the region.
+ //
+ fnRenderGlobals.findPlug("ignoreFilmGate").getValue(ignoreFilmGate);
+
+ //
+ // Check if we should render all cameras, or only the active one
+ //
+ fnRenderGlobals.findPlug("renderAll").getValue(renderAllCameras);
+
+ //
+ // Get the device aspect ratio from the resolution node.
+ //
+ fnRes.findPlug("deviceAspectRatio").getValue(deviceAspectRatio);
+ fnRes.findPlug("lockDeviceAspectRatio").getValue(deviceAspectRatioLocked);
+
+ //
+ // Two of Maya's preset device aspect ratios (1.333 and 1.777)
+ // don't have enough precision for high-definition rendering, so
+ // let's adjust those appropriately.
+ //
+ if (((deviceAspectRatio - 1.33f) <= 0.003f)
+ && ((deviceAspectRatio - 1.333f) >= -0.0f))
+ {
+ deviceAspectRatio = 1.333333f;
+ }
+ else if (((deviceAspectRatio - 1.77f) <= 0.007f)
+ && ((deviceAspectRatio - 1.777f) >= -0.0f))
+ {
+ deviceAspectRatio = 1.777777f;
+ }
+
+ return MS::kSuccess;
+}