Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # camMatch_Calculator_v 0.6_
- # status - working, need to get "Best Distance " and move to there and continue
- from pymel.core import *
- import time
- start = time.clock()
- def getPoint(camMatchLocators, imgPlane, camPos):
- planeCheck = ls("TempPlane")
- if planeCheck:
- delete("TempPlane")
- point = polyPlane(sx=1, sy=1, w=.01, h=.01, ax = [0,1,0], cuv=0, ch=0, n = "TempPlane")[0]
- move(point, camPos[0], camPos[1], camPos[2], ws=1 )
- aimConstraint(camMatchLocators, point,o= [0,0,0], w=1, aim=[0,1,0], u=[0,1,0], wut= "scene", n="TempAim")
- delete("TempAim")
- transferAttributes(imgPlane, point, pos=1, nml=0, sm=0)
- delete(point,ch=1)
- xform(point, cp=1)
- #point = point.getTranslation()
- select(point)
- setToolTo('Move')
- point = manipMoveContext('Move', q=True, p=True,m=2)
- select(cl=1)
- delete("TempPlane")
- return point
- def getCompairPoints(s, planeLocators, imgPlane, camMatchLocators):
- camPos = s.getTranslation("world")
- x = 0
- compairPoints = []
- points1 = []
- points2 = []
- for locator in planeLocators:
- t = locator.getTranslation("world")
- points1.append(t)
- point = getPoint(camMatchLocators[x], imgPlane, camPos)
- pointFmt = [i/offseter for i in point]
- points2.append(pointFmt)
- x += 1
- return points1,points2
- def getDistance(a, b): # a = locator 1, b = locator 2
- aTx = a
- bTx = b
- cleanUpDistance = ls("distanceDimension1")
- if cleanUpDistance:
- delete(cleanUpDistance)
- tmpEndPoint = spaceLocator(p = bTx, n = "tmpEndPoint")
- lctDistanceMaker = distanceDimension(sp = [aTx[0],aTx[1],aTx[2]], ep = [bTx[0],bTx[1],bTx[2]])
- rename("distanceDimension1", "tmpDistance")
- lctDistance = lctDistanceMaker.getAttr("distance")
- delete("tmpDistance")
- delete("tmpEndPoint")
- cleanUpLocators = ls("locator1")
- if cleanUpLocators:
- delete(cleanUpLocators)
- return lctDistance
- def saveLocation(s, number, direction):
- SavedCamLocationsCheck = ls("SavedCamLocations")
- if not SavedCamLocationsCheck:
- SavedCamLocationsCheck = group(n = "SavedCamLocations", em=1, w=1)
- t = s.getTranslation("world")
- r = s.getRotation("world")
- l = spaceLocator(p = (0,0,0), n = "{0}_location_{1}_{2}".format(s,number, direction))
- move(l, t[0],t[1],t[2], ls=1)
- rotate(l, r[0],r[1],r[2], ws=1)
- scale(l, .1,.1,.1, r=1)
- parent(l, "SavedCamLocations")
- return l
- def mover(s):
- startLocation = s.getTranslation("world")
- startRotation = s.getRotation("world")
- #sl = selected()
- s = sl[0]
- #______User defined___________
- calculateDuration = 10
- calculateAmnt = 1
- moveAmnt = 0.001
- rotateAmnt = 0.001
- moveDirection = [[moveAmnt,0,0], [0,moveAmnt,0], [0,0,moveAmnt],
- [-moveAmnt,0,0], [0,-moveAmnt,0], [0,0,-moveAmnt]] # X[0], Y[1], Z[2], -X[0], -Y[1], -Z[2]
- rotateDirection = [[moveAmnt,0,0], [0,moveAmnt,0], [0,0,moveAmnt],
- [-moveAmnt,0,0], [0,-moveAmnt,0], [0,0,-moveAmnt]] # X[0], Y[1], Z[2], -X[0], -Y[1], -Z[2]
- planeLocators = listRelatives("{0}_plnLocators".format(s),c=1)# points 1
- camMatchLocators = listRelatives("camMatchLocators", c=1)# points 2
- camSaveNumber = 0
- saveLocationCheck = ls("SavedCamLocations")
- if saveLocationCheck:
- delete(saveLocationCheck)
- #saveLocation(s, "start")
- distanceTracker = []
- if not camSetUpCheck:
- print "Please Run camSetup"
- else:
- z = 0
- zz = 1
- saver = 0
- while calculateDuration:
- if saver == calculateDuration + 1:
- print "thank the lordy"
- break
- saver += 1
- #_________get distance points_______
- compairPoints1, compairPoints2 = getCompairPoints(s, planeLocators, imgPlane, camMatchLocators)
- savedLocation = []# for getting best location
- xx = 0
- betterOrWorst = []
- for direction in moveDirection:
- if xx == 0:
- tmpTrans = s.getTranslation("world")
- tmpRotat = s.getRotation("world")
- # Get distances from plane locator to ground locator
- distances = []
- xxx = 0
- for c in compairPoints1:
- distance = getDistance(c,compairPoints2[xxx])
- distances.append(distance)
- x += 1
- avrgDistance = float(sum(distances)/len(distances))# the avrage distance
- distanceTracker.append(avrgDistance)# array of all distances
- refresh(cw=1)
- move(s, direction, os=1,r=1,wd=1)
- xxx += 1
- camSaveNumber += 1
- #________________________________________
- saveLocator = saveLocation(s,xx, z)
- savedLocation.append(saveLocator)
- move(s, tmpTrans, wd=1)
- xx += 1
- best = min(distanceTracker)
- print "here",z
- for i in distanceTracker:
- print i
- #bestLocation = distanceTracker.index(best)
- #print bestLocation
- #newMove = savedLocation[bestLocation].getTranslation("world")
- #move(s,newMove,ws=1)
- calculateDuration -= calculateAmnt
- z += 1
- zz += 1
- elapsed = (time.clock() - start)
- print "done, took:", elapsed
Advertisement
Add Comment
Please, Sign In to add comment