/* Bullet Continuous Collision Detection and Physics Library Maya Plugin Copyright (c) 2008 Walt Disney Studios This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Written by: Nicola Candussi */ #include "pdbIO.h" #include #include #include #define PDB_MAGIC 670 //headers used for reading and writing struct pdb_channel_data_t { int type; unsigned int datasize; unsigned int blocksize; int num_blocks; //void **block; int block; }; struct pdb_channel_t { //char *name; int name; int type; unsigned int size; unsigned int active_start; unsigned int active_end; char hide; char disconnect; //pdb_channel_data_t *data; int data; //pdb_channel_t *link; int link; //pdb_channel_t *next; int next; }; struct pdb_channel_header_t { char magic; unsigned short swap; char encoding; char type; }; /* struct pdb_data_t { int numAttributes; int numParticles; float time; // short *types; int types; // char **names; int names; // void **data; int data; }; */ struct pdb_header_t { int magic; unsigned short swap; float version; float time; unsigned int data_size; unsigned int num_data; char padding[32]; //pdb_channel_t **data; int data; }; /* struct pdb_channel_data_t { int type; unsigned datasize; unsigned long blocksize; int num_blocks; void **block; }; struct pdb_channel_t { char *name; int type; unsigned long size; unsigned long active_start; unsigned long active_end; char hide; char disconnect; pdb_channel_data_t *data; pdb_channel_t *link; pdb_channel_t *next; }; struct pdb_channel_header_t { char magic; unsigned short swap; char encoding; char type; }; struct pdb_data_t { int numAttributes; int numParticles; float time; short *types; char **names; void **data; }; struct pdb_header_t { int magic; unsigned short swap; float version; float time; unsigned data_size; unsigned num_data; char padding[32]; pdb_channel_t **data; }; */ void read_string( std::istream &in, std::string &str ) { int c; while( (c = in.get()) ) { if ( in.eof()) { str.clear(); return; } str.push_back(c); } } void write_string( std::ostream &out, std::string &str ) { for(size_t i = 0; i < str.size(); ++i) { out.put(str[i]); } out.put(0); } bool pdb_io_t::read(std::istream &in) { pdb_header_t header; pdb_channel_header_t channel_header; pdb_channel_t channel; pdb_channel_data_t channel_data; // read the header in.read( (char*)&header, sizeof(pdb_header_t) ); m_time = header.time; m_num_particles = header.data_size; m_attributes.clear(); m_attributes.resize( header.num_data ); for (unsigned int i=0; i