Read particle data from a partio file. */
| 1599 | /** Read particle data from a partio file. |
| 1600 | */ |
| 1601 | bool readParticles(const std::string &fileName, std::vector<Vector3r> &positions, std::vector<Vector3r> &velocities, std::vector<Vector3r> &angularVelocities) |
| 1602 | { |
| 1603 | if (!FileSystem::fileExists(fileName)) |
| 1604 | return false; |
| 1605 | |
| 1606 | Partio::ParticlesDataMutable* data = Partio::read(fileName.c_str()); |
| 1607 | if (!data) |
| 1608 | return false; |
| 1609 | |
| 1610 | unsigned int posIndex = 0xffffffff; |
| 1611 | unsigned int velIndex = 0xffffffff; |
| 1612 | unsigned int omegaIndex = 0xffffffff; |
| 1613 | |
| 1614 | for (int i = 0; i < data->numAttributes(); i++) |
| 1615 | { |
| 1616 | Partio::ParticleAttribute attr; |
| 1617 | data->attributeInfo(i, attr); |
| 1618 | if (attr.name == "position") |
| 1619 | posIndex = i; |
| 1620 | else if (attr.name == "velocity") |
| 1621 | velIndex = i; |
| 1622 | else if (attr.name == "angularVelocity") |
| 1623 | omegaIndex = i; |
| 1624 | } |
| 1625 | |
| 1626 | Partio::ParticleAttribute attr; |
| 1627 | |
| 1628 | if (posIndex != 0xffffffff) |
| 1629 | { |
| 1630 | unsigned int fSize = (unsigned int)positions.size(); |
| 1631 | positions.resize(fSize + data->numParticles()); |
| 1632 | data->attributeInfo(posIndex, attr); |
| 1633 | for (int i = 0; i < data->numParticles(); i++) |
| 1634 | { |
| 1635 | const float *pos = data->data<float>(attr, i); |
| 1636 | Vector3r x(pos[0], pos[1], pos[2]); |
| 1637 | positions[i + fSize] = x; |
| 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | if (velIndex != 0xffffffff) |
| 1642 | { |
| 1643 | unsigned int fSize = (unsigned int)velocities.size(); |
| 1644 | velocities.resize(fSize + data->numParticles()); |
| 1645 | data->attributeInfo(velIndex, attr); |
| 1646 | for (int i = 0; i < data->numParticles(); i++) |
| 1647 | { |
| 1648 | const float *vel = data->data<float>(attr, i); |
| 1649 | Vector3r v(vel[0], vel[1], vel[2]); |
| 1650 | velocities[i + fSize] = v; |
| 1651 | } |
| 1652 | } |
| 1653 | else |
| 1654 | { |
| 1655 | unsigned int fSize = (unsigned int)velocities.size(); |
| 1656 | velocities.resize(fSize + data->numParticles()); |
| 1657 | for (int i = 0; i < data->numParticles(); i++) |
| 1658 | velocities[i + fSize].setZero(); |
no test coverage detected