Manipulators (MPxManipulatorNode
, and MPxManipContainer
) are drawn in the old viewport using the following interface:
virtual void draw(M3dView & view, const MDagPath & path, M3dView::DisplayStyle style,M3dView::DisplayStatus status);
The Viewport 2.0 interfaces attempt to match the old interface signatures, but branch off to allow access to an MUIDrawManager
and a frame context (MFrameContext
):
virtual void preDrawUI( const M3dView &view );
virtual void drawUI( MHWRender::MUIDrawManager& drawManager, const MHWRender::MFrameContext& frameContext) const;
One key difference between Viewport 2.0 and the old viewport is that an M3dView
(3d viewport wrapper) is no longer available for use at draw time. The equivalent state information is to be extracted from the frame context.
Sample code from the example plug-in footPrintLocatorManip is shown below:
void footPrintLocatorManip::preDrawUI( const M3dView &view )
{
// Update text drawing position
fTextPosition = // DG evaluation
}
void footPrintLocatorManip::drawUI(
MHWRender::MUIDrawManager& drawManager,
const MHWRender::MFrameContext& frameContext ) const
{
// Draw some text
drawManager.beginDrawable();
drawManager.setColor( MColor( 0.0f, 1.0f, 0.1f ) );
drawManager.text( fTextPosition, “Some text", MHWRender::MUIDrawManager::kLeft );
drawManager.text2d( MPoint(100,100), “Some text in 2D", MHWRender::MUIDrawManager::kLeft );
drawManager.endDrawable();
}
Here, a text position is computed and stored in fTextPosition
. This value is then used at draw time to set the position to draw text using the MUIDrawManager
instance.
For selection, it is recommended that you have a series of manipulators which are part of a MPxManipContainer
. If the plug-in wishes to select a sub-part or handle, then the void MUIDrawManager::beginDrawable(unsigned int name, bool nameIsPickable);
method can be used. The name argument is device independent and can be used with the MPxManipulatorNode::glActiveName()
method. The name is only used for selection and is be ignored in the regular draw pass.
The lineManip
plug-in shows a sample usage:
void lineManip::drawUI(
MHWRender::MUIDrawManager& drawManager,
const MHWRender::MFrameContext& frameContext ) const
{
// Find out if we should draw using selected color
bool drawAsSelected = false;
shouldDrawHandleAsSelected(lineName, drawAsSelected);
// Everything from begin/endDrawable has the lineName handle and is considered to be pickable
drawManager.beginDrawable(lineName, true);
drawManager.setColorIndex( drawAsSelected ? fSelectedLineColorIndex : fLineColorIndex );
drawManager.line( fLineStart, fLineEnd );
drawManager.endDrawable();
// The text is not considered to be pickable
drawManager.beginDrawable();
drawManager.setColorIndex( fLineColorIndex );
drawManager.text( fLineStart, MString("line manip"));
drawManager.endDrawable();
// The 2d line is considered to be pickable and has the same handle.
drawManager.beginDrawable(lineName, true);
drawManager.setColorIndex( drawAsSelected ? fSelectedLineColorIndex : fLineColorIndex );
drawManager.line2d(MPoint(100, 100), MPoint(200, 100));
drawManager.setLineWidth(5.0f);
drawManager.endDrawable();
// The 2d text is not considered to be pickable
drawManager.beginDrawable();
drawManager.setColorIndex( fLineColorIndex );
drawManager.setLineWidth(5.0f);
drawManager.text2d(MPoint(100, 105), MString("line manip 2D"));
drawManager.endDrawable();
}