ntashev

script mod

Jan 18th, 2012
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.81 KB | None | 0 0
  1. # moded version of this script
  2. # http://forums.cgsociety.org/showthread.php?f=89&t=1030071
  3.  
  4. from pymel.core import*
  5. import maya.cmds as mc
  6. import random as r
  7. import time
  8.  
  9. # Get face locations
  10. #
  11. def getFace(a): # a = selection, b = face array, c = face place array
  12.     x = 0
  13.     b = [] # array for selecting faces
  14.     c = [] # array for face Locations
  15.     for face in a.f:
  16.         b.append(face) #add face to array
  17.         select(b[x])
  18.         mc.setToolTo('Move')
  19.         c.append(mc.manipMoveContext('Move', q=True, p=True,m=2))
  20.         select(cl=1)
  21.         x += 1
  22.     return b, c
  23.  
  24. # ========================================================================#
  25. # This thing replaces the getFace(a) function and is ~ 4x faster
  26. #
  27. import maya.OpenMaya as om
  28. def apiGetFaceCenters(obj):
  29.     sel = om.MSelectionList()
  30.     sel.add(obj)
  31.     dag = om.MDagPath()
  32.     sel.getDagPath(0, dag)
  33.     mit = om.MItMeshPolygon(dag)
  34.    
  35.     b = []
  36.     c = []
  37.    
  38.     while not mit.isDone():
  39.         ind = mit.index()
  40.         b.append(ind)
  41.         c.append( [mit.center(om.MSpace.kWorld)[i] for i in range(3)] )
  42.         mit.next()
  43.     return c
  44. # ========================================================================#
  45.  
  46. #
  47. # For every face in selected object, duplicate selected object at face.
  48. #
  49. def inctancer(a,b):# a= copy obj, b = location , returns list of duplicated objs
  50.     z = .5
  51.     x = 0
  52.     c = []
  53.     for place in b:
  54.         randoTx = r.randint(1,5)
  55.         randoTy = r.uniform(1,5)
  56.         randoTx = r.randint(1,5)
  57.         randoSx = r.uniform(.2,.4)
  58.         randoRx = r.randint(0,360)
  59.         randoRy = r.randint(0,360)
  60.         randoRz = r.randint(0,360)
  61.        
  62.         #refresh(cv=1) - Enabling this slows down the script at least 5x times on my machine
  63.         #cycleCheck(e=0) - this is global so you need to call it just once !!!
  64.  
  65.         c.append(duplicate(a, n ='{0}_copy_{1}'.format(a,x)))
  66.         move(c[x][0],b[x][0],b[x][1],b[x][2], ls=1,a=1)
  67.         normalConstraint(a,c[x][0]  , w=1, aim = (0,1,0), u = (0,1,0), wut = "scene",n = 'tempNrml')        
  68.         delete('tempNrml')
  69.         move(c[x][0],0,.3,0,os=1,r=1)        
  70.         rotate(c[x][0],0,randoRy,0, os=1, r=1)
  71.         scale(c[x][0],randoSx,randoSx,randoSx,r=1)
  72.         x += 1
  73.     return c
  74.  
  75. start = time.clock()
  76. sl = selected()
  77. x = 1
  78.  
  79. cycleCheck(e=0)
  80.  
  81. method = 0 # 0 - uses the original function, 1 - api face center function
  82.  
  83. for i in sl:
  84.     print "on:",x,"of",len(sl)
  85.     c = []
  86.     b= []
  87.     if method == 0: b, c = getFace(i) #~Took 1.38 somethings for 400f sphere
  88.     else: c = apiGetFaceCenters(i) #~Took 1.01 somethings for 400f shere
  89.     level_1 = inctancer(i,c)
  90.     scale(i, .8,.8,.8, r=1)
  91.     rotate(i, 45,45,45, r=1)
  92.     x += 1
  93. print 'done'
  94. elapsed = (time.clock() - start)
  95. print 'Took',elapsed, 'somethings'
Advertisement
Add Comment
Please, Sign In to add comment