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 text::copyStringAndFillZero(
270 io_.morph_list[i].english_name, reader_.getString(20));
275 bool parseEnglishBone()
277 for(size_t i=0; i<io_.bones.size(); ++i){
278 text::copyStringAndFillZero(
279 io_.bones[i].english_name, reader_.getString(20));
284 bool parseEnglishName()
286 text::copyStringAndFillZero(io_.english_model_name,
287 reader_.getString(20));
288 text::copyStringAndFillZero(io_.english_comment,
289 reader_.getString(256));
295 unsigned int count=reader_.getUint();
296 for(unsigned int i=0; i<count; ++i){
297 unsigned short bone=reader_.getUshort();
298 unsigned char disp=reader_.getUchar();
299 io_.bone_list.push_back(std::make_pair(bone, disp));
304 bool parseBoneNameList()
306 unsigned int count=reader_.getUchar();
307 for(unsigned int i=0; i<count; ++i){
308 io_.bone_name_list.push_back(reader_.getString(50));
315 unsigned int count=reader_.getUchar();
316 for(unsigned int i=0; i<count; ++i){
324 unsigned int count=reader_.getUshort();
325 for(unsigned int i=0; i<count; ++i){
326 io_.morph_list.push_back(Morph());
327 read(reader_, io_.morph_list.back());
334 unsigned int count=reader_.getUshort();
335 for(unsigned int i=0; i<count; ++i){
336 io_.ik_list.push_back(IK());
337 read(reader_, io_.ik_list.back());
344 unsigned int count=reader_.getUshort();
345 for(unsigned int i=0; i<count; ++i){
346 io_.bones.push_back(Bone());
347 read(reader_, io_.bones.back());
352 bool parseMaterials()
354 unsigned int count=reader_.getUint();
355 for(unsigned int i=0; i<count; ++i){
356 io_.materials.push_back(new Material());
357 read(reader_, *io_.materials.back());
364 unsigned int count=reader_.getUint();
365 for(unsigned int i=0; i<count; ++i){
366 io_.indices.push_back(reader_.getUshort());
373 unsigned int count=reader_.getUint();
374 for(unsigned int i=0; i<count; ++i){
375 io_.vertices.push_back(Vertex());
376 read(reader_, io_.vertices.back());
383 if(reader_.getString(3)!="Pmd"){
384 //std::cout << "invalid pmd" << std::endl;
387 reader_.get(io_.version);
388 if(io_.version!=1.0){
389 std::cout << "invalid vesion: " << io_.version <<std::endl;
392 text::copyStringAndFillZero(io_.name, reader_.getString(20));
393 text::copyStringAndFillZero(io_.comment, reader_.getString(256));
400 ///////////////////////////////////////////////////////////////////////////////
402 ///////////////////////////////////////////////////////////////////////////////
409 for(size_t i=0; i<materials.size(); ++i){
415 bool IO::read(binary::IReader &input)
417 Impl impl(*this, input);
422 ////////////////////////////////////////////////////////////
424 ////////////////////////////////////////////////////////////
425 if(!morph_list.empty()){
427 assert(morph_list[0].type==MORPH_BASE);
429 Morph &base=morph_list[0];
430 for(size_t i=0; i<base.vertex_count; ++i){
431 assert(vertices[base.indices[i]].pos==base.pos_list[i]);
434 for(size_t i=1; i<morph_list.size(); ++i){
435 Morph &m=morph_list[i];
436 assert(m.type!=MORPH_BASE);
439 ////////////////////////////////////////////////////////////
441 ////////////////////////////////////////////////////////////
442 for(size_t i=0; i<bones.size(); ++i){
444 if(bone.parent_index!=0xFFFF){
445 bone.parent=&bones[bone.parent_index];
446 bone.parent->children.push_back(&bone);
448 if(bone.tail_index!=0xFFFF){
449 bone.tail=bones[bone.tail_index].pos;
456 bool IO::read(const char *path)
458 //std::locale::global(std::locale("japanese"));
459 std::vector<char> all;
460 binary::readAll(path, all);
464 binary::MemoryReader reader(&all[0], all.size());
468 bool IO::write(std::ostream &os)