--- /dev/null
+#!/usr/bin/env python
+# coding: utf8
+"""
+日本語名との変換マップ
+"""
+import sys
+
+"""
+ボーン名変換
+"""
+boneMap=[
+("center", "センター", 1),
+("upper body", "上半身"),
+("neck", "首"),
+("head", "頭"),
+("eye_L", "左目", 5),
+("eye_R", "右目", 5),
+("necktie1", "ネクタイ1"),
+("necktie2", "ネクタイ2"),
+("necktie3", "ネクタイ3"),
+("lower body", "下半身"),
+("waist accessory", "腰飾り"),
+("hair1_L", "左髪1"),
+("hair2_L", "左髪2"),
+("hair3_L", "左髪3"),
+("hair4_L", "左髪4"),
+("hair5_L", "左髪5"),
+("hair6_L", "左髪6"),
+("shoulder_L", "左肩"),
+("arm_L", "左腕"),
+("arm twist_L", "左腕捩", 8),
+("elbow_L", "左ひじ"),
+("wrist twist_L", "左手捩", 8),
+("wrist_L", "左手首"),
+("sleeve_L", "左袖", 1),
+("thumb1_L", "左親指1"),
+("thumb2_L", "左親指2"),
+("fore1_L", "左人指1"),
+("fore2_L", "左人指2"),
+("fore3_L", "左人指3"),
+("middle1_L", "左中指1"),
+("middle2_L", "左中指2"),
+("middle3_L", "左中指3"),
+("third1_L", "左薬指1"),
+("third2_L", "左薬指2"),
+("third3_L", "左薬指3"),
+("little1_L", "左小指1"),
+("little2_L", "左小指2"),
+("little3_L", "左小指3"),
+("front skirt_L", "左スカート前"),
+("back skirt_L", "左スカート後"),
+("leg_L", "左足"),
+("knee_L", "左ひざ"),
+("ankle_L", "左足首"),
+("hair1_R", "右髪1"),
+("hair2_R", "右髪2"),
+("hair3_R", "右髪3"),
+("hair4_R", "右髪4"),
+("hair5_R", "右髪5"),
+("hair6_R", "右髪6"),
+("shoulder_R", "右肩"),
+("arm_R", "右腕"),
+("arm twist_R", "右腕捩", 8),
+("elbow_R", "右ひじ"),
+("wrist twist_R", "右手捩", 8),
+("wrist_R", "右手首"),
+("sleeve_R", "右袖", 1),
+("thumb1_R", "右親指1"),
+("thumb2_R", "右親指2"),
+("fore1_R", "右人指1"),
+("fore2_R", "右人指2"),
+("fore3_R", "右人指3"),
+("middle1_R", "右中指1"),
+("middle2_R", "右中指2"),
+("middle3_R", "右中指3"),
+("third1_R", "右薬指1"),
+("third2_R", "右薬指2"),
+("third3_R", "右薬指3"),
+("little1_R", "右小指1"),
+("little2_R", "右小指2"),
+("little3_R", "右小指3"),
+("front skirt_R", "右スカート前"),
+("back skirt_R", "右スカート後"),
+("leg_R", "右足"),
+("knee_R", "右ひざ"),
+("ankle_R", "右足首"),
+("eyes", "両目"),
+("front hair1", "前髪1"),
+("front hair2", "前髪2"),
+("front hair3", "前髪3"),
+("eyelight_L", "左目光"),
+("eyelight_R", "右目光"),
+("necktie3_t", "ネクタイ4"),
+("hair6_L_t", "左髪7"),
+("hair6_R_t", "右髪7"),
+("ankle_L_t", "左つま先"),
+("ankle_R_t", "右つま先"),
+("necktie IK", "ネクタイIK"),
+("hair IK_L", "左髪IK"),
+("hair IK_R", "右髪IK"),
+("leg IK_L", "左足IK"),
+("leg IK_R", "右足IK"),
+("toe IK_L", "左つま先IK"),
+("toe IK_R", "右つま先IK"),
+
+("lower body_t", "下半身先"),
+("head_t", "頭先"),
+("eye_L_t", "左目先"),
+("eye_R_t", "右目先"),
+("waist accessory_t", "腰飾り先"),
+
+("sleeve_L_t", "左袖先"),
+("wrist_L_t", "左手先"),
+("thumb2_L_t", "左親指先"),
+("fore3_L_t", "左人差指先"),
+("middle3_L_t", "左中指先"),
+("third3_L_t", "左薬指先"),
+("little3_L_t", "左小指先"),
+("front skirt_L_t", "左スカート前先"),
+("back skirt_L_t", "左スカート後先"),
+
+("sleeve_R_t", "右袖先"),
+("wrist_R_t", "右手先"),
+("thumb2_R_t", "右親指先"),
+("fore3_R_t", "右人差指先"),
+("middle3_R_t", "右中指先"),
+("third3_R_t", "右薬指先"),
+("little3_R_t", "右小指先"),
+("front skirt_R_t", "右スカート前先"),
+("back skirt_R_t", "右スカート後先"),
+
+("center_t", "センター先"),
+("eyes_t", "両目先"),
+("necktie IK_t", "ネクタイIK先"),
+("hair IK_L_t", "左髪IK先"),
+("hair IK_R_t", "右髪IK先"),
+("leg IK_L_t", "左足IK先"),
+("leg IK_R_t", "右足IK先"),
+("toe IK_L_t", "左つま先IK先"),
+("toe IK_R_t", "右つま先IK先"),
+("front hair1_t", "前髪1先"),
+("front hair2_t", "前髪2先"),
+("front hair3_t", "前髪3先"),
+("eyelight_L_t", "左目光先"),
+("eyelight_R_t", "右目光先"),
+("arm twist_L_t", "左腕捩先"),
+("wrist twist_L_t", "左手捩先"),
+("arm twist_R_t", "右腕捩先"),
+("wrist twist_R_t", "右手捩先"),
+("arm twist1_L", "左腕捩1", 9),
+("arm twist2_L", "左腕捩2", 9),
+("arm twist3_L", "左腕捩3", 9),
+("arm twist1_R", "右腕捩1", 9),
+("arm twist2_R", "右腕捩2", 9),
+("arm twist3_R", "右腕捩3", 9),
+#
+("arm twist1_L_t", "左腕捩1先"),
+("arm twist2_L_t", "左腕捩2先"),
+("arm twist3_L_t", "左腕捩3先"),
+("arm twist1_R_t", "右腕捩1先"),
+("arm twist2_R_t", "右腕捩2先"),
+("arm twist3_R_t", "右腕捩3先"),
+
+# 追加ボーン
+("root", "全ての親"),
+("root_t", "全ての親先"),
+("group", "グループ"),
+("group_t", "グループ先"),
+("front_shirt_L", "左シャツ前"),
+("front_shirt_R", "右シャツ前"),
+("back_shirt_L", "左シャツ後"),
+("back_shirt_R", "右シャツ後"),
+]
+def getEnglishBoneName(name):
+ for v in boneMap:
+ if v[1]==name:
+ return v[0]
+
+def getIndexByEnglish(name):
+ for i, v in enumerate(boneMap):
+ if v[0]==name:
+ return i
+
+def getUnicodeBoneName(name):
+ for v in boneMap:
+ if v[0]==name:
+ return v
+
+"""
+モーフ名変換
+"""
+skinMap=[
+("base", "base", 0),
+("serious", "真面目", 1),
+("sadness", "困る", 1),
+("cheerful", "にこり", 1),
+("anger", "怒り", 1),
+("go up", "上", 1),
+("go down", "下", 1),
+("blink", "まばたき", 2),
+("smile", "笑い", 2),
+("wink", "ウィンク", 2),
+("wink2", "ウィンク2", 2),
+("wink_R", "ウィンク右", 2),
+("wink2_R", "ウィンク2右", 2),
+("close><", "はぅ", 2),
+("calm", "なごみ", 2),
+("surprise", "びっくり", 2),
+("doubt", "じと目", 2),
+("confuse", "なぬ!", 2),
+("pupil", "瞳小", 4),
+("a", "あ", 3),
+("i", "い", 3),
+("u", "う", 3),
+("o", "お", 3),
+("triangle", "▲", 3),
+("regret", "∧", 3),
+("omega", "ω", 3),
+("omegabox", "ω□", 3),
+("fool", "はんっ!", 3),
+("tongue", "ぺろっ", 4),
+("e-", "えー", 3),
+("grin", "にやり", 3),
+]
+def getEnglishSkinName(name):
+ for v in skinMap:
+ if v[1]==name:
+ return v[0]
+
+def getUnicodeSkinName(name):
+ for v in skinMap:
+ if v[0]==name:
+ return v
+
+"""
+ボーングループ名変換
+"""
+boneGroupMap=[
+ ("IK", "IK"),
+ ("Body[u]", "体(上)"),
+ ("Hair", "髪"),
+ ("Arms", "腕"),
+ ("Fingers", "指"),
+ ("Body[l]", "体(下)"),
+ ("Legs", "足"),
+ ]
+def getEnglishBoneGroupName(name):
+ for v in boneGroupMap:
+ if v[1]==name:
+ return v[0]
+
+def getUnicodeBoneGroupName(name):
+ for v in boneGroupMap:
+ if v[0]==name:
+ return v[1]
+
+
+###############################################################################
+# blender2.4 str to unicode
+###############################################################################
+if sys.version_info[0]<3:
+ print('convert boneMap and skinMap to unicode...')
+ # python2.x
+ # unicodeに変換
+ for i, l in enumerate(boneMap):
+ replace=[]
+ for j, m in enumerate(l):
+ if j==1:
+ replace.append(m.decode('utf-8'))
+ else:
+ replace.append(m)
+ boneMap[i]=replace
+
+ for i, l in enumerate(skinMap):
+ replace=[]
+ for j, m in enumerate(l):
+ if j==1:
+ replace.append(m.decode('utf-8'))
+ else:
+ replace.append(m)
+ skinMap[i]=replace
+ print('done')
+
###############################################################################
# utility
###############################################################################
-def truncate_zero(string):
+def truncate_zero(src):
"""
- 0x00以é\99\8dã\82\92æ\8d¨ã\81¦ã\81¦cp932æ\96\87å\97å\88\97ã\81¨ã\81\97ã\81¦è§£é\87\88ã\81\99ã\82\8b
+ 0x00以降を捨てる
"""
- pos = string.find(b"\x00")
+ pos = src.find(b"\x00")
+ assert(type(src)==bytes)
if pos >= 0:
- return string[:pos].decode('cp932').rstrip()
+ return src[:pos]
else:
- return string.decode('cp932')
+ return src
def radian_to_degree(x):
return x/math.pi * 180.0
self.b=b
self.a=a
+ def __getitem__(self, key):
+ if key==0:
+ return self.r
+ elif key==1:
+ return self.g
+ elif key==2:
+ return self.b
+ elif key==3:
+ return self.a
+ else:
+ assert(False)
+
###############################################################################
# VMD
# PMD
###############################################################################
class Vertex(object):
- __slots__=['pos', 'normal', 'uv', 'bone0', 'bone1', 'weight0', 'flag']
- def __init__(self, x, y, z, nx, ny, nz, u, v,
- bone0, bone1, weight0, flag):
+ __slots__=['pos', 'normal', 'uv', 'bone0', 'bone1', 'weight0', 'edge_flag']
+ def __init__(self, x=0, y=0, z=0, nx=0, ny=0, nz=0, u=0, v=0,
+ bone0=0, bone1=0, weight0=0, edge_flag=0):
self.pos=Vector3(x, y, z)
self.normal=Vector3(nx, ny, nz)
self.uv=Vector2(u, v)
self.bone0=bone0
self.bone1=bone1
self.weight0=weight0
- self.flag=flag
+ self.edge_flag=edge_flag
def __str__(self):
return "<%s %s %s, (%d, %d, %d)>" % (str(self.pos), str(self.normal), str(self.uv), self.bone0, self.bone1, self.weight0)
class Material(object):
__slots__=[
- 'diffuse', 'alpha', 'shinness', 'specular',
+ 'diffuse', 'shinness', 'specular',
'ambient', 'vertex_count', 'texture', 'toon_index', 'flag',
]
- def __str__(self):
- return "<Material [%f, %f, %f, %f]>" % (
- self.diffuse[0], self.diffuse[1],
- self.diffuse[2], self.alpha
- )
-
- def getTexture(self): return self.texture
-
- def __init__(self, dr, dg, db, alpha, specular, sr, sg, sb, ar, ag, ab):
- self.diffuse=RGBA(dr, dg, db)
- self.alpha=alpha
+ def __init__(self, dr=0, dg=0, db=0, alpha=1,
+ specular=0, sr=0, sg=0, sb=0, ar=0, ag=0, ab=0):
+ self.diffuse=RGBA(dr, dg, db, alpha)
self.specular=RGBA(sr, sg, sb)
self.shinness=specular
self.ambient=RGBA(ar, ag, ab)
self.toon_index=0
self.flag=0
+ def __str__(self):
+ return "<Material [%f, %f, %f, %f]>" % (
+ self.diffuse[0], self.diffuse[1],
+ self.diffuse[2], self.diffuse[3],
+ )
+
+ def getTexture(self): return self.texture.decode('cp932')
+ def setTexture(self, u): self.texture=u
+
# @return 各マテリアルについて、そのマテリアルが保持する面の回数だけ
# マテリアル自身を返す
def material_per_face(materials):
ROLLING=8 # ?
TWEAK=9
__slots__=['name', 'index', 'type', 'parent', 'ik', 'pos',
- 'children', 'english_name', 'ik_bone',
+ 'children', 'english_name', 'ik_index',
'parent_index', 'tail_index', 'tail',
]
- def __init__(self, name, type):
+ def __init__(self, name='bone', type=0):
self.name=name
self.index=0
self.type=type
self.tail_index=0
self.tail=Vector3(0, 0, 0)
self.parent=None
- self.ik_bone=0xFFFF
+ self.ik_index=0xFFFF
self.pos=Vector3(0, 0, 0)
self.children=[]
self.english_name=''
- def getName(self): return self.name
+ def getName(self): return self.name.decode('cp932')
+ def setName(self, u): self.name=u
+ def setEnglishName(self, u): self.english_name=u
def hasParent(self):
return self.parent_index!=0xFFFF
class IK(object):
__slots__=['index', 'target', 'iterations', 'weight', 'length', 'children']
- def __init__(self, index, target):
+ def __init__(self, index=0, target=0):
self.index=index
self.target=target
self.iterations=None
return "<IK index: %d, target: %d, iterations: %d, weight: %f, children: %s(%d)>" %(self.index, self.target, self.iterations, self.weight, '-'.join([str(i) for i in self.children]), len(self.children))
class Skin(object):
- __slots__=['name', 'type', 'indices', 'pos_list', 'english_name']
- def __init__(self, name):
+ __slots__=['name', 'type', 'indices', 'pos_list', 'english_name',
+ 'vertex_count']
+ def __init__(self, name='skin'):
self.name=name
self.type=None
self.indices=[]
self.pos_list=[]
self.english_name=''
+ self.vertex_count=0
- def getName(self): return self.name
+ def getName(self): return self.name.decode('cp932')
+ def setName(self, u): self.name=u
+ def setEnglishName(self, u): self.english_name=u
+
+ def append(self, index, x, y, z):
+ self.indices.append(index)
+ self.pos_list.append(Vector3(x, y, z))
def __str__(self):
return '<Skin name: "%s", type: %d, vertex: %d>' % (
class ToonTexture(object):
__slots__=['name']
def __init__(self, name): self.name=name
- def getName(self): return self.name
+ def getName(self): return self.name.decode('cp932')
+ def setName(self, u): self.name=u
class BoneGroup(object):
__slots__=['name', 'english_name']
- def __init__(self, name): self.name=name; self.english_name='center'
- def getName(self): return self.name
- def getEnglishName(self): return self.english_name
+ def __init__(self, name='group'): self.name=name; self.english_name='center'
+ def getName(self): return self.name.decode('cp932')
+ def setName(self, u): self.name=u
+ def getEnglishName(self): return self.english_name.decode('cp932')
+ def setEnglishName(self, u): self.english_name=u
class PMDLoader(object):
__slots__=['io', 'end', 'pos',
'english_model_name', 'english_comment',
'vertices', 'indices', 'materials', 'bones',
'ik_list', 'morph_list',
- 'skin_list', 'bone_group_list', 'bone_display_list',
- 'english_skin_list', 'toon_textures',
+ 'face_list', 'bone_group_list', 'bone_display_list',
+ 'toon_textures',
'no_parent_bones',
'rigidbodies', 'constraints',
]
def __init__(self):
self.version=1.0
- self.model_name="default"
- self.comment="default"
- self.english_model_name='default'
+ self.model_name=b"default"
+ self.comment=b"default"
+ self.english_model_name=b'default'
+ self.english_comment=b'default'
self.vertices=[]
self.indices=[]
self.materials=[]
self.ik_list=[]
self.morph_list=[]
- self.skin_list=[]
+ self.face_list=[]
self.bone_group_list=[]
self.bone_display_list=[]
- self.english_skin_list=['base']
- self.toon_textures=[]
+ self.toon_textures=[
+ ToonTexture(b'toon'), ToonTexture(b'toon'),
+ ToonTexture(b'toon'), ToonTexture(b'toon'),
+ ToonTexture(b'toon'), ToonTexture(b'toon'),
+ ToonTexture(b'toon'), ToonTexture(b'toon'),
+ ToonTexture(b'toon'), ToonTexture(b'toon'),
+ ]
self.no_parent_bones=[]
self.rigidbodies=[]
self.constraints=[]
- def getEnglishName(self): return self.english_model_name
- def getEnglishComment(self): return self.english_comment
- def getName(self): return self.model_name
- def getComment(self): return self.comment
+ def getName(self): return self.model_name.decode('cp932')
+ def setName(self, u): self.model_name=u
+ def getComment(self): return self.comment.decode('cp932')
+ def setComment(self, u): self.comment=u
+ def getEnglishName(self): return self.english_model_name.decode('cp932')
+ def setEnglishName(self, u): self.english_model_name=u
+ def getEnglishComment(self): return self.english_comment.decode('cp932')
+ def setEnglishComment(self, u): self.english_comment=u
+
def getToonTexture(self, i): return self.toon_textures[i]
def each_vertex(self): return self.vertices
def getUV(self, i): return self.vertices[i].uv
+ def addVertex(self):
+ v=Vertex()
+ self.vertices.append(v)
+ return v
+ def addMaterial(self):
+ m=Material()
+ self.materials.append(m)
+ return m
+ def addBone(self):
+ b=Bone()
+ self.bones.append(b)
+ return b
+ def addIK(self):
+ ik=IK()
+ self.ik_list.append(ik)
+ return ik
+ def addMorph(self):
+ s=Skin()
+ self.morph_list.append(s)
+ return s
+ def addBoneGroup(self):
+ g=BoneGroup()
+ self.bone_group_list.append(g)
+ return g
+ def addBoneDisplay(self, b, g):
+ self.bone_display_list.append((b, g))
def __str__(self):
return '<PMDLoader version: %g, model: "%s", vertex: %d, face: %d, material: %d, bone: %d ik: %d, skin: %d>' % (
self.version, self.model_name, len(self.vertices), len(self.indices),
len(self.materials), len(self.bones), len(self.ik_list), len(self.morph_list))
- def check_position(self):
+ def _check_position(self):
"""
if self.pos:
print(self.pos, self.io.tell()-self.pos)
self.io=io
self.pos=self.io.tell()
self.end=end
- self.check_position()
+ self._check_position()
- if not self.loadHeader():
+ if not self._loadHeader():
return False
- self.check_position()
+ self._check_position()
- if not self.loadVertex():
+ if not self._loadVertex():
return False
- self.check_position()
+ self._check_position()
- if not self.loadFace():
+ if not self._loadFace():
return False
- self.check_position()
+ self._check_position()
- if not self.loadMaterial():
+ if not self._loadMaterial():
return False
- self.check_position()
+ self._check_position()
- if not self.loadBone():
+ if not self._loadBone():
return False
- self.check_position()
+ self._check_position()
- if not self.loadIK():
+ if not self._loadIK():
return False
- self.check_position()
+ self._check_position()
- if not self.loadSkin():
+ if not self._loadSkin():
return False
- self.check_position()
+ self._check_position()
- if not self.loadSkinIndex():
+ if not self._loadSkinIndex():
return False
- self.check_position()
+ self._check_position()
- if not self.loadBoneName():
+ if not self._loadBoneName():
return False
- self.check_position()
+ self._check_position()
- if not self.loadBoneIndex():
+ if not self._loadBoneIndex():
return False
- self.check_position()
+ self._check_position()
- if not self.loadExtend():
+ if not self._loadExtend():
print('fail to loadExtend')
return False
if not io:
return False
# Header
- io.write("Pmd")
+ io.write(b"Pmd")
io.write(struct.pack("f", self.version))
- io.write(struct.pack("20s", self.model_name.encode('cp932')))
- io.write(struct.pack("256s", self.comment.encode('cp932')))
+ io.write(struct.pack("20s", self.model_name))
+ io.write(struct.pack("256s", self.comment))
# Vertices
io.write(struct.pack("I", len(self.vertices)))
v.pos[0], v.pos[1], v.pos[2],
v.normal[0], v.normal[1], v.normal[2],
v.uv[0], v.uv[1],
- v.bone0, v.bone1, v.weight0, v.flag)
+ v.bone0, v.bone1, v.weight0, v.edge_flag)
io.write(data)
# Faces
io.write(struct.pack("I", len(self.indices)))
- io.write(struct.pack("=H*", *self.indices))
+ io.write(struct.pack("=%dH" % len(self.indices), *self.indices))
# material
io.write(struct.pack("I", len(self.materials)))
assert(sMaterial.size==70)
for m in self.materials:
io.write(sMaterial.pack(
- m.diffuse[0], m.diffuse[1], m.diffuse[2],
- m.alpha, m.specular,
- m.specular_color[0], m.specular_color[1], m.specular_color[2],
- m.ambient_color[0], m.ambient_color[1], m.ambient_color[2],
+ m.diffuse[0], m.diffuse[1], m.diffuse[2], m.diffuse[3],
+ m.shinness,
+ m.specular[0], m.specular[1], m.specular[2],
+ m.ambient[0], m.ambient[1], m.ambient[2],
m.toon_index, m.flag,
m.vertex_count,
- m.texture.encode('cp932')
+ m.texture
))
# bone
assert(sBone.size==39)
for b in self.bones:
io.write(sBone.pack(
- b.name.encode("cp932"),
- b.parent_index, b.tail_index, b.type, b.ik_bone,
+ b.name,
+ b.parent_index, b.tail_index, b.type, b.ik_index,
b.pos[0], b.pos[1], b.pos[2]))
# IK
io.write(struct.pack("H", len(self.morph_list)))
for s in self.morph_list:
io.write(struct.pack("20sIB",
- s.name.encode('cp932'), len(s.indices), s.type))
+ s.name, len(s.indices), s.type))
for i, v in zip(s.indices, s.pos_list):
io.write(struct.pack("I3f", i, v[0], v[1], v[2]))
# skin list
- io.write(struct.pack("B", len(self.skin_list)))
- for i in self.skin_list:
+ io.write(struct.pack("B", len(self.face_list)))
+ for i in self.face_list:
io.write(struct.pack("H", i))
# bone name
io.write(struct.pack("B", len(self.bone_group_list)))
- for name in self.bone_group_list:
- io.write(struct.pack("50s", name.encode('cp932')))
+ for g in self.bone_group_list:
+ io.write(struct.pack("50s", g.name))
# bone list
io.write(struct.pack("I", len(self.bone_display_list)))
return True
- def loadExtend(self):
+ def _loadExtend(self):
############################################################
# extend1: english name
############################################################
if struct.unpack("B", self.io.read(1))[0]==1:
if not self.loadEnglishName():
return False
- self.check_position()
+ self._check_position()
############################################################
# extend2: toon texture list
return True
if not self.loadToonTexture():
return False
- self.check_position()
+ self._check_position()
############################################################
# extend3: physics
return True
if not self.loadPhysics():
return False
- self.check_position()
+ self._check_position()
return True
- def loadHeader(self):
+ def _loadHeader(self):
signature=struct.unpack("3s", self.io.read(3))[0]
print(signature)
if signature!=b"Pmd":
struct.unpack("256s", self.io.read(256))[0])
return True
- def loadVertex(self):
+ def _loadVertex(self):
count = struct.unpack("I", self.io.read(4))[0]
for i in xrange(count):
self.vertices.append(Vertex(*struct.unpack("8f2H2B", self.io.read(38))))
return True
- def loadFace(self):
+ def _loadFace(self):
count = struct.unpack("I", self.io.read(4))[0]
for i in xrange(0, count, 3):
self.indices+=struct.unpack("HHH", self.io.read(6))
return True
- def loadMaterial(self):
+ def _loadMaterial(self):
count = struct.unpack("I", self.io.read(4))[0]
for i in xrange(count):
material=Material(*struct.unpack("4ff3f3f", self.io.read(44)))
material.vertex_count=struct.unpack("I", self.io.read(4))[0]
texture=truncate_zero(struct.unpack("20s", self.io.read(20))[0])
# todo sphere map
- material.texture=texture.split('*')[0]
+ #material.texture=texture.split('*')[0]
+ material.texture=texture
self.materials.append(material)
return True
- def loadBone(self):
+ def _loadBone(self):
size = struct.unpack("H", self.io.read(2))[0]
for i in xrange(size):
name=truncate_zero(struct.unpack("20s", self.io.read(20))[0])
bone=createBone(name, type)
bone.parent_index=parent_index
bone.tail_index=tail_index
- bone.ik_bone = struct.unpack("H", self.io.read(2))[0]
+ bone.ik_index = struct.unpack("H", self.io.read(2))[0]
bone.pos = Vector3(*struct.unpack("3f", self.io.read(12)))
bone.english_name="bone%03d" % len(self.bones)
self.bones.append(bone)
return True
- def loadIK(self):
+ def _loadIK(self):
size = struct.unpack("H", self.io.read(2))[0]
for i in xrange(size):
ik=IK(*struct.unpack("2H", self.io.read(4)))
self.ik_list.append(ik)
return True
- def loadSkin(self):
+ def _loadSkin(self):
size = struct.unpack("H", self.io.read(2))[0]
for i in xrange(size):
skin=Skin(truncate_zero(struct.unpack("20s", self.io.read(20))[0]))
self.morph_list.append(skin)
return True
- def loadSkinIndex(self):
+ def _loadSkinIndex(self):
size = struct.unpack("B", self.io.read(1))[0]
for i in xrange(size):
- self.skin_list.append(struct.unpack("H", self.io.read(2))[0])
+ self.face_list.append(struct.unpack("H", self.io.read(2))[0])
return True
- def loadBoneName(self):
+ def _loadBoneName(self):
size = struct.unpack("B", self.io.read(1))[0]
for i in xrange(size):
self.bone_group_list.append(BoneGroup(
truncate_zero(struct.unpack("50s", self.io.read(50))[0])))
return True
- def loadBoneIndex(self):
+ def _loadBoneIndex(self):
size = struct.unpack("I", self.io.read(4))[0]
for i in xrange(size):
self.bone_display_list.append(struct.unpack("HB", self.io.read(3)))
def loadEnglishName(self):
# english name
- self.english_model_name=truncate_zero(struct.unpack("20s", self.io.read(20))[0])
- self.english_comment=truncate_zero(struct.unpack("256s", self.io.read(256))[0])
+ self.english_model_name=truncate_zero(
+ struct.unpack("20s", self.io.read(20))[0])
+ self.english_comment=truncate_zero(
+ struct.unpack("256s", self.io.read(256))[0])
# english bone list
for bone in self.bones:
english_name=truncate_zero(
if english_name!=bone.name:
bone.english_name=english_name
# english skin list
- #for index in self.skin_list:
+ #for index in self.face_list:
for skin in self.morph_list:
if skin.name=='base':
continue
continue
m=RE_OPEN.match(line)
if m:
- if not self.parseBone(m.group(2).decode('cp932')):
+ if not self.parseBone(m.group(2)):
raise Exception("invalid bone")
continue