Naming custom locators C++

Naming custom locators C++

maxwellrender
Participant Participant
517 Views
1 Reply
Message 1 of 2

Naming custom locators C++

maxwellrender
Participant
Participant

Hello. I need to create a locator. To do this, I took as a basis footPrintNode.cpp from devkit. By changing the file a little, I got the following locator:

Screenshot 2022-12-02 184456.jpg

Also I divided the source file into three parts:  head, code .cpp, and ...main.cpp files in order to use the locator as part of a large plugin.

 

What I want to know.

1. Why is the custom locator named differently than the standard locator?

Screenshot 2022-12-02 181521.jpg

How to set a name like a standard locator?

2. How to change color correctly?

I tried to change the color in the code by changing the RGB values but after that, in the scene when I selected the locator, it did not change color. That is, it was not clear whether the locator was selected or not.

3. In Maya, each object in Outlander has its own icon to the left of the inscription.

How can I create an icon for my locator?

 

And if it's not difficult for you, please look at my code. Maybe something needs to be changed ^^.

0 Likes
518 Views
1 Reply
Reply (1)
Message 2 of 2

maxwellrender
Participant
Participant

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;
}

 

0 Likes