This repository has been archived by the owner on Apr 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
VVD_DATA.py
90 lines (77 loc) · 3.31 KB
/
VVD_DATA.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
from typing import List
try:
from .ByteIO import ByteIO
from .GLOBALS import SourceVertex
except Exception:
from ByteIO import ByteIO
from GLOBALS import SourceVertex
class SourceVvdFileData:
def __init__(self):
self.id = ""
self.version = 0
self.checksum = 0
self.lod_count = 0
self.lod_vertex_count = [] # type: List[int]
self.fixup_count = 0
self.fixup_table_offset = 0
self.vertex_data_offset = 0
self.tangent_data_offset = 0
self.vertexes_by_lod = {}
self.fixed_vertexes_by_lod = []
self.vertexes = [] # type: List[SourceVertex]
self.fixups = [] # type: List[SourceVvdFixup]
def read(self, reader: ByteIO):
self.id = reader.read_fourcc()
if self.id != 'IDSV':
if self.id[:-1] == 'DSV':
reader.insert_begin(b'I')
self.id = reader.read_fourcc()
print('VVD FILE WAS "PROTECTED", but screew it :P')
else:
raise NotImplementedError('VVD format {} is not supported!'.format(self.id))
self.version = reader.read_uint32()
self.checksum = reader.read_uint32()
self.lod_count = reader.read_uint32()
self.lod_vertex_count = [reader.read_uint32() for _ in range(8)]
self.fixup_count = reader.read_uint32()
self.fixup_table_offset = reader.read_uint32()
self.vertex_data_offset = reader.read_uint32()
self.tangent_data_offset = reader.read_uint32()
self.fixed_vertexes_by_lod = [[]] * self.lod_count
if self.lod_count <= 0:
return
reader.seek(self.vertex_data_offset)
for _ in range(self.lod_vertex_count[0]):
self.vertexes.append(SourceVertex().read(reader))
reader.seek(self.fixup_table_offset)
if self.fixup_count > 0:
for _ in range(self.fixup_count):
self.fixups.append(SourceVvdFixup().read(reader))
if self.lod_count > 0:
for lod_index in range(self.lod_count):
for fixup_index in range(len(self.fixups)):
fixup = self.fixups[fixup_index]
if fixup.lod_index >= lod_index:
for j in range(fixup.vertex_count):
vertex = self.vertexes[fixup.vertex_index + j]
self.fixed_vertexes_by_lod[lod_index].append(vertex)
def __str__(self):
return "<FileData id:{} version:{} lod count:{} fixup count:{}>".format(self.id, self.version, self.lod_count,
self.fixup_count)
def __repr__(self):
return self.__str__()
class SourceVvdFixup:
def __init__(self):
self.lod_index = 0
self.vertex_index = 0
self.vertex_count = 0
def read(self, reader: ByteIO):
self.lod_index = reader.read_uint32()
self.vertex_index = reader.read_uint32()
self.vertex_count = reader.read_uint32()
return self
def __str__(self):
return "<Fixup lod index:{} vertex index:{} vertex count:{}>".format(self.lod_index, self.vertex_index,
self.vertex_count)
def __repr__(self):
return self.__str__()