From a258f08b078ce1b01dbf08ee8f95ad44c6cbcd48 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Tue, 25 May 2010 07:42:40 +0900 Subject: [PATCH] implement english name. --- include/pmd.h | 22 ++++++++++++++++++-- src/pmd.cpp | 49 +++++++++++++++++++++++++++++++++----------- swig/blender24/pmd_export.py | 40 ++++++++++++++++++++++++++++++------ swig/blender24/pmd_import.py | 2 +- swig/englishmap.py | 12 +++++++++++ swig/pmd.i | 16 ++++++++++----- 6 files changed, 115 insertions(+), 26 deletions(-) diff --git a/include/pmd.h b/include/pmd.h index 017b7d3..a8cffa2 100644 --- a/include/pmd.h +++ b/include/pmd.h @@ -258,6 +258,23 @@ inline std::ostream &operator<<(std::ostream &os, const Morph &rhs) } //////////////////////////////////////////////////////////// +//! ƒ{[ƒ“•\Ž¦˜g +//////////////////////////////////////////////////////////// +struct BoneDisplayName +{ + char name[50]; + char english_name[50]; +}; + +//////////////////////////////////////////////////////////// +//! ƒgƒD[ƒ“ƒeƒNƒXƒ`ƒƒ +//////////////////////////////////////////////////////////// +struct ToonTexture +{ + char name[100]; +}; + +//////////////////////////////////////////////////////////// //! „‘Ì //////////////////////////////////////////////////////////// //! Œ`ó @@ -351,12 +368,13 @@ struct IO std::vector ik_list; std::vector morph_list; std::vector face_list; - std::vector bone_display_name_list; + std::vector bone_display_name_list; std::vector > bone_display_list; + ToonTexture toon_textures[10]; std::vector rigidbodies; std::vector constraints; - char english_model_name[20]; + char english_name[20]; char english_comment[256]; IO(); diff --git a/src/pmd.cpp b/src/pmd.cpp index 2a1c0c0..69f366e 100644 --- a/src/pmd.cpp +++ b/src/pmd.cpp @@ -293,7 +293,9 @@ private: bool parseEnglishBoneList() { for(size_t i=0; i(bone_display_name_list.size()); for(size_t i=0; i(buf, 50); + w.writeArray(bone_display_name_list[i].name, 50); } // bone list @@ -649,7 +646,35 @@ bool IO::write(binary::IWriter &w) w.writeValue(bone_display_list[i].second); } + //////////////////////////////////////////////////////////// // extend + //////////////////////////////////////////////////////////// + w.writeValue(0x01); + + //////////////////////////////////////////////////////////// + // english names + //////////////////////////////////////////////////////////// + w.writeArray(english_name, 20); + w.writeArray(english_comment, 256); + + for(size_t i=0; i(bones[i].english_name, 20); + } + + for(size_t i=1; i(morph_list[i].english_name, 20); + } + + for(size_t i=0; i(bone_display_name_list[i].english_name, 50); + } + + //////////////////////////////////////////////////////////// + // toon textures + //////////////////////////////////////////////////////////// + for(size_t i=0; i<10; ++i){ + w.writeArray(toon_textures[i].name, 100); + } return true; } diff --git a/swig/blender24/pmd_export.py b/swig/blender24/pmd_export.py index bc7192c..5fc37b8 100644 --- a/swig/blender24/pmd_export.py +++ b/swig/blender24/pmd_export.py @@ -589,9 +589,20 @@ class PmdExporter(object): # bones for b in builder.bones: bone=io.addBone() - bone_name="%s\n" % b.name + + unicode=englishmap.getUnicodeBoneName(b.name) + if unicode: + cp932=unicode.encode('cp932') + else: + cp932=b.name + bone_name="%s\n" % cp932 assert(len(bone_name)<20) bone.name=bone_name + + bone_english_name="%s\n" % b.name + assert(len(bone_english_name)<20) + bone.english_name=bone_english_name + bone.type=b.type bone.parent_index=b.parent_index if b.parent_index!=None else 0xFFFF bone.tail_index=b.tail_index if b.tail_index!=None else 0 @@ -619,7 +630,15 @@ class PmdExporter(object): for i, m in enumerate(self.oneSkinMesh.morphList): # morph morph=io.addMorph() - morph.name="%s\n" % m.name + + unicode=englishmap.getUnicodeSkinName(m.name) + if unicode: + cp932=unicode.encode('cp932') + else: + cp932=m.name + morph.name="%s\n" % cp932 + + morph.english_name="%s\n" % m.name morph.type=m.type for index, offset in zip(m.indices, m.offsets): # convert right-handed z-up to left-handed y-up @@ -630,12 +649,21 @@ class PmdExporter(object): if i>0: io.face_list.append(i) - # ボーン枠 - io.addBoneNameList("bones\n") - display=1 + # ボーン表示枠 + boneDisplayName=io.addBoneDisplayName() + boneDisplayName.name="bones\n" + boneDisplayName.english_name="bones\n" + displayIndex=1 for i, b in enumerate(builder.bones): if b.type in [6, 7]: - io.addBoneDisplay(i, display) + io.addBoneDisplay(i, displayIndex) + + # English + io.english_name="blender export model" + io.english_coment="blender export" + + for i in range(10): + io.getToonTexture(i).name="toon%02d.bmp" % i # 書き込み return io.write(path.encode(FS_ENCODING)) diff --git a/swig/blender24/pmd_import.py b/swig/blender24/pmd_import.py index a91fc77..b588610 100644 --- a/swig/blender24/pmd_import.py +++ b/swig/blender24/pmd_import.py @@ -538,7 +538,7 @@ def run(filename): # import objects container root=scene.objects.new("Empty") root.setName( - l.english_model_name if len(l.english_model_name)>0 else l.getName().encode(INTERNAL_ENCODING)) + l.english_name if len(l.english_name)>0 else l.getName().encode(INTERNAL_ENCODING)) # import mesh mesh_objects=importMesh(scene, l, tex_dir) diff --git a/swig/englishmap.py b/swig/englishmap.py index 54d29d0..0298747 100644 --- a/swig/englishmap.py +++ b/swig/englishmap.py @@ -152,6 +152,14 @@ def getEnglishBoneName(name): if v==name: return k +def getUnicodeBoneName(name): + if name.endswith('_t'): + name=name[:-2] + if name in boneMap: + return boneMap[name]+(u'先' if sys.version_info[0]<3 else '先') + else: + if name in boneMap: + return boneMap[name] skinMap={ "skin000":"base", @@ -191,6 +199,10 @@ def getEnglishSkinName(name): if v==name: return k +def getUnicodeSkinName(name): + if name in skinMap: + return skinMap[name] + if sys.version_info[0]<3: print 'convert boneMap and skinMap to unicode...', # python2.x diff --git a/swig/pmd.i b/swig/pmd.i index ced3530..41c1d37 100644 --- a/swig/pmd.i +++ b/swig/pmd.i @@ -106,15 +106,21 @@ meshio::pmd::IK *addIK() return &($self->ik_list.back()); } -void addBoneNameList(const std::string &name) -{ - $self->bone_display_name_list.push_back(name); -} - void addBoneDisplay(unsigned short bone_index, unsigned char display_index) { $self->bone_display_list.push_back( std::make_pair(bone_index, display_index)); } +meshio::pmd::BoneDisplayName *addBoneDisplayName() +{ + $self->bone_display_name_list.push_back(meshio::pmd::BoneDisplayName()); + return &($self->bone_display_name_list.back()); +} + +meshio::pmd::ToonTexture *getToonTexture(int index) +{ + return &($self->toon_textures[index]); +} + } -- 2.11.0