#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>
class Gamma:public MPxNode
{
public:
Gamma();
virtual ~Gamma();
virtual MStatus compute( const MPlug&, MDataBlock& );
virtual void postConstructor();
static void * creator();
static MStatus initialize();
static MTypeId id;
private:
static MObject aColor;
static MObject aGamma;
static MObject aOutColor;
};
MTypeId Gamma::id( 0x81009 );
MObject Gamma::aColor;
MObject Gamma::aGamma;
MObject Gamma::aOutColor;
#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 Gamma::postConstructor( )
{
setMPSafe(true);
}
Gamma::Gamma()
{
}
Gamma::~Gamma()
{
}
void *Gamma::creator()
{
return new Gamma();
}
MStatus Gamma::initialize()
{
MFnNumericAttribute nAttr;
aColor = nAttr.createColor( "color", "c" );
MAKE_INPUT(nAttr);
aGamma = nAttr.createPoint( "gamma", "g" );
MAKE_INPUT(nAttr);
CHECK_MSTATUS ( nAttr.setDefault(1.f, 1.f, 1.f) );
aOutColor= nAttr.createColor( "outColor", "oc" );
MAKE_OUTPUT(nAttr);
CHECK_MSTATUS ( addAttribute(aColor) );
CHECK_MSTATUS ( addAttribute(aGamma) );
CHECK_MSTATUS ( addAttribute(aOutColor) );
CHECK_MSTATUS ( attributeAffects( aColor, aOutColor ));
CHECK_MSTATUS ( attributeAffects( aGamma, aOutColor ));
return MS::kSuccess;
}
MStatus Gamma::compute(const MPlug &plug, MDataBlock &block)
{
if ((plug != aOutColor) && (plug.parent() != aOutColor))
return MS::kUnknownParameter;
MFloatVector & icol = block.inputValue( aColor ).asFloatVector();
MFloatVector & igam = block.inputValue( aGamma ).asFloatVector();
MDataHandle och = block.outputValue( aOutColor );
MFloatVector & ocol = och.asFloatVector();
ocol[0]= powf(icol[0], 1.f/igam[0]);
ocol[1]= powf(icol[1], 1.f/igam[1]);
ocol[2]= powf(icol[2], 1.f/igam[2]);
och.setClean();
return MS::kSuccess;
}
MStatus initializePlugin( MObject obj )
{
const MString UserClassify( "utility/color" );
MFnPlugin plugin( obj, PLUGIN_COMPANY, "4.5", "Any");
CHECK_MSTATUS ( plugin.registerNode( "gammaNode", Gamma::id,
Gamma::creator, Gamma::initialize,
MPxNode::kDependNode, &UserClassify ) );
return MS::kSuccess;
}
MStatus uninitializePlugin( MObject obj )
{
MFnPlugin plugin( obj );
CHECK_MSTATUS ( plugin.deregisterNode( Gamma::id ) );
return MS::kSuccess;
}