Thursday, July 23, 2009

assignment04__Zhu lei & Qin zhen









####### 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= 20
# 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= sin(30*i)*4
y= cos(sin(60*i)*4)*4
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= 6
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, .6)

# f) finish!

No comments:

Post a Comment