Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Cuber_v1.2
- # cwisbg
- from pymel.core import *
- import maya.cmds as mc
- import random as r
- import time
- start = time.clock()
- # Prompt Box
- promptBox1 = promptDialog(t= 'Cuber_v.1',bgc=[.5,.7,.8],
- button = 'create',
- m= "How manny Cubes would you like?")
- if promptBox1 == 'create':
- promptReturn = promptDialog(query=True, text=True)
- # Scene Clean
- cuberCheck = mc.ls("cuber_grp")
- papNm = "PapaCube"
- if cuberCheck:
- cuberChildren = listRelatives(cuberCheck, c=1)
- ittor = len(cuberChildren)
- papNm = "{0}{1}".format(papNm, ittor)
- papaCube = [polyCube( n= papNm, w = 1, h = 1, d = 1)[0]]
- parent(papaCube, cuberGrp)
- else:
- cuberGrp = group(n = "cuber_grp", em=1)
- papaCube = [polyCube( n= "{0}0".format(papNm),w = 1, h = 1, d = 1)[0]]
- parent(papaCube, cuberGrp)
- rotAmnt = 90
- rot_direction = [[rotAmnt,0,0],[0,rotAmnt,0],[0,0,rotAmnt]]
- rotLen = len(rot_direction) -1
- moveAmnt = 1
- move_direction = [[moveAmnt,0,0],[0,moveAmnt,0],[0,0,moveAmnt],
- [-moveAmnt,0,0],[0,-moveAmnt,0],[0,0,-moveAmnt]]
- moveDir_len = len(move_direction)-1
- lastPlaceCheck = ls("last_saved_lct")
- lpTracker = 0
- lP = []
- if lastPlaceCheck:
- lP = lastPlaceCheck[0].getTranslation()
- delete("last_saved_lct")
- # Cuber - Cube creation
- z = int(promptReturn) # number of cubes
- x = 0 # count down to
- i = 1 # itterator
- while x <= z:
- if x == 0:
- last = papaCube[0]
- else:
- last = cube
- rando = r.randint(0,moveDir_len)
- randoR = r.randint(0, rotLen)
- moveDir = move_direction[rando]
- lastPlace = last.getTranslation("world")
- lastPlus = [sum(l) for l in zip(moveDir, lastPlace)]
- cube = duplicate(papaCube, n = '{0}_cube_{1}'.format(papNm,x))[0]
- if lpTracker == 0 and x == 0:
- print "here"
- move(cube, lP ,os=1, wd = 1)
- else:
- move(cube, lastPlus, os=1, wd = 1 )
- cuberCheck = mc.ls("cuber_grp")
- cuberChildren = listRelatives(cuberCheck, c=1)
- for cb in cuberChildren:
- samePlace = 0
- while samePlace:
- cubeCurrent = cube.getTranslation()
- cbTrans = cb.getTranslation()
- if cbTrans == cubeCurrent:
- move(cube, lastPlus, os=1, wd = 1 )
- print "same place"
- else:
- samePlace += 1
- #rotate(cube, rot_direction[randoR], r=1)
- #a = parent(cube,papaCube[x])
- #papaCube.append(cube)
- #parent(cube, "cuber_grp")
- refresh(cw=1)
- i += 1
- x += 1
- lpTracker = 1
- """
- # selecting
- mc.select(cl=True) #clear selection
- b = z # so z is not overwritten
- while b >= 1:
- mc.refresh(cw=1)
- sl = mc.select(papaCube[b], add =1 )
- b -= 1 # Temp Proggress bar
- """
- cubeCombine = listRelatives("cuber_grp")
- lastPlace = cubeCombine[-1].getTranslation()
- lastSave = spaceLocator(n = "last_saved_lct")
- move(lastSave, lastPlace, os=1, wd = 1 )
- parent(lastSave, "cuber_grp")
- combinedCubes = polyUnite( cubeCombine, n = "test", mergeUVSets = 1, ch=0)
- polyMergeVertex(combinedCubes, d= .01, am=1, ch=0)
- polyNormal(combinedCubes, normalMode = 2, userNormalMode = 0, ch=1)
- polySoftEdge(combinedCubes, a=180, ch=0)
- elapsed = (time.clock() - start)
- elapsed = elapsed/60
- print "done, took:", elapsed
Advertisement
Add Comment
Please, Sign In to add comment