cwisbg

Shape Gen_v_0.8

Jan 21st, 2012
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.95 KB | None | 0 0
  1. """__________________
  2.    Shape Gen
  3.    Version_0.7.1
  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,2)
  35.         randoTx = r.randint(1,5)
  36.         randoSx = .3#r.uniform(.5,.7)
  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,.5,0,os=1,r=1)        
  47.         #rotate(c[x][0],0,randoRy,0, os=1, r=1)
  48.         scale(c[x][0],randoSx,randoSx,randoSx,r=1)
  49.         x += 1
  50. #        z += .01
  51.     return c
  52. #________________________________________________________________________________
  53. start = time.clock()
  54. sl = selected()
  55. x = 1
  56. for i in sl:
  57.     print "on:",x,"of",len(sl)
  58.     faceLocations = []
  59.     level_1_faces = []  
  60.     level_1_faces, faceLocations = getFace(i)
  61.     level_1 = inctancer(i,faceLocations)
  62.     #scale(i, .8,.8,.8, r=1)
  63.     #rotate(i, 45,45,45, r=1)
  64.     x += 1
  65.  
  66.  
  67. #___Duplicate level 2___
  68. x = 0
  69. level_1_len = len(level_1)
  70. z = 1
  71. for i in level_1:
  72.     if x < level_1_len :
  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.         z += 1
  79.         zero = 0    
  80.         xx = 2
  81.         zz = 1
  82.         yy = 0
  83.         for obj in level_2:
  84.             ll = len(level_2)
  85.             if zero == 0:
  86.                 polyUnite(obj[0],level_2[zz][0], n = 'obj_{0}'.format(x),ch=0)  
  87.                 zero += 1
  88.                 yy += 1    
  89.             elif yy < ll-1:
  90.                 polyUnite('obj_{0}'.format(x),level_2[xx][0], n = 'obj_{0}'.format(x+1),ch=0)
  91.                 rename('obj_{0}'.format(x+1), 'obj_{0}'.format(x))
  92.                 xx += 1
  93.                 yy += 1                
  94.         zz += 1
  95.         x += 1
  96. elapsed = (time.clock() - start)
  97. print 'Took',elapsed, 'somethings'
Advertisement
Add Comment
Please, Sign In to add comment