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
   | import pymel.core as pmc
 
#On attribut les fonctions aux variables
curveShape = str()
joints = []
 
def CS_UI():
 
    #On supprime la fenetre si elle existe
    if pmc.window("Connect_Stretch", exists = True):
        pmc.deleteUI("Connect_Stretch")
 
    #Creation de la fenetre
    window = pmc.window("Connect_Stretch", title = "Connect Stretch", w = 100, h = 120, mnb = False, mxb = False, sizeable = False)
 
    #On cree l'interface principale
    mainLayout = pmc.columnLayout(w = 120, h = 120)
 
 
    #Boutons
    gridOne = pmc.gridLayout( nc = 2, cwh = (120,30), parent = mainLayout )
    gridTwo = pmc.gridLayout( nc = 2, cwh = (120,30), parent = mainLayout )
    gridThird = pmc.gridLayout( nc = 2, cwh = (120,30), parent = mainLayout )
    gridFour = pmc.gridLayout( nc = 2, cwh = (120,30), parent = mainLayout )
 
    b1 = pmc.button(label = "Select Curve", w = 205, h = 30, c = 'ConnectStretch.CS_Curve()', parent = gridOne )
 
    b2 = pmc.button(label = "Select Joints", w = 205, h = 30, c = 'ConnectStretch.CS_Joint()', parent = gridTwo )
 
    b3 = pmc.button(label = "Let's stretch !", w = 205, h = 30, c = 'ConnectStretch.CS_Process()', parent = gridThird )
 
    b4 = pmc.button(label = "Cancel", w = 205, h = 30, c = 'ConnectStretch.CS_CloseUI()', parent = gridFour )
 
    #Affichage de la fenetre
    pmc.showWindow(window)
 
 
def CS_CloseUI():
    pmc.deleteUI("Connect_Stretch")
 
 
def CS_Curve():
    global curveShape
    Selected = pmc.ls(sl=1)
 
    if not len(Selected) > 1:
            if not len(Selected) == 0:
                curveShape = Selected[0].getShape()
    else:
        print("Merci de ne selectionner qu'une seule curve")
 
 
def CS_Joint():
    global joints
    joints = pmc.ls(sl=1)
 
 
def CS_Process():
    Name=curveShape.split("_")[0]
 
    curveInfo=pmc.createNode("curveInfo", n=Name+"_Info")
    curveStretch=pmc.createNode("multiplyDivide", n=Name+"_Stretch")
    curveStretchPow=pmc.createNode("multiplyDivide", n=Name+"_StretchPow")
    curveSquash=pmc.createNode("multiplyDivide", n=Name+"_Squash")
    VolumeConservation_Blend=pmc.createNode("blendColors", n=Name+"_VolumeConservation_Blend")
 
    pmc.connectAttr( curveShape+'.worldSpace', curveInfo.inputCurve, force=1)
    pmc.connectAttr( curveInfo+'.arcLength', curveStretch.input1.input1X, force=1)
    pmc.connectAttr( curveStretch+'.output.outputX', curveStretchPow.input1.input1X, force=1)
    pmc.connectAttr( curveStretchPow+'.output.outputX', curveSquash.input2.input2X, force=1)
    pmc.connectAttr( curveSquash+'.output.outputX', VolumeConservation_Blend.color1.color1R, force=1)
 
    pmc.setAttr(curveStretch.input2.input2X, pmc.getAttr(curveInfo+'.arcLength') )
    pmc.setAttr(curveStretch.operation, 2)
    pmc.setAttr(curveStretchPow.operation, 3)
    pmc.setAttr(curveStretchPow.input2.input2X, 0.5)
    pmc.setAttr(curveSquash.operation, 2)
    pmc.setAttr(curveSquash.input1.input1X, 1)
    pmc.setAttr(VolumeConservation_Blend.color2.color2R, 1)
    #On connecte les joints au multiply
 
    for joint in joints:
        pmc.connectAttr (curveStretch.outputX, joint.scaleX, force=1)
        pmc.connectAttr (VolumeConservation_Blend.outputR, joint.scaleY, force=1)
        pmc.connectAttr (VolumeConservation_Blend.outputR, joint.scaleZ, force=1) | 
Partager