Wednesday, July 22, 2009

Claudia_Ex04A_Polygonal Surface









####### Ex04A #######
# a) Create a curve from points
# b) create several curves
# c) loft the curves to create a Nurbs Surface
# d) Convert the Nurbs Surface to a Polygonal Surface
# e) Modify the vertices of the Polygonal Surface randomly
# f) finish
#################################

import maya.cmds as cmds
from math import*
import random

# a) Create a curve from points
# define Curve
def Curve(numPoints):
# define initial variables
numPoints= 60
# create an empty list to store the points
Points= []
#loop and gather point information
for i in range (0, numPoints,1):
# function of the conical helix to generate a curve
x= i*cos(6*i)
y= i*(sin(6*i)+2)
z= i+3
myPoint= (x,y,z)
# store the points in the list
Points.append(myPoint)
#create the curve
Curve= cmds.curve(d=3, p=Points) #curve of degree 3
return Curve

MyCurve= Curve(60)

#hide the Curve
cmds.hide(MyCurve)

# b) create several curves
# create an empty list to store the curves
myCurves=[]
# define variables
numCrvs= 9
offset= 4
# create a loop
for e in range (0, numCrvs,1):
crv= Curve(e)
offset= offset*1.2
#store the curve in the list
myCurves.append(crv)
#move the curves with an offset in the "z" axis
cmds.move(0,0,offset,crv)

# c) Loft the curves to create a Nurbs surface
myNurbsSurface= cmds.loft(myCurves, n="myNurbsSurf")

#hide the curves
cmds.hide(myCurves)

# d) convert the Nurbs Surface to Polygonal Surface
# get the Nurbs surface
myNurbsSurface= cmds.filterExpand(sm=10)

# convert
myPolySurface=cmds.nurbsToPoly("myNurbsSurf",pt=1, n="myPolySurf")

#hide the Nurbs Surface
cmds.hide("myNurbsSurf")

# e) Move the vertices of the Polygonal surface randomly
# get all the vertices of myPolySurface
allCvs= cmds.ls("myPolySurf.vtx[:][:]", fl=1)

# Move the vertices in PolySurface randomly
def moveVertiRandomly(allCvs, minimum, maximum):
if minimum>= maximum:
print "poly"
# start a loop through all vertices in "x" and "y" axes
else:
for i in allCvs:
x= random.uniform(minimum, maximum)*e
y= random.uniform(minimum, maximum)*e
z= 0
cmds.move (x,y,z,i,r=True)
# move vertices randomly
moveVertiRandomly (allCvs, 0, 0.6)

# f) finish!

No comments:

Post a Comment