diff --git a/NinjaBone.py b/NinjaBone.py index 2261dce..2e73df2 100644 --- a/NinjaBone.py +++ b/NinjaBone.py @@ -35,6 +35,9 @@ class NinjaBone: # { self.parentIndex = -1 self.local = Mat4() self.world = Mat4() + self.localRot = Mat4() + self.worldRot = Mat4() + self.parent = None self.children = [] self.rotation = [ 0, 0, 0 ] @@ -57,6 +60,9 @@ class NinjaBone: # { def getRotation(self): return self.rotation + def getWorldRot(self): + return self.worldRot.mtx + def setName(self, num): self.index = num self.name = 'bone_%03d' % num @@ -66,6 +72,7 @@ class NinjaBone: # { self.parent = parent self.parentIndex = parent.getIndex() self.world.multiply(parent.getWorld()) + self.worldRot.multiply(parent.getWorldRot()) return None def add(self, child): @@ -79,22 +86,19 @@ class NinjaBone: # { self.world.scale(vec3) return None - def setRotation(self, vec3, zxy_order = False): + def setRotation(self, vec3): - if zxy_order: - z = vec3[0] - x = vec3[1] - y = vec3[2] - else: - x = vec3[0] - y = vec3[1] - z = vec3[2] + rot = [ + vec3[0], + vec3[1], + vec3[2] + ] - rot = [ x, y, z ] self.rotation = rot - - self.local.rotate(vec3) - self.world.rotate(vec3) + self.local.rotate(rot) + self.world.rotate(rot) + self.localRot.rotate(rot) + self.worldRot.rotate(rot) return None def setPosition(self, vec3): @@ -106,6 +110,9 @@ class NinjaBone: # { def apply(self, vec3): return self.world.apply(vec3) + def applyNorm(self, vec3): + return self.worldRot.apply(vec3) + def createDmfEntry(self, file): # 0x00 Name name = self.name diff --git a/NinjaModel.py b/NinjaModel.py index 3cc5ba3..944a1d8 100644 --- a/NinjaModel.py +++ b/NinjaModel.py @@ -159,7 +159,8 @@ class NinjaModel: print("Setting Scale: %s", scl) if ( (flags & 0x02) == 0): - self.bone.setRotation(rot, flags & 0x20) + zxy_set = flags & 0x20 + self.bone.setRotation(rot) if self.debug: print("Setting Rotation: ", rot) @@ -250,6 +251,7 @@ class NinjaModel: bytes = self.file.read(12) v = struct.unpack('fff', bytes) norm = [ v[0], v[1], v[2] ] + norm = self.bone.applyNorm(norm) vertex.setNormal( norm[0], norm[1], norm[2] ) # Vertex Color @@ -260,6 +262,7 @@ class NinjaModel: b = v[1] g = v[2] a = v[3] + vertex.setColor(r, g, b, a) vertex.setSkinWeight(0, self.bone.index, 1.0) @@ -297,11 +300,6 @@ class NinjaModel: if self.debug: print("End Chunk Found") break - elif chunk_head == 9: - if self.debug: - print("Null Chunk Found") - print("Invalid header found @ 0x%08x" % self.file.tell()) - sys.exit() elif chunk_head == 0: if self.debug: print("Null Chunk Found") @@ -318,11 +316,8 @@ class NinjaModel: print("Specular exponent") elif chunk_head == 4: print("Save offset!!!") - sys.exit() elif chunk_head == 5: print("Jumpt to offset!!!") - print("Saved Index: %d" % chunk_flag) - sys.exit() elif chunk_head >= 17 and chunk_head <= 23: if self.debug: @@ -489,19 +484,13 @@ class NinjaModel: face.setNormals(va.norm, vb.norm, vc.norm) face.setDiffuseUv(a['uv'], b['uv'], c['uv']) self.face_list.append(face) - # } - - # } self.file.seek(snap_to, 0) - print("Actual End: 0x%08x" % self.file.tell()) self.strip_count = self.strip_count + 1 else: print("Unknown File Position: 0x%08x" % self.file.tell()) - #end While - return None def readNmdm(self): diff --git a/NinjaMotion.py b/NinjaMotion.py index 5e5782e..b6622eb 100644 --- a/NinjaMotion.py +++ b/NinjaMotion.py @@ -30,6 +30,7 @@ from Mat4 import Mat4 class NinjaMotion: def __init__(self): + self.debug = False self.index = -1 self.name = ""; self.skeleton = [] @@ -57,6 +58,9 @@ class NinjaMotion: def appendKeyFrame(self, boneIndex, frame, vec3, type): keyFrames = self.keyFrames[boneIndex] + if self.debug: + print("Adding %s type frame to bone %d" % (type, boneIndex)) + for keys in keyFrames: if keys['frame'] != frame: continue @@ -73,8 +77,6 @@ class NinjaMotion: def save(self, boneIndex): - print("Calling Save!!!") - bone = self.skeleton[boneIndex] keyFrames = self.keyFrames[boneIndex] diff --git a/output/readme.txt b/output/readme.txt deleted file mode 100644 index e69de29..0000000