fix strip

This commit is contained in:
Benjamin Collins 2020-08-18 07:36:14 +09:00
parent 4492ebe528
commit 63299d123b
3 changed files with 40 additions and 12 deletions

View File

@ -54,9 +54,10 @@ class NinjaModel: # {
self.bones = []
#Vertex List
self.index_lookup = [ None ] * 5000
self.index_lookup = []
self.vertex_list = []
self.face_list = []
self.strip_count = 0;
return None
@ -179,6 +180,9 @@ class NinjaModel: # {
center = (m[2], m[3], m[4])
radius = m[5]
#if self.strip_count > 0:
# return None
if vertex_ofs:
self.file.seek(vertex_ofs + self.pof, 0)
self.readVertexList()
@ -187,6 +191,9 @@ class NinjaModel: # {
self.file.seek(chunk_ofs + self.pof, 0)
self.readChunkList()
print(self.vertex_list)
print(self.index_lookup)
return None
def readVertexList(self):
@ -218,6 +225,8 @@ class NinjaModel: # {
vertex.setNormal( v[3], v[4], v[5] )
vertex.setSkinWeight(0, self.bone.id, 1.0)
self.bone.apply(vertex)
while len(self.index_lookup) < vertex_ofs + 1:
self.index_lookup.append(None)
self.index_lookup[vertex_ofs] = len(self.vertex_list)
vertex_ofs += 1
self.vertex_list.append(vertex)
@ -353,13 +362,15 @@ class NinjaModel: # {
bytes = self.file.read(2)
strip_len = struct.unpack('h', bytes)[0]
print("Strip Count: %d" % strip_len)
counter_clockwise = strip_len < 0
clockwise = strip_len < 0
strip_len = abs(strip_len)
strip = []
indices = []
for k in range (strip_len): # {
bytes = self.file.read(2)
index = struct.unpack('H', bytes)[0]
indices.append(index)
index = self.index_lookup[index]
if chunk_head == 64:
@ -386,21 +397,26 @@ class NinjaModel: # {
})
# }
for i in range(len(strip) - 2): #{
print(indices)
for k in range(len(strip) - 2): #{
if i % 2 == 0 and not counter_clockwise:
a = strip[i + 0]
b = strip[i + 1]
c = strip[i + 2]
if ((clockwise and not (k % 2)) or ( not clockwise and k % 2)):
a = strip[k + 2]
b = strip[k + 1]
c = strip[k + 0]
else :
a = strip[i + 1]
b = strip[i + 0]
c = strip[i + 2]
a = strip[k + 2]
b = strip[k + 0]
c = strip[k + 1]
ai = a['index']
bi = b['index']
ci = c['index']
print("Face: %d %d %d" % (ai, bi, ci))
va = self.vertex_list[a['index']]
vb = self.vertex_list[a['index']]
vc = self.vertex_list[a['index']]
@ -415,7 +431,8 @@ class NinjaModel: # {
# }
# }
self.strip_count = self.strip_count + 1
print("Strip End: 0x%08x" % self.file.tell())
else:
print("Unknown Chunk Type %d" % chunk_head)

View File

@ -83,3 +83,7 @@ class NinjaVertex:
file.write(struct.pack('f', self.skin_weight[2]))
file.write(struct.pack('f', self.skin_weight[3]))
return None
def __repr__(self):
return "x: %.02f, y: %.02f, z: %.02f\n" % (self.pos['x'], self.pos['y'], self.pos['z'])

View File

@ -24,9 +24,16 @@
"""
from NinjaModel import NinjaModel
model_file = 'OBJ/IKAL.NJ'
texture_file = 'OBJ/IKAL.PVM'
nj = NinjaModel(model_file, texture_file)
nj.parse()
nj.export()
model_file = 'MISC/BUTTON01.NJ'
texture_file = 'MISC/BUTTON01.PVR'
nj = NinjaModel(model_file, texture_file)
nj.parse()
nj.export()