Skip to content

Instantly share code, notes, and snippets.

@krclark
Last active November 13, 2016 20:02
Show Gist options
  • Save krclark/bcaf76304b5c26f6c1c79942e4a1c26a to your computer and use it in GitHub Desktop.
Save krclark/bcaf76304b5c26f6c1c79942e4a1c26a to your computer and use it in GitHub Desktop.
#creates an an cloth from a plane "pPlane1" and a collider from "pSphere1" and constrains the two so the cloth follows the sphere.
import maya.cmds as cmd
import maya.mel
iteration = 1
sphere = "pSphere"+str(iteration)
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 = "pPlane"+str(iteration)
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(plane+ ".vtx[70]", add=True)
cmd.select(plane+ ".vtx[59]", add=True)
cmd.select(plane+ ".vtx[71]", add=True)
cmd.select(plane+ ".vtx[49]", add=True)
cmd.select(plane+ ".vtx[50]", add=True)
cmd.select(plane+ ".vtx[61]", 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;')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment