texture parser

This commit is contained in:
Benjamin Collins 2020-08-23 20:52:20 +09:00
parent 6ed590b920
commit 96964bd1ea
5 changed files with 51 additions and 24 deletions

View File

@ -96,7 +96,7 @@ class NinjaMaterial:
file.write(struct.pack('HHHHHH', 0, 0, 0, 0, 1, 0))
# 0x30 Flags
file.write(struct.pack('HHHHHHf', 0, 0, 0, 0, 1, 0, 0.5))
file.write(struct.pack('HHHHHHf', 0, 0, 0, 0, 0, 0, 0.5))
# 0x40 Diffuse
file.write(struct.pack('f', self.diffuse['r']))

View File

@ -100,7 +100,7 @@ class NinjaModel:
length = struct.unpack('I', bytes)[0]
pos = self.file.tell() + length
self.pof = self.file.tell()
self.readNmdm()
#self.readNmdm()
self.file.seek(pos, 0)
print(self.hasMesh)
@ -176,8 +176,7 @@ class NinjaModel:
if self.debug:
print("Reading Mesh @ 0x%08x" % self.file.tell())
self.file.seek(model_ofs + self.pof, 0)
if self.bone.index in [ 22, 23, 25]:
self.readModel()
self.readModel()
if child_ofs:
self.file.seek(child_ofs + self.pof, 0)
@ -404,7 +403,7 @@ class NinjaModel:
strip_len = struct.unpack('h', bytes)[0]
if self.debug:
print("String length: %d" % strip_len)
print("Strip length: %d" % strip_len)
clockwise = strip_len < 0
strip_len = abs(strip_len)
@ -442,6 +441,8 @@ class NinjaModel:
# }
print(strip)
for k in range(len(strip) - 2): #{
if ((clockwise and not (k % 2)) or ( not clockwise and k % 2)):
@ -457,9 +458,9 @@ class NinjaModel:
bi = b['index']
ci = c['index']
va = self.vertex_list[a['index']]
vb = self.vertex_list[a['index']]
vc = self.vertex_list[a['index']]
va = self.vertex_list[ai]
vb = self.vertex_list[bi]
vc = self.vertex_list[ci]
face = NinjaFace()
face.setMatIndex(mat_index)
@ -596,6 +597,31 @@ class NinjaModel:
return None
def exportObj(self):
pre, ext = os.path.splitext(self.model_name)
pre = pre.replace('/', '_')
f = open('output/' + pre + '.OBJ', 'w')
for vert in self.vertex_list:
f.write('v')
f.write(' %.03f' % vert.pos['x'])
f.write(' %.03f' % vert.pos['y'])
f.write(' %.03f' % vert.pos['z'])
f.write('\r\n')
f.write('\r\n')
for face in self.face_list:
f.write('f')
f.write(' %d' % (face.index[0] + 1))
f.write(' %d' % (face.index[1] + 1))
f.write(' %d' % (face.index[2] + 1))
f.write('\r\n')
f.write('\r\n')
f.close()
return None
def export(self):
pre, ext = os.path.splitext(self.model_name)
pre = pre.replace('/', '_')

View File

@ -120,7 +120,7 @@ class PowerVR: # {
data = f.read()
f.close()
tex.setData(data)
os.remove(imgName)
#os.remove(imgName)
self.file.close()
@ -369,10 +369,10 @@ class PowerVR: # {
rgba = self.ARGB_4444(color)
if self.width > self.height:
self.bitmap[y][(n*size) + x*4 + 0] = rgba[0]
self.bitmap[y][(n*size) + x*4 + 1] = rgba[1]
self.bitmap[y][(n*size) + x*4 + 2] = rgba[2]
self.bitmap[y][(n*size) + x*4 + 3] = rgba[3]
self.bitmap[y][(n*size*4) + x*4 + 0] = rgba[0]
self.bitmap[y][(n*size*4) + x*4 + 1] = rgba[1]
self.bitmap[y][(n*size*4) + x*4 + 2] = rgba[2]
self.bitmap[y][(n*size*4) + x*4 + 3] = rgba[3]
else:
self.bitmap[y + (n*size)][x*4 + 0] = rgba[0]
self.bitmap[y + (n*size)][x*4 + 1] = rgba[1]

View File

@ -128,6 +128,7 @@ texture_file = 'OBJ/EVIL.PVM'
nj = NinjaModel(model_file, texture_file)
nj.parse()
nj.export()
nj.exportObj()
"""
model_file = 'OBJ/IKAL.NJ'

View File

@ -4,17 +4,17 @@ EVIL Missing Strips
[x] 1
[x] 3
[x] 4
[ ] 6
[ ] 7
[ ] 8
[ ] 10
[ ] 11
[ ] 12
[ ] 14
[ ] 15
[ ] 17
[ ] 18
[ ] 20
[x] 6
[x] 7
[x] 8
[x] 10
[x] 11
[x] 12
[x] 14
[x] 15
[x] 17
[x] 18
[x] 20
[ ] 21
[ ] 22
[ ] 23