From 2dbf87ad81f10271c083bcf20a354b57462864bb Mon Sep 17 00:00:00 2001 From: Benjamin Collins Date: Thu, 20 Aug 2020 07:55:02 +0900 Subject: [PATCH] bones --- NinjaBone.py | 24 ++++++++++++++++++++++++ NinjaModel.py | 12 +++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/NinjaBone.py b/NinjaBone.py index e20fc9b..961416a 100644 --- a/NinjaBone.py +++ b/NinjaBone.py @@ -24,6 +24,7 @@ """ import math +import struct from Mat4 import Mat4 class NinjaBone: # { @@ -77,3 +78,26 @@ class NinjaBone: # { def apply(self, vec3): return self.world.apply(vec3) + + def createDmfEntry(self, file): + + # 0x00 Name + name = self.name + while len(name) < 0x20: + name += '\0' + bytes = name.encode() + file.write(bytes) + + # 0x20 Index + file.write(struct.pack('hh', self.index, self.parentIndex)) + file.write(struct.pack('III', 0, 0, 0)) + + # 0x30 Local Matrix + m = self.local.mtx + file.write(struct.pack('ffff', m[0][0], m[0][1], m[0][2], m[0][3])) + file.write(struct.pack('ffff', m[1][0], m[1][1], m[1][2], m[1][3])) + file.write(struct.pack('ffff', m[2][0], m[2][1], m[2][2], m[2][3])) + file.write(struct.pack('ffff', m[3][0], m[3][1], m[3][2], m[3][3])) + return None + + diff --git a/NinjaModel.py b/NinjaModel.py index d1cf20c..352bb86 100644 --- a/NinjaModel.py +++ b/NinjaModel.py @@ -472,7 +472,7 @@ class NinjaModel: # { for vert in self.vertex_list: vert.createDmfEntry(f) - + while f.tell() % 0x10: f.write(struct.pack('B', 0)) @@ -489,6 +489,16 @@ class NinjaModel: # { while f.tell() % 0x10: f.write(struct.pack('B', 0)) + # Write Bones + pos = f.tell() + count = len(self.bones) + f.seek(0x58, 0) + f.write(struct.pack('II', pos, count)) + f.seek(0, 2) + + for bone in self.bones: + bone.createDmfEntry(f) + f.close() return None