#include <math.h>
#include <cstdlib>
#include <maya/MPxNode.h>
#include <maya/MIOStream.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFloatVector.h>
#include <maya/MFnPlugin.h>
#include <maya/MDrawRegistry.h>
#include <maya/MPxShadingNodeOverride.h>
#include <maya/MViewport2Renderer.h>
#include <maya/MFragmentManager.h>
#include <maya/MGlobal.h>
{
public:
CheckerNode();
~CheckerNode() override;
static void * creator();
private:
};
{
public:
~CheckerNodeOverride() override;
private:
CheckerNodeOverride(
const MObject& obj);
};
const MTypeId CheckerNode::id( 0x81006 );
#define MAKE_INPUT(attr) \
CHECK_MSTATUS(attr.setKeyable(true) ); \
CHECK_MSTATUS(attr.setStorable(true) ); \
CHECK_MSTATUS(attr.setReadable(true) ); \
CHECK_MSTATUS(attr.setWritable(true) );
#define MAKE_OUTPUT(attr) \
CHECK_MSTATUS(attr.setKeyable(false) ); \
CHECK_MSTATUS(attr.setStorable(false) ); \
CHECK_MSTATUS(attr.setReadable(true) ); \
CHECK_MSTATUS(attr.setWritable(false) );
void CheckerNode::postConstructor( )
{
setMPSafe(true);
}
CheckerNode::CheckerNode()
{
}
CheckerNode::~CheckerNode()
{
}
void * CheckerNode::creator()
{
return new CheckerNode();
}
{
MAKE_INPUT(nAttr);
MAKE_INPUT(nAttr);
MAKE_INPUT(nAttr);
aUVCoord = nAttr.
create(
"uvCoord",
"uv", child1, child2);
MAKE_INPUT(nAttr);
MAKE_OUTPUT(nAttr);
MAKE_OUTPUT(nAttr);
return MS::kSuccess;
}
{
if((plug != aOutColor) && (plug.
parent() != aOutColor) &&
(plug != aOutAlpha))
return MS::kUnknownParameter;
int count = 0;
if (uv[0] - floorf(uv[0]) < bias[0]) count++;
if (uv[1] - floorf(uv[1]) < bias[1]) count++;
if (count & 1)
else
outColor = resultColor;
float& outAlpha = outAlphaHandle.
asFloat();
outAlpha = (count & 1) ? 1.f : 0.f;
return MS::kSuccess;
}
{
return new CheckerNodeOverride(obj);
}
CheckerNodeOverride::CheckerNodeOverride(
const MObject& obj)
: MPxShadingNodeOverride(obj)
, fFragmentName("")
{
static const MString sFragmentName(
"checkerNodePluginFragment");
static const MString sFragmentOutputName(
"checkerNodePluginFragmentOutput");
static const MString sFragmentGraphName(
"checkerNodePluginGraph");
if (theRenderer)
{
if (fragmentMgr)
{
static bool sAdded = false;
if (!sAdded)
{
}
location += "/plug-ins/checkerShader";
sAdded = true;
}
bool fragAdded = fragmentMgr->
hasFragment(sFragmentName);
bool structAdded = fragmentMgr->
hasFragment(sFragmentOutputName);
bool graphAdded = fragmentMgr->
hasFragment(sFragmentGraphName);
if (!fragAdded)
{
}
if (!structAdded)
{
}
if (!graphAdded)
{
}
if (fragAdded && structAdded && graphAdded)
{
fFragmentName = sFragmentGraphName;
}
}
}
}
CheckerNodeOverride::~CheckerNodeOverride()
{
}
{
}
MString CheckerNodeOverride::fragmentName()
const
{
return fFragmentName;
}
static const MString sRegistrantId(
"checkerTexturePlugin");
{
const MString UserClassify(
"texture/2d:drawdb/shader/texture/2d/checkerTexture" );
MFnPlugin plugin(obj, PLUGIN_COMPANY,
"4.5",
"Any");
CHECK_MSTATUS( plugin.registerNode(
"checkerTexture", CheckerNode::id,
CheckerNode::creator, CheckerNode::initialize,
"drawdb/shader/texture/2d/checkerTexture",
sRegistrantId,
CheckerNodeOverride::creator));
return MS::kSuccess;
}
{
"drawdb/shader/texture/2d/checkerTexture",
sRegistrantId));
return MS::kSuccess;
}