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)
24 trim(cp932_to_unicode(reader.getString(15, true)));
25 unsigned int frame=reader.getUint();
26 IO::BoneMap::iterator found=io.boneMap.find(name);
27 if(found==io.boneMap.end()){
29 found=io.boneMap.insert(
31 new KeyFrameList<KeyFrame<BoneKey> >())).first;
32 io.boneKeys.push_back(name);
34 BoneKey &key=found->second->push(frame).key;
38 reader.get(key.interpolationX);
39 reader.get(key.interpolationY);
40 reader.get(key.interpolationZ);
41 reader.get(key.interpolationRot);
44 template<class READER>
46 readMorphMap(READER &reader, IO &io)
49 trim(cp932_to_unicode(reader.getString(15, true)));
50 unsigned int frame=reader.getUint();
51 IO::MorphMap::iterator found=io.morphMap.find(name);
52 if(found==io.morphMap.end()){
54 found=io.morphMap.insert(
56 new KeyFrameList<KeyFrame<MorphKey> >())).first;
57 io.morphKeys.push_back(name);
59 MorphKey &key=found->second->push(frame).key;
61 reader.get(key.weight);
67 binary::IReader &reader_;
70 Implementation(IO &io, binary::IReader &reader)
71 : io_(io), reader_(reader)
77 std::string line=reader_.getString(30, true);
78 if(line=="Vocaloid Motion Data file"){
80 reader_.get(io_.name);
83 else if(line=="Vocaloid Motion Data 0002"){
85 reader_.get(io_.name);
89 //std::cout << "unknown header:" << line << std::endl;
111 std::for_each(io_.boneMap.begin(), io_.boneMap.end(),
112 SortKeyFrameList<IO::BoneMap>());
113 std::for_each(io_.morphMap.begin(), io_.morphMap.end(),
114 SortKeyFrameList<IO::MorphMap>());
120 unsigned int count=reader_.getUint();
121 for(unsigned int i=0; i<count; ++i){
122 readMorphMap(reader_, io_);
129 unsigned int count=reader_.getUint();
130 for(unsigned int i=0; i<count; ++i){
131 readBoneMap(reader_, io_);
148 ///////////////////////////////////////////////////////////////////////////////
150 ///////////////////////////////////////////////////////////////////////////////
157 for(BoneMap::iterator it=boneMap.begin(); it!=boneMap.end(); ++it){
162 for(MorphMap::iterator it=morphMap.begin(); it!=morphMap.end(); ++it){
169 bool IO::read(binary::IReader &reader)
171 return Implementation(*this, reader).parse();
174 bool IO::read(const char *path)
176 std::vector<char> all;
177 binary::readAll(path, all);
181 binary::MemoryReader reader(&all[0], all.size());
185 bool IO::write(std::ostream &os)
192 } // namespace meshio