Skip to content

Instantly share code, notes, and snippets.

@PeterDrakeNichols
Created October 30, 2017 17:18
Show Gist options
  • Save PeterDrakeNichols/06fbf62cb9991898629726c519a4ebdc to your computer and use it in GitHub Desktop.
Save PeterDrakeNichols/06fbf62cb9991898629726c519a4ebdc to your computer and use it in GitHub Desktop.
nodes for falloff from driven at
def oneChannelFalloff( ctrlAt, targetAts, stepFactor = 1 ):
'''
@param ctrlAt: string, attribute driving the targets
@param ctrlAt: string, attribute driven by stepped influence from ctrlAt
@param stepFactor: float, how much influence should the effect have
@param preval: float, optional starting value of control Attr to be normalized
'''
preval = mc.getAttr( ctrlAt )
step = 1.0 / len( targetAts )
recip = 1.0 / preval
# normalize preexisting values from control attr
ctrlMulti = mc.createNode( 'multDoubleLinear', n = ctrlAt.split( '.' )[0] + 'ctrl_mlt' )
mc.setAttr( ctrlMulti + '.input1', recip )
mc.connectAttr( ctrlAt , ctrlMulti + '.input2' )
# apply factor for falloff nodes
factorMulti = mc.createNode( 'multDoubleLinear', n = ctrlAt.split( '.' )[0] + 'factor_mlt' )
mc.setAttr( factorMulti + '.input1', stepFactor )
mc.connectAttr( ctrlMulti + '.output', factorMulti + '.input2' )
factorAt = factorMulti + '.input1'
# create nodes and connect to targetAts
falloffNodes = []
for idx, targetAt in enumerate( targetAts ):
stepIdx = step * idx
targetPrefix = targetAt.split( '.' )[0]
targetPreval = mc.getAttr( targetAt )
falloffNode = mc.createNode( 'multDoubleLinear', n = targetPrefix + '_mlt' )
mc.setAttr( falloffNode + '.input1', stepIdx )
mc.connectAttr( factorMulti + '.output', falloffNode + '.input2' )
if targetPreval:
addNode = mc.createNode( 'addDoubleLinear', n = targetPrefix + '_add' )
mc.setAttr( addNode + '.input1', targetPreval )
mc.connectAttr( falloffNode + '.output', addNode + '.input2' )
mc.connectAttr( addNode + '.output', targetAt )
else:
mc.connectAttr( falloffNode + '.output' , targetAt )
falloffNodes.append( falloffNode )
return {
'falloffNodes': falloffNodes,
'factorAt': factorAt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment