Wednesday, June 10, 2009

Week 05 - script pt01

Here is the what we saw last class:


def tubulize( path, radius, tubeSections=8):
"Function to create tubes out of a curve"
#position on end of curve where i will put the circle profile
pos = cmds.pointOnCurve( path, position=1, pr=0.001, top=1)
#get tangent of this point
tan = cmds.pointOnCurve( path, tangent=1, pr=0.001, top=1)

#create the profile circle
profile = cmds.circle( c=pos, r=radius, normal=tan, s=tubeSections, ch=1 )
#center the circle pivot
cmds.xform( cp=1 )

#extrude the circle along the path
tube = cmds.extrude( profile[0], path, ucp=1, upn=1, et=2, rb=1, dl=3, ch=1, n="spiralTube")

#return values
return [tube[0], radius, profile]

The first function we wrote, used to create pipes on any curve, defining its radius. Also here, we saw what are and how to use optional function arguments, in this case, the
tubeSections
argument.

def crvMoveRandom( curve, minimum, maximum ):
"This function gets all CVs of a curve and move them"
#get all cvs of curve.
allCVs = "%s.cv[:] " % curve
print allCVs
cvs = cmds.ls( allCVs, fl=1 )
print cvs
#loop through cvs
for cv in cvs:
rx = random.uniform(minimum, maximum)
ry = random.uniform(minimum, maximum)
rz = random.uniform(minimum, maximum)
cmds.move( rx, ry, rz, cv, r=1 )

return cvs

On this function we learned a way to easily access all the control vertices (CVs) of a nurbs curve. By using the
cmds.ls
command along with the
fl
flag, you end up having a list with names of all cvs, through which you can later iterate and make whatever modifications you'd like.
We also saw that if we have a curve on which we aplpied the
tubulize()
function, the tube will automatically update when we make transformations on the curve. This happens due to Maya's construction history.

def animateCurve( curve, time ):
fps = 24
#start a loop through time
for i in range( time ):
#first go forward in time
cmds.currentTime( i * fps )
#then make transformations
cvs = crvMoveRandom(curve, -10, 10)
#set keyframe
cmds.setKeyframe(cvs)

The final function was just a quick example of what we could do with the construction history turned on, along with some animation commands. By setting keyframes on each modification, Maya automatically interpolates the frames in between returning you a smooth animation.

No comments:

Post a Comment