Thursday, July 23, 2009

03B Cosmos Bedzra



############################################################
#EXTRUDING FACE ACCORDING TO A LOCATOR.
############################################################

import maya.cmds as cmds
import math
import random

def magnitude(v):
x=v[0]
y=v[1]
z=v[2]
m=math.sqrt ((x*x)+(y*y)+(z*z))
return m

def distance (p1, p2):
x1=p1[0]
y1=p1[0]
z1=p1[1]
x1=p1[2]
x2=p1[0]
y2=p1[1]
z2=p1[2]
x= x1-x2
y= y1-y2
z= z1-z2
m= magnitude([x, y, z])
return m

def ExtrudeToLocator():
"Extrude based on a distance of a certain Locator"

selPoly= cmds.filterExpand(sm=12)
selLoc= cmds.filterExpand(sm=22)
selPoly= selPoly[0]

allFaces= cmds.ls(selPoly + ".f[:]", fl=1)

for face in allFaces:
vertex= cmds.polyListComponentConversion (face, fromFace=1, toVertex=1)
vertex= cmds.ls (vertex, fl=1)
xs= 0
ys= 0
zs= 0

for v in vertex:
pos= cmds.pointPosition(v)
x= pos[0]
y= pos[1]
z= pos[2]
xs= xs + x
ys= ys + y
zs= zs + z
centerX= xs/len(vertex)
centerY= ys/len(vertex)
centerZ= zs/len(vertex)

cmds.spaceLocator(p=(centerX, centerY, centerZ))

posLoc= cmds.pointPosition(selLoc)
d= distance([centerX, centerY, centerZ], posLoc)
print d
#extrude based on distance
cmds.polyExtrudeFacet(face, ltz=d/1)

#extruding to locator
ExtrudeToLocator()

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!

Assigment 04 - Valentina De Leon



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

#create a locator in random position
x = uniform (5,40)
selLoc = cmds.spaceLocator( p=(x,x,9*x) )
#create a curve
def curves (amplitude):

#def initial variables
numPoints= 9

#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=cos(i)*i
y=sin(i)*amplitude
z= i
myPoint= (x,y,z)

#store the points in the list
points.append(myPoint)
myCurve=cmds.curve(d=5, p=points)
return myCurve

#create an empty list to store the curves
myCurve=[]

#define number of curves
numCurves=3

#function to call the curves in a loop
for i in range(0,numCurves,1):
crv= curves (i)

#store the curve in the list
myCurve.append (crv)
print crv

#move the curves
cmds.move (15,3,30, crv)

#loft the curves
LoftSrf = cmds.loft(myCurve)

### Move Surface ###

# A) get all the vertices of the Surfaces
allCvs= cmds.ls("loftedSurface1.cv[:][:]", fl=1)
cmds.select (LoftSrf, r = True)

# B) define move cvs in surface randomly
def moveVertiRandomly(allCvs, minimum, maximum):
if minimum>= maximum:
print "hello!"
# B.1) start a loop through all cvs in z axis
else:
for i in allCvs:
x= 0
y= 0
z= uniform (minimum, maximum)
cmds.move (x,y,z,i,r=True)
# C) move cvs randomly
moveVertiRandomly (allCvs, 0, 20)

### Move Cvs of Surface according to Locator direction ###

#define coordinates between locator and CV in order to move CV
def distance1 (posPoint, posLoc, constantMin, constantMax):
#subtract both vectores
x1= posPoint[0]
y1= posPoint[1]
z1= posPoint[2]
x2= posLoc[0]
y2= posLoc[1]
z2= posLoc[2]
constant = uniform (constantMin, constantMax)
x= x1 + ((x2 - x1)/constant)
y= y1 + ((y2 - y1)/constant)
z= z1 + ((z2 - z1)/constant)
m= [x,y,z]
return m

#define moveToLocator function
def moveToLocator(selLoc):
#loop through cvs
for i in allCvs:
# refresh
cmds.refresh ()
posPoint= cmds.pointPosition(i)
posLoc= cmds.pointPosition (selLoc)
# randomly moving CVs towards the locator
d= distance1(posPoint, posLoc, 5,3)
cmds.move (d[0],d[1],d[2],i)

