#include <string.h>
#include <maya/MIOStream.h>
#include <maya/MPxNode.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnUnitAttribute.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MFnPlugin.h>
#include <maya/MNodeCacheDisablingInfoHelper.h>
#include <cassert>
#include <limits>
class simpleSimulationNode :
public MPxNode
{
public:
static void* creator();
public:
static MObject aSimulationStartTime;
};
MObject simpleSimulationNode::aTarget;
MObject simpleSimulationNode::aDampingFactor;
MObject simpleSimulationNode::aCurrentTime;
MObject simpleSimulationNode::aSimulationEnabled;
MObject simpleSimulationNode::aSimulationStartTime;
MObject simpleSimulationNode::aOutput;
MObject simpleSimulationNode::aSimulationState;
MObject simpleSimulationNode::aPrevTime;
MTypeId simpleSimulationNode::id{ 0x00081160 };
{
if (plug == aOutput)
{
assert(!aTarget.isNull());
assert(returnStatus);
assert(!aSimulationEnabled.isNull());
bool simulationEnabledValue = data.
inputValue(aSimulationEnabled, &returnStatus).
asBool();
assert(returnStatus);
if (simulationEnabledValue)
{
assert(!aPrevTime.isNull());
assert(returnStatus);
assert(!aCurrentTime.isNull());
assert(returnStatus);
if (prevTime == currentTime) {
return MS::kSuccess;
}
assert(!aSimulationStartTime.isNull());
assert(returnStatus);
simulationEnabledValue = (simulationStartTime < currentTime);
}
float outputValue = targetValue;
if (simulationEnabledValue)
{
assert(!aDampingFactor.isNull());
const float dampingFactorValue = data.
inputValue(aDampingFactor, &returnStatus).
asFloat();
assert(returnStatus);
assert(!aSimulationState.isNull());
const float simulationStateValue = data.
inputValue(aSimulationState, &returnStatus).
asFloat();
assert(returnStatus);
outputValue = simulationStateValue + (targetValue - simulationStateValue) * dampingFactorValue;
}
outputHandle.
set(outputValue);
simulationStateHandle.
set(outputValue);
}
else
{
return MS::kUnknownParameter;
}
return MS::kSuccess;
}
void simpleSimulationNode::getCacheSetup(
{
nullptr, monitoredAttributes, evaluationNode, aSimulationEnabled, false
);
if (requestSimulation)
{
}
}
{
static constexpr MTime::MTick kMaximumTimeTick = std::numeric_limits<MTime::MTick>::max()/2;
static constexpr MTime::MTick kMinimumTimeTick = std::numeric_limits<MTime::MTick>::min()/2+1;
MDataBlock data =
const_cast<simpleSimulationNode*
>(
this)->forceCache();
if (!data.
isClean(aSimulationStartTime) || !data.
isClean(aSimulationEnabled))
{
}
const bool simulationEnabled = returnStatus ? simulationEnabledData.
asBool() :
true;
if (!simulationEnabled)
{
return input;
}
const MTime simulationStartTime = returnStatus ? simulationStartTimeData.
asTime() : kMinimumTime;
const MTime simulationEndTime = kMaximumTime;
if (input.
intersects(simulationStartTime, simulationEndTime))
{
return input |
MTimeRange{ simulationStartTime, simulationEndTime };
}
else
{
}
}
void* simpleSimulationNode::creator()
{
return new simpleSimulationNode();
}
MStatus simpleSimulationNode::initialize()
{
status = addAttribute(aTarget);
assert(status);
status = addAttribute(aDampingFactor);
assert(status);
status = addAttribute(aCurrentTime);
assert(status);
status = addAttribute(aSimulationEnabled);
assert(status);
status = addAttribute(aSimulationStartTime);
assert(status);
status = addAttribute(aOutput);
assert(status);
status = addAttribute(aSimulationState);
assert(status);
status = addAttribute(aPrevTime);
assert(status);
status = attributeAffects(aTarget, aOutput);
assert(status);
status = attributeAffects(aDampingFactor, aOutput);
assert(status);
status = attributeAffects(aCurrentTime, aOutput);
assert(status);
status = attributeAffects(aSimulationEnabled, aOutput);
assert(status);
status = attributeAffects(aSimulationStartTime, aOutput);
assert(status);
return MS::kSuccess;
}
{
MFnPlugin plugin(obj, PLUGIN_COMPANY,
"1.0",
"Any");
status = plugin.registerNode(
"simpleSimulationNode",
simpleSimulationNode::id,
simpleSimulationNode::creator,
simpleSimulationNode::initialize
);
if (!status) {
status.
perror(
"registerNode");
return status;
}
return status;
}
{
status = plugin.deregisterNode(simpleSimulationNode::id);
if (!status) {
status.
perror(
"deregisterNode");
return status;
}
return status;
}