Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def getDistance(a, b): # d = getDistance(a,b)
- pointA = a.getTranslation()
- pointB = b.getTranslation()
- d = math.sqrt( math.pow( pointA[0] - pointB[0], 2) + math.pow( pointA[1] - pointB[1], 2) + math.pow( pointA[2] - pointB[2], 2) )
- return d
- #__________________________________________
- import time
- start = time.clock()
- elapsed = (time.clock() - start)
- print "done in:", elapsed,
- #__________________________________________
- # Snapper
- # cwisbg.com
- from pymel.core import *
- sl = selected()
- tp =pointConstraint(sl[1], sl[0])
- to = orientConstraint(sl[1], sl[0])
- delete(tp)
- delete(to)
- select(cl=1)
- select(sl[0])
- #__________________________________________
- # Locator at pivot
- # cwisbg.com
- from pymel.core import *
- currentSceneScale = currentUnit(q=1, l=1)
- tempSceneScale = currentUnit(l = "cm")
- def getPiv(s, type):
- if type == "transform":
- papCheck = listRelatives(s,p=1)
- if papCheck:
- try:
- parent(s,w=1)
- rot = s.getRotation()
- parent(s, papCheck)
- except:
- #print "could not get Rotation"
- rot = s.getRotation()
- #rot = [0,0,0]
- pass
- else:
- rot = s.getRotation()
- else:
- rot = [0,0,0]
- select(s)
- setToolTo('Move')
- piv = manipMoveContext('Move', q=True, p=True,m=2)
- return piv, rot
- sl = selected()
- if sl:
- type = nodeType(sl[0])
- if type == "mesh":
- t , r = getPiv(sl, type)
- l = spaceLocator(p = (0,0,0), n = "{0}_saveLocation".format(sl[0]))
- move(l, t, ws=1)
- rotate(l, r)
- else:
- for s in sl:
- type = nodeType(s)
- t , r = getPiv(s, type)
- l = spaceLocator(p = (0,0,0), n = "{0}_saveLocation".format(s))
- move(l, t, ws=1)
- rotate(l, r)
- else:
- l = spaceLocator(p = (0,0,0))
- currentUnit(l = currentSceneScale)
- print "done"
- #__________________________________________
- # Retarget Buffer
- from pymel.core import *
- def getPiv(s):
- currentSceneScale = currentUnit(q=1, l=1)
- tempSceneScale = currentUnit(l = "cm")
- select(s)
- setToolTo('Move')
- piv = manipMoveContext('Move', q=True, p=True,m=2)
- currentUnit(l = currentSceneScale)
- return piv
- def makeBufferGrp():
- sl = selected()
- for s in sl:
- name = s.split("|")[-1]
- grpCheck = ls("{0}_bufferGrp".format(name))
- if grpCheck:
- p = listRelatives(grpCheck,p=1)
- c = listRelatives(grpCheck,c=1)
- if p:
- parent(c,p)
- else:
- parent(c, w=1)
- delete(grpCheck)
- pap = listRelatives(s,p=1)
- if pap:
- g = group(n="{0}_bufferGrp".format(name),em=1,p = pap[0])
- #g = group(n="{0}_bufferGrp".format(name),em=1,w=1)
- #makeIdentity( g, a=1,t=1,r=1,s=1, n=0)
- else:
- g = group(n="{0}_bufferGrp".format(name),em=1,w=1)
- print "freezing",g
- #makeIdentity( g, a=1,t=1,r=1,s=1, n=0)
- pc = parentConstraint(s,g)
- delete(pc)
- makeIdentity( g, a=1,t=1,r=1,s=1, n=0)
- parent(s, g)
- #parent(g, pap[0])
- def removeBufferGrp():
- sl = selected()
- for s in sl:
- name = s.split("|")[-1]
- grpCheck = ls("{0}_bufferGrp".format(name))
- if grpCheck:
- p = listRelatives(grpCheck,p=1)
- c = listRelatives(grpCheck,c=1)
- if p:
- parent(c,p)
- else:
- parent(c, w=1)
- delete(grpCheck)
- def makeConnections():
- fsl = flipSl.getValue()
- dc = directConnectBox.getValue()
- m = mOffset.getValue()
- fAndT = parentConstraintBox.getValue()
- sl = selected()
- if len(sl) == 2:
- if fsl:
- target = sl[1]
- ctrl = sl[0]
- bufferGrp = listRelatives(sl[0], p=1)
- name = sl[0].split("|")[-1]
- else:
- target = sl[0]
- ctrl = sl[1]
- bufferGrp = listRelatives(sl[1], p=1)[0]
- name = sl[1].split("|")[-1]
- oCheck = ls("{0}_orientConstraint".format(name))
- if not dc:
- target = listRelatives(target, p=1)[0]
- if oCheck:
- delete(oCheck)
- if m:
- offsetObject = ctrl
- else:
- offsetObject = target
- saveOffset = spaceLocator(p = (0,0,0))
- pc = parentConstraint(offsetObject, saveOffset)
- delete(pc)
- if fAndT:
- o = parentConstraint(target, bufferGrp, n = "{0}_parentConstraint".format(name), mo = m)
- else:
- #___________________________________X_____________________________
- xx = xBoxX.getValue()
- xy = xBoxY.getValue()
- xz = xBoxZ.getValue()
- bufferGrp = bufferGrp[0]
- print target, bufferGrp, ctrl
- if xx:
- target.rotateX >> bufferGrp.rotateX
- print "connect x to x"
- if xy:
- target.rotateX >> bufferGrp.rotateY
- print "connect x to y"
- if xz:
- target.rotateX >> bufferGrp.rotateZ
- print "connect x to z"
- #___________________________________Y_____________________________
- yx = yBoxX.getValue()
- yy = yBoxY.getValue()
- yz = yBoxZ.getValue()
- if yx:
- target.rotateY >> bufferGrp.rotateX
- if yy:
- target.rotateY >> bufferGrp.rotateY
- if yz:
- target.rotateY >> bufferGrp.rotateZ
- #___________________________________Y_____________________________
- zx = zBoxX.getValue()
- zy = zBoxY.getValue()
- zz = zBoxZ.getValue()
- if zx:
- target.rotateZ >> bufferGrp.rotateX
- if zy:
- target.rotateZ >> bufferGrp.rotateY
- if zz:
- target.rotateZ >> bufferGrp.rotateZ
- #target.rotate >> bufferGrp[0].rotate
- o = orientConstraint(saveOffset, ctrl, n = "{0}_orientConstraint".format(name), mo = 0)
- delete(o)
- delete(saveOffset)
- setAttr(ctrl+".translateX",0)
- setAttr(ctrl+".translateY",0)
- setAttr(ctrl+".translateZ",0)
- setAttr(ctrl+".rotateX",0)
- setAttr(ctrl+".rotateY",0)
- setAttr(ctrl+".rotateZ",0)
- else:
- print "please select stuff"
- def unMakeConnections():
- sl = selected()
- for s in sl:
- ctrl = listRelatives(s, p=1)[0]
- print ctrl
- disconnectAttr(ctrl.rotateX)
- disconnectAttr(ctrl.rotateY)
- disconnectAttr(ctrl.rotateZ)
- name = s.split("|")[-1]
- pCheck = ls("{0}_parentConstraint".format(name))
- oCheck = ls("{0}_orientConstraint".format(name))
- if oCheck:
- delete(oCheck)
- if pCheck:
- delete(pCheck)
- rotate(ctrl, 0,0,0)
- def flipSelection():
- x = flipSl.getValue()
- if not x:
- slTip.setLabel("Target - Control")
- else:
- slTip.setLabel("Control - Target")
- print "flipping selection", x
- def bakeAnim():
- print "baking animation"
- sl = selected()
- if len(sl) < 1:
- print "select Something"
- else:
- bakeList = []
- for s in sl:
- name = s.split("|")[-1:][0]
- grpCheck = ls("{0}_bufferGrp".format(name))
- bakeList.append(grpCheck)
- tStart = playbackOptions(q=1,ast=1)
- tEnd = playbackOptions(q=1,aet=1)
- bakeResults(bakeList, simulation=1, t = (tStart,tEnd),at="rotate",sb = 1,dic = 1,preserveOutsideKeys=1,sparseAnimCurveBake=0,
- removeBakedAttributeFromLayer=0, bakeOnOverrideLayer=1,controlPoints =0, s=1)
- print "done baking animation"
- def bakeJointAnim():
- print "baking animation"
- sl = selected()
- if len(sl) < 1:
- print "select Something"
- else:
- bakeList = []
- tStart = playbackOptions(q=1,ast=1)
- tEnd = playbackOptions(q=1,aet=1)
- bakeResults(sl, simulation=1, t = (tStart,tEnd),at="rotate",sb = 1,dic = 1,preserveOutsideKeys=1,sparseAnimCurveBake=0,
- removeBakedAttributeFromLayer=0, bakeOnOverrideLayer=1,controlPoints =0, s=1)
- print "done baking animation"
- def selectOnlyJoints():
- sl = selected()
- c = sl[0]
- while c:
- c = listRelatives(c,c=1)
- for child in c:
- if nodeType(child) == "joint":
- select(child, add=1)
- def XsetCheckBoxesX():
- xBoxY.setValue(0)
- xBoxZ.setValue(0)
- def XsetCheckBoxesY():
- xBoxX.setValue(0)
- xBoxZ.setValue(0)
- def XsetCheckBoxesZ():
- xBoxY.setValue(0)
- xBoxY.setValue(0)
- def YsetCheckBoxesX():
- yBoxY.setValue(0)
- yBoxZ.setValue(0)
- def YsetCheckBoxesY():
- yBoxX.setValue(0)
- yBoxZ.setValue(0)
- def YsetCheckBoxesZ():
- yBoxY.setValue(0)
- yBoxY.setValue(0)
- def ZsetCheckBoxesX():
- zBoxY.setValue(0)
- zBoxZ.setValue(0)
- def ZsetCheckBoxesY():
- zBoxX.setValue(0)
- zBoxZ.setValue(0)
- def ZsetCheckBoxesZ():
- zBoxY.setValue(0)
- zBoxY.setValue(0)
- def tester():
- sl = selected()
- target = sl[0]
- bufferGrp = sl[1]
- xx = xBoxX.getValue()
- xy = xBoxY.getValue()
- xz = xBoxZ.getValue()
- if xx:
- target.rotateX >> bufferGrp.rotateX
- print "connect x to x"
- if xy:
- target.rotateX >> bufferGrp.rotateY
- print "connect x to y"
- if xz:
- target.rotateX >> bufferGrp.rotateZ
- print "connect x to z"
- from pymel.core import *
- x = 0
- win = window(title= "Re-Target Tool", s=0)
- mainLayout = rowColumnLayout(numberOfRows=4)
- bufferGrpBtn = frameLayout(l = "Buffer Groups", cll=1, cl=1, p = mainLayout )
- makeBufferGrpBtn = button(bgc = [1,.9,.0], l="Make Buffer Grp", command=Callback(makeBufferGrp),p = bufferGrpBtn)
- removeBufferGrpBtn = button(bgc = [.1,.3,.1], l="Remove Buffer Grp", command=Callback(removeBufferGrp),p = bufferGrpBtn)
- buttonLayout = frameLayout(l = "Connect Targets", p = mainLayout, w= 200,cll=1,cl=1 )
- flipSl = checkBox(l = "Flip Selection Order", cc = Callback(flipSelection), p = buttonLayout,v=1)
- slTip = text(l = "Control - Target", p = buttonLayout)
- mOffset = checkBox(l = "Maintain Offset", p = buttonLayout,v=1)
- parentConstraintBox = checkBox(l = "Transform and Rotation", p = buttonLayout, v=1)
- directConnectBox = checkBox(l = "Direct Connection", p = buttonLayout, v=1)
- rotationOrderLayout = frameLayout(l = "Rotation Order Remapping", cll=1, cl=1)
- #xBox = checkBox(l = "X To", p = rotationOrderLayout, v=1)
- xOrderLayout = rowColumnLayout(nr = 1, p = rotationOrderLayout )
- xOrderTxt = text(bgc = [0.4,0.08,0.08], l = " X ", p = xOrderLayout)
- xBoxX= checkBox(l = "X", p = xOrderLayout, v=1, cc = Callback(XsetCheckBoxesX))
- xBoxY= checkBox(l = "Y", p = xOrderLayout, v=0, cc = Callback(XsetCheckBoxesY))
- xBoxZ= checkBox(l = "Z", p = xOrderLayout, v=0, cc = Callback(XsetCheckBoxesZ))
- yOrderLayout = rowColumnLayout(nr = 1, p = rotationOrderLayout )
- yOrderTxt = text(bgc = [.1,.6,0], l = " Y ", p = yOrderLayout)
- yBoxX= checkBox(l = "X", p = yOrderLayout, v=0, cc = Callback(YsetCheckBoxesX))
- yBoxY= checkBox(l = "Y", p = yOrderLayout, v=1, cc = Callback(YsetCheckBoxesY))
- yBoxZ= checkBox(l = "Z", p = yOrderLayout, v=0, cc = Callback(YsetCheckBoxesZ))
- zOrderLayout = rowColumnLayout(nr = 1, p = rotationOrderLayout )
- zOrderTxt = text(bgc = [0,0,1], l = " Z ", p = zOrderLayout)
- zBoxX= checkBox(l = "X", p = zOrderLayout, v=0, cc = Callback(ZsetCheckBoxesX))
- zBoxY= checkBox(l = "Y", p = zOrderLayout, v=0, cc = Callback(ZsetCheckBoxesY))
- zBoxZ= checkBox(l = "Z", p = zOrderLayout, v=1, cc = Callback(ZsetCheckBoxesZ))
- connect = button(bgc = [0,.7,.2], l="Connect to Target", command=Callback(makeConnections),p = buttonLayout)
- text(l = "Select Joint and", p = buttonLayout, w= 200)
- disconnect = button(bgc = [.7,.1,0],l="Disconnect Target", command=Callback(unMakeConnections),p = buttonLayout)
- bakeLayout = frameLayout(l = "Bake Animation", p = mainLayout, w= 200,cll=1,cl=1 )
- text(l = "Select Root Joint and", p = bakeLayout, w= 200)
- selectBakeJoints = button(bgc = [1,.6,.0] ,l="Select Joint Hierarchy", command=Callback(selectOnlyJoints),p=bakeLayout,w= 200)
- bakeGrpAnimation = button(bgc = [.1,.3,1],l="Bake Animation to Group", command=Callback(bakeAnim),p=bakeLayout)
- bakeGrpAnimation = button(l="Test Button", command=Callback(tester),p=mainLayout)
- win.show()
- #__________________________________________
- #__________________________________________
Advertisement
Add Comment
Please, Sign In to add comment