#call the function
moveToLocator(selLoc)


### Move Curves ###

# A) get all the cvsNames of a curve
crvCvs = cmds.ls("curve1.cv[:]", fl=1)

# B) define move cvs randomly
def moveVertRandomly (allCvs, minimum, maximum):
if minimum>= maximum:
print "hello!"
# B.1) start a loop through all cvs
else:
for cv in allCvs:
rx = uniform(minimum, maximum)
ry = uniform(minimum, maximum)
rz = uniform(minimum, maximum)
cmds.move (rx,ry,rz,cv,r=5)
# refresh
cmds.refresh ()
cmds.pause (sec=1)
# C) move cvs randomly
moveVertRandomly (crvCvs, 0, 20)


### Move Curve 5 according to Locator direction ####

def moveCrvFive (selLoc):
fiveCvs = cmds.ls("curve5.cv[:]", fl=1)
for j in fiveCvs:
posPoint= cmds.pointPosition(j)
posLoc= cmds.pointPosition (selLoc)
# randomly moving CVs towards the locator
d= distance1(posPoint, posLoc, 3,2)
cmds.move (d[0],d[1],d[2],j)
# refresh
cmds.refresh ()
cmds.pause (sec=1)

moveCrvFive (selLoc)

03--B Zhulei








#######################
## Ex03B_Move Cvs of a Nurbs according to Locator direction
#######################

import maya.cmds as cmds
import math
import random

#define distance between PolFaces and locator
def magnitude (v):
#v is a list of x,y,z values
x= v[0]
y= v[1]
z= v[2]
m= math.sqrt ( (x*x) + (y*y) + (z*z) )
return m

def distance (posVert, posLoc):
#subtract both vectors
x1= posVert[0]
y1= posVert[1]
z1= posVert[2]
x2= posLoc[0]
y2= posLoc[1]
z2= posLoc[2]
x= x1 - x2
y= y1 - y2
z= z1 - z2
m= magnitude ([x,y,z])
return m

#define moveToLocator function
def moveToLocator():
# A) get all the verticesNames of a plane
allVertices= cmds.ls ("pSphere1.vtx[:]", fl=1)

#create an empty list to store the points
MyVerts=[]

#get selected Locator
selLoc= cmds.filterExpand(sm=22)

#loop through vertices
for v in allVertices:
pos= cmds.pointPosition(v)
x= pos[0]
y= pos[1]
z= pos[2]

#find distance to Locator
posVert= cmds.pointPosition(v)
posLoc= cmds.pointPosition(selLoc)
d= distance(posVert, posLoc)
print d
x= random.uniform(0, .5)
y= random.uniform(0,.5)
cmds.move (d*x,d*y,0,v,r=True)

#store the cvs in a list
MyVerts.append(allVertices)

#call the function
moveToLocator()

03-A Zhulei








import maya.cmds as cmds
import random
import math

def moveVertRandomly (allCvs, minimum, maximum):
if minimum>= maximum:
print "Find new variables!"
else:
for i in allCvs:
rx = random.uniform(1, 19)
ry = random.uniform(minimum, maximum)
rz = random.uniform(minimum, maximum)
cmds.move (rx,ry,rz,i,r=8)

def moveVerticeRandomly (allCvs, minimum, maximum, x,y,z):
if minimum>= maximum:
print "Find new variables!"
else:
for i in allCvs:

z = random.uniform(minimum, maximum)
cmds.move (x,y,z,i,r=12)

def extrudeFacesRandomly(allFaces, minimum, maximum):
if minimum>= maximum:
print "Find new variables!"
else:
for i in allFaces:
rz = random.uniform(minimum, maximum)
cmds.polyExtrudeFacet(i, ltz = rz)

def polygonVertices (allVert, minimum, maximum):
if minimum>= maximum:
print "Find new variables!"
else:
for i in allVert:
rx = random.uniform(minimum, maximum)
ry = random.uniform(minimum, maximum)
rz = random.uniform(minimum, maximum)
cmds.move (rx,ry,rz,i,r=7)


