OSDN Git Service

fix mqo_import smoothing, mirroring.
[meshio/meshio.git] / src / vmd.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 1d494ba..322344d
@@ -12,23 +12,26 @@ struct SortKeyFrameList
        typedef T MAP;
        void operator()(typename MAP::value_type &channel)
        {
-               channel.second.sort();
+               channel.second->sort();
        }
 };
 
 template<class READER>
        void
-       read(READER &reader, IO::BoneMap &channels)
+       readBoneMap(READER &reader, IO &io)
        {
-               std::string name=reader.getString(15);
+               std::wstring name=
+                       text::trim(text::to_WideChar(CP_OEMCP, reader.getString(15, true)));
                unsigned int frame=reader.getUint();
-               IO::BoneMap::iterator found=channels.find(name);
-               if(found==channels.end()){
+               IO::BoneMap::iterator found=io.boneMap.find(name);
+               if(found==io.boneMap.end()){
                        // not found
-                       found=channels.insert(
-                                               std::make_pair(name, KeyFrameList<BoneKey>())).first;
+                       found=io.boneMap.insert(
+                                               std::make_pair(name, 
+                            new KeyFrameList<KeyFrame<BoneKey> >())).first;
+                       io.boneKeys.push_back(name);
                }
-               BoneKey &key=found->second.push(frame).key;
+               BoneKey &key=found->second->push(frame).key;
 
                reader.get(key.pos);
                reader.get(key.q);
@@ -40,17 +43,20 @@ template<class READER>
 
 template<class READER>
        void
-       read(READER &reader, IO::MorphMap &channels)
+       readMorphMap(READER &reader, IO &io)
        {
-               std::string name=reader.getString(15);
+               std::wstring name=
+                       text::trim(text::to_WideChar(CP_OEMCP, reader.getString(15, true)));
                unsigned int frame=reader.getUint();
-               IO::MorphMap::iterator found=channels.find(name);
-               if(found==channels.end()){
+               IO::MorphMap::iterator found=io.morphMap.find(name);
+               if(found==io.morphMap.end()){
                        // not found
-                       found=channels.insert(
-                                       std::make_pair(name, KeyFrameList<MorphKey>())).first;
+                       found=io.morphMap.insert(
+                                       std::make_pair(name, 
+                        new KeyFrameList<KeyFrame<MorphKey> >())).first;
+                       io.morphKeys.push_back(name);
                }
-               MorphKey &key=found->second.push(frame).key;
+               MorphKey &key=found->second->push(frame).key;
 
                reader.get(key.weight);
        }
@@ -113,7 +119,7 @@ private:
        {
                unsigned int count=reader_.getUint();
                for(unsigned int i=0; i<count; ++i){
-                       read(reader_, io_.morphMap);
+                       readMorphMap(reader_, io_);
                }
                return true;
        }
@@ -122,7 +128,7 @@ private:
        {
                unsigned int count=reader_.getUint();
                for(unsigned int i=0; i<count; ++i){
-                       read(reader_, io_.boneMap);
+                       readBoneMap(reader_, io_);
                }
                return true;
        }
@@ -146,15 +152,61 @@ IO::IO()
 {
 }
 
+IO::~IO()
+{
+       for(BoneMap::iterator it=boneMap.begin(); it!=boneMap.end(); ++it){
+               delete it->second;
+       }
+       boneMap.clear();
+
+       for(MorphMap::iterator it=morphMap.begin(); it!=morphMap.end(); ++it){
+               delete it->second;
+       }
+       morphMap.clear();
+
+}
+
 bool IO::read(binary::IReader &reader)
 {
        return Implementation(*this, reader).parse();
 }
 
+bool IO::read(const wchar_t *path)
+{
+       std::vector<char> all;
+       binary::readAll(path, all);
+       if(all.empty()){
+               return false;
+       }
+       binary::MemoryReader reader(&all[0], all.size());
+       return read(reader);
+}
+
+bool IO::read(const char *path)
+{
+       std::vector<char> all;
+       binary::readAll(path, all);
+       if(all.empty()){
+               return false;
+       }
+       binary::MemoryReader reader(&all[0], all.size());
+       return read(reader);
+}
+
 bool IO::write(std::ostream &os)
 {
        return false;
 }
 
+BoneKeyFrameList* IO::getBoneKeyFrameList(const std::wstring &name)
+{
+       return boneMap[name];
+}
+
+MorphKeyFrameList* IO::getMorphKeyFrameList(const std::wstring &name)
+{
+       return morphMap[name];
+}
+
 } // namespace vmd
 } // namespace meshio