| 6 | |
| 7 | |
| 8 | bool PartioReaderWriter::readParticles(const std::string &fileName, const Vector3r &translation, const Matrix3r &rotation, const Real scale, |
| 9 | std::vector<Vector3r> &positions, std::vector<Vector3r> &velocities) |
| 10 | { |
| 11 | if (!FileSystem::fileExists(fileName)) |
| 12 | return false; |
| 13 | |
| 14 | Partio::ParticlesDataMutable* data = Partio::read(fileName.c_str()); |
| 15 | if (!data) |
| 16 | return false; |
| 17 | |
| 18 | unsigned int posIndex = 0xffffffff; |
| 19 | unsigned int velIndex = 0xffffffff; |
| 20 | |
| 21 | for (int i = 0; i < data->numAttributes(); i++) |
| 22 | { |
| 23 | Partio::ParticleAttribute attr; |
| 24 | data->attributeInfo(i, attr); |
| 25 | if (attr.name == "position") |
| 26 | posIndex = i; |
| 27 | else if (attr.name == "velocity") |
| 28 | velIndex = i; |
| 29 | } |
| 30 | |
| 31 | Partio::ParticleAttribute attr; |
| 32 | |
| 33 | if (posIndex != 0xffffffff) |
| 34 | { |
| 35 | unsigned int fSize = (unsigned int) positions.size(); |
| 36 | positions.resize(fSize + data->numParticles()); |
| 37 | data->attributeInfo(posIndex, attr); |
| 38 | for (int i = 0; i < data->numParticles(); i++) |
| 39 | { |
| 40 | const float *pos = data->data<float>(attr, i); |
| 41 | Vector3r x(pos[0], pos[1], pos[2]); |
| 42 | x = rotation * (x*scale) + translation; |
| 43 | positions[i + fSize] = x; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | if (velIndex != 0xffffffff) |
| 48 | { |
| 49 | unsigned int fSize = (unsigned int) velocities.size(); |
| 50 | velocities.resize(fSize + data->numParticles()); |
| 51 | data->attributeInfo(velIndex, attr); |
| 52 | for (int i = 0; i < data->numParticles(); i++) |
| 53 | { |
| 54 | const float *vel = data->data<float>(attr, i); |
| 55 | Vector3r v(vel[0], vel[1], vel[2]); |
| 56 | velocities[i + fSize] = v; |
| 57 | } |
| 58 | } |
| 59 | else |
| 60 | { |
| 61 | unsigned int fSize = (unsigned int) velocities.size(); |
| 62 | velocities.resize(fSize + data->numParticles()); |
| 63 | for (int i = 0; i < data->numParticles(); i++) |
| 64 | velocities[i + fSize].setZero(); |
| 65 | } |