forked from sxhebing/mdl-importer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLayerParser.py
63 lines (47 loc) · 1.6 KB
/
LayerParser.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
from .Layer import Layer
from .MaterialAlpha import MaterialAlpha
from .Parser import Parser
class LayerParser(Parser):
def __init__(self, file):
self.tokens = [
"FilterMode", "Unshaded", "SphereEnvironmentMap",
"TwoSided", "Unfogged", "NoDepthTest", "NoDepthSet",
"TextureID", "Alpha", "Linear"
]
super(LayerParser, self).__init__(file)
def parse(self, context):
layer = Layer()
bracket_count = 1
line, bracket_count = self.read(bracket_count)
while bracket_count > 0:
label, *data = line.split(" ")
if label == "static":
label = data[0]
data = data[1:]
if label in self.tokens:
if label in Layer.SHADING_FLAGS:
layer.shading_flags |= Layer.SHADING_FLAGS[label]
elif label == "FilterMode":
if data[0] in Layer.FILTER_MODES:
layer.filter_mode = data[0]
else:
raise Exception("Unknown FilterMode: '%s'" % data[0])
elif label == "Alpha":
if len(data) > 1:
layer.material_alpha = MaterialAlpha()
line, bracket_count = self.read(bracket_count)
while bracket_count > 1:
label, *data = line.replace(":", "").strip().split(" ")
if label in ["Linear", "Hermite", "Bezier", "DontInterp"]:
layer.material_alpha.interpolation_type = label
else:
layer.material_alpha.tracks[label] = data[0]
line, bracket_count = self.read(bracket_count)
else:
layer.alpha = data[0]
elif label == "TextureID":
layer.texture_id = int(data[0])
else:
raise Exception("Unknown data in layer: %s %s" % (label, data))
line, bracket_count = self.read(bracket_count)
return layer