#include <maya/MIOStream.h>
#include <maya/MFnPlugin.h>
#include <maya/MString.h>
#include <maya/MPxCustomEvaluator.h>
#include <maya/MEulerRotation.h>
#include <maya/MCustomEvaluatorClusterNode.h>
#include <maya/MGlobal.h>
#include <maya/MTime.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MPlugArray.h>
#include <maya/MPlug.h>
#include <maya/MAnimControl.h>
#include <maya/MSelectionList.h>
#include <maya/MFnSet.h>
#include <maya/MProfiler.h>
#include <maya/MItDependencyNodes.h>
#include <vector>
#include <string>
template <class T>
inline void hash_combine(std::size_t & seed, const T & v)
{
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
{
public:
virtual ~simpleEvaluator();
static void* creator();
protected:
void buildPlugListWithControllerTag();
void buildHashValue();
private:
std::size_t fOldHashValue;
std::size_t fCurrentHashValue;
};
{
return true;
}
void simpleEvaluator::buildPlugListWithControllerTag()
{
if (stat == MS::kSuccess)
{
const char* values[] = {"translateX", "translateY", "translateZ", "rotateX", "rotateY", "rotateZ"};
for (; !dgIter.isDone(); dgIter.next())
{
if (stat != MS::kSuccess) continue;
MPlug currControllerTagPlug = controllerTagNode.findPlug(
"controllerObject",
true, &stat);
if (stat != MS::kSuccess) continue;
if (currControllerTagPlug.
connectedTo(source,
true ,
false , &stat))
{
if (stat != MS::kSuccess) continue;
MObject controllerNode = source[0].node(&stat);
if (stat != MS::kSuccess) continue;
for (unsigned int j = 0; j < 6; j++)
{
MPlug currPlug = currControllerNode.findPlug(values[j],
true, &stat);
if (stat == MS::kSuccess)
{
fControllerPlugs.append(currPlug);
}
else
{
std::cerr <<
"NO PLUG: " << currControllerNode.
name().
asChar() <<
"." << values[j] << std::endl;
}
}
}
}
}
}
void simpleEvaluator::buildHashValue()
{
unsigned int length = fControllerPlugs.length();
for (unsigned int i = 0; i < length; i++)
{
float value = 0;
stat = fControllerPlugs[i].getValue(value);
if (stat == MS::kSuccess)
{
hash_combine(fCurrentHashValue, value);
}
else
{
std::cerr << "NO VALUE: " << fControllerPlugs[i].name().asChar() << std::endl;
}
}
}
{
}
{
MProfilingScope profilingScopeForEval(_profilerCategory, MProfiler::kColorD_L1,
"buildPoseHash",
"building pose hash");
buildHashValue();
}
{
fOldHashValue = fCurrentHashValue;
fCurrentHashValue = 0;
}
{
if (fControllerPlugs.length() == 0)
{
buildPlugListWithControllerTag();
}
return true;
}
{
if (fOldHashValue != fCurrentHashValue)
{
}
}
{
if (fControllerPlugs.length() > 0)
{
fControllerPlugs.clear();
}
}
void* simpleEvaluator::creator()
{
return new simpleEvaluator();
}
simpleEvaluator::~simpleEvaluator()
{
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"3.0",
"Any");
status = plugin.registerEvaluator("SimpleEvaluator", 40 , simpleEvaluator::creator);
if (!status)
{
status.
perror(
"registerEvaluator");
return status;
}
return status;
}
{
status = plugin.deregisterEvaluator( "SimpleEvaluator" );
if (!status)
{
status.
perror(
"deRegisterEvaluator");
return status;
}
return status;
}