cwisbg

# Cam Match Setup_v 0.03_stable

Jun 28th, 2012
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.80 KB | None | 0 0
  1. # Cam Match Helper _v 0.03
  2. from pymel.core import *
  3. import time
  4.  
  5. start = time.clock()
  6. camSetUpCheck = 0
  7.  
  8. def cleanScene():
  9.     camDataCheck = ls("camMatch_data")
  10.     if not camDataCheck:
  11.         group(n="camMatch_data", em=1, w=1)  
  12.     keyObjsCheck = ls("camMatchLocators")
  13.     if keyObjsCheck:
  14.         keyObjFam = listRelatives(keyObjsCheck, c=1)
  15.         if len(keyObjFam) < 0:
  16.             print "Please create some location objects in camMatchLocators"
  17.     else:
  18.         print "Please create some location objects in camMatchLocators"
  19.         group(n="camMatchLocators", em=1, w=1)
  20.         parent("camMatchLocators","camMatch_data" )
  21.     crvGrpCheck = ls("camMatchCurves")
  22.     if len(crvGrpCheck) == 0:
  23.         crvGrp = group(n="camMatchCurves", w=1,em=1)
  24.         parent("camMatchCurves","camMatch_data" )
  25.     else:
  26.         delete(crvGrpCheck)
  27.         crvGrp = group(n="camMatchCurves", w=1,em=1)
  28.         parent("camMatchCurves","camMatch_data" )
  29.        
  30. def createAlighnmentCurves(camPos, keyLocations, s):
  31.     x = 0
  32.     for location in keyLocations:
  33.         c = curve(p = [(location[0], location[1], location[2]),(camPos[0],camPos[1],
  34.         camPos[2])], d=1,  n = "crv_{0}_{1}".format(s, x))
  35.         crvCluster = cluster(c.cv[1], n = "{0}_cluster".format(c))
  36.         setAttr(crvCluster[1]+".visibility",0)
  37.         parent(c, "camMatchCurves")
  38.         parent(crvCluster[1], s)
  39.         x += 1                 
  40.  
  41. def getMatchLocations():                   
  42.     camMatchLocators = listRelatives("camMatchLocators",c=1)
  43.     keyLocations = []    
  44.     for i in camMatchLocators:
  45.         x = i.getTranslation("world")
  46.         keyLocations.append(x)
  47.     return keyLocations,camMatchLocators
  48.    
  49. def getPoint(camMatchLocators, locator, imgPlane, camPos):
  50.     #lSpace = l.getTranslation("world")
  51.     planeCheck = ls("TempPlane")
  52.     if planeCheck:
  53.         delete("TempPlane")
  54.     point = polyPlane(sx=1, sy=1, w=.01, h=.01, ax = [0,1,0], cuv=0, ch=0, n = "TempPlane")[0]
  55.     move(point, camPos[0], camPos[1], camPos[2], ws=1 )
  56.     aimConstraint(camMatchLocators, point,o= [0,0,0], w=1, aim=[0,1,0], u=[0,1,0], wut= "scene", n="TempAim")
  57.     delete("TempAim")
  58.     transferAttributes(imgPlane, point, pos=1, nml=0, sm=0)
  59.     delete(point,ch=1)
  60.     xform(point, cp=1)
  61.     #point = point.getTranslation()
  62.     select(point)
  63.     setToolTo('Move')
  64.     point = manipMoveContext('Move', q=True, p=True,m=2)
  65.     select(cl=1)
  66.     delete("TempPlane")
  67.     return point
  68.    
  69. def getPlane(s):
  70.     imgPlane = listRelatives(s, c=1)
  71.     for c in imgPlane:
  72.         if c[-8:] == "planeGrp":
  73.             imgPlane = listRelatives(c, c=1)
  74.             for c2 in imgPlane:              
  75.                 if c2[-8:] == "camPlane":
  76.                     imgPlane = str(c2)
  77.     return imgPlane
  78.    
  79. def cleanPlnLocators(imgPlane):
  80.     cleaner = listRelatives(imgPlane, c=1)
  81.     if cleaner:
  82.         for i in cleaner:
  83.             if i[-10:] == "plnLocator":
  84.                 delete(i)
  85.    
  86. sl = selected()
  87.  
  88. cleanScene()
  89. keyLocations, camMatchLocators = getMatchLocations()
  90. offsetr = 100
  91.  
  92. for s in sl:
  93.     camPos = s.getTranslation("world")
  94.     imgPlane = getPlane(s)
  95.     createAlighnmentCurves(camPos, keyLocations, s)
  96.     cleanPlnLocators(imgPlane)
  97.     z = 0
  98.    
  99.    
  100.     grpClean = ls("{0}_plnLocators".format(s))
  101.     if grpClean:
  102.         print "cleaning old locators"
  103.         delete("{0}_plnLocators".format(s))
  104.     grpLctr = group(n = "{0}_plnLocators".format(s), em=1, w=1)
  105.     parent(grpLctr, imgPlane)
  106.    
  107.    
  108.     for location in keyLocations:    
  109.         point = getPoint(camMatchLocators[z],location, imgPlane, camPos)
  110.         lctr = spaceLocator(n = "{0}_plnLocator_{1}".format(s,z))
  111.         move(lctr,point[0]/offsetr,point[1]/offsetr,point[2]/offsetr, ws=1)
  112.         parent(lctr, grpLctr)
  113.         scale(lctr, .1,.1,.1, r=1)# Temp
  114.         z += 1    
  115. elapsed = (time.clock() - start)
  116. print "done, took:", elapsed
  117. camSetUpCheck = 1
Advertisement
Add Comment
Please, Sign In to add comment