cwisbg

# camMatch_Calculator_v 0.6_

Jun 29th, 2012
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.39 KB | None | 0 0
  1. # camMatch_Calculator_v 0.6_
  2. # status - working, need to get "Best Distance " and move to there and continue
  3. from pymel.core import *
  4. import time
  5. start = time.clock()
  6.  
  7. def getPoint(camMatchLocators, imgPlane, camPos):
  8.     planeCheck = ls("TempPlane")
  9.     if planeCheck:
  10.         delete("TempPlane")
  11.     point = polyPlane(sx=1, sy=1, w=.01, h=.01, ax = [0,1,0], cuv=0, ch=0, n = "TempPlane")[0]
  12.     move(point, camPos[0], camPos[1], camPos[2], ws=1 )
  13.     aimConstraint(camMatchLocators, point,o= [0,0,0], w=1, aim=[0,1,0], u=[0,1,0], wut= "scene", n="TempAim")
  14.     delete("TempAim")
  15.     transferAttributes(imgPlane, point, pos=1, nml=0, sm=0)
  16.     delete(point,ch=1)
  17.     xform(point, cp=1)
  18.     #point = point.getTranslation()
  19.     select(point)
  20.     setToolTo('Move')
  21.     point = manipMoveContext('Move', q=True, p=True,m=2)
  22.     select(cl=1)
  23.     delete("TempPlane")
  24.     return point
  25. def getCompairPoints(s, planeLocators, imgPlane, camMatchLocators):
  26.     camPos = s.getTranslation("world")
  27.     x = 0    
  28.     compairPoints = []
  29.     points1 = []
  30.     points2 = []
  31.     for locator in planeLocators:
  32.         t = locator.getTranslation("world")
  33.         points1.append(t)
  34.         point = getPoint(camMatchLocators[x], imgPlane, camPos)
  35.         pointFmt = [i/offseter for i in point]
  36.         points2.append(pointFmt)
  37.         x += 1
  38.     return points1,points2
  39.    
  40. def getDistance(a, b): # a = locator 1, b = locator 2
  41.     aTx = a
  42.     bTx = b
  43.     cleanUpDistance = ls("distanceDimension1")
  44.     if cleanUpDistance:
  45.         delete(cleanUpDistance)
  46.     tmpEndPoint = spaceLocator(p = bTx, n = "tmpEndPoint")
  47.     lctDistanceMaker = distanceDimension(sp = [aTx[0],aTx[1],aTx[2]], ep = [bTx[0],bTx[1],bTx[2]])
  48.     rename("distanceDimension1", "tmpDistance")
  49.     lctDistance = lctDistanceMaker.getAttr("distance")
  50.     delete("tmpDistance")
  51.     delete("tmpEndPoint")
  52.    
  53.     cleanUpLocators = ls("locator1")
  54.     if cleanUpLocators:
  55.         delete(cleanUpLocators)          
  56.     return lctDistance
  57.    
  58. def saveLocation(s, number, direction):
  59.     SavedCamLocationsCheck = ls("SavedCamLocations")
  60.     if not SavedCamLocationsCheck:
  61.         SavedCamLocationsCheck = group(n = "SavedCamLocations", em=1, w=1)
  62.     t = s.getTranslation("world")
  63.     r = s.getRotation("world")
  64.     l = spaceLocator(p = (0,0,0), n = "{0}_location_{1}_{2}".format(s,number, direction))
  65.     move(l, t[0],t[1],t[2], ls=1)
  66.     rotate(l, r[0],r[1],r[2], ws=1)
  67.     scale(l, .1,.1,.1, r=1)
  68.     parent(l, "SavedCamLocations")
  69.     return l
  70.    
  71. def mover(s):
  72.     startLocation = s.getTranslation("world")
  73.     startRotation = s.getRotation("world")
  74.    
  75.  
  76.    
  77.    
  78.        
  79. #sl = selected()
  80. s = sl[0]
  81.  
  82. #______User defined___________
  83. calculateDuration = 10
  84.  
  85. calculateAmnt = 1
  86. moveAmnt = 0.001
  87. rotateAmnt = 0.001
  88.  
  89. moveDirection = [[moveAmnt,0,0], [0,moveAmnt,0], [0,0,moveAmnt],
  90. [-moveAmnt,0,0], [0,-moveAmnt,0], [0,0,-moveAmnt]] # X[0], Y[1], Z[2], -X[0], -Y[1], -Z[2]
  91. rotateDirection = [[moveAmnt,0,0], [0,moveAmnt,0], [0,0,moveAmnt],
  92. [-moveAmnt,0,0], [0,-moveAmnt,0], [0,0,-moveAmnt]] # X[0], Y[1], Z[2], -X[0], -Y[1], -Z[2]
  93.    
  94.    
  95. planeLocators = listRelatives("{0}_plnLocators".format(s),c=1)# points 1
  96. camMatchLocators = listRelatives("camMatchLocators", c=1)# points 2  
  97.  
  98.  
  99. camSaveNumber = 0
  100. saveLocationCheck = ls("SavedCamLocations")
  101. if saveLocationCheck:
  102.     delete(saveLocationCheck)
  103.     #saveLocation(s, "start")
  104.  
  105.  
  106. distanceTracker = []
  107. if not camSetUpCheck:
  108.     print "Please Run camSetup"
  109. else:
  110.     z = 0
  111.     zz = 1
  112.     saver = 0
  113.  
  114.     while calculateDuration:
  115.  
  116.  
  117.         if saver == calculateDuration + 1:
  118.             print "thank the lordy"
  119.             break
  120.         saver += 1
  121.         #_________get distance points_______
  122.         compairPoints1, compairPoints2 = getCompairPoints(s, planeLocators, imgPlane, camMatchLocators)
  123.         savedLocation = []# for getting best location
  124.        
  125.        
  126.        
  127.         xx = 0
  128.         betterOrWorst = []
  129.         for direction in moveDirection:
  130.             if xx == 0:
  131.                 tmpTrans = s.getTranslation("world")
  132.                 tmpRotat = s.getRotation("world")
  133.             # Get distances from plane locator to ground locator       
  134.             distances = []  
  135.             xxx = 0  
  136.             for c in compairPoints1:
  137.                 distance = getDistance(c,compairPoints2[xxx])
  138.                 distances.append(distance)
  139.                 x += 1
  140.                 avrgDistance = float(sum(distances)/len(distances))# the avrage distance
  141.                 distanceTracker.append(avrgDistance)# array of all distances
  142.                 refresh(cw=1)
  143.                 move(s, direction,  os=1,r=1,wd=1)
  144.                 xxx += 1
  145.                 camSaveNumber += 1
  146.                 #________________________________________
  147.             saveLocator = saveLocation(s,xx, z)
  148.             savedLocation.append(saveLocator)
  149.             move(s, tmpTrans, wd=1)
  150.             xx += 1  
  151.  
  152.         best = min(distanceTracker)
  153.  
  154.         print "here",z
  155.         for i in  distanceTracker:
  156.             print i
  157.              #bestLocation = distanceTracker.index(best)
  158.         #print bestLocation
  159.        #newMove = savedLocation[bestLocation].getTranslation("world")
  160.         #move(s,newMove,ws=1)
  161.        
  162.         calculateDuration -= calculateAmnt
  163.        
  164.         z += 1
  165.         zz += 1
  166.  
  167. elapsed = (time.clock() - start)
  168. print "done, took:", elapsed
Advertisement
Add Comment
Please, Sign In to add comment