Search code examples
c++graphicsmaya

MUIDrawManager gets cleaned when mouse moves


I try to develop in Maya a plugin that draws a curve based on control point (basically I want to copy the default curve tool).

I am creating a basic Context and receives the doPress event to draw a simple line:

MStatus flowNodeOnly::doPress( MEvent& event, MHWRender::MUIDrawManager &drawManager, const MHWRender::MFrameContext &context)
{
    short x,y;

    event.getPosition(x,y);
    context.viewportToWorld(x,y,pos,far);
    linePlaneIntersection(contact,MVector(far-pos),pos,MVector(0,1,0),MVector(0,0,0));

    drawManager.beginDrawable();
    drawManager.setColor( MColor(1.0f, 1.0f, 0.0f) );
    drawManager.line( MPoint( 0, 0,0), MPoint(contact.x,0, contact.z) );
    drawManager.endDrawable();
}

The line gets well drawn in Maya's Viewport 2.0, however as soon as I move the mouse, the line disappears. How to get my line persistent ?


Solution

  • OK, found it, drawing my lines in

    MStatus drawFeedback ( MHWRender::MUIDrawManager& drawMgr, const MHWRender::MFrameContext& context );
    

    makes it be persistent.