| 194 | }; |
| 195 | |
| 196 | NvFlexExtAsset* NvFlexExtCreateTearingClothFromMesh(const float* particles, int numParticles, int maxParticles, const int* indices, int numTriangles, float stretchStiffness, float bendStiffness, float pressure) |
| 197 | { |
| 198 | FlexExtTearingClothAsset* asset = new FlexExtTearingClothAsset(); |
| 199 | memset(asset, 0, sizeof(*asset)); |
| 200 | |
| 201 | asset->particles = new float[maxParticles*4]; |
| 202 | memcpy(asset->particles, particles, numParticles*sizeof(float)*4); |
| 203 | |
| 204 | asset->triangleIndices = new int[numTriangles*3]; |
| 205 | memcpy(asset->triangleIndices, indices, numTriangles*3*sizeof(int)); |
| 206 | |
| 207 | asset->numParticles = numParticles; |
| 208 | asset->maxParticles = maxParticles; |
| 209 | |
| 210 | asset->numTriangles = numTriangles; |
| 211 | |
| 212 | // create and store cloth mesh |
| 213 | asset->mMesh = new ClothMesh((Vec4*)particles, numParticles, indices, numTriangles*3, stretchStiffness, bendStiffness, true); |
| 214 | |
| 215 | ClothMesh& cloth = *asset->mMesh; |
| 216 | |
| 217 | if (cloth.mValid) |
| 218 | { |
| 219 | const int numSprings = int(cloth.mConstraintCoefficients.size()); |
| 220 | |
| 221 | // asset references cloth mesh memory directly |
| 222 | asset->springIndices = &cloth.mConstraintIndices[0]; |
| 223 | asset->springCoefficients = &cloth.mConstraintCoefficients[0]; |
| 224 | asset->springRestLengths = &cloth.mConstraintRestLengths[0]; |
| 225 | asset->numSprings = numSprings; |
| 226 | |
| 227 | if (pressure > 0.0f) |
| 228 | { |
| 229 | asset->inflatable = true; |
| 230 | asset->inflatableVolume = cloth.mRestVolume; |
| 231 | asset->inflatableStiffness = cloth.mConstraintScale; |
| 232 | asset->inflatablePressure = pressure; |
| 233 | } |
| 234 | } |
| 235 | else |
| 236 | { |
| 237 | NvFlexExtDestroyAsset(asset); |
| 238 | return NULL; |
| 239 | } |
| 240 | |
| 241 | return asset; |
| 242 | |
| 243 | } |
| 244 | |
| 245 | void NvFlexExtDestroyTearingCloth(NvFlexExtAsset* asset) |
| 246 | { |
no test coverage detected