Tyler Thornock - Character TD
Rigs Scripts Tutorials Demo Reel Resume

Using soft selection in Maya

Opacity, everything can benefit from falloff and blending! Soft select and reflection are two extremely useful features that should be harnessed by any script you can. Imagine, maya's copySkinWeights using the soft selection to blend weights, or perhaps when adding, scaling, or smoothing weights to a skin influence or painted attribute, or when matching points on one mesh to another... the list could go on. The ability to base the falloff distance on Volume or Surface can be extremely useful as well.

So, blah blah how do you get the opacity per vert and reflection? Enter, MRichSelection and its functions getSelection and getSymmetry which return a MSelectionList, but with a twist. The MObject representing the components actually contains the opacity value (somewhat hidden) for that component.

So here is a working example for querying soft selection opacities:

import maya.OpenMaya as OpenMaya
import maya.OpenMayaAnim as OpenMayaAnim
import maya.cmds as cmds
import maya.mel as mel

def getSoftSelection (opacityMult=1.0):
	allDags, allComps, allOpacities = [], [], []

	# if soft select isn't on, return
	if not cmds.softSelect(q=True, sse=True):
		return allDags, allComps, allOpacities
	richSel = OpenMaya.MRichSelection()
		# get currently active soft selection
		raise Exception('Error getting soft selection.')

	richSelList = OpenMaya.MSelectionList()
	selCount = richSelList.length()

	for x in xrange(selCount):
		shapeDag = OpenMaya.MDagPath()
		shapeComp = OpenMaya.MObject()
			richSelList.getDagPath(x, shapeDag, shapeComp)
		except RuntimeError:
			# nodes like multiplyDivides will error
		compOpacities = {}
		compFn = OpenMaya.MFnSingleIndexedComponent(shapeComp)
			# get the secret hidden opacity value for each component (vert, cv, etc)
			for i in xrange(compFn.elementCount()):
				weight = compFn.weight(i)
				compOpacities[compFn.element(i)] = weight.influence() * opacityMult
		except Exception, e:
			print e.__str__()
			print 'Soft selection appears invalid, skipping for shape "%s".' % shapeDag.partialPathName()

	return allDags, allComps, allOpacities

allDags, allComps, allOpacities = getSoftSelection()


Now that you have the opacities the hard part is converting scripts and tools that werent designed for blending... but once you start supporting it you'll love it!