forked from REDxEYE/io_texture_VTF
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vmt.py
42 lines (37 loc) · 1.51 KB
/
vmt.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
import os
from .ValveFileSystem.valve import KeyValueFile, GameInfoFile, MaterialPathResolver
from pathlib import Path
if os.environ.get('VProject', None):
del os.environ['VProject']
class VMT:
def _get_proj_root(self, path: Path):
if path.parts[-1] == 'materials':
return path.parent
else:
return self._get_proj_root(path.parent)
def __init__(self, filepath, game_dir=None):
self.filepath = Path(filepath)
if not game_dir:
game_dir = self._get_proj_root(self.filepath)
os.environ['VProject'] = str(game_dir)
self.textures = {}
self.kv = KeyValueFile(filepath=filepath)
self.shader = self.kv.root_chunk.key
self.material_data = self.kv.as_dict[self.shader]
gameinfo_path = game_dir / 'gameinfo.txt'
if os.path.isfile(gameinfo_path):
self.gameinfo = GameInfoFile(gameinfo_path)
else:
# We might not be dealing with a Source installation.
# Use material path instead
self.gameinfo = MaterialPathResolver(game_dir)
def parse(self):
print(self.shader)
for key, value in self.material_data.items():
if isinstance(value, str):
texture = self.gameinfo.find_texture(value)
if texture:
self.textures[key] = texture
# print(texture)
# if textureAsGameTexture(value):
# self.textures[key[1:].lower()] = textureAsGameTexture(value)