OSDN Git Service

separate vertex with uv or normal.
[meshio/meshio.git] / src / pmd.cpp
index 2f11d0f..c5ac48f 100755 (executable)
 namespace meshio {
 namespace pmd {
 
+// IO
+bool IO::write(const char *path)
+{
+       binary::FileWriter w(path);
+       return write(w);
+}
+
+bool IO::write(const wchar_t *path)
+{
+       binary::FileWriter w(path);
+       return write(w);
+}
+
 std::wstring 
-       Material::getTexture()const
-       {
-               return text::trim(text::to_WideChar(CP_OEMCP, 
-                                       std::string(texture, texture+20)));
-       }
+IO::getName()const
+{
+       return text::trim(text::to_WideChar(CP_OEMCP, 
+                               std::string(name, name+20)));
+}
 
 std::wstring 
+IO::getComment()const
+{
+       return text::trim(text::to_WideChar(CP_OEMCP, 
+                               std::string(comment, comment+256)));
+}
+
+std::wstring 
+IO::getEnglishName()const
+{
+       return text::trim(text::to_WideChar(CP_OEMCP, 
+                               std::string(english_name, english_name+20)));
+}
+
+std::wstring 
+IO::getEnglishComment()const
+{
+       return text::trim(text::to_WideChar(CP_OEMCP, 
+                               std::string(english_comment, english_comment+256)));
+}
+
+const Vector2* IO::getUV(int index)const
+{
+       return &vertices[index].uv;
+}
+
+void IO::setName(const char *src)
+{
+       strncpy(name, src, 20);
+}
+
+void IO::setComment(const char *src)
+{
+       strncpy(comment, src, 256);
+}
+
+void IO::setEnglishName(const char *src)
+{
+       strncpy(english_name, src, 20);
+}
+
+void IO::setEnglishComment(const char *src)
+{
+       strncpy(english_comment, src, 256);
+}
+
+
+// Material
+std::wstring 
+Material::getTexture()const
+{
+       return text::trim(text::to_WideChar(CP_OEMCP, 
+                               std::string(texture, texture+20)));
+}
+
+void Material::setTexture(const char *src)
+{
+       strncpy(texture, src, 20);
+}
+
+// Bone
+std::wstring 
        Bone::getName()const
        {
                return text::trim(text::to_WideChar(CP_OEMCP, 
                                        std::string(name, name+20)));
        }
 
+void Bone::setName(const char *src)
+{
+       strncpy(name, src, 20);
+}
+
+void Bone::setEnglishName(const char *src)
+{
+       strncpy(english_name, src, 20);
+}
+
+// Morph
 std::wstring 
        Morph::getName()const
        {
@@ -33,34 +118,74 @@ void
                pos_list.push_back(Vector3(x, y, z));
        }
 
+void Morph::setName(const char *src)
+{
+       strncpy(name, src, 20);
+}
+
+void Morph::setEnglishName(const char *src)
+{
+       strncpy(english_name, src, 20);
+}
+
+// BoneGroup
 std::wstring 
-       IO::getName()const
+       BoneGroup::getName()const
        {
                return text::trim(text::to_WideChar(CP_OEMCP, 
-                                       std::string(name, name+20)));
+                                       std::string(name, name+50)));
        }
 
+void BoneGroup::setName(const char *src)
+{
+       strncpy(name, src, 50);
+}
+
+void BoneGroup::setEnglishName(const char *src)
+{
+       strncpy(english_name, src, 50);
+}
+
+// RigidBody
 std::wstring 
-       IO::getEnglishName()const
+       RigidBody::getName()const
        {
                return text::trim(text::to_WideChar(CP_OEMCP, 
-                                       std::string(english_name, english_name+20)));
+                                       std::string(name, name+20)));
        }
 
+void RigidBody::setName(const char *src)
+{
+       strncpy(name, src, 20);
+}
+
+// Constraint
 std::wstring 
-       RigidBody::getName()const
+       Constraint::getName()const
        {
                return text::trim(text::to_WideChar(CP_OEMCP, 
                                        std::string(name, name+20)));
        }
 
+void Constraint::setName(const char *src)
+{
+       strncpy(name, src, 20);
+}
+
+// ToonTexture
 std::wstring 
-       Constraint::getName()const
+       ToonTexture::getName()const
        {
                return text::trim(text::to_WideChar(CP_OEMCP, 
-                                       std::string(name, name+20)));
+                                       std::string(name, name+100)));
        }
 
+void ToonTexture::setName(const char *src)
+{
+       strncpy(name, src, 100);
+}
+
+
 // 38bytes
 template<class READER>
        void
