Repository navigation
Expand file tree
/
Copy pathtileGenerator.py
More file actions
176 lines (112 loc) · 6.02 KB
/
Copy pathtileGenerator.py
File metadata and controls
176 lines (112 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import maya.cmds as cmds
import math
import random
import functools
def createUI( pWindowTitle, pApplyCallback ) :
windowID = 'Tile Generator'
if cmds.window( windowID, exists=True ) :
cmds.deleteUI( windowID )
cmds.window( windowID, title=pWindowTitle, sizeable=True, resizeToFitChildren=True )
cmds.columnLayout(adj=True)
cmds.separator( h=10, style='none' )
shakeAmount = cmds.intSliderGrp(l = "Shake Amount", min = 0, max = 180, field = True)
cmds.separator( h=10, style='none' )
displaceAmount = cmds.intSliderGrp(l = "Displace Amount", min = 0, max = 30, field = True)
cmds.separator( h=10, style='none' )
cutoffAmount = cmds.intSliderGrp(l = "Cutoff Amount", min = 0, max = 10, field = True)
cmds.separator( h=10, style='none' )
cmds.separator( h=10, style='none' )
cmds.button( label='Apply', command=functools.partial( pApplyCallback, shakeAmount, displaceAmount, cutoffAmount ) )
def cancelCallback( *pArgs ):
if cmds.window( windowID, exists=True ) :
cmds.deleteUI( windowID )
cmds.button( label='Cancel', command=cancelCallback )
cmds.showWindow()
def getVtxPos( shapeNode ) :
vtxWorldPosition = []
vtxIndexList = cmds.getAttr( shapeNode+".vrts", multiIndices=True )
for i in vtxIndexList :
curPointPosition = cmds.xform( str( shapeNode )+".pnts["+str(i)+"]", query=True, translation=True, worldSpace=True )
vtxWorldPosition.append( curPointPosition )
return vtxWorldPosition
def calculateXlength( shapeNode ) :
bbox = cmds.xform( shapeNode, query=True, bb=True )
Xlength=abs( bbox[3]-bbox[0] )
return Xlength
def calculateYlength( shapeNode ) :
bbox = cmds.xform( shapeNode, query=True, bb=True )
Ylength=abs( bbox[4]-bbox[1] )
return Ylength
def calculateZlength( shapeNode ) :
bbox = cmds.xform( shapeNode, query=True, bb=True )
Zlength=abs( bbox[5]-bbox[2] )
return Zlength
def displaceBrick( shapeNode ) :
rY = random.uniform( -10,10 )
if ( random.randint( 0,1 )==0 ) :
tZ = random.uniform( 0, ( calculateZlength( shapeNode ) / 2) )
tY = random.uniform( 0, calculateYlength( shapeNode ) )
rX = random.uniform( 0,10 )
cmds.xform( shapeNode, t = [0, tY, -tZ] , ro = [rX, rY, 0] , r=True, worldSpace=True )
else :
tX = random.uniform( 0, ( calculateXlength( shapeNode ) / 2) )
tY = random.uniform( 0, calculateYlength( shapeNode ) )
rZ = random.uniform( 0,10 )
cmds.xform( shapeNode, t = [-tX, tY, 0] , ro = [0, rY, -rZ] , r=True, worldSpace=True )
def applyCallback( pShakeAmount, pDisplaceAmount, pCutoffAmount, *pArgs ):
shakeAmount = cmds.intSliderGrp( pShakeAmount, query=True, value=True)
displaceAmount = cmds.intSliderGrp( pDisplaceAmount, query=True, value=True)
cutoffAmount = cmds.intSliderGrp( pCutoffAmount, query=True, value=True)
brickList = cmds.ls( 'grp_brickInstance' )
if len( brickList ) > 0 :
cmds.delete( brickList )
cmds.duplicate( 'brick', name='brickModel' )
brickBase = cmds.ls( 'brickModel' ) #brickBase = template brick
ground = cmds.ls( 'ground' )
brickAmountZ = int( calculateZlength(ground)/calculateZlength(brickBase) )
brickAmountX = int( calculateXlength(ground)/calculateXlength(brickBase) )
tempPosition = getVtxPos( 'ground' )[0]
cmds.xform(brickBase, t = tempPosition, worldSpace=True)
cmds.xform(brickBase, t = [( calculateXlength(brickBase)/2 ), ( calculateYlength( brickBase )/2 ) , -( calculateZlength( brickBase )/2 )], r=True, worldSpace=True)
initX = cmds.getAttr( 'brickModel.translateX' )
initZ = cmds.getAttr( 'brickModel.translateZ' )
print cutoffAmount
print brickAmountX
brickCounter = 0
cutoff_rate = brickAmountX - ( cutoffAmount/10.0 ) * brickAmountX
createMax = brickAmountZ + 1
for i in range( 1, brickAmountX+1 ) :
xT = ( i-1 )*calculateXlength( brickBase )
displaced = 0
createCounter = 0
doCreate = 0
if ( i>=cutoff_rate ) :
createMax -= random.randint( 0,1 )
for j in range( 1, brickAmountZ+1 ) :
if ( i>=cutoff_rate+1 ) :
doCreate = random.randint( 0,1 )
createCounter += 1
else :
doCreate = 1
if (doCreate == 1) & ( createCounter <= createMax ) :
brickCounter += 1
cmds.instance( brickBase, name='brickInstance_#' )
zT = ( j-1 ) * calculateZlength( brickBase )
cmds.xform( 'brickInstance_'+str( brickCounter ), t = [xT, 0, -zT], r=True, worldSpace=True)
if ( ( random.randint(0,1)==0 ) & ( random.randint( 0,1 )==0 ) & ( displaced != 1 ) ) :
displaceBrick ( 'brickInstance_'+str(brickCounter) )
displaced = 1
else :
if ( random.randint(0,1)==0 ) :
randY = 0
displaced = 0
if ( random.randint(0,1)==0 ) :
randY = random.uniform(-1,1) * shakeAmount
randX = random.uniform(-1,1) * displaceAmount
randZ = random.uniform(-1,1) * displaceAmount
cmds.xform( 'brickInstance_'+str(brickCounter), ro = [randX, randY, randZ], r=True, )
brickList = cmds.ls( 'brickInstance_*' )
cmds.group(brickList, name='grp_brickInstance')
cmds.delete( 'brickModel' )
cmds.select( clear=True)
createUI( 'Tiler', applyCallback )