#################################################
#####
### 03B
#####
import maya.cmds as cmds
import math
import random
#EXTRUDE FACES OF POLYGON ACCORDING TO DISTANCE TO LOCATOR
def magnitude(v):
x=v[0]
y=v[1]
z=v[2]
m=math.sqrt ((x*x)+(y*y)+(z*z))
return m
def distance (p1, p2):
x1=p1[0]
y1=p1[0]
z1=p1[1]
x1=p1[2]
x2=p1[0]
y2=p1[1]
z2=p1[2]
x= x1-x2
y= y1-y2
z= z1-z2
m= magnitude([x, y, z])
return m
def ExtrudeToLocator():
"Extrude based on a distance of a certain Locator"
#GET LOCATOR AND POLYGON
selPoly= cmds.filterExpand(sm=12)
selLoc= cmds.filterExpand(sm=22)
selPoly= selPoly[0]
#GET ALL FACES OF POLYGON
allFaces= cmds.ls(selPoly + ".f[:]", fl=1)
#LOOP THROUGH FACES
for face in allFaces:
vertex= cmds.polyListComponentConversion (face, fromFace=1, toVertex=1)
vertex= cmds.ls (vertex, fl=1)
# find the center of the face
xs= 0
ys= 0
zs= 0
# LOOP THROUGH VERTICES
for v in vertex:
pos= cmds.pointPosition(v)
x= pos[0]
y= pos[1]
z= pos[2]
xs= xs + x
ys= ys + y
zs= zs + z
centerX= xs/len(vertex)
centerY= ys/len(vertex)
centerZ= zs/len(vertex)
#PLACE LOCATOR
cmds.spaceLocator(p=(centerX, centerY, centerZ))
#DISTANCE TO LOCATOR
posLoc= cmds.pointPosition(selLoc)
d= distance([centerX, centerY, centerZ], posLoc)
print d
#extrude based on distance
cmds.polyExtrudeFacet(face, ltz=d/10)
#EXTRUDE TO LOCATOR
ExtrudeToLocator()
#####
### 03B
#####
import maya.cmds as cmds
import math
import random
#EXTRUDE FACES OF POLYGON ACCORDING TO DISTANCE TO LOCATOR
def magnitude(v):
x=v[0]
y=v[1]
z=v[2]
m=math.sqrt ((x*x)+(y*y)+(z*z))
return m
def distance (p1, p2):
x1=p1[0]
y1=p1[0]
z1=p1[1]
x1=p1[2]
x2=p1[0]
y2=p1[1]
z2=p1[2]
x= x1-x2
y= y1-y2
z= z1-z2
m= magnitude([x, y, z])
return m
def ExtrudeToLocator():
"Extrude based on a distance of a certain Locator"
#GET LOCATOR AND POLYGON
selPoly= cmds.filterExpand(sm=12)
selLoc= cmds.filterExpand(sm=22)
selPoly= selPoly[0]
#GET ALL FACES OF POLYGON
allFaces= cmds.ls(selPoly + ".f[:]", fl=1)
#LOOP THROUGH FACES
for face in allFaces:
vertex= cmds.polyListComponentConversion (face, fromFace=1, toVertex=1)
vertex= cmds.ls (vertex, fl=1)
# find the center of the face
xs= 0
ys= 0
zs= 0
# LOOP THROUGH VERTICES
for v in vertex:
pos= cmds.pointPosition(v)
x= pos[0]
y= pos[1]
z= pos[2]
xs= xs + x
ys= ys + y
zs= zs + z
centerX= xs/len(vertex)
centerY= ys/len(vertex)
centerZ= zs/len(vertex)
#PLACE LOCATOR
cmds.spaceLocator(p=(centerX, centerY, centerZ))
#DISTANCE TO LOCATOR
posLoc= cmds.pointPosition(selLoc)
d= distance([centerX, centerY, centerZ], posLoc)
print d
#extrude based on distance
cmds.polyExtrudeFacet(face, ltz=d/10)
#EXTRUDE TO LOCATOR
ExtrudeToLocator()
No comments:
Post a Comment