Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.60 KB | None | 0 0
  1. from itertools import chain
  2. import math
  3.  
  4.  
  5. def mapping(x, y):
  6. #return math.cos(y/4096*2*math.pi)*1024/2+0*x+y/2
  7. return math.sin((x+y)/4096*8*math.pi)*1024/8+math.sin(x/2047*math.pi)*1024/4
  8.  
  9.  
  10. def dispmaker(info):
  11. x, y, z, length, width, func = info[0], info[1], info[2], info[3], info[4], info[5]
  12. start = "[{0} {1} {2}]".format(x, y, z)
  13. s = '''
  14. dispinfo
  15. {{
  16. "power" "3"
  17. "startposition" "{0}"
  18. "flags" "0"
  19. "elevation" "0"
  20. "subdiv" "0"
  21. normals
  22. {{
  23. '''.format(start)
  24.  
  25. i = 0
  26. while i < 9:
  27. s +=''' "row{0}" "{1}"
  28. '''.format(i, ' '.join(map(str, [0, 0, -1] * 9)))
  29. i+=1
  30. s += ''' }
  31. distances
  32. {
  33. '''
  34. r = 0
  35. while r < 9:
  36. rowdist = []
  37. i = 0
  38. while i < 9:
  39. rowdist.append(round(func(r * length / 8 + x, i * width / 8 + y), 2))
  40. i += 1
  41. k = ''' "row{0}" "{1}"
  42. '''.format(r, ' '.join(map(str, rowdist)))
  43. s += k
  44. r += 1
  45. s+=''' }
  46. offsets
  47. {
  48. "row0" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  49. "row1" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  50. "row2" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  51. "row3" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  52. "row4" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  53. "row5" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  54. "row6" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  55. "row7" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  56. "row8" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  57. }
  58. offset_normals
  59. {
  60. "row0" "0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1"
  61. "row1" "0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1"
  62. "row2" "0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1"
  63. "row3" "0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1"
  64. "row4" "0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1"
  65. "row5" "0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1"
  66. "row6" "0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1"
  67. "row7" "0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1"
  68. "row8" "0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1"
  69. }
  70. alphas
  71. {
  72. "row0" "0 0 0 0 0 0 0 0 0"
  73. "row1" "0 0 0 0 0 0 0 0 0"
  74. "row2" "0 0 0 0 0 0 0 0 0"
  75. "row3" "0 0 0 0 0 0 0 0 0"
  76. "row4" "0 0 0 0 0 0 0 0 0"
  77. "row5" "0 0 0 0 0 0 0 0 0"
  78. "row6" "0 0 0 0 0 0 0 0 0"
  79. "row7" "0 0 0 0 0 0 0 0 0"
  80. "row8" "0 0 0 0 0 0 0 0 0"
  81. }
  82. triangle_tags
  83. {
  84. "row0" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  85. "row1" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  86. "row2" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  87. "row3" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  88. "row4" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  89. "row5" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  90. "row6" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  91. "row7" "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  92. }
  93. allowed_verts
  94. {
  95. "10" "-1 -1 -1 -1 -1 -1 -1 -1 -1 -1"
  96. }
  97. }
  98. '''
  99. return s
  100.  
  101.  
  102. class Vertex:
  103. def __init__(self, x, y, z):
  104. self.x = x
  105. self.y = y
  106. self.z = z
  107.  
  108. def return_fixed_z(self):
  109. return self.x, self.y, self.z
  110.  
  111. def __add__(self, other):
  112. return Vertex(self.x+other.x, self.y+other.y,self.z+other.z)
  113.  
  114.  
  115. class Face:
  116. id_counter = 1
  117.  
  118. def __init__(self, v1: Vertex, v2: Vertex, v3: Vertex):
  119. self.v1 = v1
  120. self.v2 = v2
  121. self.v3 = v3
  122.  
  123. def return_all(self):
  124. return self.v1, self.v2, self.v3
  125.  
  126. def __add__(self, other):
  127. return Face(self.v1+other.v1,self.v2+other.v2,self.v3+other.v3)
  128.  
  129. def generate_face(self, uaxis, vaxis, i, dispinfo):
  130. Face.id_counter += 1
  131. side = '''
  132. side
  133. {{
  134. "id" "{9}"
  135. "plane" "({0} {1} {2}) ({3} {4} {5}) ({6} {7} {8})"
  136. "material" "TOOLS/TOOLSNODRAW"
  137. "uaxis" "{10} 0.25"
  138. "vaxis" "{11} 0.25"
  139. "rotation" "0"
  140. "lightmapscale" "16"
  141. "smoothing_groups" "0"'''.format(*self.v1.return_fixed_z(), *self.v2.return_fixed_z(), *self.v3.return_fixed_z(), self.id_counter, uaxis, vaxis)
  142. if i == 1:
  143. side += dispmaker(dispinfo)
  144. side +='''
  145. }'''
  146. return side
  147.  
  148.  
  149. class Shape:
  150. id_counter = 1
  151. teleport_target = "default"
  152. use_landmark_angles = True
  153. csgo = 0
  154.  
  155. def __init__(self, *args: Face):
  156. self.faces = []
  157. self.faces.extend(args)
  158.  
  159.  
  160. def get_all_vertices(self):
  161. return list(chain.from_iterable([f.return_all() for f in self.faces]))
  162.  
  163. def generate_shape(self, dispinfo):
  164. s = '''
  165. solid
  166. {{
  167. "id" "{0}"'''.format(self.id_counter)
  168. Shape.id_counter += 1
  169. i = 0
  170. while i < len(self.faces):
  171. if i == 0 or i == 1:
  172. uaxis = "[1 0 0 0]"
  173. vaxis = "[0 -1 0 0]"
  174. elif i == 2 or i == 3:
  175. uaxis = "[0 1 0 0]"
  176. vaxis = "[0 0 -1 0]"
  177. elif i == 4 or i == 5:
  178. uaxis = "[1 0 0 0]"
  179. vaxis = "[0 0 -1 0]"
  180.  
  181. s += self.faces[i].generate_face(uaxis, vaxis, i, dispinfo)
  182. i += 1
  183. s += '''
  184. editor
  185. {
  186. "color" "0 136 109"
  187. "visgroupshown" "1"
  188. "visgroupautoshown" "1"
  189. }
  190. }'''
  191.  
  192. return s
  193.  
  194.  
  195. def brushmaker(length, width, x, y, z, func):
  196. h, l, w = Vertex(0, 0, 128), Vertex(length, 0, 0), Vertex(0, width, 0)
  197. sp = Vertex(x, y, z)
  198. zero = Vertex(0, 0, 0)
  199. startface = Face(sp, sp, sp)
  200. face1 = Face(h+w, h+l+w, h+l)+startface
  201. face2 = Face(zero, l, l+w)+startface
  202. face3 = Face(h+w, h, zero)+startface
  203. face4 = Face(l+w, l, h+l)+startface
  204. face5 = Face(h+l+w, h+w, w)+startface
  205. face6 = Face(l, zero, h)+startface
  206. dispinfo = [x, y, z, length, width, func]
  207.  
  208. return Shape(face1, face2, face3, face4, face5, face6).generate_shape(dispinfo)
  209.  
  210.  
  211. def brushwriter(file, xamount, yamount, length, width, func):
  212. i = 0
  213. while i < xamount:
  214. j = 0
  215. while j < yamount:
  216. file.writelines(brushmaker(length, width, i*length, j*width, 0, func))
  217. j +=1
  218. i +=1
  219.  
  220.  
  221. intro = '''versioninfo
  222. {
  223. "editorversion" "400"
  224. "editorbuild" "8075"
  225. "mapversion" "0"
  226. "formatversion" "100"
  227. "prefab" "0"
  228. }
  229. viewsettings
  230. {
  231. "bSnapToGrid" "1"
  232. "bShowGrid" "1"
  233. "bShowLogicalGrid" "0"
  234. "nGridSpacing" "64"
  235. "bShow3DGrid" "0"
  236. }
  237. world
  238. {
  239. "id" "1"
  240. "mapversion" "0"
  241. "classname" "worldspawn"
  242. "skyname" "sky_tf2_04"
  243. "maxpropscreenwidth" "-1"
  244. "detailvbsp" "detail_2fort.vbsp"
  245. "detailmaterial" "detail/detailsprites_2fort"'''
  246. outro = '''
  247. }
  248. cameras
  249. {
  250. "activecamera" "-1"
  251. }
  252. cordons
  253. {
  254. "active" "0"
  255. }'''
  256.  
  257. with open("newmap2.vmf", "w") as text:
  258. text.writelines(intro)
  259. brushwriter(text, 16, 16, 256, 256, mapping)
  260. # file, the amount of copies in x direction, amount in y direction, length (x), width (y).
  261. text.writelines(outro)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement