forked from niacdoial/blemd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drw1.py
92 lines (71 loc) · 2.94 KB
/
Drw1.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
#! /usr/bin/python3
# -- loads correctly: count=113, offsetToW=20, offsetToD=134 [20 + 113 = 133 (nextBit = offsetToD)]
from math import ceil
class Drw1Header:
size = 20
def __init__(self): # GENERATED!
pass
def LoadData(self, br):
self.tag = br.ReadFixedLengthString(4)
self.sizeOfSection = br.ReadDWORD()
self.count = br.ReadWORD()
self.pad = br.ReadWORD()
# stores for each matrix if it's weighted (normal (0)/skinned (1) matrix types)
self.offsetToIsWeighted = br.ReadDWORD()
# for normal (0) matrices, this is an index into the global matrix
# table (which stores a matrix for every joint). for skinned
# matrices (1), I'm not yet totally sure how this works (but it's
# probably an offset into the Evp1-array)
self.offsetToData = br.ReadDWORD()
def DumpData(self, bw):
bw.WriteString('DRW1')
bw.WriteDword(self.sizeOfSection)
bw.WriteWord(self.count)
bw.WriteWord(self.pad)
bw.WriteDword(self.offsetToIsWeighted)
bw.WriteDword(self.offsetToData)
class Drw1:
def __init__(self): # GENERATED!
self.data= []
self.isWeighted= []
def LoadData(self, br):
drw1Offset = br.Position()
header = Drw1Header()
header.LoadData(br)
# -- read bool array
self.isWeighted = [False] * header.count
# -- self.isWeighted.resize(h.count);
br.SeekSet(drw1Offset + header.offsetToIsWeighted)
for i in range(header.count):
v = br.GetByte() # -- u8 v; fread(&v, 1, 1, f);
if v == 0:
pass
# self.isWeighted[i] = False
# already done when initialized
elif v == 1:
self.isWeighted[i] = True
else:
raise ValueError("drw1: unexpected value in isWeighted array: " + str(v))
# -- read self.data array
self.data = [0] * header.count
# -- dst.self.data.resize(h.count);
br.SeekSet(drw1Offset + header.offsetToData)
for i in range(header.count):
self.data[i] = br.ReadWORD()
def DumpData(self, bw):
drw1Offset = bw.Position()
header = Drw1Header()
header.count = len(self.data)
if len(self.isWeighted) != header.count:
raise ValueError('Broken Drw1 section')
header.pad = 0xff
header.offsetToIsWeighted = bw.addPadding(Drw1Header.size)
header.offsetToData = header.offsetToIsWeighted + header.count
header.sizeOfSection = bw.addPadding(header.offsetToData + 2*header.count)
header.DumpData(bw)
bw.writePadding(header.offsetToIsWeighted - Drw1Header.size)
for bool in self.isWeighted:
bw.WriteByte(int(bool))
for index in self.data:
bw.WriteWord(index)
bw.writePadding(drw1Offset + header.sizeOfSection - bw.Position())