Skip to content

Instantly share code, notes, and snippets.

@PeterDrakeNichols
Created January 3, 2018 00:21
Show Gist options
  • Save PeterDrakeNichols/fcead7062e78f53eb1d5bb28b93f4457 to your computer and use it in GitHub Desktop.
Save PeterDrakeNichols/fcead7062e78f53eb1d5bb28b93f4457 to your computer and use it in GitHub Desktop.
ball control class
"""
class for creating ball control object
@category Rigging @subcategory Rigbase
@tags control class
@author: petey
"""
import maya.cmds as mc
class ballControl():
def __init__(
self,
prefix = 'new',
scale = 1.0,
translateTo = '',
rotateTo = '',
parent = '',
lockChannels = ['s','v']
):
"""
@param prefix: str, prefix to name new objects
@param scale: float, scale value for size of control shapes
@param translateTo: str, reference object for control position
@param rotateTo: str, reference object for control orientation
@param parent: str, object to be parent of new control
@param lockChannels: list( str ), list of channels on control to be locked and non-keyable
@return: None
"""
#control and offset group
ctlOffset = mc.group(n = '%s_grp'%prefix, em =1)
ctlObject = mc.sphere( n ='%s_ctl'%prefix, ch = False, radius = scale )[0]
mc.parent(ctlObject,ctlOffset)
#color based on naming convention
ctlShapes = mc.listRelatives(ctlObject, s=1, type = 'nurbsSurface') #returns name instead of list
for s in ctlShapes:
mc.setAttr('%s.ove'%s, 1)
if(prefix[0:2] == 'l_'):
mc.setAttr('%s.ovc'%s,6)
elif(prefix[0:2] == 'r_'):
mc.setAttr('%s.ovc'%s,13)
else:
mc.setAttr('%s.ovc'%s,30)
#disconnect from initShading group
mc.sets(s , rm = 'initialShadingGroup')
#mc.disconnectAttr(s + '.instObjGroups[0]', 'initialShadingGroup.dagSetMembers[0]')
#match translation and rotation of ctlOffset
if mc.objExists(translateTo):
mc.delete(mc.pointConstraint(translateTo, ctlOffset))
if(mc.objExists(rotateTo)):
mc.delete(mc.orientConstraint(rotateTo, ctlOffset))
#parent ctlOffset
if mc.objExists(parent):
mc.parent(ctlOffset,parent)
# lock controls
singleAttributeLockList = []
for lockChannel in lockChannels:
if lockChannel in ['t','r','s']:
for axis in ['x','y','z']:
at = lockChannel + axis
singleAttributeLockList.append(at)
else:
#if not compound example:visibility
singleAttributeLockList.append(lockChannel)
for at in singleAttributeLockList:
mc.setAttr('%s.%s'%(ctlObject,at),l=1, k=0)
# add public binMembership
self.C = ctlObject
self.Off = ctlOffset
ctl = ballControl()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment