OSDN Git Service

separate vertex with uv or normal.
[meshio/meshio.git] / src / pmd.cpp
index 5b5e0c2..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,6 +118,17 @@ 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 
        BoneGroup::getName()const
        {
@@ -40,20 +136,17 @@ std::wstring
                                        std::string(name, name+50)));
        }
 
-std::wstring 
-       IO::getName()const
-       {
-               return text::trim(text::to_WideChar(CP_OEMCP, 
-                                       std::string(name, name+20)));
-       }
+void BoneGroup::setName(const char *src)
+{
+       strncpy(name, src, 50);
+}
 
-std::wstring 
-       IO::getEnglishName()const
-       {
-               return text::trim(text::to_WideChar(CP_OEMCP, 
-                                       std::string(english_name, english_name+20)));
-       }
+void BoneGroup::setEnglishName(const char *src)
+{
+       strncpy(english_name, src, 50);
+}
 
+// RigidBody
 std::wstring 
        RigidBody::getName()const
        {
@@ -61,6 +154,12 @@ std::wstring
                                        std::string(name, name+20)));
        }
 
+void RigidBody::setName(const char *src)
+{
+       strncpy(name, src, 20);
+}
+
+// Constraint
 std::wstring 
        Constraint::getName()const
        {
@@ -68,6 +167,12 @@ std::wstring
                                        std::string(name, name+20)));
        }
 
+void Constraint::setName(const char *src)
+{
+       strncpy(name, src, 20);
+}
+
+// ToonTexture
 std::wstring 
        ToonTexture::getName()const
        {
@@ -75,6 +180,12 @@ std::wstring
                                        std::string(name, name+100)));
        }
 
+void ToonTexture::setName(const char *src)
+{
+       strncpy(name, src, 100);
+}
+
+
 // 38bytes
 template<class READER>
        void
@@ -524,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;
                }
        }
@@ -668,7 +782,7 @@ 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_group_list.size());
        for(size_t i=0; i<bone_group_list.size(); ++i){
@@ -699,6 +813,7 @@ 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);
        }
@@ -780,73 +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 Bone::setEnglishName(const char *src)
-{
-       strncpy(english_name, src, 20);
-}
-
-void BoneGroup::setName(const char *src)
-{
-       strncpy(name, src, 20);
-}
-
-void BoneGroup::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);
-}
-
-void ToonTexture::setName(const char *src)
-{
-       strncpy(name, src, 100);
-}
-
 
 } // namespace
 } // namespace