Tuesday, June 16, 2009

Assiment_02B




Assignment 03A

For this assignment, you should mainly work with components of objects in Maya (cvs, edges, faces, vertices). You should try and create a function definition for each one of the exercises, making them flexible by passing arguments and using if/else statements in your code.

  1. Curve CVs: function to randomly move all control vertices of a curve. As arguments in your function, you should pass the minimum and maximum values for the random movement
  2. Nurbs Surfaces CVs: function to randomly move all control vertices of a nurbs surface. As arguments in your function, you should pass the minimum and maximum values for the random movement, as well as the axis in which you want to randomly move the CVs (x, y or z)
  3. Faces of a polygon: function for randomly extrude all faces of a polygonal surface. As arguments in your function, you should pass the minimum and maximum values for the random extrusion
  4. Polygon Vertices: function to randomly move all vertices of a polygonal surface. As arguments in your function, you should pass the minimum and maximum values for the random movement, as well as the axis in which you want to randomly move the vertices (x, y or z)
  5. Add an if statement to the above functions to jump every n element (you choose the number). If you want, you can also change the operation being performed (for example, use poke face instead of extrude face, or extrude vertex instead of move vertex). Check the Python Command Reference in the Help menu to look for other operations that could be used with the desired component.

All the above is repetition of everything we saw in class and that you have been producing the past weeks.

Please, post your results (scripts along with screenshots) on the blog by 21.06, around midday.

w06 - recap and scripts

Yesterday we tried to do a kind of workshop in class. It was good, but a bit slower than I imagined. We started by seeing how to access all cvs of curves and nurbs surfaces, and all faces, vertices and edges of polygonal surfaces, and how to start a loop to make modifications with them.

## how to get all CVs of a curve
## this will result in a list containing all the names of the curve CVs
allCVs = cmds.ls("nameOfCurve.cv[:]", fl=1)

## you can also use the same code for a selected curve on stage
## which would make more sense for the flexibility of your script

# this will return you the name of all nurbs curves selected on stage
curve = cmds.filterExpand(sm=9)

#this will return you the names of all CVs from the first selected curve
#or of the only curve in case there is only one
allCVs = cmds.ls(curve[0] + ".cv[:]", fl=1)

## the same can be done with any selected nurbs surface
srf = cmds.filterExpand(sm=10)
allCVs = cmds.ls(srf[0] + ".cv[:][:]", fl=1)

## and with polygons
poly = cmds.filterExpand(sm=12)
# all faces:
allFaces = cmds.ls(poly[0] + ".f[:]", fl=1)
# all vertices:
allVertices = cmds.ls(poly[0] + ".vtx[:]", fl=1)
# all edges:
allEdges = cmds.ls(poly[0] + ".e[:]", fl=1)

## Then, if you want to make modifications on each one
## of those elements, you have to start a loop through the list.

#In the case of all cvs of a curve, for example:
for cv in allCVs:
#here come the code you want to perform with each cv
print cv

# or with faces of a polygon.
for face in allFaces:
#do something...

# keep in mind that the words cv or face in the line above
# are simply names of variables which you define, and which
# represent the cv or face at each iteration of the loop

## another way to do a loop, would be:
numCVs = len(allCVs) #this will return you the amount of elements you have in allCVs list
for i in range(numCVs):
print i #this will iterate through numbers
cv = allCVs[i] #like this you get the name of the CV
#and here you can put your code to make transformations with each cv



## One thing you can do in a loop is to jump in certain steps
## like for example, only perform action every 5th element, for example
## you do that by using the % operator and an if statement
for i in range(numCVs):
if i % 5 == 0:
#whatever is indented here will oly be executed everytime
#the above if statement is equal to true
print i

02B_COSMOS BEDZRA_SURFACE





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


#REVOLVING A CURVE TO FORM A SURFACE
def revolve(numPoints,myAxis,myEndSweep):
"revolve a curve"
myPoints=[]
for i in range(numPoints):
x=uniform(0,20)
y=10
z=i*5
myPoints.append([x,y,z])
crv=cmds.curve(ep=myPoints,d=3)
cmds.revolve(crv,axis=myAxis,endSweep=myEndSweep)
revolve(10,[1,0,1],90)

Monday, June 15, 2009

week05_assignment_Masha















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


def Curve(numPoints):
#create an empty list to store the point
points = []
#loop and gather point information
for i in range (1, numPoints, 1):
amplitude = randint(0,3)
amp = randint(0,3)
#function for the spiral curve
a=i*0.3
x = cos(a)*amplitude
y = 0

z =-i
myPoint = (x,y,z)
#store the point in the list
points.append(myPoint)

#create the curve
myCurve = cmds.curve (d = 3, p=points) #degree 3
return myCurve

def Curve2(numPoints):
#create an empty list to store the point
points = []
#loop and gather point information
for i in range (1, numPoints, 1):
amplitude = randint(0,3)
amp = randint(0,3)
#function for the spiral curve
a = i*0.3
x = sin(a)*amplitude
y = i
z = amp*4
myPoint = (x,y,z)
#store the point in the list
points.append(myPoint)

