Sunday, July 12, 2009

Ex03B_PolyPlane_Deborah&Claudia




#######################
## Ex03B_Move Cvs of a Nurbs according to Locator direction
#######################

import maya.cmds as cmds
import math

#define distance between PolFaces and locator
def magnitude (v):
#v is a list of x,y,z values
x= v[0]
y= v[1]
z= v[2]
m= math.sqrt ( (x*x) + (y*y) + (z*z) )
return m

def distance (posVert, posLoc):
#subtract both vectors
x1= posVert[0]
y1= posVert[1]
z1= posVert[2]
x2= posLoc[0]
y2= posLoc[1]
z2= posLoc[2]
x= x1 - x2
y= y1 - y2
z= z1 - z2
m= magnitude ([x,y,z])
return m

#define moveToLocator function
def moveToLocator():
# A) get all the verticesNames of a plane
allVertices= cmds.ls ("pPlane1.vtx[:]", fl=1)

#create an empty list to store the points
MyVerts=[]

#get selected Locator
selLoc= cmds.filterExpand(sm=22)

#loop through vertices
for v in allVertices:
pos= cmds.pointPosition(v)
x= pos[0]
y= pos[1]
z= pos[2]

#find distance to Locator
posVert= cmds.pointPosition(v)
posLoc= cmds.pointPosition(selLoc)
d= distance(posVert, posLoc)
print d
cmds.move (d,3,d,v,r=True)

#store the cvs in a list
MyVerts.append(allVertices)

#call the function
moveToLocator()

No comments:

Post a Comment