chunk parse

This commit is contained in:
Benjamin Collins 2020-08-11 16:21:09 +09:00
parent 6ed59766cd
commit ea6dabdd78

View File

@ -202,6 +202,7 @@ class NinjaModel: # {
} }
self.bone.apply(vertex['pos']) self.bone.apply(vertex['pos'])
self.index_lookup[vertex_ofs] = len(self.vertex_list) self.index_lookup[vertex_ofs] = len(self.vertex_list)
vertex_ofs += 1
self.vertex_list.append(vertex) self.vertex_list.append(vertex)
pos = self.file.tell() pos = self.file.tell()
@ -232,6 +233,9 @@ class NinjaModel: # {
if chunk_head == 255: if chunk_head == 255:
break break
elif chunk_head == 0:
print("Null Chunk")
continue
elif chunk_head >= 17 and chunk_head <= 23: elif chunk_head >= 17 and chunk_head <= 23:
print("Chunk: Material") print("Chunk: Material")
bytes = self.file.read(2) bytes = self.file.read(2)
@ -284,8 +288,11 @@ class NinjaModel: # {
filter_sample = chunk_body >> 14 & 0x03 filter_sample = chunk_body >> 14 & 0x03
elif chunk_head >= 64 and chunk_head <= 66: elif chunk_head >= 64 and chunk_head <= 66:
print("Chunk Strip!!!") print("Chunk Strip!!!")
bytes = self.file.read(2)
chunk_body = struct.unpack('H', bytes)[0] bytes = self.file.read(4)
h = struct.unpack('HH', bytes)
chunk_len = h[0] * 2
chunk_body = h[1]
ignore_light = chunk_flag & 0x01 ignore_light = chunk_flag & 0x01
ignore_specular = chunk_flag & 0x02 ignore_specular = chunk_flag & 0x02
@ -299,10 +306,81 @@ class NinjaModel: # {
user_offset = chunk_body >> 14 user_offset = chunk_body >> 14
print("Strip count: %d" % strip_count) print("Strip count: %d" % strip_count)
break for i in range (strip_count):
bytes = self.file.read(2)
strip_len = struct.unpack('h', bytes)[0]
counter_clockwise = strip_len < 0
strip_len = abs(strip_len)
strip = []
for k in range (strip_len):
bytes = self.file.read(2)
index = struct.unpack('H', bytes)[0]
index = self.index_lookup[index]
if chunk_head == 64:
strip.append({
'index' : index
})
continue
bytes = self.file.read(4)
uv = struct.unpack('hh', bytes)
u = uv[0]
v = uv[1]
if chunk_head == 65:
u = u / 255.0
v = v / 255.0
elif chunk_head == 66:
u = u / 1023.0
v = v / 1023.0
strip.append({
'index' : index,
'uv' : [ u, v ]
})
for i in range(len(strip) - 2): #{
if i % 2 == 0 and counter_clockwise:
a = strip[i + 0]
b = strip[i + 1]
c = strip[i + 2]
else :
a = strip[i + 1]
b = strip[i + 0]
c = strip[i + 2]
va = self.vertex_list[a['index']]
vb = self.vertex_list[a['index']]
vc = self.vertex_list[a['index']]
self.face_list.append({
'index' : (
a['index'],
b['index'],
b['index']
),
'norm' : (
va['norm'],
vb['norm'],
vc['norm']
),
uv : (
a['uv'],
b['uv'],
c['uv']
)
})
# }
print("Strip End: 0x%08x" % self.file.tell())
else: else:
print("Unknown Chunk Type %d" % chunk_head) print("Unknown Chunk Type %d" % chunk_head)
print("Unknown Chunk Flag %d" % chunk_flag) print("Unknown Chunk Flag %d" % chunk_flag)
print("Unknown File Position: 0x%08x" % self.file.tell())
break break
#end While #end While