#create the curve
myCurve = cmds.curve (d = 3, p=points) #degree 3
return myCurve

def tubulize (path, radius, tubeSections = 8):
"Function to create tubes out of 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 of circle pivot
cmds.xform (cp = 1)
#extrude the circle along path
tube =cmds.extrude (profile [0], path, ucp =1, upn=1,et=1,rb=1,dl=3,ch=1, n ="spiralTube" )
#returne values
return [tube[0],radius,profile]

radius = 6
numCurves = 200
myCrv = []
y1 = 0
angle = 360/numCurves
x1 = radius
z1 = 10

for i in range (0, numCurves+1, 1):
rad = randint(3,8)
r = rad/10.0

if i%2 == 0:
curve1 = Curve(50)

else:
curve1 = Curve2(50)

#cmds.move (0,0,10, curve1)
#cmds.rotate( 0, 0, 90, curve1, pivot=(0,0,0))
#curve1= Curve(30)
cmds.rotate( 0, 0, angle*i+i,curve1, pivot=(x1,y1,z1))
crv1 = tubulize (curve1, r, tubeSections = 8)
#cmds.move (j,j,0, curve1)
myCrv.append (curve1)

Wednesday, June 10, 2009

02 B - Valentina De León



import maya.cmds as cmds
from math import*
from random import*
#creating the curve
def curves (amplitude):
numPoints= 40
points=[]
#loop
for i in range (1,numPoints,1):
#function of the spiral curve:
x=sin(i)*amplitude
y=cos(i)*amplitude/30
z= i
myPoint= (x,y,z)
#points in the list
points.append(myPoint)
myCurve=cmds.curve(d=30, p=points)
return myCurve
#list to store the curves
myCurve=[]
numCurves=70
#function
for i in range(0,numCurves,5):
crv= curves (i)
myCurve.append (crv)
print crv
#moving the curves
cmds.move (45,70,35, crv)
cmds.loft(myCurve)

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.

Week 05 - recap

Yesterday we saw how to identify and correct some common scripting mistakes. We saw that the output panel from the script editor in Maya always tells us exactly what is wrong with our script and where the mistake is located.

We also tried to go into surface manipulation techniques, which unfortunately wasn't completed as expected. You were supposed to have seen how to access and manupilate nurbs CVs, polygons vertices, faces and edges. But we ended up only seeing how to use construction history to manipulate surfaces my modifying their generating curves.

Tuesday, June 9, 2009

02B - Deborah Kaiser - Lofting curves (exploring the results with different functions)



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

# Surfaces from curves
#Curves
def curves (amplitude):
numPoints= 50
#list to store the points
points=[]
#loop
for i in range (1,numPoints,1):
#function of the spiral curve:
x=i*i/10
y=x*x*.5
z=y*x*sin(i)*.03
myPoint= (x,y,z)
#store the points in the list
points.append(myPoint)
myCurve=cmds.curve(d=3, p=points)
return myCurve
#List to store the curves
myCurve=[]
#Number of curves
numCurves=20
#Call the curve in a loop
for i in range(0,numCurves,2):
crv= curves (i)
#Store the curve in the list
myCurve.append (crv)
print crv
#move the curves
cmds.move (15,10,30, crv)
#Lofting the curves
cmds.loft(myCurve)

Assingnment 01B - 3D GRID










import maya.cmds as cmds
#3d points grid
from math import*
numRows = 50
numColumns = 10
num3rdDimension =40
for i in range(0,numRows,3):
x = (i)
for j in range(0,numColumns,1):
y = j
for k in range(-1,num3rdDimension,1):
z = sin(k*i*j)
myPoint=(x,y,z)
cmds.spaceLocator(p=myPoint)

Monday, June 8, 2009

02B - Deborah Kaiser - Lofting curves (exploring the results with different functions)



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

# Surfaces from curves
#Curves
def curves (amplitude):
numPoints= 50
#list to store the points
points=[]
#loop
for i in range (1,numPoints,1):
#function of the spiral curve:
x=tan(i)*amplitude
y=sin(i)*cos(i)*20
z=tan(i)*10
myPoint= (x,y,z)
#store the points in the list
points.append(myPoint)
myCurve=cmds.curve(d=3, p=points)
return myCurve
#List to store the curves
myCurve=[]
#Number of curves
numCurves=20
#Call the curve in a loop
for i in range(0,numCurves,2):
crv= curves (i)
#Store the curve in the list
myCurve.append (crv)
print crv
#move the curves
cmds.move (10,20,10, crv)
#Lofting the curves
cmds.loft(myCurve)

Lofting curves - Deborah Kaiser



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

# Surfaces from curves
#Curves
def curves (amplitude):
numPoints= 50
#list to store the points
points=[]
#loop
for i in range (1,numPoints,1):
#function of the spiral curve:
x=sin(i)*100
y=cos(i)*amplitude*i/10*tan(i)
z= i*2*sin(i)
myPoint= (x,y,z)
#store the points in the list
points.append(myPoint)
myCurve=cmds.curve(d=3, p=points)
return myCurve
#List to store the curves
myCurve=[]
#Number of curves
numCurves=20
#Call the curve in a loop
for i in range(0,numCurves,2):
crv= curves (i)
#Store the curve in the list
myCurve.append (crv)
print crv
#move the curves
cmds.move (10,50,1, crv)
#Lofting the curves
cmds.loft(myCurve)

