Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. import pymel.core as pm
  2. import random
  3.  
  4. win_width = 150
  5.  
  6. length = 4
  7. width = 4
  8.  
  9. def random_size():
  10.  
  11. ranList = []
  12. while len(ranList) < 3:
  13. x = random.randint(6,15)
  14. y = abs(random.gauss(30,50))
  15. z = random.randint(1,30)
  16.  
  17. if len(ranList) == 0:
  18. ranList.append(x)
  19.  
  20. if 2 < y / ranList[0] and y / ranList[0] < 20:
  21. if len(ranList) == 1:
  22. ranList.append(y)
  23.  
  24. if 0.5 < z / ranList[0] and z / ranList[0] < 2:
  25. if len(ranList) == 2:
  26. ranList.append(z)
  27.  
  28. # if len(ranList) == 3:
  29. # break
  30. print ranList
  31. return ranList
  32.  
  33.  
  34. def create_plane():
  35. plane = pm.nurbsPlane(ch=1, d=3, patchesV=length, p=(0, 0, 0), patchesU=width, w=120, ax=(0, 1, 0), lr=1)
  36. return plane
  37.  
  38. def create_hair():
  39.  
  40. pm.mel.createHair(length, width, 10, 0, 0, 0, 0, 5, 0, 2, 1, 1);
  41.  
  42. for i in range(1, length * width * 2, 2):
  43.  
  44. pm.delete('curve' + str(i))
  45.  
  46. pm.delete('nucleus1', 'hairSystem1', 'hairSystem1OutputCurves');
  47.  
  48. hairs = pm.ls('hairSystem1Follicles', dag = True)[1::2]
  49.  
  50. return hairs
  51.  
  52. def create_one_building(ranList, i, buildingGrp):
  53.  
  54.  
  55. building = pm.polyCube(d= ranList[0], h= ranList[1], w= ranList[2])
  56.  
  57. pm.move(0,ranList[1]/2,0)
  58.  
  59. #snap building to hair with pointConstraint
  60. michael = pm.pointConstraint(i, building[0], skip='y')
  61.  
  62. pm.delete(michael)
  63.  
  64. pm.parent(building[0], buildingGrp)
  65.  
  66. def create():
  67.  
  68. buildingGrp = pm.group(name = 'buildingGrp')
  69.  
  70. plane = create_plane()
  71. hairs = create_hair()
  72.  
  73. for current_hair in hairs:
  74.  
  75. ranList = random_size()
  76.  
  77. print ranList
  78.  
  79. create_one_building(ranList, current_hair, buildingGrp)
  80.  
  81. pm.parent(plane[0], buildingGrp)
  82.  
  83. pm.delete('hairSystem1Follicles')
  84. pm.select(cl = True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement