Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # moded version of this script
- # http://forums.cgsociety.org/showthread.php?f=89&t=1030071
- from pymel.core import*
- import maya.cmds as mc
- import random as r
- import time
- # Get face locations
- #
- def getFace(a): # a = selection, b = face array, c = face place array
- x = 0
- b = [] # array for selecting faces
- c = [] # array for face Locations
- for face in a.f:
- b.append(face) #add face to array
- select(b[x])
- mc.setToolTo('Move')
- c.append(mc.manipMoveContext('Move', q=True, p=True,m=2))
- select(cl=1)
- x += 1
- return b, c
- # ========================================================================#
- # This thing replaces the getFace(a) function and is ~ 4x faster
- #
- import maya.OpenMaya as om
- def apiGetFaceCenters(obj):
- sel = om.MSelectionList()
- sel.add(obj)
- dag = om.MDagPath()
- sel.getDagPath(0, dag)
- mit = om.MItMeshPolygon(dag)
- b = []
- c = []
- while not mit.isDone():
- ind = mit.index()
- b.append(ind)
- c.append( [mit.center(om.MSpace.kWorld)[i] for i in range(3)] )
- mit.next()
- return c
- # ========================================================================#
- #
- # For every face in selected object, duplicate selected object at face.
- #
- def inctancer(a,b):# a= copy obj, b = location , returns list of duplicated objs
- z = .5
- x = 0
- c = []
- for place in b:
- randoTx = r.randint(1,5)
- randoTy = r.uniform(1,5)
- randoTx = r.randint(1,5)
- randoSx = r.uniform(.2,.4)
- randoRx = r.randint(0,360)
- randoRy = r.randint(0,360)
- randoRz = r.randint(0,360)
- #refresh(cv=1) - Enabling this slows down the script at least 5x times on my machine
- #cycleCheck(e=0) - this is global so you need to call it just once !!!
- c.append(duplicate(a, n ='{0}_copy_{1}'.format(a,x)))
- move(c[x][0],b[x][0],b[x][1],b[x][2], ls=1,a=1)
- normalConstraint(a,c[x][0] , w=1, aim = (0,1,0), u = (0,1,0), wut = "scene",n = 'tempNrml')
- delete('tempNrml')
- move(c[x][0],0,.3,0,os=1,r=1)
- rotate(c[x][0],0,randoRy,0, os=1, r=1)
- scale(c[x][0],randoSx,randoSx,randoSx,r=1)
- x += 1
- return c
- start = time.clock()
- sl = selected()
- x = 1
- cycleCheck(e=0)
- method = 0 # 0 - uses the original function, 1 - api face center function
- for i in sl:
- print "on:",x,"of",len(sl)
- c = []
- b= []
- if method == 0: b, c = getFace(i) #~Took 1.38 somethings for 400f sphere
- else: c = apiGetFaceCenters(i) #~Took 1.01 somethings for 400f shere
- level_1 = inctancer(i,c)
- scale(i, .8,.8,.8, r=1)
- rotate(i, 45,45,45, r=1)
- x += 1
- print 'done'
- elapsed = (time.clock() - start)
- print 'Took',elapsed, 'somethings'
Advertisement
Add Comment
Please, Sign In to add comment