Skip to content

Instantly share code, notes, and snippets.

@krclark
Created November 13, 2016 20:04
Show Gist options
  • Save krclark/fc83e345e545c54b6d91d22039b8d982 to your computer and use it in GitHub Desktop.
Save krclark/fc83e345e545c54b6d91d22039b8d982 to your computer and use it in GitHub Desktop.
#creates a ball and plane for each joint under the hierarchy core, then creates an nCloth and collider out of the two objects and constrains them
import maya.cmds as cmd
import maya.mel
core = "AnimData_Hips"
jointsAll = cmd.listRelatives(core, allDescendents=True)
jointsAll.reverse()
iteration = 1
for place in jointsAll:
sphere = "ball_"+place
xhips = cmd.getAttr(sphere+".translateX", asString=False)
yhips = cmd.getAttr(sphere+".translateY", asString=False)
zhips = cmd.getAttr(sphere+".translateZ", asString=False)
cmd.spaceLocator( n="loco"+str(iteration), p=(xhips, yhips, zhips))
cmd.parent('loco'+str(iteration), sphere)
maya.mel.eval("select -r "+sphere+";")
#maya.mel.eval("makeCollideNCloth;")
plane = "cloth_"+place
maya.mel.eval("select -r "+plane+";")
maya.mel.eval("createNCloth 1;")
plane = 'polySurface'+str(iteration)
cmd.select(cl=True)
cmd.select(plane+ ".vtx[60]", add=True)
cmd.select(sphere+".vtx[381]", add=True)
for i in range(360, 380):
cmd.select(sphere+".vtx["+str(i)+"]", add=True)
cmd.select(plane, add=True)
cmd.select(sphere, add=True)
maya.mel.eval("createNConstraint transform 0;")
cmd.parent('dynamicConstraint'+str(iteration), 'loco'+str(iteration))
maya.mel.eval('setAttr "nClothShape'+str(iteration)+'.stretchResistance" 2.455;')
maya.mel.eval('setAttr "nClothShape'+str(iteration)+'.compressionResistance" 0.03;')
maya.mel.eval('setAttr "nClothShape'+str(iteration)+'.bendResistance" 0.03;')
iteration +=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment