add types
This commit is contained in:
parent
ea6dabdd78
commit
e8e109a60c
22
NinjaBone.py
22
NinjaBone.py
@ -69,6 +69,7 @@ class NinjaBone: # {
|
||||
|
||||
def setName(self, num):
|
||||
self.save()
|
||||
self.id = num
|
||||
self.name = 'bone_%03d' % num
|
||||
return None
|
||||
|
||||
@ -145,19 +146,22 @@ class NinjaBone: # {
|
||||
self.multiplyLocal(tmp)
|
||||
return None
|
||||
|
||||
def apply(self, vec3):
|
||||
vec3.append(1)
|
||||
def apply(self, vertex):
|
||||
print(vertex.pos)
|
||||
vec3 = [
|
||||
vertex.pos['x'],
|
||||
vertex.pos['y'],
|
||||
vertex.pos['z'],
|
||||
1
|
||||
]
|
||||
res = [0,0,0,0]
|
||||
for i in range(4):
|
||||
t = 0.0
|
||||
for j in range(4):
|
||||
t = t + (vec3[j] * self.worldMatrix[j][i])
|
||||
res[i] = t
|
||||
x = res[0] / res[3];
|
||||
y = res[1] / res[3];
|
||||
z = res[2] / res[3];
|
||||
vec3[0] = x
|
||||
vec3[1] = y
|
||||
vec3[2] = z
|
||||
vec3.pop()
|
||||
x = res[0] / res[3]
|
||||
y = res[1] / res[3]
|
||||
z = res[2] / res[3]
|
||||
vertex.setPosition(x, y, z)
|
||||
return None
|
||||
|
71
NinjaFace.py
Normal file
71
NinjaFace.py
Normal file
@ -0,0 +1,71 @@
|
||||
"""
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Benjamin Collins (kion @ dashgl.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
"""
|
||||
|
||||
class NinjaFace:
|
||||
|
||||
def __init__(self):
|
||||
self.mat_index = -1
|
||||
self.index = ( 0, 0, 0 )
|
||||
self.color = (
|
||||
{ 'r' : 255, 'g' : 255, 'b' : 255, 'a' : 255 },
|
||||
{ 'r' : 255, 'g' : 255, 'b' : 255, 'a' : 255 },
|
||||
{ 'r' : 255, 'g' : 255, 'b' : 255, 'a' : 255 }
|
||||
)
|
||||
self.norm = (
|
||||
{ 'x' : 0.0, 'y' : 0.0, 'z' : 0.0 },
|
||||
{ 'x' : 0.0, 'y' : 0.0, 'z' : 0.0 },
|
||||
{ 'x' : 0.0, 'y' : 0.0, 'z' : 0.0 }
|
||||
)
|
||||
self.diffuse_uv = (
|
||||
{ 'u' : 0.0, 'v' : 0.0 },
|
||||
{ 'u' : 0.0, 'v' : 0.0 },
|
||||
{ 'u' : 0.0, 'v' : 0.0 }
|
||||
)
|
||||
return None
|
||||
|
||||
def setMatIndex(self, index):
|
||||
self.mat_index = index
|
||||
return None
|
||||
|
||||
def setIndexes(self, a, b, c):
|
||||
self.index[0] = a
|
||||
self.index[1] = b
|
||||
self.index[2] = c
|
||||
return None
|
||||
|
||||
def setNormals(self, a, b, c):
|
||||
self.norm[0] = a
|
||||
self.norm[1] = b
|
||||
self.norm[2] = c
|
||||
return None
|
||||
|
||||
def setDiffuseUv(self, a, b, c):
|
||||
self.diffuse_uv[0] = a
|
||||
self.diffuse_uv[1] = b
|
||||
self.diffuse_uv[2] = c
|
||||
return None
|
||||
|
||||
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
import os
|
||||
import struct
|
||||
from NinjaVertex import NinjaVertex
|
||||
from NinjaFace import NinjaFace
|
||||
from NinjaBone import NinjaBone
|
||||
|
||||
class NinjaModel: # {
|
||||
@ -196,11 +198,11 @@ class NinjaModel: # {
|
||||
|
||||
bytes = self.file.read(24)
|
||||
v = struct.unpack('ffffff', bytes)
|
||||
vertex = {
|
||||
'pos' : [ v[0], v[1], v[2] ],
|
||||
'norm' : [ v[3], v[4], v[5] ]
|
||||
}
|
||||
self.bone.apply(vertex['pos'])
|
||||
vertex = NinjaVertex()
|
||||
vertex.setPosition( v[0], v[1], v[2] )
|
||||
vertex.setNormal( v[3], v[4], v[5] )
|
||||
vertex.setSkinWeight(0, self.bone.id, 1.0)
|
||||
self.bone.apply(vertex)
|
||||
self.index_lookup[vertex_ofs] = len(self.vertex_list)
|
||||
vertex_ofs += 1
|
||||
self.vertex_list.append(vertex)
|
||||
@ -236,6 +238,20 @@ class NinjaModel: # {
|
||||
elif chunk_head == 0:
|
||||
print("Null Chunk")
|
||||
continue
|
||||
elif chunk_head >= 1 and chunk_head <= 5:
|
||||
print("Tiny Chunk Found!!!")
|
||||
|
||||
if chunk_head == 1:
|
||||
print("Blend Alpha Adjust!!")
|
||||
elif chunk_head == 2:
|
||||
print("Mipmap adjust")
|
||||
elif chunk_head == 3:
|
||||
print("Specular exponent")
|
||||
elif chunk_head == 4:
|
||||
print("Save offset!!!")
|
||||
elif chunk_head == 5:
|
||||
print("Jumpt to offset!!!")
|
||||
|
||||
elif chunk_head >= 17 and chunk_head <= 23:
|
||||
print("Chunk: Material")
|
||||
bytes = self.file.read(2)
|
||||
@ -308,8 +324,10 @@ class NinjaModel: # {
|
||||
|
||||
for i in range (strip_count):
|
||||
|
||||
print("Strip Start: 0x%08x" % self.file.tell())
|
||||
bytes = self.file.read(2)
|
||||
strip_len = struct.unpack('h', bytes)[0]
|
||||
print("Strip Count: %d" % strip_len)
|
||||
counter_clockwise = strip_len < 0
|
||||
strip_len = abs(strip_len)
|
||||
strip = []
|
||||
@ -364,9 +382,9 @@ class NinjaModel: # {
|
||||
b['index']
|
||||
),
|
||||
'norm' : (
|
||||
va['norm'],
|
||||
vb['norm'],
|
||||
vc['norm']
|
||||
va.norm,
|
||||
vb.norm,
|
||||
vc.norm
|
||||
),
|
||||
uv : (
|
||||
a['uv'],
|
||||
@ -381,7 +399,6 @@ class NinjaModel: # {
|
||||
print("Unknown Chunk Type %d" % chunk_head)
|
||||
print("Unknown Chunk Flag %d" % chunk_flag)
|
||||
print("Unknown File Position: 0x%08x" % self.file.tell())
|
||||
break
|
||||
|
||||
#end While
|
||||
|
||||
|
69
NinjaVertex.py
Normal file
69
NinjaVertex.py
Normal file
@ -0,0 +1,69 @@
|
||||
"""
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Benjamin Collins (kion @ dashgl.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
"""
|
||||
|
||||
class NinjaVertex:
|
||||
|
||||
def __init__(self):
|
||||
self.pos = {
|
||||
'x' : 0.0,
|
||||
'y' : 0.0,
|
||||
'z' : 0.0
|
||||
}
|
||||
|
||||
self.norm = {
|
||||
'x' : 0.0,
|
||||
'y' : 0.0,
|
||||
'z' : 0.0
|
||||
}
|
||||
|
||||
self.color = {
|
||||
'r' : 255,
|
||||
'g' : 255,
|
||||
'b' : 255,
|
||||
'a' : 255
|
||||
}
|
||||
|
||||
self.skin_weight = [ 0, 0, 0, 0 ]
|
||||
self.skin_index = [ 0, 0, 0, 0 ]
|
||||
return None
|
||||
|
||||
def setPosition(self, x, y, z):
|
||||
self.pos['x'] = x
|
||||
self.pos['y'] = y
|
||||
self.pos['z'] = z
|
||||
return None
|
||||
|
||||
def setNormal(self, x, y, z):
|
||||
self.norm['x'] = x
|
||||
self.norm['y'] = y
|
||||
self.norm['z'] = z
|
||||
return None
|
||||
|
||||
def setSkinWeight(self, n, index, weight):
|
||||
self.skin_weight[n] = weight;
|
||||
self.skin_index[n] = index
|
||||
return None
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user