Assingnment 01B - Points to curves



import maya.cmds as cmds
from math import*
from random import*
######################################################
#from points to curves
#defining initial variables
numRows= 30
numColumns=3
numLevels=9
amplitude = 7
#create an empty list to store the points
points= []
#defining the loop and gather information
for i in range (-1,numRows,1):
x= sin(6*i)*amplitude
for j in range (-1,numColumns,2):
y= cos(i)*8
for k in range (0,numLevels,2):
z= k+1
myPoint=(x,y,z)
#store the point in the list
points.append(myPoint)
#create the curve
cmds.curve (d= 3, p= points) #curve degree 3

Clau_Ex 02B



#Exercise 02B
import maya.cmds as cmds
from math import*
from random import*
#from curves to surfaces
#1 Step: create a curve
def curves (amplitude):
#def initial variables
numPoints= 50
#create an empty list to store the points
points=[]
#loop and gather information
for i in range (1,numPoints,1):
#function of the spiral curve:
x=sin(i)*amplitude
y=cos(i)*amplitude/1.2
z= i
myPoint= (x,y,z)
#store the points in the list
points.append(myPoint)
myCurve=cmds.curve(d=3, p=points)
return myCurve

#create an empty list to store the curves
myCurve=[]
#define the number of curves
numCurves=20
#function to call the curve in a loop
for i in range(0,numCurves,2):
crv= curves (i)
#store the curve in the list
myCurve.append (crv)
print crv
#move the curves
cmds.move (25,15,15, crv)
#loft the curves
cmds.loft(myCurve)

Assignment 01 A Pseudo Code

for humans

boil the water
put rice in the water
wait 20 min

for computer

function boilWater:
with waterBoiler
fill with coldWater
if waterBoiler = full:
stop fill
turn waterBoiler.switch to „on“
when waterBoiler.switch = „off“:
execute function fillPot

function fillPot:
get pot
place pot right to waterBoiler
with waterBoiler:
move 30cm up
turn -90°
if pot = „full“
with waterBoiler:
turn 90°
move 15cm down
execute function makeRice

function makeRice:
desiredRice = 200
desiredTime = 20min
get rice
with rice:
place inside pot

start counting time
if time = 20min:
put pot in initial position
when waterBoiler.switch = „off“:
finish

Week 05 - file to download

In our next class (08.06), we will start by learning how to detect, identify, and correct common scripting mistakes. For that you should download this Python script and save it in your script folder.

We will also take a look on how can we access sub-elements (vertices, faces, edges, control vertices, etc) of polygonal and Nurbs surfaces and apply transformations to them.

Assignment 02B

As discussed in class on 25.05, the Assignment 2B is a simple exercise coming from the previous assignment.

Now that you created series of curves with variations (by using functions and arguments) go one step further and from these curves generate surfaces.

You can use one of the several surface generation commands in Maya, but always using commands which depend on curves to work - loft, revolve, planar, boundary, birail, extrude, etc.

You should create a few variations, and post on the blog along with your code and screenshots. Don't forget to explain a bit what you were trying to do as well!

As I had a problem to post this before, the deadline for this assignment is 14.06 by noon.

Sunday, June 7, 2009

02B - Masha - Loft












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

#numPoints = 60
numCurves = 40.0
radius = 10

def Curve(numPoints):

#create an empty list to store the point
points = []
#loop and gather point information
for i in range (1, numPoints, 1):
amplitude = 1
#function for the spiral curve
x = sin(i)*amplitude
y = 0
z = i
myPoint = (x,y,z)
#store the point in the list
points.append(myPoint)

#create the curve
myCurve = cmds.curve (d = 3, p=points) #degree 3
return myCurve

def Curve2(numPoints):

#create an empty list to store the point
points = []
#loop and gather point information
for i in range (1, numPoints, 1):
amplitude = 1
#function for the spiral curve
x = (cos(i)*amplitude)
y = 0
z = i
myPoint = (x,y,z)
#store the point in the list
points.append(myPoint)

#create the curve
myCurve = cmds.curve (d = 3, p=points) #degree 3
return myCurve

myCrv = []
y1 = 0
angle = 360/numCurves
x1 = radius
z1 = 10
for i in range (0, numCurves+1, 1):
if i%2 == 0:
curve1 = Curve(50)
else:
curve1 = Curve2(50)
#cmds.move (0,0,10, curve1)
#cmds.rotate( 0, 0, 90, curve1, pivot=(0,0,0))
cmds.rotate( 0, 0, angle*i,curve1, pivot=(x1,y1,z1))

#cmds.move (j,j,0, curve1)
myCrv.append (curve1)
print myCrv

cmds.loft(myCrv)