Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Cam Match Helper _v 0.03
- from pymel.core import *
- import time
- start = time.clock()
- camSetUpCheck = 0
- def cleanScene():
- camDataCheck = ls("camMatch_data")
- if not camDataCheck:
- group(n="camMatch_data", em=1, w=1)
- keyObjsCheck = ls("camMatchLocators")
- if keyObjsCheck:
- keyObjFam = listRelatives(keyObjsCheck, c=1)
- if len(keyObjFam) < 0:
- print "Please create some location objects in camMatchLocators"
- else:
- print "Please create some location objects in camMatchLocators"
- group(n="camMatchLocators", em=1, w=1)
- parent("camMatchLocators","camMatch_data" )
- crvGrpCheck = ls("camMatchCurves")
- if len(crvGrpCheck) == 0:
- crvGrp = group(n="camMatchCurves", w=1,em=1)
- parent("camMatchCurves","camMatch_data" )
- else:
- delete(crvGrpCheck)
- crvGrp = group(n="camMatchCurves", w=1,em=1)
- parent("camMatchCurves","camMatch_data" )
- def createAlighnmentCurves(camPos, keyLocations, s):
- x = 0
- for location in keyLocations:
- c = curve(p = [(location[0], location[1], location[2]),(camPos[0],camPos[1],
- camPos[2])], d=1, n = "crv_{0}_{1}".format(s, x))
- crvCluster = cluster(c.cv[1], n = "{0}_cluster".format(c))
- setAttr(crvCluster[1]+".visibility",0)
- parent(c, "camMatchCurves")
- parent(crvCluster[1], s)
- x += 1
- def getMatchLocations():
- camMatchLocators = listRelatives("camMatchLocators",c=1)
- keyLocations = []
- for i in camMatchLocators:
- x = i.getTranslation("world")
- keyLocations.append(x)
- return keyLocations,camMatchLocators
- def getPoint(camMatchLocators, locator, imgPlane, camPos):
- #lSpace = l.getTranslation("world")
- 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 getPlane(s):
- imgPlane = listRelatives(s, c=1)
- for c in imgPlane:
- if c[-8:] == "planeGrp":
- imgPlane = listRelatives(c, c=1)
- for c2 in imgPlane:
- if c2[-8:] == "camPlane":
- imgPlane = str(c2)
- return imgPlane
- def cleanPlnLocators(imgPlane):
- cleaner = listRelatives(imgPlane, c=1)
- if cleaner:
- for i in cleaner:
- if i[-10:] == "plnLocator":
- delete(i)
- sl = selected()
- cleanScene()
- keyLocations, camMatchLocators = getMatchLocations()
- offsetr = 100
- for s in sl:
- camPos = s.getTranslation("world")
- imgPlane = getPlane(s)
- createAlighnmentCurves(camPos, keyLocations, s)
- cleanPlnLocators(imgPlane)
- z = 0
- grpClean = ls("{0}_plnLocators".format(s))
- if grpClean:
- print "cleaning old locators"
- delete("{0}_plnLocators".format(s))
- grpLctr = group(n = "{0}_plnLocators".format(s), em=1, w=1)
- parent(grpLctr, imgPlane)
- for location in keyLocations:
- point = getPoint(camMatchLocators[z],location, imgPlane, camPos)
- lctr = spaceLocator(n = "{0}_plnLocator_{1}".format(s,z))
- move(lctr,point[0]/offsetr,point[1]/offsetr,point[2]/offsetr, ws=1)
- parent(lctr, grpLctr)
- scale(lctr, .1,.1,.1, r=1)# Temp
- z += 1
- elapsed = (time.clock() - start)
- print "done, took:", elapsed
- camSetUpCheck = 1
Advertisement
Add Comment
Please, Sign In to add comment