anim table

This commit is contained in:
Benjamin Collins 2020-08-20 23:52:17 +09:00
parent 2dbf87ad81
commit 9a2b20a3fc
2 changed files with 90 additions and 9 deletions

View File

@ -49,6 +49,7 @@ class NinjaModel: # {
# Textures
self.mat_list = []
self.tex_list = []
self.anim_list = []
# Bone List
self.bones = []
@ -78,19 +79,25 @@ class NinjaModel: # {
if(bytes == b'NJTL') :
bytes = self.file.read(4)
len = struct.unpack('I', bytes)[0]
pos = self.file.tell() + len
length = struct.unpack('I', bytes)[0]
pos = self.file.tell() + length
self.readNjtl()
self.file.seek(pos, 0)
elif (bytes == b'NJCM') :
bytes = self.file.read(4)
len = struct.unpack('I', bytes)[0]
pos = self.file.tell() + len
length = struct.unpack('I', bytes)[0]
pos = self.file.tell() + length
self.pof = self.file.tell()
self.readNjcm(None)
self.file.seek(pos, 0)
elif (bytes == b'NMDM') :
print('Found Ninja Direct Motion')
bytes = self.file.read(4)
length = struct.unpack('I', bytes)[0]
pos = self.file.tell() + length
self.pof = self.file.tell()
self.readNmdm()
self.file.seek(pos, 0)
self.file.close()
return None
@ -138,11 +145,6 @@ class NinjaModel: # {
self.bone.setName(num)
self.bones.append(self.bone)
print()
print(self.bone.name)
print("Flags: %d" % flags);
print(pos)
if ( (flags & 0x04) == 0):
self.bone.setScale(scl)
@ -418,6 +420,83 @@ class NinjaModel: # {
return None
def readNmdm(self):
# Read Header
bytes = self.file.read(12)
p = struct.unpack('IIHH', bytes)
table_ofs = self.pof + p[0]
frame_count = p[1]
motion_type = {
'pos' : p[2] & 0x01,
'rot' : p[2] & 0x02,
'scl' : p[2] & 0x04
}
factor_count = p[3] & 0x03
spline_interpolation = p[3] & 0x40
user_function_interpolation = p[3] & 0x80
print("READING ANIMTION!!!!")
print(motion_type)
print("FRAME COUNT: %d" % frame_count)
print("Factor Count %d" % factor_count)
print("Spline Function %d" % spline_interpolation)
# Read Motion Table
anim_vals = []
print("Table Offset: 0x%08x" % table_ofs)
self.file.seek(table_ofs, 0)
for i in range(len(self.bones)):
print("Current Offset: 0x%08x" % self.file.tell())
entry = {
'bone_index' : i,
'pos_ofs' : 0,
'pos_num' : 0,
'rot_ofs' : 0,
'rot_num' : 0,
'scl_ofs' : 0,
'scl_num' : 0
}
bytes = self.file.read(4)
p = struct.unpack('I', bytes)
if(p[0]):
entry['pos_ofs'] = self.pof + p[0]
bytes = self.file.read(4)
p = struct.unpack('I', bytes)
if(p[0]):
entry['rot_ofs'] = self.pof + p[0]
bytes = self.file.read(4)
p = struct.unpack('I', bytes)
if(p[0]):
entry['scl_ofs'] = self.pof + p[0]
bytes = self.file.read(4)
p = struct.unpack('I', bytes)
entry['pos_num'] = p[0]
print("Row Offset: 0x%08x" % self.file.tell())
bytes = self.file.read(4)
p = struct.unpack('I', bytes)
entry['rot_num'] = p[0]
bytes = self.file.read(4)
p = struct.unpack('I', bytes)
entry['scl_num'] = p[0]
anim_vals.append(entry)
print(entry)
return None
def export(self):
pre, ext = os.path.splitext(self.model_name)
pre = pre.replace('/', '_')

View File

@ -101,6 +101,8 @@ class PowerVR: # {
data = f.read()
f.close()
tex.setData(data)
os.remove(imgName)
self.file.close()
return self.tex_list