cwisbg

ScaleDistance

Dec 20th, 2018
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. from pymel.core import *
  2. import maya.api.OpenMaya as om
  3. import time
  4. import math
  5. def getPiv(s):    
  6.     select(s)
  7.     setToolTo('Move')
  8.     piv = manipMoveContext('Move', q=True, p=True,m=2)
  9.     return piv
  10. def getDist(p1,p2):
  11.     dist = math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2 + (p1[2] - p2[2])**2)
  12.     return dist    
  13. start = time.clock()
  14. #sl = selected()
  15. tStart = playbackOptions(q=1,ast=1)
  16. tEnd = playbackOptions(q=1,aet=1)
  17. objects = sl[:-1]
  18. lctr = sl[-1]
  19.  
  20. fallOffAmnt = 100
  21. startScale = 2
  22. offsetAmnt = 2
  23. i = 0
  24. for f in range(int(tStart),int(tEnd)+1):
  25.     lctrPos = getPiv(lctr)
  26.     DistCheck = getAttr(lctr+".scale")[0] # Radius
  27.     lctrPos = om.MVector(lctrPos)
  28.    
  29.     currentTime(i, u=1)
  30.     for o in objects:
  31.         dPos = getPiv(o)
  32.         direction = om.MVector(lctrPos) - om.MVector(dPos)
  33.         directionN = direction.normalize() * offsetAmnt
  34.        
  35.         objScale = startScale#d[0].getScale()
  36.         directionMag = directionN.length()
  37.         distFar =  getDist(directionN, dPos)
  38.         distNear =  getDist(lctrPos, directionN)
  39.        
  40.         if distFar < DistCheck:
  41.             fallOff = distFar / DistCheck  # scales down/ mapps to 0-1
  42.             newScale =  (objScale * fallOff)# + offset
  43.             scale(o, newScale, newScale, newScale)
  44.             if newScale < 0.1:    
  45.                 scale(o, 0, 0, 0)
  46.              
  47.         elif distNear < directionMag:
  48.             scale(o, 0, 0, 0)
  49.             print "cat"
  50.         else:
  51.              scale(o, objScale,objScale,objScale)
  52.  
  53.         setKeyframe(o+".scale")
  54.        
  55.     i += 1
  56.  
  57. elapsedChunk = (time.clock() - start)
  58. print "done, took:", elapsedChunk
Advertisement
Add Comment
Please, Sign In to add comment