OSDN Git Service

refactoring.
[meshio/meshio.git] / src / pmd.cpp
index 1f1eed5..9a88bd3 100644 (file)
@@ -293,7 +293,9 @@ private:
        bool parseEnglishBoneList()
        {
                for(size_t i=0; i<io_.bone_display_name_list.size(); ++i){
-                       std::string english=reader_.getString(50);
+                       text::copyStringAndFillZero(
+                                       io_.bone_display_name_list[i].english_name, 
+                                       reader_.getString(50));
                }
                return true;
        }
@@ -319,7 +321,7 @@ private:
 
        bool parseEnglishName()
        {
-               text::copyStringAndFillZero(io_.english_model_name, 
+               text::copyStringAndFillZero(io_.english_name, 
                                reader_.getString(20));
                text::copyStringAndFillZero(io_.english_comment, 
                                reader_.getString(256));
@@ -341,7 +343,10 @@ private:
        {
                unsigned int count=reader_.getUchar();
                for(unsigned int i=0; i<count; ++i){
-                       io_.bone_display_name_list.push_back(reader_.getString(50));
+                       io_.bone_display_name_list.push_back(BoneDisplayName());
+                       text::copyStringAndFillZero(
+                                       io_.bone_display_name_list.back().name,
+                                       reader_.getString(50));
                }
                return true;
        }
@@ -477,11 +482,12 @@ bool IO::read(binary::IReader &input)
        ////////////////////////////////////////////////////////////
        for(size_t i=0; i<bones.size(); ++i){
                Bone &bone=bones[i];
+               bone.index=i;
                if(bone.parent_index!=0xFFFF){
                        bone.parent=&bones[bone.parent_index];
                        bone.parent->children.push_back(&bone);
                }
-               if(bone.tail_index!=0xFFFF){
+               if(bone.tail_index!=0){
                        bone.tail=bones[bone.tail_index].pos;
                }
        }
@@ -630,15 +636,7 @@ bool IO::write(binary::IWriter &w)
        w.writeValue<BYTE>(bone_display_name_list.size());
        for(size_t i=0; i<bone_display_name_list.size(); ++i){
                // 50bytes
-               char buf[]={
-                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-               };
-               sprintf(buf, "%s\r", bone_display_name_list[i].c_str());
-               w.writeArray<char>(buf, 50);
+               w.writeArray<char>(bone_display_name_list[i].name, 50);
        }
 
        // bone list
@@ -649,7 +647,35 @@ bool IO::write(binary::IWriter &w)
                w.writeValue<BYTE>(bone_display_list[i].second);
        }
 
+       ////////////////////////////////////////////////////////////
        // extend
+       ////////////////////////////////////////////////////////////
+       w.writeValue<char>(0x01);
+
+       ////////////////////////////////////////////////////////////
+       // english names
+       ////////////////////////////////////////////////////////////
+       w.writeArray<char>(english_name, 20);
+       w.writeArray<char>(english_comment, 256);
+
+       for(size_t i=0; i<bones.size(); ++i){
+               w.writeArray<char>(bones[i].english_name, 20);
+       }
+
+       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);
+       }
+
+       ////////////////////////////////////////////////////////////
+       // toon textures
+       ////////////////////////////////////////////////////////////
+       for(size_t i=0; i<10; ++i){
+               w.writeArray<char>(toon_textures[i].name, 100);
+       }
 
        return true;
 }