Custom Locator

Custom Locator

MehdiZangenehBar
Advocate Advocate
280 Views
0 Replies
Message 1 of 1

Custom Locator

MehdiZangenehBar
Advocate
Advocate

i just created a cutom locator, everything will build with no error, node will be created in the scene, but nothing is shown:

#include <maya/MFnPlugin.h>
#include <maya/MPxLocatorNode.h>
#include <maya/MPxDrawOverride.h>
#include <maya/MDrawRegistry.h>
#include <maya/MUIDrawManager.h>
#include <maya/MBoundingBox.h>
#include <maya/MColor.h>
#include <maya/MPoint.h>

class Test_Locator : public MPxLocatorNode
{
public:
    static const MTypeId id;
    static const MString typeName;
    static const MString drawClassification;
    static const MString drawRegistrantId;

    static void* creator()
    {
        return new Test_Locator();
    }

    static MStatus initialize()
    {
        return MS::kSuccess;
    }

    bool isBounded() const override
    {
        return true;
    }

    MBoundingBox boundingBox() const override
    {
        return MBoundingBox(MPoint(-1.0, -1.0, -1.0), MPoint(1.0, 1.0, 1.0));
    }
};

const MTypeId Test_Locator::id(0x0011FF01);
const MString Test_Locator::typeName("Test_Locator");
const MString Test_Locator::drawClassification("drawdb/geometry/Test_Locator");
const MString Test_Locator::drawRegistrantId("Test_LocatorPlugin");

class Test_Locator_DrawOverride : public MHWRender::MPxDrawOverride
{
public:
    static MHWRender::MPxDrawOverride* creator(const MObject& obj)
    {
        return new Test_Locator_DrawOverride(obj);
    }

    Test_Locator_DrawOverride(const MObject& obj)
        : MHWRender::MPxDrawOverride(obj, nullptr, false)
    {
    }

    MHWRender::DrawAPI supportedDrawAPIs() const override
    {
        return MHWRender::kAllDevices;
    }

    bool isBounded(const MDagPath& path, const MDagPath& cameraPath) const override
    {
        return true;
    }

    MBoundingBox boundingBox(const MDagPath& path, const MDagPath& cameraPath) const override
    {
        return MBoundingBox(MPoint(-1.0, -1.0, -1.0), MPoint(1.0, 1.0, 1.0));
    }

    MUserData* prepareForDraw(
        const MDagPath& objPath,
        const MDagPath& cameraPath,
        const MHWRender::MFrameContext& frameContext,
        MUserData* oldData) override
    {
        return oldData;
    }

    void addUIDrawables(
        const MDagPath& objPath,
        MHWRender::MUIDrawManager& drawManager,
        const MHWRender::MFrameContext& frameContext,
        const MUserData* data) override
    {
        drawManager.beginDrawable();
        drawManager.setColor(MColor(0.0f, 1.0f, 0.0f));
        drawManager.setLineWidth(2.0);

        MPoint center(0.0, 0.0, 0.0);
        double radius = 1.0;
        drawManager.sphere(center, radius, false);

        drawManager.endDrawable();
    }
};

MStatus initializePlugin(MObject obj)
{
    MFnPlugin plugin(obj, "YourName", "1.0", "Any");

    plugin.registerNode(
        Test_Locator::typeName,
        Test_Locator::id,
        Test_Locator::creator,
        Test_Locator::initialize,
        MPxNode::kLocatorNode,
        &Test_Locator::drawClassification);

    MHWRender::MDrawRegistry::registerDrawOverrideCreator(
        Test_Locator::drawClassification,
        Test_Locator::drawRegistrantId,
        Test_Locator_DrawOverride::creator);

    return MS::kSuccess;
}

MStatus uninitializePlugin(MObject obj)
{
    MFnPlugin plugin(obj);

    plugin.deregisterNode(Test_Locator::id);

    MHWRender::MDrawRegistry::deregisterDrawOverrideCreator(
        Test_Locator::drawClassification,
        Test_Locator::drawRegistrantId);

    return MS::kSuccess;
}
0 Likes
281 Views
0 Replies
Replies (0)