Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.24 KB | None | 0 0
  1. #Jack Frost Hair System
  2. import sys
  3. from mcRig.Utilities.Name import name_count
  4. from mcRig.UI.UITools import AskName
  5. import mcRig.RigTools.Ribbon as RIB
  6. ribbon = RIB()
  7. import mcRig.CtrlTools as CT
  8. my_ctrl = CT.Control()
  9. import mcRig.RigTools.Attribute as ATTR
  10.  
  11.  
  12.  
  13. def convert_VecPth_to_hair_rig(input = False):
  14.  
  15. if not input:
  16. input = cmds.ls(sl=True)
  17.  
  18. for every in input:
  19. #Make a jointFollowChain on the Ribbon
  20. stuff = cmds.listRelatives(every,c=True)
  21. trgts = [x for x in stuff if '_POS_' in x]
  22. trgts.sort()
  23. print(trgts)
  24. jnts = []
  25. last = False
  26. for e in trgts:
  27. cmds.select(cl=True)
  28. jnt2 = cmds.joint(n=e.replace('POS','Path').replace('trgt','Offset_Jnt'))
  29. jnt = cmds.joint(n=e.replace('POS','Path').replace('trgt','Jnt'),rad = .5)
  30. cmds.delete(cmds.parentConstraint(e,jnt2,mo=False))
  31. if last:
  32. cmds.parent(jnt2,last)
  33. else:
  34. grp = cmds.group(em=True, n=e.replace('POS','Path').replace('trgt','RIG'))
  35. cmds.delete(cmds.parentConstraint(jnt,grp,mo=False))
  36. cmds.parent(jnt2,grp)
  37. last=jnt
  38. jnts.append(jnt)
  39.  
  40. cmds.makeIdentity(jnts[0], a = True, r = True, pn = True)
  41.  
  42. #Make a control system that follows the ribbon Joints
  43. last = False
  44. for e in jnts:
  45. cmds.parentConstraint(e.replace('Jnt','trgt').replace('Path','POS'),e,mo=True)
  46.  
  47. #####
  48. #ctrl = cst.BuildControl(Type = 'D3Cube', Color = 'pink', Size = 1, Snap = e, Name = e.replace('Jnt','Ctrl'))
  49. #cst.TopGrp(AddName='Drv', Input = [ctrl])
  50. #cst.TopGrp(Search='Drv',Replace='Offset')
  51. #tweak = cst.BuildControl(Type = 'D3Cube', Color = 'pink', Size = .5, Snap = e, Name = e.replace('Jnt','Ctrl'))
  52. #cst.TopGrp(AddName='Offset', Input = [tweak])
  53. #####
  54.  
  55. my_ctrl.name = e.replace('Jnt','Ctrl')
  56. my_ctrl.idcode = '2D_Pin_Circle'
  57. my_ctrl.color = 'yellow'
  58. my_ctrl.size = 3
  59. my_ctrl.snapto = e
  60. ctrl = my_ctrl.make_control()
  61. my_ctrl.top_group(add='Drv', input=[ctrl])
  62. my_ctrl.top_group(searchfor = 'Drv',replacewith='Offset')
  63.  
  64. my_ctrl.name = e.replace('Jnt','Tweak_Ctrl')
  65. my_ctrl.idcode = '2D_Simple_Circle'
  66. my_ctrl.color = 'blue'
  67. my_ctrl.size = 1
  68. my_ctrl.snapto = e
  69. tweak = my_ctrl.make_control()
  70. my_ctrl.top_group(add='Offset', input=[tweak])
  71.  
  72. cmds.parent(tweak+'_Offset_Grp',ctrl)
  73.  
  74. cmds.select(cl=True)
  75. bnd = cmds.joint(n=e.replace('Jnt','Bnd').replace('_Path_','_'))
  76. cmds.parentConstraint(tweak,bnd,mo=False)
  77. cmds.scaleConstraint(tweak,bnd,mo=False)
  78. if not cmds.objExists(jnts[0].replace('Jnt','Bnd')+'_Grp'):
  79. cmds.group(em=True, n=jnts[0].replace('Jnt','Bnd')+'_Grp')
  80. cmds.parent(bnd,jnts[0].replace('Jnt','Bnd')+'_Grp')
  81.  
  82. if last:
  83. cmds.parent(ctrl+'_Offset_Grp',last)
  84.  
  85. cmds.connectAttr(e+'.r',ctrl+'_Drv_Grp.r')
  86. cmds.connectAttr(e+'.t',ctrl+'_Drv_Grp.t')
  87.  
  88. last = ctrl
  89.  
  90. return(jnts[0].replace('Jnt','Bnd')+'_Grp', jnts[0].replace('Jnt','Ctrl_Offset')+'_Grp', jnts[0].replace('Jnt','RIG'))
  91.  
  92.  
  93.  
  94.  
  95.  
  96. def nurbs_to_hair(input = False, name = False, jointCount = False, anti_stretch = True):
  97. #select all of the ribbons you wish to turn into hair
  98. if not input:
  99. input = cmds.ls(sl=True)
  100.  
  101. #give a name for the system to name the ribbons for you just to make sure they are proper.
  102. if not name:
  103. name = AskName(Message = 'Name for the Hair System', Title = 'Name')
  104. check = name_count(name + '_01_Ribn')
  105. count = check[0]+1
  106.  
  107. ribn_list=[]
  108. for each in input:
  109. new_name = cmds.rename(each, name+'_%02d_Ribn' % count)
  110. ribn_list.append(new_name)
  111. count = count+1
  112.  
  113. #We will then for each of the ribbons make a vector path system
  114.  
  115. vecPath_list = []
  116. if not jointCount:
  117. jointCount = int(AskName(Message = 'How many Joints in system', Title = 'Count'))
  118. for each in ribn_list:
  119. build = ribbon.ribbon_vector_setup(uiclear=True, input=[each], jointCount=jointCount)
  120. vecPath_list.append(build['container'])
  121.  
  122. #For each of the vecor path systems we will make a hair system
  123. rigs = []
  124. ctrls = []
  125. bnds = []
  126. for each in vecPath_list:
  127. build = convert_VecPth_to_hair_rig(input = [each]) # Bnd, Ctrl, Rig
  128. bnds.append(build[0])
  129. ctrls.append(build[1])
  130. rigs.append(build[2])
  131.  
  132.  
  133. anti_stretch_list = [x for x in cmds.listRelatives(each, c=True, type = 'dagContainer') if x.endswith('CrvPth')]
  134. moPth_list = cmds.container(anti_stretch_list, q=True, nl=True)
  135.  
  136. #moPth_list no holds all the nodes that we need to install the anti stretch system to
  137. #add in the anti stretch system
  138. if anti_stretch:
  139. # for each motionPath we will need to find out what curve is attached to it.
  140. for moPth in moPth_list:
  141. curve = cmds.listConnections(moPth+'.geometryPath')[0]
  142. # if set up dose not exists
  143. ref_info = curve.replace('_Crv', '_AS_Ref_Crv_CI')
  144. curve_info = curve.replace('_Crv', '_AS_Crv_CI')
  145. ref_md = curve.replace('_Crv', '_AS_MD')
  146. if not cmds.objExists(ref_md):
  147. # Duplicate that curve and put it in a reference group
  148. ref = cmds.duplicate(curve, n=curve.replace('_Crv', '_AS_Ref_Crv'))[0]
  149. # Make a curve info node to get the length of both curves.
  150. cmds.createNode('curveInfo', n=ref_info)
  151. cmds.createNode('curveInfo', n=curve_info)
  152. cmds.createNode('multiplyDivide',n=ref_md)
  153. # Connect them together with a MD to get the offset.
  154. cmds.connectAttr(curve+'.worldSpace', curve_info+'.inputCurve')
  155. cmds.connectAttr(ref+'.worldSpace', ref_info+'.inputCurve')
  156. cmds.connectAttr(ref_info+'.arcLength', ref_md+'.input1X')
  157. cmds.connectAttr(curve_info+'.arcLength', ref_md+'.input2X')
  158. cmds.setAttr(ref_md+'.operation', 2)
  159. # Set up the control override if wanted
  160. cmds.container(each, e = True, an=[ref_info, curve_info, ref_md])
  161.  
  162. if cmds.objExists('Utility_Cns_Grp'):
  163. cmds.scaleConstraint('Utility_Cns_Grp', ref, mo=True)
  164.  
  165.  
  166. # Connect the strand driver system to the motion path with the md offset 0-1
  167. # make a md for each moPth and then set that to the path value, and then drive the other with the ref_md output
  168. as_md = cmds.createNode('multiplyDivide',n=moPth+'_AS_Offset_MD')
  169. cmds.container(each, e = True, an=[as_md])
  170. cmds.setAttr(as_md+'.input1X', cmds.getAttr(moPth+'.uValue'))
  171. cmds.connectAttr(ref_md+'.outputX', as_md+'.input2X')
  172. cmds.connectAttr(as_md+'.outputX', moPth+'.uValue')
  173.  
  174.  
  175. cmds.group(ribn_list, vecPath_list, n=name+'_Utl_Grp')
  176. cmds.group(bnds, n=name+'_Bnd_Jnt_Grp')
  177. cmds.group(ctrls, n=name+'_Ctrl_Grp')
  178. cmds.group(rigs, n=name+'_RIG_Grp')
  179. for rig in rigs:
  180. cmds.setAttr(rig+'.inheritsTransform', 0)
  181.  
  182.  
  183. attr = ATTR()
  184. attr.type = 'enum'
  185. attr.name = 'HairControls'
  186. attr.default = 1
  187. attr.keyable = False
  188. attr.object = 'Control_Ctrl'
  189. attr.make_attr()
  190. cmds.connectAttr('Control_Ctrl.HairControls', name+'_Ctrl_Grp.v')
  191.  
  192. # set up the chain blends to and from the ribbons
  193. attr = ATTR()
  194. for each in ctrls:
  195. stuff = [x for x in cmds.listRelatives(each, ad=True) if x.endswith('_Ctrl')]
  196. final = [x for x in stuff if 'Tweak' not in x]
  197. #these are the controls we need to add a blend to for turning the chain off from the rest.
  198. my_ctrl.color = 'red'
  199. my_ctrl.name = final[0]
  200. my_ctrl.set_coloroverride()
  201.  
  202. attr.type = 'float'
  203. attr.name = 'Follow'
  204. attr.min = 0
  205. attr.max = 1
  206. attr.default = 1
  207. attr.object = final[0]
  208. attr.make_attr()
  209.  
  210. #adjust the controls and connect them to the blends
  211. nodes = []
  212. for ctrl in final:
  213. if ctrl != final[0]:
  214. cmds.rotate(90, 0, 0, ctrl+'.cv[0:*]')
  215.  
  216. if ctrl != final[-1]:
  217. # bc for the trans and rot
  218. drv = cmds.listRelatives(ctrl, p=True)[0]
  219. tbc = cmds.createNode('blendColors', n=drv.replace('Grp', 'Follow_T_BC'))
  220. rbc = cmds.createNode('blendColors', n=drv.replace('Grp', 'Follow_R_BC'))
  221. # set the bc to the current values for trans and rot
  222. cmds.setAttr(tbc+'.color2R', cmds.getAttr(drv+'.tx'))
  223. cmds.setAttr(tbc+'.color2G', cmds.getAttr(drv+'.ty'))
  224. cmds.setAttr(tbc+'.color2B', cmds.getAttr(drv+'.tz'))
  225.  
  226. cmds.setAttr(rbc+'.color2R', cmds.getAttr(drv+'.rx'))
  227. cmds.setAttr(rbc+'.color2G', cmds.getAttr(drv+'.ry'))
  228. cmds.setAttr(rbc+'.color2B', cmds.getAttr(drv+'.rz'))
  229. # connect the final[0] to the bc inputs. 1 is follow
  230. cmds.connectAttr(final[0]+'.Follow', tbc+'.blender')
  231. cmds.connectAttr(final[0]+'.Follow', rbc+'.blender')
  232.  
  233. driver = cmds.listConnections(drv+'.t')[0]
  234. # connect the incomming data to the bc in color 1
  235. cmds.connectAttr(driver+'.t', tbc+'.color1')
  236. cmds.connectAttr(driver+'.r', rbc+'.color1')
  237. # set the bc color 2 to the current values for trans and rot
  238. # connect the out of blend to the origanal driver gorup
  239. cmds.connectAttr(tbc+'.output', drv+'.t', f=True)
  240. cmds.connectAttr(rbc+'.output', drv+'.r', f=True)
  241.  
  242. nodes.append(tbc)
  243. nodes.append(rbc)
  244.  
  245. cmds.container(each.replace('_Path_', '_Ribn_Setup_').replace('_Ctrl_Offset_Grp', '_VecPth'), e = True, an=nodes)
  246. cmds.setAttr(each+'.inheritsTransform', 0)
  247.  
  248. # now we can override the above group inputs with a md system for translate and rotate.
  249.  
  250. #Make nurbs strips like normal.
  251. #then select them and run this
  252. # or supply input with a list of the nurbs surfaces.
  253. # once built i can have a deformer on the nurbs (skin fk chain), then i can move the deformer and all the hair groups and it shoudl move and stay together
  254. # each chain has a red tip, this is where you can blend the fk chain on and off from the ribbon system, when off only the first control follows the ribbon, so skinning of the ribbon is important here
  255. nurbs_to_hair(input = False, name = False, jointCount = False, anti_stretch = True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement