This commit is contained in:
Benjamin Collins 2020-08-11 13:58:35 +09:00
parent 96842ea045
commit 6ed59766cd

View File

@ -231,13 +231,81 @@ class NinjaModel: # {
chunk_flag = c[1]
if chunk_head == 255:
break
elif chunk_head >= 17 and chunk_head <= 23:
print("Chunk: Material")
bytes = self.file.read(2)
short_len = struct.unpack('H', bytes)
self.material = {}
dst_alpha = chunk_flag & 0x07
src_alpha = chunk_flag >> 3
if chunk_head & 0x01:
bytes = self.file.read(4)
c = struct.unpack('BBBB', bytes)
self.material['diffuse'] = {
'b' : c[0] / 255.0,
'g' : c[1] / 255.0,
'r' : c[2] / 255.0,
'a' : c[3] / 255.0
}
if chunk_head & 0x02:
bytes = self.file.read(4)
c = struct.unpack('BBBB', bytes)
self.material['ambient'] = {
'b' : c[0] / 255.0,
'g' : c[1] / 255.0,
'r' : c[2] / 255.0,
'a' : c[3] / 255.0
}
if chunk_head & 0x04:
bytes = self.file.read(4)
c = struct.unpack('BBBB', bytes)
self.material['specular'] = {
'b' : c[0] / 255.0,
'g' : c[1] / 255.0,
'r' : c[2] / 255.0,
'coef' : c[3] / 255.0
}
elif chunk_head >= 8 and chunk_head <= 9:
print("Chunk: Tiny")
bytes = self.file.read(2)
chunk_body = struct.unpack('H', bytes)[0]
mip_depth = chunk_flag & 0x07
clamp_u = chunk_flag & 0x08
clamp_v = chunk_flag & 0x10
flip_u = chunk_flag & 0x20
flip_v = chunk_flag & 0x40
self.material['tex_id'] = chunk_body & 0x1fff
super_sample = chunk_body >> 13 & 0x01
filter_sample = chunk_body >> 14 & 0x03
elif chunk_head >= 64 and chunk_head <= 66:
print("Chunk Strip!!!")
bytes = self.file.read(2)
chunk_body = struct.unpack('H', bytes)[0]
ignore_light = chunk_flag & 0x01
ignore_specular = chunk_flag & 0x02
ignore_ambient = chunk_flag & 0x04
use_alpha = chunk_flag & 0x08
double_side = chunk_flag & 0x10
flat_shading = chunk_flag & 0x20
environment_mapping = chunk_flag & 0x20
strip_count = chunk_body & 0x3fff;
user_offset = chunk_body >> 14
print("Strip count: %d" % strip_count)
break
else:
print("Unknown Chunk Type %d" % chunk_head)
print("Unknown Chukn Flag %d" % chunk_flag)
print("Unknown Chunk Flag %d" % chunk_flag)
break
break
#end While
return None