import maya.cmds as cmds
import random
from random import uniform as rand
import random
from random import uniform as rand
# Put this in the custom script shelf
def borrar():
if cmds.objExists('m*')==True:
cmds.select( 'mansion*', 'president*', visible=True )
cmds.delete()
def borrar():
if cmds.objExists('m*')==True:
cmds.select( 'mansion*', 'president*', visible=True )
cmds.delete()
def selectDir():
if cmds.objExists('buildingTex'):
cmds.delete('buildingTex')
filename = cmds.fileDialog2(fileMode=1, caption="Import Ground Texture:")
myFile=str(filename)
filePath=myFile.split("'")[1]
cmds.textFieldButtonGrp('buildingTex', edit=True,text=filePath)
houseOutline=cmds.shadingNode('file', name='buildingTex',asTexture=True)
# We will set the user selected file and add to the texture
cmds.setAttr(houseOutline+'.fileTextureName',filePath, type='string')
if cmds.objExists('buildingTex'):
cmds.delete('buildingTex')
filename = cmds.fileDialog2(fileMode=1, caption="Import Ground Texture:")
myFile=str(filename)
filePath=myFile.split("'")[1]
cmds.textFieldButtonGrp('buildingTex', edit=True,text=filePath)
houseOutline=cmds.shadingNode('file', name='buildingTex',asTexture=True)
# We will set the user selected file and add to the texture
cmds.setAttr(houseOutline+'.fileTextureName',filePath, type='string')
def xfrange(start, stop, step):
if (step<.05):
raise Exception('Cannot have step of less than .05. Maya will hang')
while start <= stop:
yield start
start += step
def buildCity():
if cmds.objExists('h*')==True:
cmds.delete('h*')
cmds.file("T:\VSFX-160-02\lbermu20\mansionn.mb",i=True)
cmds.file("T:\VSFX-160-02\lbermu20\presidentt.mb",i=True)
density=cmds.floatSliderGrp("densityOfCity",query=True,value=True)
density=1.0-density
for z in xfrange(0,10,density):
for x in xfrange(0,10,density):
# colorAtPoint command makes the script possible. Gets the rgb color at a specific
# point on the texture
colorOfPoint=cmds.colorAtPoint( 'buildingTex',output='RGB', coordU=(x/10), coordV=(z/10))
temp=cmds.pointOnSurface( 'nurbsPlane1', v=z/10, u=x/10, position=True )
# colorAtPoint returns a single indexed array, where colorOfPoint[0] is the red value
if (colorOfPoint[0]>.7):
nextHouse=cmds.instance('president')
cmds.select(nextHouse)
cmds.move(temp[0],temp[1],temp[2])
cmds.rotate(0,random.randrange(0,360),0)
cmds.scale(.3,.3,.3)
if (colorOfPoint[1]>.7):
nextHouse=cmds.instance('mansion')
cmds.select(nextHouse)
cmds.move(temp[0],temp[1],temp[2])
cmds.rotate(0,random.randrange(0,360),0)
cmds.scale(.3,.3,.3)
cmds.select('president','mansion')
cmds.move(10000,0,0)
if (step<.05):
raise Exception('Cannot have step of less than .05. Maya will hang')
while start <= stop:
yield start
start += step
def buildCity():
if cmds.objExists('h*')==True:
cmds.delete('h*')
cmds.file("T:\VSFX-160-02\lbermu20\mansionn.mb",i=True)
cmds.file("T:\VSFX-160-02\lbermu20\presidentt.mb",i=True)
density=cmds.floatSliderGrp("densityOfCity",query=True,value=True)
density=1.0-density
for z in xfrange(0,10,density):
for x in xfrange(0,10,density):
# colorAtPoint command makes the script possible. Gets the rgb color at a specific
# point on the texture
colorOfPoint=cmds.colorAtPoint( 'buildingTex',output='RGB', coordU=(x/10), coordV=(z/10))
temp=cmds.pointOnSurface( 'nurbsPlane1', v=z/10, u=x/10, position=True )
# colorAtPoint returns a single indexed array, where colorOfPoint[0] is the red value
if (colorOfPoint[0]>.7):
nextHouse=cmds.instance('president')
cmds.select(nextHouse)
cmds.move(temp[0],temp[1],temp[2])
cmds.rotate(0,random.randrange(0,360),0)
cmds.scale(.3,.3,.3)
if (colorOfPoint[1]>.7):
nextHouse=cmds.instance('mansion')
cmds.select(nextHouse)
cmds.move(temp[0],temp[1],temp[2])
cmds.rotate(0,random.randrange(0,360),0)
cmds.scale(.3,.3,.3)
cmds.select('president','mansion')
cmds.move(10000,0,0)
def buildPlane():
heightBump=cmds.floatSliderGrp('heightPlane',query=True,value=True)
if cmds.objExists('nurbsPlane1')==True:
cmds.delete('nurbsPlane1')
cmds.nurbsPlane(width=20,axis=[0,90,0],patchesU=30,patchesV=30)
for i in range(10):
randU=rand(0,29)
randV=rand(0,29)
cmds.select('nurbsPlane1.cv[%f][%f]' % (randU,randV))
cmds.softSelect(softSelectEnabled=True,softSelectDistance=6,softSelectUVDistance=.5)
cmds.move(0,rand(-heightBump,heightBump),0, relative=True)
heightBump=cmds.floatSliderGrp('heightPlane',query=True,value=True)
if cmds.objExists('nurbsPlane1')==True:
cmds.delete('nurbsPlane1')
cmds.nurbsPlane(width=20,axis=[0,90,0],patchesU=30,patchesV=30)
for i in range(10):
randU=rand(0,29)
randV=rand(0,29)
cmds.select('nurbsPlane1.cv[%f][%f]' % (randU,randV))
cmds.softSelect(softSelectEnabled=True,softSelectDistance=6,softSelectUVDistance=.5)
cmds.move(0,rand(-heightBump,heightBump),0, relative=True)
# This will delete any existing window that is named 'myWindow', which is what we
# are calling the window that we are making. Notice 'myWindow' has to be in quotes
if cmds.window('myWindow',ex=True)==True:
cmds.deleteUI('myWindow')
if cmds.dockControl ("autoDock", exists = True):
cmds.deleteUI("autoDock", control = True)
cmds.window('myWindow',title="Supreme City Generator",resizeToFitChildren=True, sizeable=False)
# We need a layout and columnLayout is the easiest to use for now
#cmds.columnLayout(adjustableColumn=False, width=376,columnAlign='left')
cmds.columnLayout(adjustableColumn=True, width=376)
cmds.picture(image = 'T:/VSFX-160-02\lbermu20\luxend2.jpg')
# are calling the window that we are making. Notice 'myWindow' has to be in quotes
if cmds.window('myWindow',ex=True)==True:
cmds.deleteUI('myWindow')
if cmds.dockControl ("autoDock", exists = True):
cmds.deleteUI("autoDock", control = True)
cmds.window('myWindow',title="Supreme City Generator",resizeToFitChildren=True, sizeable=False)
# We need a layout and columnLayout is the easiest to use for now
#cmds.columnLayout(adjustableColumn=False, width=376,columnAlign='left')
cmds.columnLayout(adjustableColumn=True, width=376)
cmds.picture(image = 'T:/VSFX-160-02\lbermu20\luxend2.jpg')
cmds.separator( height=15, style='out' )
houseTextureFile = cmds.textFieldButtonGrp( 'buildingTex',columnWidth=(1,70),columnAlign3=['left','left','left'],label=' Select Image',
buttonLabel='Browse' ,buttonCommand='selectDir()')
buttonLabel='Browse' ,buttonCommand='selectDir()')
cmds.floatSliderGrp("heightPlane",value=1,label="Height of Plane Bumps", min=0,max=4,field=True)
cmds.floatSliderGrp("densityOfCity",columnWidth3=(90,100,170),columnAlign3=['left','left','left'],value=.5,label=" Density of City",min=.1,max=.9,field=True)
#cmds.attrColorSliderGrp( at='%s.color' % blinn , rgb=(0.5, 0.05, .05))
#cmds.intSliderGrp("length",value=80,label="Length",min=1,max=200,field=True)
#cmds.floatSliderGrp("height",value=.3,label="Height",min=.1,max=2,field=True)
# Adding a color slider to change the color of the blinn shader
# The slider will have a default color of red, definedx by the rgb
#cmds.attrColorSliderGrp( at='%s.color' % blinn , rgb=(0.5, 0.05, .05))
cmds.floatSliderGrp("densityOfCity",columnWidth3=(90,100,170),columnAlign3=['left','left','left'],value=.5,label=" Density of City",min=.1,max=.9,field=True)
#cmds.attrColorSliderGrp( at='%s.color' % blinn , rgb=(0.5, 0.05, .05))
#cmds.intSliderGrp("length",value=80,label="Length",min=1,max=200,field=True)
#cmds.floatSliderGrp("height",value=.3,label="Height",min=.1,max=2,field=True)
# Adding a color slider to change the color of the blinn shader
# The slider will have a default color of red, definedx by the rgb
#cmds.attrColorSliderGrp( at='%s.color' % blinn , rgb=(0.5, 0.05, .05))
cmds.separator( height=15, style='out' )
cmds.button(label="Create Terrain",width=400,command="buildPlane()")
cmds.button(label="Generate Supreme City",width=376,command="buildCity()")
cmds.button(label="delete",width=376,command="borrar()")
cmds.button(label="Create Terrain",width=400,command="buildPlane()")
cmds.button(label="Generate Supreme City",width=376,command="buildCity()")
cmds.button(label="delete",width=376,command="borrar()")
allowedAreas = ['right', 'left']
cmds.dockControl("autoDock", area='right', content='myWindow',width=376,fixedWidth=False,allowedArea=allowedAreas,
label = 'Supreme City Generator',visible=True )
cmds.dockControl("autoDock", area='right', content='myWindow',width=376,fixedWidth=False,allowedArea=allowedAreas,
label = 'Supreme City Generator',visible=True )