diff --git a/main.py b/__init__.py similarity index 93% rename from main.py rename to __init__.py index 5c6e1a2..b2e1e0c 100644 --- a/main.py +++ b/__init__.py @@ -23,4 +23,9 @@ """ -print('Hello World!!') + +from njcm import NJCM + +model_file = 'OBJ/IKAL.NJ' +nj = NJCM(model_file) +nj.parse() diff --git a/njcm.py b/njcm.py index 7e0a528..424c5f7 100644 --- a/njcm.py +++ b/njcm.py @@ -23,8 +23,95 @@ """ -class NJCM: +import os +import struct - def __init__(self): - self.name = "hello" - return None; +class NJCM: # { + + def __init__(self, filename): # { + + # File Information + self.path = 'input/' + filename + self.file = open(self.path, 'rb') + self.length = os.path.getsize(self.path) + + # Textures + self.tex_list = [] + + return None + # } + + def parse(self): # { + + while self.file.tell() < self.length: # { + + bytes = self.file.read(4) + + if(bytes == 'NJTL') : + print('Found Ninja Texture List') + bytes = self.file.read(4) + len = struct.unpack('I', bytes)[0] + pos = self.file.tell() + len + self.readNjtl() + self.file.seek(pos, 0) + elif (bytes == 'NJCM') : + print('Found Ninja Chunk Model') + bytes = self.file.read(4) + len = struct.unpack('I', bytes)[0] + pos = self.file.tell() + len + self.readNjcm() + self.file.seek(pos, 0) + elif (bytes == 'NMDM') : + print('Found Ninja Direct Motion') + + # } + + return None + # } + + def readNjtl(self): # { + + pof = self.file.tell() + + bytes = self.file.read(8) + n = struct.unpack('II', bytes) + + str_ofs = [] + + self.file.seek(n[0] + pof, 0) + for i in range(0, n[1]): # { + bytes = self.file.read(12) + m = struct.unpack('III', bytes) + str_ofs.append(m[0] + pof) + # } + + for ofs in str_ofs: # { + + str = '' + self.file.seek(ofs, 0) + + while 1: # { + + ch = self.file.read(1) + if(ch == '\0'): + break + str += ch + #} + + self.tex_list.append(str) + + # } + + return None + # } + + def readNjcm(self, parentBone): # { + + bytes = self.file.read(52) + b = struct.unpack('IIfffiiifffII', bytes) + + return None + # } + + +# }