OSDN Git Service

add englishmap.
authorousttrue <ousttrue@gmail.com>
Sat, 31 Jul 2010 05:54:33 +0000 (14:54 +0900)
committerousttrue <ousttrue@gmail.com>
Sat, 31 Jul 2010 05:54:33 +0000 (14:54 +0900)
swig/blender/cp.py
swig/blender/mqo_import.py
swig/blender/pmd_export.py
swig/blender/pmd_import.py
swig/englishmap.py [new file with mode: 0644]
swig/pymeshio/mmd.py

index e1ac927..1142e3b 100644 (file)
@@ -47,12 +47,12 @@ def copy25(src):
 
 def copy_pymeshio():
     print("copy_pymeshio...")
+    # englishmap
+    shutil.copy("../englishmap.py", "../pymeshio/")
     for parent in DST_25:
         dst="%s/pymeshio" % parent
         if not os.path.exists(dst):
             os.mkdir(dst)
-        # englishmap
-        shutil.copy("../englishmap.py", dst)
         # pymethio
         for file in os.listdir("../pymeshio"):
             if file.endswith(".py"):
index 67603bd..885da51 100644 (file)
@@ -45,6 +45,7 @@ import sys
 try:\r
     # C extension\r
     from meshio import mqo\r
+    print('use meshio C module')\r
 except ImportError:\r
     # full python\r
     from pymeshio import mqo\r
index c6770f0..14ac2bd 100644 (file)
@@ -78,10 +78,12 @@ import sys
 try:
     # C extension
     from meshio import pmd, englishmap
+    print('use meshio C module')
 except ImportError:
     # full python
     from pymeshio import englishmap
-    from pymeshio.mmd import PMDLoader as pmd
+    from pymeshio import mmd as pmd
+    pmd.IO=pmd.PMDLoader
 
 def isBlender24():
     return sys.version_info[0]<3
@@ -102,7 +104,7 @@ if isBlender24():
         material.diffuse.b=m.B
         material.diffuse.a=m.alpha
         # specular
-        material.sinness=0 if m.spec<1e-5 else m.spec*10
+        material.shinness=0 if m.spec<1e-5 else m.spec*10
         material.specular.r=m.specR
         material.specular.g=m.specG
         material.specular.b=m.specB
@@ -134,7 +136,7 @@ else:
         material.diffuse.b=m.diffuse_color[2]
         material.diffuse.a=m.alpha
         # specular
-        material.sinness=0 if m.specular_toon_size<1e-5 else m.specular_hardness*10
+        material.shinness=0 if m.specular_toon_size<1e-5 else m.specular_hardness*10
         material.specular.r=m.specular_color[0]
         material.specular.g=m.specular_color[1]
         material.specular.b=m.specular_color[2]
@@ -1187,7 +1189,7 @@ class PmdExporter(object):
             constraint.springRot.z=obj[CONSTRAINT_SPRING_ROT][2]
 
         # 書き込み
-        bl.message('write %s' % path)
+        bl.message('write: %s' % path)
         return io.write(path)
 
 
index 5ef212f..1d2ac0c 100755 (executable)
@@ -86,6 +86,7 @@ import math
 try:
     # C extension
     from meshio import pmd, englishmap
+    print('use meshio C module')
 except ImportError:
     # full python
     from pymeshio import englishmap
diff --git a/swig/englishmap.py b/swig/englishmap.py
new file mode 100644 (file)
index 0000000..301f3bc
--- /dev/null
@@ -0,0 +1,283 @@
+#!/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')        
+
index 45be688..185f6ab 100755 (executable)
@@ -35,15 +35,16 @@ if sys.version_info[0]>=3:
 ###############################################################################
 # 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
@@ -205,6 +206,18 @@ class RGBA(object):
         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
@@ -434,16 +447,16 @@ class VMDLoader(object):
 # 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)
@@ -460,21 +473,13 @@ class Vertex(object):
 
 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)
@@ -483,6 +488,15 @@ class Material(object):
         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):
@@ -503,10 +517,10 @@ class Bone(object):
     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
@@ -514,12 +528,14 @@ class Bone(object):
         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
@@ -642,7 +658,7 @@ def createBone(name, type):
 
 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
@@ -653,15 +669,23 @@ class IK(object):
         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>' % (
@@ -670,13 +694,16 @@ class Skin(object):
 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',
@@ -684,16 +711,17 @@ class PMDLoader(object):
             '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=[]
@@ -701,32 +729,68 @@ class PMDLoader(object):
         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)
@@ -743,49 +807,49 @@ class PMDLoader(object):
         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
 
@@ -817,10 +881,10 @@ class PMDLoader(object):
         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)))
@@ -831,12 +895,12 @@ class PMDLoader(object):
                 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)))
@@ -844,13 +908,13 @@ class PMDLoader(object):
         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
@@ -859,8 +923,8 @@ class PMDLoader(object):
         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
@@ -876,19 +940,19 @@ class PMDLoader(object):
         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)))
@@ -901,7 +965,7 @@ class PMDLoader(object):
         return True
 
 
-    def loadExtend(self):
+    def _loadExtend(self):
         ############################################################
         # extend1: english name
         ############################################################
@@ -910,7 +974,7 @@ class PMDLoader(object):
         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
@@ -919,7 +983,7 @@ class PMDLoader(object):
             return True
         if not self.loadToonTexture():
             return False
-        self.check_position()
+        self._check_position()
 
         ############################################################
         # extend3: physics
@@ -928,11 +992,11 @@ class PMDLoader(object):
             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":
@@ -944,19 +1008,19 @@ class PMDLoader(object):
                 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)))
@@ -965,11 +1029,12 @@ class PMDLoader(object):
             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])
@@ -978,13 +1043,13 @@ class PMDLoader(object):
             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)))
@@ -996,7 +1061,7 @@ class PMDLoader(object):
             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]))
@@ -1010,20 +1075,20 @@ class PMDLoader(object):
             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)))
@@ -1040,8 +1105,10 @@ class PMDLoader(object):
 
     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(
@@ -1049,7 +1116,7 @@ class PMDLoader(object):
             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
@@ -1139,7 +1206,7 @@ class VPDLoader(LineLoader):
                 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