#include <math.h>
#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>
{
public:
DispNode();
~DispNode() override;
static void * creator();
private:
};
MObject DispNode::aOutTransparency;
MObject DispNode::aOutDisplacement;
void DispNode::postConstructor( )
{
setMPSafe(true);
}
DispNode::DispNode()
{
}
DispNode::~DispNode()
{
}
void* DispNode::creator()
{
return new DispNode();
}
{
aOutTransparency = nAttr.
createColor(
"outTransparency",
"ot" );
aOutDisplacement = nAttr.
create(
"displacement",
"od",
return MS::kSuccess;
}
{
if ((plug == aOutColor) || (plug.
parent() == aOutColor) ||
(plug == aOutDisplacement))
{
resultColor = InputColor;
float scalar = resultColor[0] + resultColor[1] + resultColor[2];
if (scalar != 0.0) {
scalar /= 3.0;
scalar *= MultValue;
}
outColor = resultColor;
float& outDisp = outDispHandle.
asFloat();
outDisp = scalar;
}
else if ((plug == aOutTransparency) || (plug.
parent() == aOutTransparency))
{
outTrans = transparency;
}
else
return MS::kUnknownParameter;
return MS::kSuccess;
}
{
const MString UserClassify(
"shader/displacement" );
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"4.5",
"Any");
CHECK_MSTATUS( plugin.registerNode(
"dispNodeExample", DispNode::id,
DispNode::creator, DispNode::initialize,
return MS::kSuccess;
}
{
return MS::kSuccess;
}