head file:
#include <maya/MPxLocatorNode.h>
// Viewport 2.0 includes
#include <maya/MDrawContext.h>
#include <maya/MHWGeometryUtilities.h>
#include <maya/MPointArray.h>
#include <maya/MGlobal.h>
#include <maya/MEventMessage.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MDrawRegistry.h>
#include <maya/MPxDrawOverride.h>
#include <maya/MUserData.h>
#include <assert.h>
class footPrint : public MPxLocatorNode
{
public:
footPrint();
~footPrint() override;
MStatus compute(const MPlug& plug, MDataBlock& data) override;
bool isBounded() const override;
MBoundingBox boundingBox() const override;
MStatus preEvaluation(const MDGContext& context, const MEvaluationNode& evaluationNode) override;
void getCacheSetup(const MEvaluationNode& evalNode, MNodeCacheDisablingInfo& disablingInfo, MNodeCacheSetupInfo& cacheSetupInfo, MObjectArray& monitoredAttributes) const override;
static void* creator();
static MStatus initialize();
static MObject size; // The size of the foot
public:
static MTypeId id;
static MString drawDbClassification;
static MString drawRegistrantId;
static MObject worldS;
};
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Viewport 2.0 override implementation
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
class FootPrintData : public MUserData
{
public:
MColor fColor{ 1.f, 0.f, 0.f, 1.f };
unsigned int fDepthPriority;
MPointArray fLineList;
MPointArray fTriangleList;
};
class FootPrintDrawOverride : public MHWRender::MPxDrawOverride
{
public:
static MHWRender::MPxDrawOverride* Creator(const MObject& obj)
{
return new FootPrintDrawOverride(obj);
}
~FootPrintDrawOverride() override;
MHWRender::DrawAPI supportedDrawAPIs() const override;
bool isBounded(
const MDagPath& objPath,
const MDagPath& cameraPath) const override;
MBoundingBox boundingBox(
const MDagPath& objPath,
const MDagPath& cameraPath) const override;
MUserData* prepareForDraw(
const MDagPath& objPath,
const MDagPath& cameraPath,
const MHWRender::MFrameContext& frameContext,
MUserData* oldData) override;
bool hasUIDrawables() const override { return true; }
void addUIDrawables(
const MDagPath& objPath,
MHWRender::MUIDrawManager& drawManager,
const MHWRender::MFrameContext& frameContext,
const MUserData* data) override;
bool traceCallSequence() const override
{
// Return true if internal tracing is desired.
return false;
}
void handleTraceMessage(const MString& message) const override
{
MGlobal::displayInfo("footPrintDrawOverride: " + message);
// Some simple custom message formatting.
fputs("footPrintDrawOverride: ", stderr);
fputs(message.asChar(), stderr);
fputs("\n", stderr);
}
private:
FootPrintDrawOverride(const MObject& obj);
float getMultiplier(const MDagPath& objPath) const;
static void OnModelEditorChanged(void* clientData);
footPrint* fFootPrint;
MCallbackId fModelEditorChangedCbId;
};
main cpp file
#include <maya/MFnPlugin.h>
#include "BasicLocator.h"
MStatus initializePlugin(MObject obj)
{
MStatus status;
MFnPlugin plugin(obj, PLUGIN_COMPANY, "3.0", "Any");
status = plugin.registerNode(
"footPrint",
footPrint::id,
&footPrint::creator,
&footPrint::initialize,
MPxNode::kLocatorNode,
&footPrint::drawDbClassification);
if (!status) {
status.perror("registerNode");
return status;
}
status = MHWRender::MDrawRegistry::registerDrawOverrideCreator(
footPrint::drawDbClassification,
footPrint::drawRegistrantId,
FootPrintDrawOverride::Creator);
if (!status) {
status.perror("registerDrawOverrideCreator");
return status;
}
return status;
}
MStatus uninitializePlugin(MObject obj)
{
MStatus status;
MFnPlugin plugin(obj);
status = MHWRender::MDrawRegistry::deregisterDrawOverrideCreator(
footPrint::drawDbClassification,
footPrint::drawRegistrantId);
if (!status) {
status.perror("deregisterDrawOverrideCreator");
return status;
}
status = plugin.deregisterNode(footPrint::id);
if (!status) {
status.perror("deregisterNode");
return status;
}
return status;
}