Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pymel.core import *
- import maya.api.OpenMaya as om
- import time
- import math
- def getPiv(s):
- select(s)
- setToolTo('Move')
- piv = manipMoveContext('Move', q=True, p=True,m=2)
- return piv
- def getDist(p1,p2):
- dist = math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2 + (p1[2] - p2[2])**2)
- return dist
- start = time.clock()
- #sl = selected()
- tStart = playbackOptions(q=1,ast=1)
- tEnd = playbackOptions(q=1,aet=1)
- objects = sl[:-1]
- lctr = sl[-1]
- fallOffAmnt = 100
- startScale = 2
- offsetAmnt = 2
- i = 0
- for f in range(int(tStart),int(tEnd)+1):
- lctrPos = getPiv(lctr)
- DistCheck = getAttr(lctr+".scale")[0] # Radius
- lctrPos = om.MVector(lctrPos)
- currentTime(i, u=1)
- for o in objects:
- dPos = getPiv(o)
- direction = om.MVector(lctrPos) - om.MVector(dPos)
- directionN = direction.normalize() * offsetAmnt
- objScale = startScale#d[0].getScale()
- directionMag = directionN.length()
- distFar = getDist(directionN, dPos)
- distNear = getDist(lctrPos, directionN)
- if distFar < DistCheck:
- fallOff = distFar / DistCheck # scales down/ mapps to 0-1
- newScale = (objScale * fallOff)# + offset
- scale(o, newScale, newScale, newScale)
- if newScale < 0.1:
- scale(o, 0, 0, 0)
- elif distNear < directionMag:
- scale(o, 0, 0, 0)
- print "cat"
- else:
- scale(o, objScale,objScale,objScale)
- setKeyframe(o+".scale")
- i += 1
- elapsedChunk = (time.clock() - start)
- print "done, took:", elapsedChunk
Advertisement
Add Comment
Please, Sign In to add comment