compacts all constraints into linear arrays
| 155 | |
| 156 | // compacts all constraints into linear arrays |
| 157 | void CompactObjects(NvFlexExtContainer* c) |
| 158 | { |
| 159 | int totalNumSprings = 0; |
| 160 | int totalNumTris = 0; |
| 161 | int totalNumShapes = 0; |
| 162 | int totalNumShapeIndices = 0; |
| 163 | |
| 164 | // pre-calculate array sizes |
| 165 | for (size_t i = 0; i < c->mInstances.size(); ++i) |
| 166 | { |
| 167 | NvFlexExtInstance* inst = c->mInstances[i]; |
| 168 | |
| 169 | const NvFlexExtAsset* asset = inst->asset; |
| 170 | |
| 171 | // index into the triangle array for this instance |
| 172 | inst->triangleIndex = totalNumTris; |
| 173 | |
| 174 | totalNumSprings += asset->numSprings; |
| 175 | totalNumTris += asset->numTriangles; |
| 176 | |
| 177 | totalNumShapeIndices += asset->numShapeIndices; |
| 178 | totalNumShapes += asset->numShapes; |
| 179 | } |
| 180 | |
| 181 | //---------------------- |
| 182 | // map buffers |
| 183 | |
| 184 | // springs |
| 185 | c->mSpringIndices.map(); |
| 186 | c->mSpringLengths.map(); |
| 187 | c->mSpringCoefficients.map(); |
| 188 | |
| 189 | // cloth |
| 190 | c->mTriangleIndices.map(); |
| 191 | c->mTriangleNormals.map(); |
| 192 | |
| 193 | // inflatables |
| 194 | c->mInflatableStarts.map(); |
| 195 | c->mInflatableCounts.map(); |
| 196 | c->mInflatableRestVolumes.map(); |
| 197 | c->mInflatableCoefficients.map(); |
| 198 | c->mInflatableOverPressures.map(); |
| 199 | |
| 200 | // shapes |
| 201 | c->mShapeIndices.map(); |
| 202 | c->mShapeRestPositions.map(); |
| 203 | c->mShapeOffsets.map(); |
| 204 | c->mShapeCoefficients.map(); |
| 205 | |
| 206 | c->mShapeTranslations.map(); |
| 207 | c->mShapeRotations.map(); |
| 208 | |
| 209 | //---------------------- |
| 210 | // resize buffers |
| 211 | |
| 212 | // springs |
| 213 | c->mSpringIndices.resize(totalNumSprings * 2); |
| 214 | c->mSpringLengths.resize(totalNumSprings); |