-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadmmdl.py
101 lines (91 loc) · 2.93 KB
/
readmmdl.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
import mmdl
import sys
import traceback
import prettyprint
modelfile = ''
logfile = ''
def main(argv):
global modelfile
global logfile
try:
for i in range(len(argv)):
if (argv[i] == "-m"):
i += 1
modelfile = argv[i]
elif (argv[i] == "-l"):
i += 1
logfile = argv[i]
if (modelfile != ''):
try:
if (logfile != ''):
initializelog()
readmmdl(modelfile)
except Exception as err:
print(f"Error: {err}")
sys.exit(110)
else:
raise
except:
print("Syntax Error!\r\n Usage: readmmdl.py -m model.mmdl [-l logfile.txt]")
sys.exit(1)
def readmmdl(modelfilename):
try:
mmdlFile = mmdl.MMDL()
mmdlFile.ReadMMDL(modelfilename)
logoutput(f"File: {mmdlFile.fileName}")
logoutput(f"Object table size: {mmdlFile.objectTableSize}")
logoutput(f"Vertices table size: {mmdlFile.verticesTableSize}")
logoutput(f"Face table size: {mmdlFile.faceTableSize}")
logoutput(f"Unknown Value 1: {mmdlFile.unknownValue1}")
logoutput(f"Vertice size: {mmdlFile.verticesEntrySize}")
logoutput(f"Vertice count: {mmdlFile.verticesCount}")
logoutput(f"Face size: {mmdlFile.faceEntrySize}")
logoutput(f"Face count: {mmdlFile.faceCount}")
# Object
logbuf = prettyprint.print(f"\n{mmdlFile.objectEntries}\n")
logoutput(logbuf)
# Vertices
logbuf = ''
i = 0
for vertices in mmdlFile.verticesTable:
i += 1
if (mmdlFile.verticesEntrySize == 24):
logbuf += f"Vertice {i}: {vertices.X}, {vertices.Y}, {vertices.Z}, {hex(vertices.Colour)}, {vertices.U}, {vertices.V}\n"
else:
logbuf += f"Vertice {i}: {vertices.X}, {vertices.Y}, {vertices.Z}, {vertices.NX}, {vertices.NY}, {vertices.NZ}, {hex(vertices.Colour)}, {vertices.U}, {vertices.V}\n"
logoutput(logbuf)
# Faces
logbuf = ''
i = 0
for face in mmdlFile.faceTable:
i += 1
logbuf += f"Face {i}: {face}\n"
logoutput(logbuf)
except Exception as err:
print(f"Error: {err}")
print(traceback.format_exc())
def logoutput(logstr):
global logfile
print(logstr)
if (logfile == ''):
return
try:
file = open(logfile, "a")
file.write(f"{logstr}\n")
file.close
except Exception as err:
print(f"Error writing to log file: {err}")
sys.exit(110)
def initializelog():
global logfile
if (logfile == ''):
return
try:
file = open(logfile, "w")
file.write("")
file.close
except Exception as err:
print(f"Error writing to log file: {err}")
sys.exit(110)
if (__name__ == "__main__"):
main(sys.argv[1:])