@@ -225,7 +350,7 @@ public:
                if(!parseFaceList()){
                        return false;
                }
-               if(!parseBoneNameList()){
+               if(!parseBoneGroupList()){
                        return false;
                }
                if(!parseBoneList()){
@@ -306,16 +431,18 @@ private:
        bool parseToonTextures()
        {
                for(size_t i=0; i<10; ++i){
-                       reader_.getString(100);
+                       text::copyStringAndFillZero(
+                                       io_.toon_textures[i].name,
+                                       reader_.getString(100));
                }
                return true;
        }
 
        bool parseEnglishBoneList()
        {
-               for(size_t i=0; i<io_.bone_display_name_list.size(); ++i){
+               for(size_t i=0; i<io_.bone_group_list.size(); ++i){
                        text::copyStringAndFillZero(
-                                       io_.bone_display_name_list[i].english_name, 
+                                       io_.bone_group_list[i].english_name, 
                                        reader_.getString(50));
                }
                return true;
@@ -360,13 +487,13 @@ private:
                return true;
        }
 
-       bool parseBoneNameList()
+       bool parseBoneGroupList()
        {
                unsigned int count=reader_.getUchar();
                for(unsigned int i=0; i<count; ++i){
-                       io_.bone_display_name_list.push_back(BoneDisplayName());
+                       io_.bone_group_list.push_back(BoneGroup());
                        text::copyStringAndFillZero(
-                                       io_.bone_display_name_list.back().name,
+                                       io_.bone_group_list.back().name,
                                        reader_.getString(50));
                }
                return true;
@@ -508,7 +635,10 @@ bool IO::read(binary::IReader &input)
                        bone.parent=&bones[bone.parent_index];
                        bone.parent->children.push_back(&bone);
                }
-               if(bone.tail_index!=0){
+               if(bone.tail_index==0){
+                       bone.tail=Vector3(0, 0, 0);
+               }
+               else{
                        bone.tail=bones[bone.tail_index].pos;
                }
        }
@@ -652,12 +782,12 @@ bool IO::write(binary::IWriter &w)
                w.writeArray<WORD>(&face_list[0], face_list.size());
        }
 
-       // bone naem list
+       // bone name list
        //std::cout << "bone name list" << std::endl;
-       w.writeValue<BYTE>(bone_display_name_list.size());
-       for(size_t i=0; i<bone_display_name_list.size(); ++i){
+       w.writeValue<BYTE>(bone_group_list.size());
+       for(size_t i=0; i<bone_group_list.size(); ++i){
                // 50bytes
-               w.writeArray<char>(bone_display_name_list[i].name, 50);
+               w.writeArray<char>(bone_group_list[i].name, 50);
        }
 
        // bone list
@@ -683,12 +813,13 @@ bool IO::write(binary::IWriter &w)
                w.writeArray<char>(bones[i].english_name, 20);
        }
 
+       // skip base
        for(size_t i=1; i<morph_list.size(); ++i){
                w.writeArray<char>(morph_list[i].english_name, 20);
        }
 
-       for(size_t i=0; i<bone_display_name_list.size(); ++i){
-               w.writeArray<char>(bone_display_name_list[i].english_name, 50);
+       for(size_t i=0; i<bone_group_list.size(); ++i){
+               w.writeArray<char>(bone_group_list[i].english_name, 50);
        }
 
        ////////////////////////////////////////////////////////////
@@ -764,63 +895,6 @@ bool IO::write(binary::IWriter &w)
        return true;
 }
 
-bool IO::write(const char *path)
-{
-       binary::FileWriter w(path);
-       return write(w);
-}
-
-bool IO::write(const wchar_t *path)
-{
-       binary::FileWriter w(path);
-       return write(w);
-}
-
-const Vector2* IO::getUV(int index)const
-{
-       return &vertices[index].uv;
-}
-
-void Bone::setName(const char *src)
-{
-       strncpy(name, src, 20);
-}
-
-void BoneDisplayName::setName(const char *src)
-{
-       strncpy(name, src, 20);
-}
-
-void BoneDisplayName::setEnglishName(const char *src)
-{
-       strncpy(english_name, src, 20);
-}
-
-void Morph::setName(const char *src)
-{
-       strncpy(name, src, 20);
-}
-
-void Morph::setEnglishName(const char *src)
-{
-       strncpy(english_name, src, 20);
-}
-
-void RigidBody::setName(const char *src)
-{
-       strncpy(name, src, 20);
-}
-
-void Constraint::setName(const char *src)
-{
-       strncpy(name, src, 20);
-}
-
-void Material::setTexture(const char *src)
-{
-       strncpy(texture, src, 20);
-}
-
 
 } // namespace
 } // namespace