cwisbg

Shape Gen_v_plant_Stage2

Jan 22nd, 2012
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.58 KB | None | 0 0
  1. """__________________
  2.    Shape Gen
  3.    Version_plant_Stage2
  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.  
  21.         if face == a.f[0]:
  22.             pass
  23.         else:
  24.             b.append(face) #add face to array
  25.             select(b[x])
  26.             mc.setToolTo('Move')
  27.             c.append(mc.manipMoveContext('Move', q=True, p=True,m=2))
  28.             select(cl=1)
  29.             x += 1
  30.     return b, c  
  31. # For every face in selected object, duplicate selected object at face.
  32. def inctancer(a,b):# a= copy obj, b = location , returns list of duplicated objs
  33.     z = 0
  34.     x = 0
  35.     c = []
  36.     for place in b:
  37.         randoTx = r.randint(1,5)
  38.         randoTy = r.uniform(1,2)
  39.         randoTx = r.randint(1,5)
  40.         randoSx = .25#r.uniform(0,.1)
  41.         randoRx = r.randint(0,360)
  42.         randoRy = r.randint(0,360)
  43.         randoRz = r.randint(0,360)
  44.         refresh(cv=1)
  45.         #cycleCheck(e=0)
  46.         c.append(duplicate('dupObj', n ='{0}_copy_{1}'.format(a,x)))
  47.         move(c[x][0],b[x][0],b[x][1],b[x][2], ls=1,a=1)
  48.         normalConstraint(a,c[x][0]  , w=1, aim = (0,1,0), u = (0,1,0), wut = "scene",n = 'tempNrml')        
  49.         delete('tempNrml')
  50.         #move(c[x][0],0,0,0,os=1,r=1)        
  51.         #rotate(c[x][0],0,randoRy,0, os=1, r=1)
  52.         scale(c[x][0],randoSx-z,randoSx-z,randoSx-z,r=1)
  53.         x += 1
  54.         z += .001
  55.     return c
  56. #________________________________________________________________________________
  57. start = time.clock()
  58. sl = selected()
  59. x = 1
  60. for i in sl:
  61.     print "on:",x,"of",len(sl)
  62.     faceLocations = []
  63.     level_1_faces = []  
  64.     level_1_faces, faceLocations = getFace(i)
  65.     level_1 = inctancer(i,faceLocations)
  66.     #scale(i, .8,.8,.8, r=1)
  67.     #rotate(i, 45,45,45, r=1)
  68.     zero = 0
  69.     xx = 2
  70.     zz = 1
  71.     yy = 0
  72.     x += 1
  73.     for obj in level_1:
  74.        
  75.         ll = len(level_1)
  76.         if zero == 0:
  77.             polyUnite(obj[0],level_1[zz][0], n = 'obj_{0}'.format(x),ch=0)  
  78.             zero += 1
  79.             yy += 1    
  80.         elif yy < ll-1:
  81.             polyUnite('obj_{0}'.format(x),level_1[xx][0], n = 'obj_{0}'.format(x+1),ch=0)
  82.             rename('obj_{0}'.format(x+1), 'obj_{0}'.format(x))
  83.             xx += 1
  84.             yy += 1
  85.    
  86.  
  87. """
  88. #___Duplicate level 2___
  89. x = 0
  90. level_1_len = len(level_1)
  91. z = 1
  92. for i in level_1:
  93.    if x < level_1_len :
  94.        print 'on lv2:', x, 'of', len(level_1)
  95.        faceLocations2 = []
  96.        level_2_faces = []  
  97.        level_2_faces, faceLocations2 = getFace(i[0])
  98.        level_2 = inctancer(i,faceLocations2)            
  99.        z += 1
  100.        zero = 0    
  101.        xx = 2
  102.        zz = 1
  103.        yy = 0
  104.        
  105.        for obj in level_2:
  106.            ll = len(level_2)
  107.            if zero == 0:
  108.                polyUnite(obj[0],level_2[zz][0], n = 'obj_{0}'.format(x),ch=0)  
  109.                zero += 1
  110.                yy += 1    
  111.            elif yy < ll-1:
  112.                polyUnite('obj_{0}'.format(x),level_2[xx][0], n = 'obj_{0}'.format(x+1),ch=0)
  113.                rename('obj_{0}'.format(x+1), 'obj_{0}'.format(x))
  114.                xx += 1
  115.                yy += 1
  116.                              
  117.        zz += 1
  118.        x += 1
  119.      
  120. """
  121.  
  122. elapsed = (time.clock() - start)
  123. print 'Took',elapsed, 'somethings'
Advertisement
Add Comment
Please, Sign In to add comment