1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
| def Rig_Generate(self):
if self.Rig_Obj_Check(): return
self.Rig_Back_Btn.setEnabled(True)
Main_JNT_Num = int(self.Main_JNT_Num.text()) if self.Main_JNT_Num.text() != "" else 20 IK_JNT_Num = int(self.IK_JNT_Num.text()) if self.IK_JNT_Num.text() != "" else 20 Curve_Span_Num = int(self.Curve_Span_Num.text()) if self.Curve_Span_Num.text() != "" else 20
Geo_Name_Text = self.Geo_Name_Text.text() if self.Geo_Name_Text.text() != "" else "TengMan" Main_JNT_Name_Text = self.Main_JNT_Name_Text.text() if self.Main_JNT_Name_Text.text() != "" else "gan_joint" IK_JNT_Name_Text = self.IK_JNT_Name_Text.text() if self.IK_JNT_Name_Text.text() != "" else "ganJoint" Curve_Name_Text = self.Curve_Name_Text.text() if self.Curve_Name_Text.text() != "" else "gan" IK_CTRL_Name_Text = self.IK_CTRL_Name_Text.text() if self.IK_CTRL_Name_Text.text() != "" else "gan_ctrl" Start_Ctrl_Text = self.Start_Ctrl_Text.text() if self.Start_Ctrl_Text.text() != "" else "main2" End_IK_Text = self.End_IK_Text.text() if self.End_IK_Text.text() != "" else "main" Character_Ctrl_Text = self.Character_Ctrl_Text.text() if self.Character_Ctrl_Text.text() != "" else "Character"
styleSheet = self.IK_CTRL_ColorBtn.styleSheet().split("(")[1].split(",") r = float(styleSheet[0])/255 g = float(styleSheet[1])/255 b = float(styleSheet[2].split(")")[0])/255 IK_CTRL_ColorBtn = (r,g,b)
styleSheet = self.Start_Ctrl_ColorBtn.styleSheet().split("(")[1].split(",") r = float(styleSheet[0])/255 g = float(styleSheet[1])/255 b = float(styleSheet[2].split(")")[0])/255 Start_Ctrl_ColorBtn = (r,g,b)
styleSheet = self.End_IK_ColorBtn.styleSheet().split("(")[1].split(",") r = float(styleSheet[0])/255 g = float(styleSheet[1])/255 b = float(styleSheet[2].split(")")[0])/255 End_IK_ColorBtn = (r,g,b)
styleSheet = self.Character_Ctrl_ColorBtn.styleSheet().split("(")[1].split(",") r = float(styleSheet[0])/255 g = float(styleSheet[1])/255 b = float(styleSheet[2].split(")")[0])/255 Character_Ctrl_ColorBtn = (r,g,b)
cmds.select(self.Start_JNT) Start_JNT_Coordinate = cmds.xform(q=True,a=True,ws=True,piv=True)
cmds.select(self.End_JNT) End_JNT_Coordinate = cmds.xform(q=True,a=True,ws=True,piv=True) cmds.select(cl=True)
Xdistance = End_JNT_Coordinate[0] - Start_JNT_Coordinate[0] Ydistance = End_JNT_Coordinate[1] - Start_JNT_Coordinate[1] Zdistance = End_JNT_Coordinate[2] - Start_JNT_Coordinate[2]
cmds.circle( nr=(Xdistance, Ydistance, Zdistance), c=(End_JNT_Coordinate[0], End_JNT_Coordinate[1], End_JNT_Coordinate[2]),n=End_IK_Text,r=1) Main_Ctrl = cmds.ls(sl=True)[0] cmds.setAttr(Main_Ctrl + ".overrideEnabled",1)
if mel.eval("getApplicationVersionAsFloat;")>=2017: cmds.setAttr(Main_Ctrl + ".overrideRGBColors",1) cmds.setAttr(Main_Ctrl + ".overrideColorRGB",End_IK_ColorBtn[0],End_IK_ColorBtn[1],End_IK_ColorBtn[2]) else: cmds.setAttr( Main_Ctrl +".overrideRGBColors",0) cmds.setAttr( Main_Ctrl +".overrideColor",self.End_IK_ColorSlider.value()) cmds.setAttr(Main_Ctrl+".visibility",lock=True,keyable=False,channelBox=False) cmds.setAttr(Main_Ctrl+".sx",lock=True,keyable=False,channelBox=False) cmds.setAttr(Main_Ctrl+".sy",lock=True,keyable=False,channelBox=False) cmds.setAttr(Main_Ctrl+".sz",lock=True,keyable=False,channelBox=False) cmds.addAttr(ln="show_mod",at="double",min=0,max=1,dv=1) cmds.setAttr(Main_Ctrl+".show_mod",edit=True,keyable=True) cmds.addAttr(ln="grow",at="double",min=0,max=10,dv=10)
for Main_JNT in range(Main_JNT_Num): x = Xdistance * Main_JNT / (Main_JNT_Num-1) + Start_JNT_Coordinate[0] y = Ydistance * Main_JNT / (Main_JNT_Num-1) + Start_JNT_Coordinate[1] z = Zdistance * Main_JNT / (Main_JNT_Num-1) + Start_JNT_Coordinate[2] JNT = cmds.joint( p=(x, y, z), n = Main_JNT_Name_Text + str(Main_JNT+1)) cmds.setAttr( JNT + ".tx", k=False,cb=True ) cmds.setAttr( JNT + ".ty", k=False,cb=True ) cmds.setAttr( JNT + ".tz", k=False,cb=True ) cmds.setAttr( JNT + ".rx", k=False,cb=True ) cmds.setAttr( JNT + ".ry", k=False,cb=True ) cmds.setAttr( JNT + ".rz", k=False,cb=True ) cmds.setAttr( JNT + ".sx", k=False,cb=True ) cmds.setAttr( JNT + ".sy", k=False,cb=True ) cmds.setAttr( JNT + ".sz", k=False,cb=True ) cmds.setAttr( JNT + ".visibility", k=False,cb=True ) cmds.expression( s=JNT + ".sx = "+ Main_Ctrl +".grow/10/"+str(Main_JNT+1) ) cmds.expression( s=JNT + ".sy = "+ Main_Ctrl +".grow/10/"+str(Main_JNT+1) ) cmds.expression( s=JNT + ".sz = "+ Main_Ctrl +".grow/10/"+str(Main_JNT+1) ) if Main_JNT == 0: Start_Main_JNT = cmds.ls(sl=True)[0]
End_Main_JNT = cmds.ls(sl=True) cmds.select(Start_Main_JNT) cmds.select(End_Main_JNT,tgl=True) ikList = cmds.ikHandle(sol="ikSplineSolver" ) cmds.select(cl=True) CtrlList = [] for IK_JNT in range(IK_JNT_Num): x = Xdistance * IK_JNT / (IK_JNT_Num-1) + Start_JNT_Coordinate[0] y = Ydistance * IK_JNT / (IK_JNT_Num-1) + Start_JNT_Coordinate[1] z = Zdistance * IK_JNT / (IK_JNT_Num-1) + Start_JNT_Coordinate[2] cmds.joint( p=(x, y, z), n = IK_JNT_Name_Text + str(IK_JNT+1))
Curent_JNT = cmds.ls(sl=True)[0]
IK_JNT_Coordinate = cmds.xform(q=True,ws=True,t=True)
cmds.circle( nr=(Xdistance, Ydistance, Zdistance), c=(IK_JNT_Coordinate[0], IK_JNT_Coordinate[1], IK_JNT_Coordinate[2]),n=IK_CTRL_Name_Text+str(IK_JNT+1),r=0.4)
IK_Ctrl = cmds.ls(sl=True)[0]
cmds.setAttr( IK_Ctrl +".overrideEnabled",1)
if mel.eval("getApplicationVersionAsFloat;")>=2017: cmds.setAttr( IK_Ctrl +".overrideRGBColors",1) cmds.setAttr( IK_Ctrl +".overrideColorRGB",IK_CTRL_ColorBtn[0],IK_CTRL_ColorBtn[1],IK_CTRL_ColorBtn[2]) else: cmds.setAttr( IK_Ctrl +".overrideRGBColors",0) cmds.setAttr( IK_Ctrl +".overrideColor",self.IK_CTRL_ColorSlider.value())
cmds.CenterPivot() cmds.makeIdentity( apply=True, t=1, r=1, s=1, n=2 )
CtrlList.append(cmds.ls(sl=True)[0])
cmds.parentConstraint( CtrlList[IK_JNT] , Curent_JNT )
cmds.select(Curent_JNT) cmds.setAttr( Curent_JNT + ".tx", k=False,cb=True ) cmds.setAttr( Curent_JNT + ".ty", k=False,cb=True ) cmds.setAttr( Curent_JNT + ".tz", k=False,cb=True ) cmds.setAttr( Curent_JNT + ".rx", k=False,cb=True ) cmds.setAttr( Curent_JNT + ".ry", k=False,cb=True ) cmds.setAttr( Curent_JNT + ".rz", k=False,cb=True ) cmds.setAttr( Curent_JNT + ".sx", k=False,cb=True ) cmds.setAttr( Curent_JNT + ".sy", k=False,cb=True ) cmds.setAttr( Curent_JNT + ".sz", k=False,cb=True ) cmds.setAttr( Curent_JNT + ".visibility", k=False,cb=True )
if IK_JNT == 0: Start_IK_JNT = cmds.ls(sl=True)[0]
cmds.select(ikList[2]) cmds.rebuildCurve( rt=0, s=Curve_Span_Num ) cmds.select(Start_IK_JNT,hi=True) cmds.select(ikList[2],tgl=True) cmds.optionVar(iv=('bindTo',2)) cmds.optionVar(iv=('skinMethod',1)) cmds.optionVar(iv=('multipleBindPosesOpt',1)) cmds.optionVar(iv=('bindMethod',1)) cmds.optionVar(iv=('removeUnusedInfluences',0)) cmds.optionVar(iv=('colorizeSkeleton',0)) cmds.optionVar(iv=('maxInfl',3)) cmds.optionVar(iv=('normalizeWeights',2)) cmds.optionVar(iv=('obeyMaxInfl',2))
cmds.SmoothBindSkin()
cmds.select(Start_Main_JNT,hi=True) cmds.select(self.Rig_Obj,tgl=True) cmds.SmoothBindSkin()
if self.Delete_CheckBox.isChecked(): cmds.delete(self.Start_JNT) cmds.delete(self.End_JNT) cmds.select(self.Rig_Obj) Geo_Grp = cmds.group(n=Geo_Name_Text+"_geo") CtrlList = list(reversed(CtrlList)) Grp = "" for Ctrl in CtrlList: cmds.select(Ctrl) cmds.group(n=Ctrl+"_C") IKFKC_Grp = cmds.group(n=Ctrl+"_IKFKC") if Grp != "": cmds.parent( Grp, IKFKC_Grp ) cmds.select(IKFKC_Grp) Grp = cmds.group(n=Ctrl+"_G")
cmds.select(Start_IK_JNT) temp = cmds.group(n=Start_IK_JNT+"_G") cmds.setAttr(temp+".visibility",0) cmds.setAttr(temp+".visibility",lock=True) cmds.setAttr( temp + ".tx", lock=True ) cmds.setAttr( temp + ".ty", lock=True ) cmds.setAttr( temp + ".tz", lock=True ) cmds.setAttr( temp + ".rx", lock=True ) cmds.setAttr( temp + ".ry", lock=True ) cmds.setAttr( temp + ".rz", lock=True ) cmds.setAttr( temp + ".sx", lock=True ) cmds.setAttr( temp + ".sy", lock=True ) cmds.setAttr( temp + ".sz", lock=True ) cmds.select(Grp,tgl=True) MotionSystem_Grp = cmds.group(n="MotionSystem")
cmds.select(Start_Main_JNT) Start_Main_JNT_Grp = cmds.group(n=Start_Main_JNT+"_G") cmds.setAttr( Start_Main_JNT_Grp+".visibility",0) cmds.setAttr( Start_Main_JNT_Grp+".visibility",lock=True) cmds.setAttr( Start_Main_JNT_Grp + ".tx", lock=True ) cmds.setAttr( Start_Main_JNT_Grp + ".ty", lock=True ) cmds.setAttr( Start_Main_JNT_Grp + ".tz", lock=True ) cmds.setAttr( Start_Main_JNT_Grp + ".rx", lock=True ) cmds.setAttr( Start_Main_JNT_Grp + ".ry", lock=True ) cmds.setAttr( Start_Main_JNT_Grp + ".rz", lock=True ) cmds.setAttr( Start_Main_JNT_Grp + ".sx", lock=True ) cmds.setAttr( Start_Main_JNT_Grp + ".sy", lock=True ) cmds.setAttr( Start_Main_JNT_Grp + ".sz", lock=True ) DeformationSystem_Grp = cmds.group(n="DeformationSystem")
cmds.circle( nr=(Xdistance, Ydistance, Zdistance), c=(Start_JNT_Coordinate[0], Start_JNT_Coordinate[1], Start_JNT_Coordinate[2]),n=Start_Ctrl_Text,r=1)
Main2_Ctrl = cmds.ls(sl=True)[0]
cmds.setAttr(Main2_Ctrl + ".overrideEnabled",1) if mel.eval("getApplicationVersionAsFloat;")>=2017: cmds.setAttr(Main2_Ctrl + ".overrideRGBColors",1) cmds.setAttr(Main2_Ctrl + ".overrideColorRGB",Start_Ctrl_ColorBtn[0],Start_Ctrl_ColorBtn[1],Start_Ctrl_ColorBtn[2]) else: cmds.setAttr( Main2_Ctrl +".overrideRGBColors",0) cmds.setAttr( Main2_Ctrl +".overrideColor",self.Start_Ctrl_ColorSlider.value())
cmds.setAttr(Main2_Ctrl+".visibility",lock=True,keyable=False,channelBox=False) cmds.setAttr(Main2_Ctrl+".sx",lock=True,keyable=False,channelBox=False) cmds.setAttr(Main2_Ctrl+".sy",lock=True,keyable=False,channelBox=False) cmds.setAttr(Main2_Ctrl+".sz",lock=True,keyable=False,channelBox=False)
cmds.select(DeformationSystem_Grp) cmds.select(MotionSystem_Grp,tgl=True) cmds.select(Main2_Ctrl,tgl=True) cmds.parent()
cmds.pickWalk( direction='up' ) Main2_Ctrl = cmds.ls(sl=True)[0] Main2_Ctrl_C = cmds.group(n=Main2_Ctrl+"_C") Main2_Ctrl_G = cmds.group(n=Main2_Ctrl+"_G") Main2_Ctrl = cmds.ls(sl=True)[0]
cmds.setAttr(Main_Ctrl+".grow",edit=True,keyable=True) cmds.connectAttr(Main_Ctrl+".show_mod",Geo_Grp+".visibility") cmds.parent(Main2_Ctrl,Main_Ctrl) cmds.pickWalk( direction='up' ) cmds.group(n=Main_Ctrl+"_C") cmds.group(n=Main_Ctrl+"_G")
Main_Ctrl_G = cmds.ls(sl=True)[0]
cmds.curve(d=1, p=[(-1, 0,-1), (-1, 0,1), (1, 0, 1), (1,0, -1), (-1, 0,-1)], k=[0,1,2,3,4] ,n=Character_Ctrl_Text)
Character = cmds.ls(sl=True)[0] cmds.setAttr(Character + ".overrideEnabled",1)
if mel.eval("getApplicationVersionAsFloat;")>=2017: cmds.setAttr(Character + ".overrideRGBColors",1) cmds.setAttr(Character + ".overrideColorRGB",Character_Ctrl_ColorBtn[0],Character_Ctrl_ColorBtn[1],Character_Ctrl_ColorBtn[2]) else: cmds.setAttr( Character +".overrideRGBColors",0) cmds.setAttr( Character +".overrideColor",self.Character_Ctrl_ColorSlider.value())
cmds.setAttr(Character+".visibility",lock=True,keyable=False,channelBox=False) cmds.xform(a=True,ws=True,t=(End_JNT_Coordinate[0], End_JNT_Coordinate[1], End_JNT_Coordinate[2])) cmds.parent(Main_Ctrl_G,Character) cmds.pickWalk( direction='up' ) cmds.group(n=Character+"_C") cmds.group(n=Character+"_G") Grp = cmds.group(n=Geo_Name_Text+"_rig")
cmds.setAttr(ikList[2]+".visibility",0) cmds.setAttr(ikList[2]+".visibility",lock=True,keyable=False,channelBox=False) cmds.setAttr(ikList[0]+".visibility",0) cmds.setAttr(ikList[0]+".visibility",lock=True) cmds.setAttr( ikList[0] + ".tx", lock=True ) cmds.setAttr( ikList[0] + ".ty", lock=True ) cmds.setAttr( ikList[0] + ".tz", lock=True ) cmds.setAttr( ikList[0] + ".rx", lock=True ) cmds.setAttr( ikList[0] + ".ry", lock=True ) cmds.setAttr( ikList[0] + ".rz", lock=True ) cmds.setAttr( ikList[0] + ".sx", lock=True ) cmds.setAttr( ikList[0] + ".sy", lock=True ) cmds.setAttr( ikList[0] + ".sz", lock=True ) cmds.setAttr( ikList[0] + ".poleVectorX", lock=True ) cmds.setAttr( ikList[0] + ".poleVectorY", lock=True ) cmds.setAttr( ikList[0] + ".poleVectorZ", lock=True ) cmds.setAttr( ikList[0] + ".offset", lock=True ) cmds.setAttr( ikList[0] + ".roll", lock=True ) cmds.setAttr( ikList[0] + ".twist", lock=True ) cmds.setAttr( ikList[0] + ".ikBlend", lock=True ) cmds.rename(ikList[2],Curve_Name_Text) cmds.select(ikList[0]) cmds.select(Curve_Name_Text,tgl=True) cmds.group(n="IK_G") cmds.group(n="other_G") cmds.pickWalk( direction='up' ) cmds.select(Grp,tgl=True) cmds.parent() Other_Grp = cmds.pickWalk( direction='up' )
cmds.select(Geo_Grp) self.Main_Grp = cmds.group(n=Geo_Name_Text+"_all") cmds.select(Other_Grp) cmds.select(self.Main_Grp,tgl=True) cmds.parent()
|