############################################################
#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()
Thursday, July 23, 2009
03B Cosmos Bedzra
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)
Wednesday, July 22, 2009
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)
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)
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)
03-A Anthony Adelmann Confusion
I have some trouble getting this script to work, a lot of weird spacing errors popped up.
#assignment 3A
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(minimum, maximum)
ry = random.uniform(minimum, maximum)
rz = random.uniform(minimum, maximum)
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=3)
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:
rz = random.uniform(minimum, maximum)
ry = random.uniform(minimum, maximum)
rz = random.uniform(minimum, maximum)
cmds.move (rx, ry, rz, i, r=2)
allCvs = cmds.ls("curve1.cv[:]", fl=4)
moveVertRandomly (allCvs, 11, 17)
allCvs1 = cmds.ls("nurbsPlane1.cv[:][:]", fl=1)
moveVerticeRandomly (allCvs, 5, 11, 7, 7, 12)
allFaces = cmds.ls ("pPlanel.f[:]", fl = 7)
extrudeFacesRandomly(allFaces, 7, 17)
allVert = cmds.ls("pPlane2.vtx[:]", fl=8)
polygonVertices (allVert, 6, 12)
#assignment 3A
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(minimum, maximum)
ry = random.uniform(minimum, maximum)
rz = random.uniform(minimum, maximum)
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=3)
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:
rz = random.uniform(minimum, maximum)
ry = random.uniform(minimum, maximum)
rz = random.uniform(minimum, maximum)
cmds.move (rx, ry, rz, i, r=2)
allCvs = cmds.ls("curve1.cv[:]", fl=4)
moveVertRandomly (allCvs, 11, 17)
allCvs1 = cmds.ls("nurbsPlane1.cv[:][:]", fl=1)
moveVerticeRandomly (allCvs, 5, 11, 7, 7, 12)
allFaces = cmds.ls ("pPlanel.f[:]", fl = 7)
extrudeFacesRandomly(allFaces, 7, 17)
allVert = cmds.ls("pPlane2.vtx[:]", fl=8)
polygonVertices (allVert, 6, 12)
Claudia_Ex04B_Nurbs Surfaces
########## EX04B ###########
# 1) Create a curve from points
# 2) Tubulize the curve
# 3) Create 3 more tubes displaced in a radial way
# 4) Move the Cvs of each tube
# according to a locator distance
# 5) Populate each tube with cylinders
# 6) finish!
###########################
import maya.cmds as cmds
from math import*
from random import*
# 1) Create a list of points to generate a curve
# define initial variables
numPoints= 15
# create an empty list to store the points
myPoints= []
# def Curve
def Curve(amplitude):
#loop and gather point information
for i in range (0, numPoints, 1):
# function of the helix to generate a curve
x= cos(7*i)
y= sin(7*i)
z= i*amplitude
myPoint= (x,y,z)
# store the points in the list
myPoints.append(myPoint)
#create the curve
Curve= cmds.curve(d=3, p=myPoints, n="myCurve") #curve of degree 3
#call function
myCurve=Curve(5)
# 2) Create a tube
# first select the curve
myCurve= cmds.filterExpand(sm=9)
# define the function
def tubulize(path,radius,tubeSections):
# function to create tubes out of a curve
#position on end of the 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, n="circle")
#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")
# call function
myTube=tubulize(myCurve,6,10)
# 3) duplicate tubes rotating them according to a Locator
# create a locator
pivot= (-12,15,0)
myPoint= cmds.spaceLocator( p=pivot, n="myPoint")
# create a list to store the tubes
myTubes=[]
# select the tube to copy
selObjects=cmds.select("spiralTube")
# define variables
numTubes=3
rot = 0
# duplicate the tubes
for e in range (0,numTubes,1):
rot=rot+70
mynewTubes= cmds.duplicate("spiralTube", n="myNewTubes_%s" %e)
cmds.rotate(0,0,rot, "myNewTubes_%s" %e, p=pivot)
myTubes.append("myNewTubes_%s" %e)
#4) Move the vertices of each tube according
# a locator distance
# 4.1) For the Spiral Tube
#define distance between cvs 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 (posPoint,pivot):
#subtract both vectors
x1= posPoint[0]
y1= posPoint[1]
z1= posPoint[2]
x2= pivot[0]
y2= pivot[1]
z2= pivot[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 cvsNames of myTubes
spiralTubeCvs = cmds.ls("spiralTube.cv[:]", fl=1)
#create an empty list to store the points
mySpiralCvs=[]
#get selected Locator
#myPoint= cmds.filterExpand(sm=22)
myPointPos= cmds.ls("myPoint", fl=1)
#loop through cvs
for i in spiralTubeCvs:
posPoint= cmds.pointPosition(i)
posPivot= cmds.pointPosition(myPoint)
d= distance(posPoint, pivot)
cmds.move (d,d,d,i,r=True)
#store the cvs in a list
mySpiralCvs.append(spiralTubeCvs)
#call the function
moveToLocator()
#####################3
# 4.2) For myNewTubes_0
#define moveToLocator function
def moveToLocator():
# A) get all the cvsNames of myTubes
newTubeCvs = cmds.ls("myNewTubes_0.cv[:]", fl=1)
#create an empty list to store the points
myNewTubeCvs=[]
#get selected Locator
#myPoint= cmds.filterExpand(sm=22)
myPointPos= cmds.ls("myPoint", fl=1)
#loop through cvs
for i in newTubeCvs:
posPoint= cmds.pointPosition(i)
posPivot= cmds.pointPosition(myPoint)
d= distance(posPoint, pivot)
cmds.move (d,d,d,i,r=True)
#store the cvs in a list
myNewTubeCvs.append(newTubeCvs)
#call the function
moveToLocator()
###################
#4.3) For myNewTubes_1
#define moveToLocator function
def moveToLocator():
# A) get all the cvsNames of myTubes
newTube1Cvs = cmds.ls("myNewTubes_1.cv[:]", fl=1)
#create an empty list to store the points
myNewTube1Cvs=[]
#get selected Locator
#myPoint= cmds.filterExpand(sm=22)
myPointPos= cmds.ls("myPoint", fl=1)
#loop through cvs
for i in newTube1Cvs:
posPoint= cmds.pointPosition(i)
posPivot= cmds.pointPosition(myPoint)
d= distance(posPoint, pivot)
cmds.move (d,d,d,i,r=True)
#store the cvs in a list
myNewTube1Cvs.append(newTube1Cvs)
#call the function
moveToLocator()
###################
#4.3) For myNewTubes_2
#define moveToLocator function
def moveToLocator():
# A) get all the cvsNames of myTubes
newTube2Cvs = cmds.ls("myNewTubes_2.cv[:]", fl=1)
#create an empty list to store the points
myNewTube2Cvs=[]
#get selected Locator
#myPoint= cmds.filterExpand(sm=22)
myPointPos= cmds.ls("myPoint", fl=1)
#loop through cvs
for i in newTube2Cvs:
posPoint= cmds.pointPosition(i)
posPivot= cmds.pointPosition(myPoint)
d= distance(posPoint, pivot)
print d
cmds.move (d,d,d,i,r=True)
#store the cvs in a list
myNewTube2Cvs.append(newTube2Cvs)
#call the function
moveToLocator()
###############################
# 5) Populate each Tube with cylinders
def cylindersOnSurface(numU, numV):
#5.1)Select objects on stage
SelTubes= cmds.select("spiralTube", "myNewTubes_0", "myNewTubes_1", "myNewTubes_2")
#5.2) get selected objects
tubs= cmds.filterExpand(sm=10)
#5.3) create cylinders on the surface
for srf in tubs:
# first find the maximum number in U and V
U= cmds.getAttr(srf + ".minMaxRangeU")
V= cmds.getAttr(srf + ".minMaxRangeV")
U=U[0]
V=V[0]
rangeU= U[1]-U[0]
stepU= rangeU/numU
rangeV= V[1]-V[0]
stepV= rangeV/numV
#loop in U direction
for i in range (numU):
u = i*stepU
#loop in V direction
for j in range (numV):
v= j*stepV
coord= cmds.pointOnSurface(srf, p=1, u=u, v=v)
cmds.spaceLocator(p=coord)
normal = cmds.pointOnSurface(srf, u=u, v=v, normalizedNormal=1)
#create cilinders perpendicular to the normal of the tube
cmds.cylinder(p=coord, ax=normal, radius=4)
### call the function
cylindersOnSurface(10,10)
# erase the cilinder profile, the initial curve and the locator
cmds.delete("myCurve", "myPoint", "circle")
# 6) Finish!
Claudia_Ex04A_Polygonal Surface
####### 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= 60
# 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= i*cos(6*i)
y= i*(sin(6*i)+2)
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= 9
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, 0.6)
# f) finish!
Tuesday, July 21, 2009
Sunday, July 12, 2009
Masha - Assignment 03B
import maya.cmds as cmds
import random
import math
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):
#substract both vectors
x1 = p1[0]
y1 = p1[1]
z1 = p1[2]
x2 = p2[0]
y2 = p2[1]
z2 = p2[2]
x = x1-x2
y = y1-y2
z = z1-z2
m = magnitude ([x,y,z])
return m
def unit(v):
#returns unit vector of v
#first get magnitude
m = magnitude(v)
x = v[0]
y = v[1]
z = v[2]
#devide each element by magnitude
x = x/m
y = y/m
z = z/m
vu = [x,y,z]
return vu
def move (v, amount):
"Move by certaine amount in directio v"
x = v[0]
y = v[1]
z = v[2]
x = x+amount
y = y+amount
z = z+amount
newP = [x,y,z]
return amount
def vectorBetweenPoints (p1, p2):
"Returns vector between p1 and p2"
#substract both vectors
x1 = p1[0]
y1 = p1[1]
z1 = p1[2]
x2 = p2[0]
y2 = p2[1]
z2 = p2[2]
x = x1-x2
y = y1-y2
z = z1-z2
newV = [x,y,z]
return newV
def moveVert (allCvs):
selLoc = cmds.filterExpand (sm = 22)
xs = 0
ys = 0
zs = 0
for i in allCvs:
pos = cmds.pointPosition(i)
posLoc = cmds.pointPosition (selLoc)
dd = distance ([centerX, centerY, centerZ], posLoc)
print dd
cmds.polyExtrudeVertex( l =dd, w=3, d=4 )
def moveVertice (allCvs):
selLoc = cmds.filterExpand (sm = 22)
allCvs1 = cmds.ls("nurbsPlane2.cv[:][:]", fl=1)
#d=1000
dist =1000
allDist =[]
print selLoc
for i in allCvs1:
pos = cmds.pointPosition(i)
for j in selLoc:
posLoc = cmds.pointPosition (j)
dd = distance (pos, posLoc)
if dd
03B - Deborah Kaiser - Extrudying faces of a polygon according to locator
#################################################
#####
### 03B
#####
import maya.cmds as cmds
import math
import random
#EXTRUDE FACES OF POLYGON ACCORDING TO DISTANCE TO LOCATOR
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"
#GET LOCATOR AND POLYGON
selPoly= cmds.filterExpand(sm=12)
selLoc= cmds.filterExpand(sm=22)
selPoly= selPoly[0]
#GET ALL FACES OF POLYGON
allFaces= cmds.ls(selPoly + ".f[:]", fl=1)
#LOOP THROUGH FACES
for face in allFaces:
vertex= cmds.polyListComponentConversion (face, fromFace=1, toVertex=1)
vertex= cmds.ls (vertex, fl=1)
# find the center of the face
xs= 0
ys= 0
zs= 0
# LOOP THROUGH VERTICES
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)
#PLACE LOCATOR
cmds.spaceLocator(p=(centerX, centerY, centerZ))
#DISTANCE TO LOCATOR
posLoc= cmds.pointPosition(selLoc)
d= distance([centerX, centerY, centerZ], posLoc)
print d
#extrude based on distance
cmds.polyExtrudeFacet(face, ltz=d/10)
#EXTRUDE TO LOCATOR
ExtrudeToLocator()
#####
### 03B
#####
import maya.cmds as cmds
import math
import random
#EXTRUDE FACES OF POLYGON ACCORDING TO DISTANCE TO LOCATOR
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"
#GET LOCATOR AND POLYGON
selPoly= cmds.filterExpand(sm=12)
selLoc= cmds.filterExpand(sm=22)
selPoly= selPoly[0]
#GET ALL FACES OF POLYGON
allFaces= cmds.ls(selPoly + ".f[:]", fl=1)
#LOOP THROUGH FACES
for face in allFaces:
vertex= cmds.polyListComponentConversion (face, fromFace=1, toVertex=1)
vertex= cmds.ls (vertex, fl=1)
# find the center of the face
xs= 0
ys= 0
zs= 0
# LOOP THROUGH VERTICES
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)
#PLACE LOCATOR
cmds.spaceLocator(p=(centerX, centerY, centerZ))
#DISTANCE TO LOCATOR
posLoc= cmds.pointPosition(selLoc)
d= distance([centerX, centerY, centerZ], posLoc)
print d
#extrude based on distance
cmds.polyExtrudeFacet(face, ltz=d/10)
#EXTRUDE TO LOCATOR
ExtrudeToLocator()
Ex03B_PolyPlane_Deborah&Claudia
#######################
## Ex03B_Move Cvs of a Nurbs according to Locator direction
#######################
import maya.cmds as cmds
import math
#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 ("pPlane1.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
cmds.move (d,3,d,v,r=True)
#store the cvs in a list
MyVerts.append(allVertices)
#call the function
moveToLocator()
Subscribe to:
Posts (Atom)