SHARE
TWEET

The Waller Suite 0.1.0

jeffwincek Oct 11th, 2011 20 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # The Waller Suite 0.1.0 by Jeff Wincek
  2. # this file contains all that is needed to generate a wall from scratch
  3. # at the bottom is the actual command to run this all
  4.  
  5. import maya.cmds as plg
  6. import random
  7.  
  8. # pass this method an object and some scaling factor
  9. # this will iterate through all of the verticies and wiggle them slightly
  10. # to wiggle in this context means translate in a random direction
  11. def wiggler(whichOne, howMuch):
  12.     scalingFactor = int(howMuch)
  13.     for x in range(0,len(plg.getAttr(whichOne+ '.vtx[*]',size=True))):
  14.         whichVertToChange = whichOne + '.vtx[' + str(x) + ']'
  15.         howFarX = random.random()/scalingFactor
  16.         howFarY = random.random()/scalingFactor
  17.         howFarZ = random.random()/scalingFactor
  18.         plg.setAttr(whichVertToChange, howFarX, howFarY, howFarZ, type="double3")
  19.  
  20. # takes one object selected and rockifies it.
  21. # needs the wiggler to run
  22. # recommended to run the proportionizer on the object first
  23. # 4 is a good number for howManyIterations, 5 is pushing it
  24.  
  25.  
  26. def rockifier(whichOne, howMuch,howManyIterations):
  27.    # proportionizer(whichOne,howMuch)
  28.     for x in range(1,howManyIterations):
  29.         #uncomment the next two lines if you want the bricks to be less rectalinear
  30.         #if x == 1 or x == 2:
  31.         #       plg.polyAverageVertex(whichOne, iterations = 2)
  32.         wiggler(whichOne, howMuch*x)
  33.         plg.polySmooth( name = whichOne)
  34.     plg.polyAverageVertex(whichOne, iterations = 2)
  35.  
  36.  
  37. # select one object
  38. # This object will sub-divide the object in the X and Z directions so that
  39. # there are divisions approximately as often as the object is tall.
  40. def proportionizer(whichOne,howMuch):
  41.     #whichOne= plg.ls(selection =  True)[0]
  42.     active = plg.polyEvaluate(whichOne, boundingBox = True)
  43.     sizeX = active[0][1] - active[0][0]
  44.     sizeY = active[1][1] - active[1][0]
  45.     sizeZ = active[2][1] - active[2][0]
  46.     hardPart = ''
  47.     largerFactor = howMuch - 1
  48.     if sizeX > sizeY:
  49.         largerFactor = float(sizeX/sizeY)
  50.         hardPart += ', sx = ' + str(largerFactor)
  51.     if sizeZ > sizeY:
  52.         largerFactor = float(sizeZ/sizeY)
  53.         hardPart += ', sz = ' + str(largerFactor)
  54.        
  55.     if largerFactor > howMuch:
  56.         print 'true'
  57.         thingsToCall = "plg.polyCube(\'" + whichOne + "\', e=True " + hardPart + ")"
  58.         print thingsToCall
  59.         eval(thingsToCall)
  60.     else:
  61.         print 'false'
  62.  
  63.  
  64. #if range(1,10) only nine in a directionbricks will be produced
  65. def waller(howManyRows,howManyColumns,levelOfDetail,howLong):
  66.     howLong = float(howLong)
  67.     for y in range(1,int(howManyRows)+1):
  68.         print 'doing row' + str(y)
  69.         for z in range(1,int(howManyColumns)+1):
  70.             shortOffset = z*float(howLong)+float(howLong)/20
  71.             longOffset= z*float(howLong)+(float(howLong)/20)+float(howLong)/4
  72.             currentName = 'brick' + str(y) + str(z)
  73.             plg.polyCube(d = int(howLong),sx = 2,sy = 2, sz= int(howLong)*2, name = currentName)
  74.             if bool(y&1):
  75.                 plg.setAttr(currentName +'.translateZ', float(shortOffset))
  76.             else:
  77.                 plg.setAttr(currentName +'.translateZ', float(longOffset))
  78.             plg.setAttr(currentName +'.translateY', (y)+.1)
  79.             rockifier(currentName, 3, int(levelOfDetail))
  80.  
  81.  
  82. # use this command to run it all
  83. # waller(howManyRows,howManyColumns,levelOfDetail,howLong)
  84. waller(10,10,4,3)
  85.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top