allCvs = cmds.ls("curve1.cv[:]", fl=5)
moveVertRandomly (allCvs, -1, 20)

allCvs1 = cmds.ls("nurbsPlane1.cv[:][:]", fl=5)
moveVerticeRandomly (allCvs, 1, 2,3,4,5)
allFaces = cmds.ls ("pPlane1.f[:]", fl = 5)

extrudeFacesRandomly(allFaces, 0, 6)
allVert = cmds.ls("pPlane2.vtx[:]", fl=5)
polygonVertices (allVert, 0, 20)

02-B Zhulei









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,15)
y=i*3
z=cos(sin(5*i))*i
myPoints.append([x,y,z])
crv=cmds.curve(ep=myPoints,d=3)
cmds.revolve(crv,axis=myAxis,endSweep=myEndSweep)
revolve(20,[1,0,1],360)

02-A Zhulei







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

#from curves to surfaces
#step 1, create a curve
def curves (amplitude):
#def initial variables
numPoints=80
#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*3)
y=cos(cos(i)*2+1)
z=i
myPoint=(x,y,z)
#store the points in the list
points.append(myPoint)
myCurve=cmds.curve(d=60, p=points)

#create an empty list to store the curves
myCurve=[]
#define the number of curves
numCurves=10
#function to call the curves 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(2,11,4, crv)
#loft the curves
cmds.loft(myCurve)

qinzhen_3b


Wednesday, July 22, 2009

Assiment_03B_DengLei




04 Cosmos Bedzra



import maya.cmds as cmds
import random
import math


#revolve a curve to form a surface
def revolve(numPoints,myAxis,myEndSweep):
"revolve 12a 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,[0,0,1],180)


#get all the Cvs of the revolved surface
allCvs= cmds.ls("revolvedSurface8.cv[:][:]", fl=1)

#define move cvs in nurbsPlane randomly
def moveVertiRandomly(allCvs, minimum, maximum,x,y,z):
if minimum>= maximum:
print "hello!"
#start a loop through all cvs in x axis
else:
for i in allCvs:
x= random.uniform(minimum, maximum)
y=0
z=0
cmds.move (x,y,z,i,r=True)
#move Cvs randomly
moveVertiRandomly (allCvs, 2, 18, 0,0,7)

03A Cosmos Bedzra




import maya.cmds as cmds
import random
import math

##################################################
#Curve CVs
##################################################
# getting all CVs of the curve
allCvs = cmds.ls("curve1.cv[:]", fl=1)

# randomly moving CVs
def moveVertRandomly (allCvs, minimum, maximum):
if minimum>= maximum:
print "Dessau!"
# start a loop through all cvs
else:
for cv in allCvs:
rx = random.uniform(minimum, maximum)
ry = random.uniform(minimum, maximum)
rz = random.uniform(minimum, maximum)
cmds.move (rx,ry,rz,cv,r=2)

moveVertRandomly (allCvs, -5, 5)

##################################################
# Nurbs Surfaces CVs
##################################################
# getting vertices of the Nurbs surface
allCvs= cmds.ls("nurbsPlane1.cv[:][:]", fl=1)

# randomly moving Cvs of the Nurbs surface
def moveVertiRandomly(allCvs, minimum, maximum,x,y,z):
if minimum>= maximum:
print "Dessau!"
# start a loop through all cvs in z axis
else:
for i in allCvs:
x= 0
y= 0
z= random.uniform(minimum, maximum)
cmds.move (x,y,z,i,r=True)

moveVertiRandomly (allCvs, -1, 3, 0,0,1)

##################################################
# Faces of a polygon
##################################################
# getting all faces of Polygon
allFaces= cmds.ls ("pSolid1.f[:]", fl=1)

# extruding faces of the polygon
def ExtrudeFacesRandom (allFaces, minimum, maximum):
if minimum>= maximum:
print "Dessau"
# start a loop through all faces in y axis
else:
for face in allFaces:
ry= random.uniform(minimum, maximum)
cmds.polyExtrudeFacet(face, ltz=ry)

ExtrudeFacesRandom(allFaces, 0,2)

##################################################
# Polygon Vertices
##################################################
# getting all vertices of a Polygon
allVertices= cmds.ls ("pPlane1.vtx[:]", fl=1)

# randomly moving Polygon Vertices
def movePolVert (allVertices, minimum, maximum):
if minimum>= maximum:
print "Dessau"
# start a loop through vertices in z axis
else:
for e in allVertices:
rx= random.uniform (minimum, maximum)
ry= random.uniform (minimum, maximum)
rz= random.uniform (minimum, maximum)
cmds.move (rx,ry,rz,e,r=True)

movePolVert(allVertices,-1,1)

qinzhen_3a



qinzhen assignment2b


04 - Deborah Kaiser - images


04 - Deborah Kaiser

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

#create a locator in random position
x = uniform (10,30)
selLoc = cmds.spaceLocator( p=(x,x,2*x) )
#create a curve
def curves (amplitude):

#def initial variables
numPoints= 35

#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=cos(i)*i
y=sin(i)*amplitude
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 number of curves
numCurves=5

#function to call the curves in a loop
for i in range(0,numCurves,1):
crv= curves (i)

#store the curve in the list
myCurve.append (crv)
print crv

#move the curves
cmds.move (10,5,5, crv)

#loft the curves
LoftSrf = cmds.loft(myCurve)

### Move Surface ###

# A) get all the vertices of the Surfaces
allCvs= cmds.ls("loftedSurface1.cv[:][:]", fl=1)
cmds.select (LoftSrf, r = True)

# B) define move cvs in surface randomly
def moveVertiRandomly(allCvs, minimum, maximum):
if minimum>= maximum:
print "hello!"
# B.1) start a loop through all cvs in z axis
else:
for i in allCvs:
x= 0
y= 0
z= uniform (minimum, maximum)
cmds.move (x,y,z,i,r=True)
# C) move cvs randomly
moveVertiRandomly (allCvs, 0, 10)

### Move Cvs of Surface according to Locator direction ###

#define coordinates between locator and CV in order to move CV
def distance1 (posPoint, posLoc, constantMin, constantMax):
#subtract both vectores
x1= posPoint[0]
y1= posPoint[1]
z1= posPoint[2]
x2= posLoc[0]
y2= posLoc[1]
z2= posLoc[2]
constant = uniform (constantMin, constantMax)
x= x1 + ((x2 - x1)/constant)
y= y1 + ((y2 - y1)/constant)
z= z1 + ((z2 - z1)/constant)
m= [x,y,z]
return m

#define moveToLocator function
def moveToLocator(selLoc):
#loop through cvs
for i in allCvs:
# refresh
cmds.refresh ()
posPoint= cmds.pointPosition(i)
posLoc= cmds.pointPosition (selLoc)
# randomly moving CVs towards the locator
d= distance1(posPoint, posLoc, 2,5)
cmds.move (d[0],d[1],d[2],i)

#call the function
moveToLocator(selLoc)


### Move Curves ###

# A) get all the cvsNames of a curve
crvCvs = cmds.ls("curve1.cv[:]", fl=1)

# B) define move cvs randomly
def moveVertRandomly (allCvs, minimum, maximum):
if minimum>= maximum:
print "hello!"
# B.1) start a loop through all cvs
else:
for cv in allCvs:
rx = uniform(minimum, maximum)
ry = uniform(minimum, maximum)
rz = uniform(minimum, maximum)
cmds.move (rx,ry,rz,cv,r=2)
# refresh
cmds.refresh ()
cmds.pause (sec=1)
# C) move cvs randomly
moveVertRandomly (crvCvs, 0, 17)


### Move Curve 5 according to Locator direction ####

def moveCrvFive (selLoc):
fiveCvs = cmds.ls("curve5.cv[:]", fl=1)
for j in fiveCvs:
posPoint= cmds.pointPosition(j)
posLoc= cmds.pointPosition (selLoc)
# randomly moving CVs towards the locator
d= distance1(posPoint, posLoc, 2,2)
cmds.move (d[0],d[1],d[2],j)
# refresh
cmds.refresh ()
cmds.pause (sec=1)

moveCrvFive (selLoc)