Skip to content

Instantly share code, notes, and snippets.

@Roumenov
Created September 29, 2020 04:40
Show Gist options
  • Save Roumenov/fa5c05cc1cd957334b8550fe83834ef7 to your computer and use it in GitHub Desktop.
Save Roumenov/fa5c05cc1cd957334b8550fe83834ef7 to your computer and use it in GitHub Desktop.
messing around with creating attributes to drive shader params
eye_ramp = pm.ls('geo:R_eye_ramp')[0]
eye_joints = pm.ls(sl=1)
eye_control = pm.ls(sl=1)[0]
#checked items fill list of attrs
#'blink'
eye_parts = ('pupil', 'iris') #'offset'
eye_attrs = ('radius', 'shape', 'angle', 'stretch')
#pm.addAttr(longName = 'iris', type = 'float')
for joint in eye_joints:
if '_L_' in joint.name():
side = 'L'
elif '_R_' in joint.name():
side = 'R'
else:
side = None
setup_eye_attrs(joint=joint, control = eye_control, ramp = eye_ramp)
def setup_eye_attrs(joint, control, ramp, pupil = False, side = None):
if joint.hasAttr('blink'):
pass
else:
pm.addAttr(joint,longName = 'blink', attributeType = 'double', defaultValue = 0.0, minValue = -1.0, maxValue = 1.0)
joint.setAttr('blink', keyable = True)
eye_control.new_control_attr >> joint.attr
def setup_iris_attrs(joint, control, ramp, side = None):
if joint.hasAttr('radius'):
pass
else:
radius_attr = pm.addAttr(joint,longName = 'radius', attributeType = 'double', defaultValue = 1.0, minValue = 0.0, maxValue = 1.0)
joint.setAttr('radius', keyable = True)
if side:
control_radius = side+'Radius'#+attr[0].upper()+attr[1:]
else:
control_radius = 'radius'
if control.hasAttr(control_radius):
pass
else:
pm.addAttr(joint,longName = control_radius, attributeType = 'double', defaultValue = 1.0, minValue = 0.0, maxValue = 1.0)
joint.setAttr(control_radius, keyable = True)
pm.addAttr(item,longName = 'RIrisShape', attributeType = 'double', defaultValue = 0.0)
item.setAttr('RIrisShape', keyable = True)
pm.addAttr(item,longName = 'RIrisAngle', attributeType = 'double', defaultValue = 0.0)
item.setAttr('RIrisAngle', keyable = True)
radius_default = float(eye_ramp.getAttr('colorEntryList[1]')[0])#pm.getAttr(eye_ramp.colorEntryList[1].position)
#pm.shadingNode('floatMath', asUtility = True, name = 'test')
radius_math = pm.createNode('floatMath', name = str(side+'irisRadius_FM')) #float math to add
radius_math.setAttr('floatA', radius_default)
radius_math.setAttr('operation', 2)
radius_attr >> radius_math.floatB
radius_math.outFloat >> eye_ramp.colorEntryList[1].position
pass
def setup_pupil(joint, control, eye_ramp):
#make pupil
#setAttr geo:R_eye_ramp.colorEntryList[2].color -type double3 0.404 0 0;
#setAttr geo:R_eye_ramp.colorEntryList[2].position 0.0299401;
pass
if joint.hasAttr(attr):
pass
else:
pm.addAttr(joint,longName = attr, attributeType = 'double', defaultValue = 0.0, minValue = -1.0, maxValue = 1.0)
joint.setAttr(attr, keyable = True)
pass
for item in eye_targets:
if item.hasAttr('RBlink'):
pass
else:
pm.addAttr(item,longName = 'R_blink', attributeType = 'double', defaultValue = 0.0, minValue = -1.0, maxValue = 1.0)
item.setAttr('RBlink', keyable = True)
if item.hasAttr('LBlink'):
pass
else:
pm.addAttr(item,longName = 'R_blink', attributeType = 'double', defaultValue = 0.0, minValue = -1.0, maxValue = 1.0)
item.setAttr('LBlink', keyable = True)
if item.hasAttr('pupilRadius'):
pass
else:
pm.addAttr(item, longName = 'RPupilRadius', attributeType = 'double', defaultValue = 1.0)
item.setAttr('RPupilRadius', keyable = True)
if item.hasAttr('RIrisRadius'):
pass
else:
pm.addAttr(item,longName = 'RIrisRadius', attributeType = 'double', defaultValue = 1.0)
item.setAttr('RIrisRadius', keyable = True)
if item.hasAttr('LIrisRadius'):
pass
else:
pm.addAttr(item,longName = 'LIrisRadius', attributeType = 'double', defaultValue = 1.0)
item.setAttr('LIrisRadius', keyable = True)
pm.addAttr(item,longName = 'LStretchX', attributeType = 'double', defaultValue = 1.0)
item.setAttr('LStretchX', keyable = True)
pm.addAttr(item,longName = 'RStretchY', attributeType = 'double', defaultValue = 1.0)
item.setAttr('RStretchY', keyable = True)
pm.addAttr(item,longName = 'RIrisShape', attributeType = 'double', defaultValue = 0.0)
item.setAttr('RIrisShape', keyable = True)
pm.addAttr(item,longName = 'RIrisShape', attributeType = 'double', defaultValue = 0.0)
item.setAttr('RIrisShape', keyable = True)
pm.addAttr(item,longName = 'RIrisAngle', attributeType = 'double', defaultValue = 0.0)
item.setAttr('RIrisAngle', keyable = True)
for item in eye_targets:
pm.addAttr(item,longName = 'irisShape', attributeType = 'double', defaultValue = 0.0)
item.setAttr('irisShape', keyable = True)
pm.addAttr(item,longName = 'irisX', attributeType = 'double', defaultValue = 1.0)
item.setAttr('irisX', keyable = True)
pm.addAttr(item,longName = 'irisY', attributeType = 'double', defaultValue = 1.0)
item.setAttr('irisY', keyable = True)
pm.addAttr(item,longName = 'irisShape', attributeType = 'double', defaultValue = 0.0)
item.setAttr('irisShape', keyable = True)
pm.addAttr(item,longName = 'irisX', attributeType = 'double', defaultValue = 1.0)
item.setAttr('irisX', keyable = True)
pm.addAttr(item,longName = 'irisY', attributeType = 'double', defaultValue = 1.0)
item.setAttr('irisY', keyable = True)
#update constraint offsets?
#parentConstraint -e -maintainOffset GenChar_lShoulderJ Skel_L_Shoulder_parentConstraint1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment