Wednesday, July 8, 2009

w08 - recap and script

As we saw last class, this semester we studied the following topics:

a. Basics of scripting
    i. Variables
    ii. Lists
    iii. Loops
    iv. Conditional statements
    v. Functions
b. Object manipulation in maya
    i. Points
        1. How to represent a point
        2. How to plot points in space
    ii. Curves
        1. How to get points coordinates and use them to draw a curve
        2. Using mathematical functions to generate curves
    iii. Surfaces
        1. How to use curves to generate surfaces
        2. Primitive surfaces in Maya
        3. Types of surfaces
            a. Polygonal surfaces
            b. Nurbs surfaces
            c. Subdivisions
        4. Object components
            a. Polygons
                i. Vertices
                ii. Faces
                iii. Edges
            b. Nurbs
                i. Control vertices
                ii. Isoparms
                iii. Surface points
        5. Volumes
            a. Primitives

In our last class we saw the last function for the semester, which showed you how to determine point on a nurbs surface and how to use the normals to orient the placement of objects on them. Here is the whole function, with some modifications to increase flexibility:

####################
## GSI
## w08
####################

import maya.cmds as cmds

def createCellsNormalToSurface(whatCell, numU, numV, size):
#determine the scale of the objects
scale = (size/100.)*.5
#get selected objects
objs = cmds.ls(sl=1)
#check if you do have selected objects on stage
if (len(objs) == 0):
#in case you dont, stop the function execution
print "You need to select at least one surface!"
return

#if you have selected surfaces,
#apply the objects on each one of the
for mySurface in objs:
for i in range(numU):
myu = i/float(numU)
for j in range(numV):
myv = j/float(numV)
#get the coordinates and the normal on the current uv parameter
myCoord = cmds.pointOnSurface(mySurface, top=1, u=myu, v=myv, p=1)
myNorm = cmds.pointOnSurface(mySurface, top=1, normalizedNormal=1, u=myu, v=myv)
#then according to the type of object you want place it
if (whatCell == "Cylinder"):
myCell = cmds.cylinder(p=myCoord,ax=myNorm, r=scale, hr=scale)
elif (whatCell == "Plane"):
myCell = cmds.nurbsPlane(p=myCoord, ax=myNorm, w=scale, lr=scale)
elif (whatCell == "Cone"):
myCell = cmds.cone(p=myCoord, ax=myNorm, r=scale, s=20, hr=scale)

else:
print "You need to specify Cylinder, Plane or Cone!

##call the function
createCellsNormalToSurface("Cylinder", 30, 15, 200)

No comments:

Post a Comment