cwisbg

shapeGen_v.07

Jan 17th, 2012
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.50 KB | None | 0 0
  1. """___________________
  2.    Shape Gen
  3.    Version_0.7
  4.    
  5.    cwisbg
  6.    Brandon Gillespie
  7.    1/16/2012
  8. ______________________      
  9. """
  10. from pymel.core import*
  11. import maya.cmds as mc
  12. import random as r
  13. import time
  14. # Get face locations
  15. def getFace(a):# a = selection, b = face array, c = face place array
  16.     x = 0
  17.     b = [] # array for selecting faces
  18.     c = [] # array for face Locations
  19.     for face in a.f:
  20.         b.append(face) #add face to array
  21.         select(b[x])
  22.         mc.setToolTo('Move')
  23.         c.append(mc.manipMoveContext('Move', q=True, p=True,m=2))
  24.         select(cl=1)
  25.         x += 1
  26.     return b, c  
  27. # For every face in selected object, duplicate selected object at face.
  28. def inctancer(a,b):# a= copy obj, b = location , returns list of duplicated objs
  29.     z = .5
  30.     x = 0
  31.     c = []
  32.     for place in b:
  33.         randoTx = r.randint(1,5)
  34.         randoTy = r.uniform(1,5)
  35.         randoTx = r.randint(1,5)
  36.         randoSx = r.uniform(.2,.4)
  37.         randoRx = r.randint(0,360)
  38.         randoRy = r.randint(0,360)
  39.         randoRz = r.randint(0,360)
  40.         refresh(cv=1)
  41.         cycleCheck(e=0)
  42.         c.append(duplicate(a, n ='{0}_copy_{1}'.format(a,x)))
  43.         move(c[x][0],b[x][0],b[x][1],b[x][2], ls=1,a=1)
  44.         normalConstraint(a,c[x][0]  , w=1, aim = (0,1,0), u = (0,1,0), wut = "scene",n = 'tempNrml')        
  45.         delete('tempNrml')
  46.         move(c[x][0],0,.3,0,os=1,r=1)        
  47.         rotate(c[x][0],0,randoRy,0, os=1, r=1)
  48. #        scale(c[x][0],scaler[0]-z,scaler[1]-z,scaler[2]-z,r=1)
  49.         scale(c[x][0],randoSx,randoSx,randoSx,r=1)
  50.         x += 1
  51. #        z += .01
  52.     return c
  53. #________________________________________________________________________________
  54. start = time.clock()
  55. sl = selected()
  56. x = 1
  57. for i in sl:
  58.     print "on:",x,"of",len(sl)
  59.     faceLocations = []
  60.     level_1_faces = []  
  61.     level_1_faces, faceLocations = getFace(i)
  62.     level_1 = inctancer(i,faceLocations)
  63.     scale(i, .8,.8,.8, r=1)
  64.     rotate(i, 45,45,45, r=1)
  65.     x += 1
  66.  
  67. #___Duplicate level 2___
  68. x = 0
  69. xx = 0
  70. zz = 1
  71. z = 1
  72. for i in level_1:
  73.     print 'on lv2:', x, 'of', len(level_1)
  74.     faceLocations2 = []
  75.     level_2_faces = []  
  76.     level_2_faces, faceLocations2 = getFace(i[0])
  77.     level_2 = inctancer(i,faceLocations2)    
  78.  
  79.     x += 1
  80.     z += 1
  81. """
  82.    for obj in level_2:
  83.        print obj[0],level_2[zz][0]
  84.        if xx == 0:
  85.            polyUnite(obj[0],level_2[zz][0], n = 'ab',ch=0)
  86.            xx += 1      
  87.        else:
  88.            polyUnite('ab',level_2[zz][0], n = 'ab1',ch=1)
  89.            rename('ab1', 'ab')
  90.            print zz
  91.        zz += 1
  92.        
  93.        ______________________________________      
  94. for cube in level_2:
  95.    print level_2[0][0],cube[0]
  96.    if x == 0:
  97.        polyUnite(cube[0],level_2[xx][0], n='ab',ch = 0)
  98.    else:
  99.        polyUnite('ab',level_2[xx][0], n='ab1',ch = 0)
  100.        rename('ab1','ab')
  101.    x += 1
  102.    xx += 1
  103.  
  104. polyUnite -ch 1 nt_Transform_u_pCube2_copy_4____copy_2 nt_Transform_u_pCube2_copy_4____copy_1
  105. nt_Transform_u_pCube2_copy_4____copy_4 nt_Transform_u_pCube2_copy_4____copy_5
  106. """
  107. print 'done'
  108. elapsed = (time.clock() - start)
  109. print 'Took',elapsed, 'somethings'
  110.  
  111.  
  112. """
  113. cl = len(c)-1
  114. cl2= cl - 1
  115. cl3 = 9
  116. x = 0
  117. xx = 1
  118. for cube in level_2:
  119.    print level_2[0][0],cube[0]
  120.    if x == 0:
  121.        polyUnite(cube[0],level_2[xx][0], n='ab',ch = 0)
  122.    else:
  123.        polyUnite('ab',level_2[xx][0], n='ab1',ch = 0)
  124.        rename('ab1','ab')
  125.    x += 1
  126.    xx += 1
  127.  
  128. """
Advertisement
Add Comment
Please, Sign In to add comment