-
Notifications
You must be signed in to change notification settings - Fork 0
/
VMFWriter.py
160 lines (136 loc) · 5.11 KB
/
VMFWriter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
class VMFWriter:
def __init__(self, file, grid, scale):
self.file = file
self.grid = grid
self.scale = scale*grid
self.listOfBlocks = []
def add_cuboid(self, pointsMin, pointsMax, texture=None):
pointsMin = (pointsMin[0] * self.scale, pointsMin[1] * self.scale, pointsMin[2] * self.scale)
pointsMax = (pointsMax[0] * self.scale, pointsMax[1] * self.scale, pointsMax[2] * self.scale)
top = Plane(
(pointsMin[0], pointsMin[1], pointsMax[2]),
(pointsMin[0], pointsMax[1], pointsMax[2]),
(pointsMax[0], pointsMax[1], pointsMax[2]),
((1, 0, 0), (0, -1, 0)),
"ECO/GRASS"
)
bot = Plane(
(pointsMin[0], pointsMax[1], pointsMin[2]),
(pointsMin[0], pointsMin[1], pointsMin[2]),
(pointsMax[0], pointsMin[1], pointsMin[2]),
((1, 0, 0), (0, -1, 0))
)
left = Plane(
(pointsMin[0], pointsMin[1], pointsMin[2]),
(pointsMin[0], pointsMax[1], pointsMin[2]),
(pointsMin[0], pointsMax[1], pointsMax[2]),
((0, 1, 0), (0, 0, -1)),
"ECO/GRASSEDGE"
)
right = Plane(
(pointsMax[0], pointsMax[1], pointsMin[2]),
(pointsMax[0], pointsMin[1], pointsMin[2]),
(pointsMax[0], pointsMin[1], pointsMax[2]),
((0, 1, 0), (0, 0, -1)),
"ECO/GRASSEDGE"
)
front = Plane(
(pointsMin[0], pointsMax[1], pointsMin[2]),
(pointsMax[0], pointsMax[1], pointsMin[2]),
(pointsMax[0], pointsMax[1], pointsMax[2]),
((1, 0, 0), (0, 0, -1)),
"ECO/GRASSEDGE"
)
back = Plane(
(pointsMax[0], pointsMin[1], pointsMin[2]),
(pointsMin[0], pointsMin[1], pointsMin[2]),
(pointsMin[0], pointsMin[1], pointsMax[2]),
((1, 0, 0), (0, 0, -1)),
"ECO/GRASSEDGE"
)
solid = Solid([top, bot, left, right, front, back])
self.listOfBlocks.append(solid)
def save(self):
stdout = open(self.file, "w")
stdout.write('versioninfo\n')
stdout.write('{\n')
stdout.write(' "editorversion" "400"\n')
stdout.write(' "editorbuild" "8456"\n')
stdout.write(' "mapversion" "1"\n')
stdout.write(' "formatversion" "100"\n')
stdout.write(' "prefab" "0"\n')
stdout.write('}\n\n')
stdout.write('visgroups\n')
stdout.write('{\n')
stdout.write('}\n\n')
stdout.write('viewsettings\n')
stdout.write('{\n')
stdout.write(' "bSnapToGrid" "1"\n')
stdout.write(' "bShowGrid" "1"\n')
stdout.write(' "bShowLogicalGrid" "0"\n')
stdout.write(' "nGridSpacing" "{0}"\n'.format(self.grid))
stdout.write(' "bShow3DGrid" "0"\n')
stdout.write('}\n\n')
stdout.write('world\n')
stdout.write('{\n')
stdout.write(' "id" "1"\n')
stdout.write(' "mapversion" "1"\n')
stdout.write(' "classname" "worldspawn"\n')
stdout.write(' "skyname" "sky_dust"\n')
stdout.write(' "maxpropscreenwidth" "-1"\n')
stdout.write(' "detailvbsp" "detail.vbsp"\n')
stdout.write(' "detailmaterial" "detail/detailsprites"\n')
for i in self.listOfBlocks:
stdout.write(i.dump())
stdout.write('}\n\n')
stdout.write('cameras\n')
stdout.write('{\n')
stdout.write(' "activecamera" "-1"\n')
stdout.write('}\n\n')
stdout.write('cordons\n')
stdout.write('{\n')
stdout.write(' "active" "0"\n')
stdout.write('}\n')
class Plane:
id = 0
def __init__(self, A, B, C, UV, material="TOOLS/TOOLSNODRAW"):
Plane.id += 1
self.id = Plane.id
self.material = material
self.A = A
self.B = B
self.C = C
self.UV = UV
def dump(self):
output = 'side\n'
output += '{\n'
output += ' "id" "{0}"\n'.format(self.id)
output += ' "plane" "({0} {1} {2}) ({3} {4} {5}) ({6} {7} {8})"\n'.format(
self.A[0], self.A[1], self.A[2],
self.B[0], self.B[1], self.B[2],
self.C[0], self.C[1], self.C[2]
)
output += ' "material" "{}"\n'.format(self.material)
output += ' "uaxis" "[{0} {1} {2} 0] 0.25"\n'.format(self.UV[0][0], self.UV[0][1], self.UV[0][2])
output += ' "vaxis" "[{0} {1} {2} 0] 0.25"\n'.format(self.UV[1][0], self.UV[1][1], self.UV[1][2])
output += ' "rotation" "0"\n'
output += ' "lightmapscale" "16"\n'
output += ' "smoothing_groups" "0"\n'
output += '}\n'
return output
class Solid:
id = 0
def __init__(self, planes=[]):
Solid.id += 1
self.id = Solid.id
self.planes = planes
def add_plane(self, plane: Plane):
self.planes.append(plane)
def dump(self):
output = 'solid\n'
output += '{\n'
output += ' "id" "{0}"\n'.format(self.id)
for i in self.planes:
output += i.dump()
output += '}\n'
return output