View difference between Paste ID: SinpN5w9 and
SHOW: | | - or go back to the newest paste.
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
    for y in range(1,int(howManyRows)+1):
67
    	print 'doing row' + str(y)
68
    	for z in range(1,int(howManyColumns)+1):
69
            currentName = 'brick' + str(y) + str(z)
70
            plg.polyCube(d = int(howLong),sx = 2,sy = 2, sz= int(howLong)*2, name = currentName)
71
            if bool(y&1):
72
                plg.setAttr(currentName +'.translateZ', float(z*howLong+howLong/20))
73
            else:
74
                plg.setAttr(currentName +'.translateZ', float(z*howLong+(howLong/20)+howLong/4))
75
            plg.setAttr(currentName +'.translateY', (y)+.1)
76
            rockifier(currentName, 3, int(levelOfDetail))
77
78
79
# use this command to run it all
80
# waller(howManyRows,howManyColumns,levelOfDetail,howLong)
81
waller(10,10,4,3.0)
82
 
83