#include "atomCachedPlugs.h"
#include <maya/MAnimUtil.h>
#include <maya/MPlugArray.h>
#include <maya/MObjectArray.h>
template <class T>
void atomCachedValues<T>::resize(unsigned int numItems,unsigned int stride)
{
mNumItems = numItems;
mStride = stride;
int total = numItems *stride;
mValues.resize(total);
}
template <class T>
void atomCachedValues<T>::setValue(T &value,unsigned int item,unsigned int element)
{
mValues[(item * mStride) + element] = value;
}
template <class T>
T atomCachedValues<T>::getValue(unsigned int item, unsigned int element)
{
return mValues[(item * mStride) + element];
}
atomShortValues::atomShortValues(
MPlug &plug,
unsigned int numItems) :atomBasePlugAndValues(plug)
{
mCachedValues.resize(numItems,1);
}
void atomShortValues::setValue(
MDGContext &context,
unsigned int index)
{
MObject attribute = mPlug.attribute();
{
switch(fnAttrib.unitType())
{
{
bool value;
mPlug.getValue(value,context);
short ival = value == true ? 1 : 0;
mCachedValues.setValue(ival,index);
break;
}
{
char value;
mPlug.getValue(value,context);
short ival = (short) value;
mCachedValues.setValue(ival,index);
break;
}
{
short value;
mPlug.getValue(value,context);
mCachedValues.setValue(value,index);
break;
}
default:
break;
}
}
{
short value;
mPlug.getValue(value,context);
mCachedValues.setValue(value,index);
}
}
void atomShortValues::writeToAtomFile(ofstream & clip)
{
for(unsigned int i=0;i<mCachedValues.numItems();++i)
{
clip << mCachedValues.getValue(i);
clip << " ";
}
}
atomIntValues::atomIntValues(
MPlug &plug,
unsigned int numItems) :atomBasePlugAndValues(plug)
{
mCachedValues.resize(numItems,1);
}
void atomIntValues::setValue(
MDGContext &context,
unsigned int index)
{
MObject attribute = mPlug.attribute();
{
{
int value;
mPlug.getValue(value,context);
mCachedValues.setValue(value,index);
}
}
}
void atomIntValues::writeToAtomFile(ofstream & clip)
{
for(unsigned int i=0;i<mCachedValues.numItems();++i)
{
clip << mCachedValues.getValue(i);
clip << " ";
}
}
atomFloatValues::atomFloatValues(
MPlug &plug,
unsigned int numItems,
unsigned int stride) :atomBasePlugAndValues(plug)
{
mCachedValues.resize(numItems,stride);
}
void atomFloatValues::setValue(
MDGContext &context,
unsigned int index)
{
MObject attribute = mPlug.attribute();
{
switch(fnAttrib.unitType())
{
{
float value;
mPlug.getValue(value,context);
mCachedValues.setValue(value,index);
break;
}
default:
break;
}
}
}
void atomFloatValues::writeToAtomFile(ofstream & clip)
{
for(unsigned int i=0;i<mCachedValues.numItems();++i)
{
for(unsigned int j=0;j<mCachedValues.stride();++j)
{
clip << mCachedValues.getValue(i,j);
clip << " ";
}
}
}
atomDoubleValues::atomDoubleValues(
MPlug &plug,
unsigned int numItems,
double scale) :atomBasePlugAndValues(plug), mScale(scale)
{
mCachedValues.resize(numItems,1);
}
void atomDoubleValues::setValue(
MDGContext &context,
unsigned int index)
{
MObject attribute = mPlug.attribute();
{
switch(fnAttrib.unitType())
{
{
double value;
mPlug.getValue(value,context);
mCachedValues.setValue(value,index);
break;
}
default:
break;
}
}
{
switch(fnAttrib.unitType())
{
{
double value;
mPlug.getValue(value,context);
value *= mScale;
mCachedValues.setValue(value,index);
break;
}
{
double value;
mPlug.getValue(value,context);
value *= mScale;
mCachedValues.setValue(value,index);
break;
}
{
double value;
mPlug.getValue(value,context);
mCachedValues.setValue(value,index);
break;
}
default:
{
break;
}
}
}
}
void atomDoubleValues::writeToAtomFile(ofstream & clip)
{
for(unsigned int i=0;i<mCachedValues.numItems();++i)
{
clip << mCachedValues.getValue(i);
clip << " ";
}
}
bool sdk, bool constraint, bool animLayers, std::set<std::string> &attrStrings,
atomTemplateReader &templateReader,
unsigned int numItems,
MAngle::Unit angularUnit,
{
getCachedPlugs(nodeName,animatablePlugs, sdk, constraint, animLayers, attrStrings,templateReader,numItems,angularUnit,linearUnit);
}
atomCachedPlugs::~atomCachedPlugs()
{
for(unsigned int z =0; z< mCachedPlugs.size(); ++z)
{
if(mCachedPlugs[z])
delete mCachedPlugs[z];
}
}
void atomCachedPlugs::getCachedPlugs(
MString &nodeName,
const MPlugArray &animatablePlugs,
bool sdk, bool constraint, bool animLayers,
std::set<std::string> &attrStrings,atomTemplateReader &templateReader,unsigned int numItems,
{
std::set<std::string>::const_iterator constIter = attrStrings.end();
unsigned int numPlugs = animatablePlugs.
length();
for (unsigned int i = 0; i < numPlugs; i++)
{
MPlug plug = animatablePlugs[i];
bool isConnected = plug.
connectedTo (destPlugArray,
true,
false);
bool isConnectedButNotToAnimCurve = (isConnected && (destPlugArray.
length() == 1 &&
bool animCurveIsConnected = false;
if (isConnectedButNotToAnimCurve ==
false && destPlugArray.
length() ==1 &&
{
MPlug curve = destPlugArray[0];
animCurveIsConnected = destPlugArray.
length() > 0;
}
bool shouldBeCached = isConnectedButNotToAnimCurve ||animCurveIsConnected;
if(sdk==false)
{
drivers))
shouldBeCached = true;
}
if (shouldBeCached )
{
MObject attrObj = attrPlug.attribute();
atomBase::getAttrName(plug,attrName);
if(templateReader.findNodeAndAttr(nodeName,attrName) == false)
continue;
if(attrStrings.size() == 0 || attrStrings.find(std::string(fnLeafAttr.shortName().asChar())) != constIter)
{
if(constraint)
{
continue;
}
if(animLayers)
{
if(MAnimUtil::findAnimationLayers(plug,layers,plugs))
continue;
}
}
}
}
{
mCachedPlugs.resize(cachedPlugs.
length());
for(
unsigned int i =0 ;i< cachedPlugs.
length(); ++i)
{
atomBasePlugAndValues * plugAndValue = NULL;
MPlug &plug = cachedPlugs[i];
{
switch(fnAttrib.unitType())
{
{
plugAndValue = new atomShortValues(plug, numItems);
break;
}
{
plugAndValue = new atomIntValues(plug, numItems);
break;
}
{
plugAndValue = new atomFloatValues(plug, numItems,1);
break;
}
{
plugAndValue = new atomDoubleValues(plug, numItems,1.0);
break;
}
default:
break;
}
}
{
switch(fnAttrib.unitType())
{
{
double scale = angle.as(angularUnit);
plugAndValue = new atomDoubleValues(plug, numItems,scale);
break;
}
{
double scale = distance.as(linearUnit);
plugAndValue = new atomDoubleValues(plug, numItems,scale);
break;
}
{
plugAndValue = new atomDoubleValues(plug, numItems,1.0);
break;
}
default:
{
break;
}
}
}
{
plugAndValue = new atomShortValues(plug, numItems);
}
mCachedPlugs[i] = plugAndValue;
}
}
}
MPlug& atomCachedPlugs::getPlug(
unsigned int item)
{
return mCachedPlugs[item]->getPlug();
}
void atomCachedPlugs::calculateValue(
MDGContext &ctx,
unsigned int item)
{
for(unsigned int i = 0;i< mCachedPlugs.size(); ++i)
{
if(mCachedPlugs[i])
}
}
void atomCachedPlugs::writeValues(ofstream &clip,unsigned int item)
{
if(item< mCachedPlugs.size())
{
if(mCachedPlugs[item])
mCachedPlugs[item]->writeToAtomFile(clip);
}
}
bool atomCachedPlugs::isAttrCached(
const MString &attrName,
const MString &layerName)
{
if(hasCached())
{
for(unsigned int i = 0;i< mCachedPlugs.size(); ++i)
{
if(mCachedPlugs[i])
{
MPlug plug = mCachedPlugs[i]->getPlug();
atomBase::getAttrName(plug,name);
if(name == attrName)
return true;
}
}
}
return false;
}