Support Soft Selection with custom MPxComponentShape

MPxComponentShape allows the implementation of new user-defined shapes using components, however all the UI related feature (such as selection/drawing) has to be implemented with another class MPxSurfaceShapeUI.

In the MPxSurfaceShapeUI class, there are select() and draw() functions you need to implement for your custom shape. The Maya devkit has 2 examples that demonstrates how to use this class: apiMeshShape and apiSimpleShape. The apiSimpleShape shows to how to use MPxSurfaceShapeUI to work with MPxComponentShape to achieve component selection and drawing. But this is not Soft Selection!

SoftSelectIntro
Unfortunately there is no direct way to achieve Soft Selection in Maya by API. However there is a workaround in an in-direct way. The pseudo-code below shows how to get soft selection in component mode.

softSelection = OpenMaya.MRichSelection()
OpenMaya.MGlobal.getRichSelection(softSelection)
selection = OpenMaya.MSelectionList()
softSelection.getSelection(selection)
pathDag = OpenMaya.MDagPath()
oComp = OpenMaya.MObject()
selection.getDagPath(0, pathDag, oComp)
fnComp = OpenMaya.MFnSingleIndexedComponent(oComp)
for i in range(fnComp.elementCount()):
print fnComp.element(i), fnComp.weight(i).influence()

C++ API:

The below enum and function are there in

  1. To set the component mode
    In “enum MSelectionMode” set “kSelectComponentMode”
  2. To get soft selection
    static MStatus getRichSelection (MRichSelection &dest, bool defaultToActiveSelection=true)

 


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading