Thursday, July 23, 2009

03B Cosmos Bedzra



############################################################
#EXTRUDING FACE ACCORDING TO A LOCATOR.
############################################################

import maya.cmds as cmds
import math
import random

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"

selPoly= cmds.filterExpand(sm=12)
selLoc= cmds.filterExpand(sm=22)
selPoly= selPoly[0]

allFaces= cmds.ls(selPoly + ".f[:]", fl=1)

for face in allFaces:
vertex= cmds.polyListComponentConversion (face, fromFace=1, toVertex=1)
vertex= cmds.ls (vertex, fl=1)
xs= 0
ys= 0
zs= 0

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)

cmds.spaceLocator(p=(centerX, centerY, centerZ))

posLoc= cmds.pointPosition(selLoc)
d= distance([centerX, centerY, centerZ], posLoc)
print d
#extrude based on distance
cmds.polyExtrudeFacet(face, ltz=d/1)

#extruding to locator
ExtrudeToLocator()

1 comment:

  1. hello... hapi blogging... have a nice day! just visiting here....

    ReplyDelete