10 read(READER &reader, Vertex &v)
12 unsigned int pos=reader.getPos();
18 reader.get(v.weight0);
19 reader.get(v.edge_flag);
20 assert(reader.getPos()-pos==38);
25 template<class READER>
27 read(READER &reader, Material &m)
29 unsigned int pos=reader.getPos();
30 reader.get(m.diffuse);
31 reader.get(m.shinness);
32 reader.get(m.specular);
33 reader.get(m.ambient);
34 reader.get(m.toon_index);
36 reader.get(m.vertex_count);
37 text::copyStringAndFillZero(m.texture, reader.getString(20));
38 assert(reader.getPos()-pos==70);
42 template<class READER>
44 read(READER &reader, Bone &b)
46 unsigned int pos=reader.getPos();
47 text::copyStringAndFillZero(b.name, reader.getString(20));
48 reader.get(b.parent_index);
49 reader.get(b.tail_index);
50 b.type=static_cast<BONE_TYPE>(reader.getUchar());
51 reader.get(b.ik_index);
53 assert(reader.getPos()-pos==39);
56 // 11+2xIK_COUNT bytes
57 template<class READER>
59 read(READER &reader, IK &ik)
63 reader.get(ik.target);
64 reader.get(ik.length);
65 reader.get(ik.iterations);
66 reader.get(ik.weight);
68 for(unsigned short j=0; j<ik.length; ++j){
69 ik.children.push_back(reader.getUshort());
73 // 25+12xMORPH_COUNT bytes
74 template<class READER>
76 read(READER &reader, Morph &m)
79 text::copyStringAndFillZero(m.name, reader.getString(20));
80 reader.get(m.vertex_count);
81 m.type=static_cast<MORPH_TYPE>(reader.getUchar());
82 // 12 x vertex_count bytes
83 for(unsigned short i=0; i<m.vertex_count; ++i){
84 m.indices.push_back(reader.getUint());
85 m.pos_list.push_back(Vector3());
86 reader.get(m.pos_list.back());
91 template<class READER>
93 read(READER &reader, RigidBody &r)
95 unsigned int pos=reader.getPos();
96 text::copyStringAndFillZero(r.name, reader.getString(20));
97 reader.get(r.boneIndex);
100 r.shapeType=static_cast<SHAPE_TYPE>(reader.getUchar());
104 reader.get(r.position);
105 reader.get(r.rotation);
106 reader.get(r.weight);
107 reader.get(r.linearDamping);
108 reader.get(r.angularDamping);
109 reader.get(r.restitution);
110 reader.get<float>(r.friction);
111 r.processType=static_cast<PROCESS_TYPE>(reader.getUchar());
112 assert(reader.getPos()-pos==83);
116 template<class READER>
118 read(READER &reader, Constraint &c)
120 unsigned int base_pos=reader.getPos();
121 text::copyStringAndFillZero(c.name, reader.getString(20));
122 reader.get(c.rigidA);
123 reader.get(c.rigidB);
126 reader.get(c.constraintPosMin);
127 reader.get(c.constraintPosMax);
128 reader.get(c.constraintRotMin);
129 reader.get(c.constraintRotMax);
130 reader.get(c.springPos);
131 reader.get(c.springRot);
132 assert(reader.getPos()-base_pos==124);
138 binary::IReader &reader_;
141 Impl(IO &io, binary::IReader &reader)
142 : io_(io), reader_(reader)
150 if(!parseVertices()){
156 if(!parseMaterials()){
168 if(!parseFaceList()){
171 if(!parseBoneNameList()){
174 if(!parseBoneList()){
181 ////////////////////////////////////////////////////////////
183 ////////////////////////////////////////////////////////////
185 ////////////////////////////////////////////////////////////
186 if(reader_.getChar()){
187 if(!parseEnglishName()){
190 if(!parseEnglishBone()){
193 if(!parseEnglishMorph()){
196 if(!parseEnglishBoneList()){
205 ////////////////////////////////////////////////////////////
206 if(!parseToonTextures()){
214 ////////////////////////////////////////////////////////////
218 if(!parseConstraint()){
223 assert(reader_.isEnd());
229 bool parseConstraint()
231 unsigned int count=reader_.getUint();
232 for(unsigned int i=0; i<count; ++i){
233 io_.constraints.push_back(Constraint());
234 read(reader_, io_.constraints.back());
241 unsigned int count=reader_.getUint();
242 for(unsigned int i=0; i<count; ++i){
243 io_.rigidbodies.push_back(RigidBody());
244 read(reader_, io_.rigidbodies.back());
249 bool parseToonTextures()
251 for(size_t i=0; i<10; ++i){
252 reader_.getString(100);
257 bool parseEnglishBoneList()
259 for(size_t i=0; i<io_.bone_name_list.size(); ++i){
260 std::string english=reader_.getString(50);
265 bool parseEnglishMorph()
267 int count=io_.morph_list.size()-1;
268 for(int i=0; i<count; ++i){
269 std::string english_morph_name=reader_.getString(20);
274 bool parseEnglishBone()
276 for(size_t i=0; i<io_.bones.size(); ++i){
277 std::string english_bone_name=reader_.getString(20);
282 bool parseEnglishName()
284 std::string english_mdoel_name=reader_.getString(20);
285 std::string english_comment=reader_.getString(256);
291 unsigned int count=reader_.getUint();
292 for(unsigned int i=0; i<count; ++i){
293 unsigned short bone=reader_.getUshort();
294 unsigned char disp=reader_.getUchar();
295 io_.bone_list.push_back(std::make_pair(bone, disp));
300 bool parseBoneNameList()
302 unsigned int count=reader_.getUchar();
303 for(unsigned int i=0; i<count; ++i){
304 io_.bone_name_list.push_back(reader_.getString(50));
311 unsigned int count=reader_.getUchar();
312 for(unsigned int i=0; i<count; ++i){
320 unsigned int count=reader_.getUshort();
321 for(unsigned int i=0; i<count; ++i){
322 io_.morph_list.push_back(Morph());
323 read(reader_, io_.morph_list.back());
330 unsigned int count=reader_.getUshort();
331 for(unsigned int i=0; i<count; ++i){
332 io_.ik_list.push_back(IK());
333 read(reader_, io_.ik_list.back());
340 unsigned int count=reader_.getUshort();
341 for(unsigned int i=0; i<count; ++i){
342 io_.bones.push_back(Bone());
343 read(reader_, io_.bones.back());
348 bool parseMaterials()
350 unsigned int count=reader_.getUint();
351 for(unsigned int i=0; i<count; ++i){
352 io_.materials.push_back(Material());
353 read(reader_, io_.materials.back());
360 unsigned int count=reader_.getUint();
361 for(unsigned int i=0; i<count; ++i){
362 io_.indices.push_back(reader_.getUshort());
369 unsigned int count=reader_.getUint();
370 for(unsigned int i=0; i<count; ++i){
371 io_.vertices.push_back(Vertex());
372 read(reader_, io_.vertices.back());
379 if(reader_.getString(3)!="Pmd"){
380 //std::cout << "invalid pmd" << std::endl;
383 reader_.get(io_.version);
384 if(io_.version!=1.0){
385 std::cout << "invalid vesion: " << io_.version <<std::endl;
388 text::copyStringAndFillZero(io_.name, reader_.getString(20));
389 text::copyStringAndFillZero(io_.comment, reader_.getString(256));
396 ///////////////////////////////////////////////////////////////////////////////
398 ///////////////////////////////////////////////////////////////////////////////
403 bool IO::read(binary::IReader &input)
405 Impl impl(*this, input);
410 ////////////////////////////////////////////////////////////
412 ////////////////////////////////////////////////////////////
413 if(!morph_list.empty()){
415 assert(morph_list[0].type==MORPH_BASE);
417 Morph &base=morph_list[0];
418 for(size_t i=0; i<base.vertex_count; ++i){
419 assert(vertices[base.indices[i]].pos==base.pos_list[i]);
422 for(size_t i=1; i<morph_list.size(); ++i){
423 Morph &m=morph_list[i];
424 assert(m.type!=MORPH_BASE);
431 bool IO::read(const char *path)
433 //std::locale::global(std::locale("japanese"));
434 std::vector<char> all;
435 binary::readAll(path, all);
439 binary::MemoryReader reader(&all[0], all.size());
443 bool IO::write(std::ostream &os)