| 93 | } |
| 94 | |
| 95 | ParticlesDataMutable* |
| 96 | clone(const ParticlesData& other, bool particles) |
| 97 | { |
| 98 | ParticlesDataMutable* p = create(); |
| 99 | // Fixed attributes |
| 100 | FixedAttribute srcFixedAttr, dstFixedAttr; |
| 101 | for (int i(0), iend(other.numFixedAttributes()); i < iend; ++i) { |
| 102 | other.fixedAttributeInfo(i, srcFixedAttr); |
| 103 | |
| 104 | dstFixedAttr = p->addFixedAttribute( |
| 105 | srcFixedAttr.name.c_str(), srcFixedAttr.type, srcFixedAttr.count); |
| 106 | assert(srcFixedAttr.type == dstFixedAttr.type); |
| 107 | assert(srcFixedAttr.count == dstFixedAttr.count); |
| 108 | // Register indexed strings |
| 109 | if (srcFixedAttr.type == Partio::INDEXEDSTR) { |
| 110 | const std::vector<std::string>& values = other.fixedIndexedStrs(srcFixedAttr); |
| 111 | for (int j = 0, jend = values.size(); j < jend; ++j) { |
| 112 | p->registerFixedIndexedStr(dstFixedAttr, values[j].c_str()); |
| 113 | } |
| 114 | } |
| 115 | // Copy fixed data |
| 116 | const void* src = other.fixedData<void>(srcFixedAttr); |
| 117 | void* dst = p->fixedDataWrite<void>(dstFixedAttr); |
| 118 | size_t size = Partio::TypeSize(dstFixedAttr.type) * dstFixedAttr.count; |
| 119 | std::memcpy(dst, src, size); |
| 120 | } |
| 121 | if (!particles) { |
| 122 | return p; |
| 123 | } |
| 124 | // Particle data |
| 125 | Partio::ParticleAttribute srcAttr, dstAttr; |
| 126 | const int numAttributes = other.numAttributes(); |
| 127 | const size_t numParticles = other.numParticles(); |
| 128 | std::vector<Partio::ParticleAttribute> dstAttrs; |
| 129 | |
| 130 | p->addParticles(numParticles); |
| 131 | |
| 132 | // We can't assume that the particle backend stores data contiguously, so |
| 133 | // we copy one particle at a time. A bulk memcpy would be faster. |
| 134 | for (int i = 0; i < numAttributes; ++i) { |
| 135 | other.attributeInfo(i, srcAttr); |
| 136 | // Register indexed strings |
| 137 | if (srcAttr.type == Partio::INDEXEDSTR) { |
| 138 | const std::vector<std::string>& values = other.indexedStrs(srcAttr); |
| 139 | for (int m = 0, mend = values.size(); m < mend; ++m) { |
| 140 | p->registerIndexedStr(dstAttr, values[m].c_str()); |
| 141 | } |
| 142 | } |
| 143 | size_t size = Partio::TypeSize(srcAttr.type) * srcAttr.count; |
| 144 | dstAttr = p->addAttribute(srcAttr.name.c_str(), srcAttr.type, srcAttr.count); |
| 145 | |
| 146 | for (Partio::ParticleIndex j = 0; j < numParticles; ++j) { |
| 147 | const void *src = other.data<void>(srcAttr, j); |
| 148 | void *dst = p->dataWrite<void>(dstAttr, j); |
| 149 | std::memcpy(dst, src, size); |
| 150 | } |
| 151 | } |
| 152 |
no test coverage detected