10 struct SortKeyFrameList
13 void operator()(typename MAP::value_type &channel)
15 channel.second->sort();
19 template<class READER>
21 readBoneMap(READER &reader, IO &io)
23 std::string name=reader.getString(15, true);
24 unsigned int frame=reader.getUint();
25 IO::BoneMap::iterator found=io.boneMap.find(name);
26 if(found==io.boneMap.end()){
28 found=io.boneMap.insert(
30 new KeyFrameList<KeyFrame<BoneKey> >())).first;
31 io.boneKeys.push_back(name);
33 BoneKey &key=found->second->push(frame).key;
37 reader.get(key.interpolationX);
38 reader.get(key.interpolationY);
39 reader.get(key.interpolationZ);
40 reader.get(key.interpolationRot);
43 template<class READER>
45 readMorphMap(READER &reader, IO &io)
47 std::string name=reader.getString(15, true);
48 unsigned int frame=reader.getUint();
49 IO::MorphMap::iterator found=io.morphMap.find(name);
50 if(found==io.morphMap.end()){
52 found=io.morphMap.insert(
54 new KeyFrameList<KeyFrame<MorphKey> >())).first;
55 io.morphKeys.push_back(name);
57 MorphKey &key=found->second->push(frame).key;
59 reader.get(key.weight);
65 binary::IReader &reader_;
68 Implementation(IO &io, binary::IReader &reader)
69 : io_(io), reader_(reader)
75 std::string line=reader_.getString(30, true);
76 if(line=="Vocaloid Motion Data file"){
78 text::copyStringAndFillZero(io_.name, reader_.getString(10));
81 else if(line=="Vocaloid Motion Data 0002"){
83 text::copyStringAndFillZero(io_.name, reader_.getString(20));
87 //std::cout << "unknown header:" << line << std::endl;
109 std::for_each(io_.boneMap.begin(), io_.boneMap.end(),
110 SortKeyFrameList<IO::BoneMap>());
111 std::for_each(io_.morphMap.begin(), io_.morphMap.end(),
112 SortKeyFrameList<IO::MorphMap>());
118 unsigned int count=reader_.getUint();
119 for(unsigned int i=0; i<count; ++i){
120 readMorphMap(reader_, io_);
127 unsigned int count=reader_.getUint();
128 for(unsigned int i=0; i<count; ++i){
129 readBoneMap(reader_, io_);
146 ///////////////////////////////////////////////////////////////////////////////
148 ///////////////////////////////////////////////////////////////////////////////
155 for(BoneMap::iterator it=boneMap.begin(); it!=boneMap.end(); ++it){
160 for(MorphMap::iterator it=morphMap.begin(); it!=morphMap.end(); ++it){
167 bool IO::read(binary::IReader &reader)
169 return Implementation(*this, reader).parse();
172 bool IO::read(const wchar_t *path)
174 std::vector<char> all;
175 binary::readAll(path, all);
179 binary::MemoryReader reader(&all[0], all.size());
183 bool IO::read(const char *path)
185 std::vector<char> all;
186 binary::readAll(path, all);
190 binary::MemoryReader reader(&all[0], all.size());
194 bool IO::write(std::ostream &os)
199 BoneKeyFrameList* IO::getBoneKeyFrameList(const std::string &name)
201 return boneMap[name];
204 MorphKeyFrameList* IO::getMorphKeyFrameList(const std::string &name)
206 return morphMap[name];
210 } // namespace meshio