cwisbg

Maya rock gen

Oct 6th, 2014
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.13 KB | None | 0 0
  1. # maya rock gen
  2. # creates a good rock every once in a while, other times it makes nothing.
  3. # just create 100 and pikc out the good ones.
  4. from pymel.core import *
  5. import random as r
  6. def randE(object):
  7.     ea = []
  8.     for edge in object.e:
  9.         rE = r.randint(0,6)
  10.         if rE == 3:
  11.             polyCollapseEdge(edge,ch=0)
  12.             ea.append(edge)
  13. def randEs(object):
  14.     ea = []
  15.     for edge in object.e:
  16.         rE = r.randint(0,6)
  17.         if rE == 3:
  18.             polyCollapseEdge(edge,ch=0)
  19.             ea.append(edge)
  20. def randoY(object):
  21.     rx = r.randint(0,360)
  22.     ry = r.randint(0,360)
  23.     rz = r.randint(0,360)
  24.     rotate(object,rx,ry,rz)
  25.        
  26. def cleanRock(rock):
  27.     #select(cl=1)
  28.     #select(rock,add=1)
  29.     #bb = polyEvaluate(b=1)
  30.     nwMesh = polyCube()[0]
  31.     polySmooth(nwMesh,dv=2)
  32.     delete(rock, ch = 1)
  33.     polySmooth(nwMesh,dv=1)
  34.     print nwMesh, rock
  35.     #select(cl=1)
  36.     #select([nwMesh[0],rock])
  37.     #transferAttributes(nwMesh,rock,pos=1,sm=0)
  38. def worldCenter(object):
  39.     xform(object,cp=1)
  40.     l = spaceLocator(n = "temp_position")
  41.     pc = pointConstraint(l,object)
  42.     delete(pc,l)
  43.  
  44. def randoT(rock):
  45.     amount = .1
  46.     ammountNeg = -amount
  47.     tY = r.uniform(ammountNeg,amount)
  48.     tX = r.uniform(ammountNeg,amount)
  49.     tZ = r.uniform(ammountNeg,amount)
  50.     print rock[0]
  51.     move(rock[0],tX,tY,tZ, r=1)
  52.    
  53.    
  54.                          
  55. def makeRock():
  56.     c = polyCube(ch=0,n="rock_")[0]
  57.     c1 = c
  58.     complexity = 1
  59.     for i in range(0,complexity):
  60.         randEs(c)
  61.         polyTriangulate(c,ch=0)
  62.         polySmooth(c,ch=0)
  63.         randE(c)
  64.        
  65.         polyAutoProjection(c, p = 6, l=2,ch=0)
  66.         polyTriangulate(c,ch=0)
  67.         polySmooth(c,ch=0)
  68.     c2 = duplicate(c)
  69.     randoY(c2)
  70.     randoT(c2)
  71.     rock = polyBoolOp(c,c2, op=3, o=1)
  72.     worldCenter(c1)
  73.  
  74.     #sets("rocksSG",e=1, fe = c1)
  75.     #cleanRock(c)
  76.     #select(c1)
  77.     #print "c1 is ",c1
  78.     return rock[0]
  79.  
  80. slList = []
  81. for i in range(0,1):
  82.     rock = makeRock()
  83.     print rock.getShape()
  84.  
  85.     delete(rock,all=1,ch = 1)
  86.     slList.append(rock)  
  87. select(slList)
Advertisement
Add Comment
Please, Sign In to add comment