-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvmf2map.py
120 lines (88 loc) · 2.69 KB
/
vmf2map.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
import sys
if not len(sys.argv) == 3:
print("Usage: main.py <in_file.vmf> <out_file.map>")
sys.exit()
TEXTURE_CONVERT = {
"tools/toolsskip": "clip",
"tools/toolshint": "hintskip",
"tools/toolsnodraw": "skip",
"tools/toolsplayerclip": "clip"
}
#f = open("koth_sawmill_d.vmf", "r")
print(sys.argv[1])
f = open(sys.argv[1], "r")
LINES = f.readlines()
f.close()
class ent:
def __init__(self, Lines, index):
self.name = Lines[index].replace("\t", "").replace('\n','')
#print(self.name)
self.size = 3 #name + { and }
index += 2
self.keys = {}
self.ents = []
#get all key value pairs
while '"' in Lines[index]:
splitPoint = Lines[index].find(" ")
#print(splitPoint)
#print(Lines[index][0:splitPoint].replace('"','').replace('\t',''), Lines[index][splitPoint:].replace('"','').replace('\n','') )
key = Lines[index][0:splitPoint].replace('"','').replace('\t','')
value = Lines[index][splitPoint+1:].replace('"','').replace('\n','')
self.keys[ key ] = value
index += 1
self.size += 1
#print(self.keys)
while not "}" in Lines[index]:
self.ents.append(ent(Lines, index))
index += self.ents[-1].size
self.size += self.ents[-1].size
#print("done ent")
def hasDisplacement(self):
out = False
for en in self.ents:
if en.name == "solid":
for side in en.ents:
if len(side.ents) > 0:
out = True
return out
def ToMapString(self):
out = "{\n"
for key in self.keys:
out += '"' + key + '" "' + self.keys[key] + '"\n'
for en in self.ents:
if en.name == "solid":
out += "{\n"
for side in en.ents:
rotation = "0"
if "rotation" in side.keys:
rotation = side.keys["rotation"]
texture = side.keys["material"]
if texture in TEXTURE_CONVERT:
texture = TEXTURE_CONVERT[texture]
out += side.keys["plane"] + " " + texture + " "
#out += " -0 -0 -0 1 1\n"
out += "[ " + side.keys["uaxis"][1:side.keys["uaxis"].find("] ") ] + " ] "
out += "[ " + side.keys["vaxis"][1:side.keys["vaxis"].find("] ") ] + " ] "
out += rotation + " " #rotation
out += side.keys["uaxis"][side.keys["uaxis"].find("] ")+2: ] + " "
out += side.keys["vaxis"][side.keys["vaxis"].find("] ")+2: ] + "\n"
out += "}\n"
out += "}\n"
return out
entities = []
currentName = ""
index = 0
while index < len(LINES):
le = ent(LINES, index)
index += le.size
entities.append( le )
print(le.name)
#print(entities[-1].name)
f = open(sys.argv[2], "w")
f.write("// Game: Quake\n")
f.write("// Format: Valve\n")
for i in entities:
t = i.ToMapString()
#print(t)
f.write(t)
f.close()