#include <stdlib.h>
#include <maya/MFnPlugin.h>
#include <maya/MTypeId.h>
#include <maya/MGlobal.h>
#include <api_macros.h>
#include <maya/MIOStream.h>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MPxThreadedDeviceNode.h>
{
public:
randomizerDeviceNode();
~randomizerDeviceNode() override;
static void* creator();
public:
private:
};
MTypeId randomizerDeviceNode::id( 0x00081051 );
MObject randomizerDeviceNode::outputTranslate;
MObject randomizerDeviceNode::outputTranslateX;
MObject randomizerDeviceNode::outputTranslateY;
MObject randomizerDeviceNode::outputTranslateZ;
randomizerDeviceNode::randomizerDeviceNode()
{}
randomizerDeviceNode::~randomizerDeviceNode()
{
destroyMemoryPools();
}
void randomizerDeviceNode::postConstructor()
{
attrArray.
append( randomizerDeviceNode::outputTranslate );
setRefreshOutputAttributes( attrArray );
createMemoryPools( 24, 3, sizeof(double));
}
static double getRandomX()
{
const double kScale = 10.0;
double i = (double) rand();
return ( i / RAND_MAX ) * kScale;
}
void randomizerDeviceNode::threadHandler()
{
#ifdef DEBUG
#endif
setDone( false );
while ( ! isDone() )
{
if ( ! isLive() )
continue;
status = acquireDataStorage(buffer);
if ( ! status )
continue;
beginThreadLoop();
{
double* doubleData =
reinterpret_cast<double*
>(buffer.
ptr());
doubleData[0] = getRandomX() ; doubleData[1] = 0.0; doubleData[2] = 0.0;
pushThreadData( buffer );
}
endThreadLoop();
}
setDone( true );
#ifdef DEBUG
#endif
}
void randomizerDeviceNode::threadShutdownHandler()
{
setDone( true );
}
void* randomizerDeviceNode::creator()
{
return new randomizerDeviceNode;
}
MStatus randomizerDeviceNode::initialize()
{
MCHECKERROR(status, "create outputTranslateX");
MCHECKERROR(status, "create outputTranslateY");
MCHECKERROR(status, "create outputTranslateZ");
outputTranslate = numAttr.
create(
"outputTranslate",
"ot", outputTranslateX, outputTranslateY,
outputTranslateZ, &status);
MCHECKERROR(status, "create outputTranslate");
ADD_ATTRIBUTE(outputTranslate);
ATTRIBUTE_AFFECTS( live, outputTranslate);
ATTRIBUTE_AFFECTS( frameRate, outputTranslate);
return MS::kSuccess;
}
{
if( plug == outputTranslate || plug == outputTranslateX ||
plug == outputTranslateY || plug == outputTranslateZ )
{
if ( popThreadData(buffer) )
{
double* doubleData =
reinterpret_cast<double*
>(buffer.
ptr());
MCHECKERROR(status, "Error in block.outputValue for outputTranslate");
double3& outputTranslate = outputTranslateHandle.
asDouble3();
outputTranslate[0] = doubleData[0];
outputTranslate[1] = doubleData[1];
outputTranslate[2] = doubleData[2];
releaseDataStorage(buffer);
return ( MS::kSuccess );
}
else
{
return MS::kFailure;
}
}
return ( MS::kUnknownParameter );
}
{
MFnPlugin plugin(obj, PLUGIN_COMPANY,
"3.0",
"Any");
status = plugin.registerNode( "randomizerDevice",
randomizerDeviceNode::id,
randomizerDeviceNode::creator,
randomizerDeviceNode::initialize,
if( !status ) {
status.
perror(
"failed to registerNode randomizerDeviceNode");
}
return status;
}
{
status = plugin.deregisterNode( randomizerDeviceNode::id );
if( !status ) {
status.
perror(
"failed to deregisterNode randomizerDeviceNode");
}
return status;
}