Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The Waller Suite 0.1.0 by Jeff Wincek
- # this file contains all that is needed to generate a wall from scratch
- # at the bottom is the actual command to run this all
- import maya.cmds as plg
- import random
- # pass this method an object and some scaling factor
- # this will iterate through all of the verticies and wiggle them slightly
- # to wiggle in this context means translate in a random direction
- def wiggler(whichOne, howMuch):
- scalingFactor = int(howMuch)
- for x in range(0,len(plg.getAttr(whichOne+ '.vtx[*]',size=True))):
- whichVertToChange = whichOne + '.vtx[' + str(x) + ']'
- howFarX = random.random()/scalingFactor
- howFarY = random.random()/scalingFactor
- howFarZ = random.random()/scalingFactor
- plg.setAttr(whichVertToChange, howFarX, howFarY, howFarZ, type="double3")
- # takes one object selected and rockifies it.
- # needs the wiggler to run
- # recommended to run the proportionizer on the object first
- # 4 is a good number for howManyIterations, 5 is pushing it
- def rockifier(whichOne, howMuch,howManyIterations):
- # proportionizer(whichOne,howMuch)
- for x in range(1,howManyIterations):
- #uncomment the next two lines if you want the bricks to be less rectalinear
- #if x == 1 or x == 2:
- # plg.polyAverageVertex(whichOne, iterations = 2)
- wiggler(whichOne, howMuch*x)
- plg.polySmooth( name = whichOne)
- plg.polyAverageVertex(whichOne, iterations = 2)
- # select one object
- # This object will sub-divide the object in the X and Z directions so that
- # there are divisions approximately as often as the object is tall.
- def proportionizer(whichOne,howMuch):
- #whichOne= plg.ls(selection = True)[0]
- active = plg.polyEvaluate(whichOne, boundingBox = True)
- sizeX = active[0][1] - active[0][0]
- sizeY = active[1][1] - active[1][0]
- sizeZ = active[2][1] - active[2][0]
- hardPart = ''
- largerFactor = howMuch - 1
- if sizeX > sizeY:
- largerFactor = float(sizeX/sizeY)
- hardPart += ', sx = ' + str(largerFactor)
- if sizeZ > sizeY:
- largerFactor = float(sizeZ/sizeY)
- hardPart += ', sz = ' + str(largerFactor)
- if largerFactor > howMuch:
- print 'true'
- thingsToCall = "plg.polyCube(\'" + whichOne + "\', e=True " + hardPart + ")"
- print thingsToCall
- eval(thingsToCall)
- else:
- print 'false'
- #if range(1,10) only nine in a directionbricks will be produced
- def waller(howManyRows,howManyColumns,levelOfDetail,howLong):
- howLong = float(howLong)
- for y in range(1,int(howManyRows)+1):
- print 'doing row' + str(y)
- for z in range(1,int(howManyColumns)+1):
- shortOffset = z*float(howLong)+float(howLong)/20
- longOffset= z*float(howLong)+(float(howLong)/20)+float(howLong)/4
- currentName = 'brick' + str(y) + str(z)
- plg.polyCube(d = int(howLong),sx = 2,sy = 2, sz= int(howLong)*2, name = currentName)
- if bool(y&1):
- plg.setAttr(currentName +'.translateZ', float(shortOffset))
- else:
- plg.setAttr(currentName +'.translateZ', float(longOffset))
- plg.setAttr(currentName +'.translateY', (y)+.1)
- rockifier(currentName, 3, int(levelOfDetail))
- # use this command to run it all
- # waller(howManyRows,howManyColumns,levelOfDetail,howLong)
- waller(10,10,4,3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement