def constrain(source, destination, translate=True, rotate=True, scale=False):
'''
Constrain two objects, even if they have some locked attributes.
'''
transAttr = None
rotAttr = None
scaleAttr = None
if translate:
transAttr = mc.listAttr(destination, keyable=True, unlocked=True, string='translate*')
if rotate:
rotAttr = mc.listAttr(destination, keyable=True, unlocked=True, string='rotate*')
if scale:
scaleAttr = mc.listAttr(destination, keyable=True, unlocked=True, string='scale*')
rotSkip = list()
transSkip = list()
for axis in ['x','y','z']:
if transAttr and not 'translate'+axis.upper() in transAttr:
transSkip.append(axis)
if rotAttr and not 'rotate'+axis.upper() in rotAttr:
rotSkip.append(axis)
if not transSkip:
transSkip = 'none'
if not rotSkip:
rotSkip = 'none'
constraints = list()
if rotAttr and transAttr and rotSkip == 'none' and transSkip == 'none':
constraints.append(mc.parentConstraint(source, destination))
else:
if transAttr:
constraints.append(mc.pointConstraint(source, destination, skip=transSkip))
if rotAttr:
constraints.append(mc.orientConstraint(source, destination, skip=rotSkip))
return constraints
评论列表
文章目录