| 82 | } |
| 83 | |
| 84 | NvFlexExtAsset* NvFlexExtCreateClothFromMesh(const float* particles, int numVertices, const int* indices, int numTriangles, float stretchStiffness, float bendStiffness, float tetherStiffness, float tetherGive, float pressure) |
| 85 | { |
| 86 | NvFlexExtAsset* asset = new NvFlexExtAsset(); |
| 87 | memset(asset, 0, sizeof(*asset)); |
| 88 | |
| 89 | asset->particles = new float[numVertices*4]; |
| 90 | memcpy(asset->particles, particles, numVertices*sizeof(float)*4); |
| 91 | |
| 92 | asset->triangleIndices = new int[numTriangles*3]; |
| 93 | memcpy(asset->triangleIndices, indices, numTriangles*3*sizeof(int)); |
| 94 | |
| 95 | asset->numParticles = numVertices; |
| 96 | asset->maxParticles = numVertices; |
| 97 | |
| 98 | asset->numTriangles = numTriangles; |
| 99 | |
| 100 | // create cloth mesh |
| 101 | ClothMesh cloth((Vec4*)particles, numVertices, indices, numTriangles*3, stretchStiffness, bendStiffness, true); |
| 102 | |
| 103 | if (cloth.mValid) |
| 104 | { |
| 105 | // create tethers |
| 106 | if (tetherStiffness > 0.0f) |
| 107 | { |
| 108 | std::vector<int> anchors; |
| 109 | anchors.reserve(numVertices); |
| 110 | |
| 111 | // find anchors |
| 112 | for (int i=0; i < numVertices; ++i) |
| 113 | { |
| 114 | Vec4& particle = ((Vec4*)particles)[i]; |
| 115 | |
| 116 | if (particle.w == 0.0f) |
| 117 | anchors.push_back(i); |
| 118 | } |
| 119 | |
| 120 | if (anchors.size()) |
| 121 | { |
| 122 | // create tethers |
| 123 | for (int i=0; i < numVertices; ++i) |
| 124 | { |
| 125 | Vec4& particle = ((Vec4*)particles)[i]; |
| 126 | if (particle.w == 0.0f) |
| 127 | continue; |
| 128 | |
| 129 | float minSqrDist = FLT_MAX; |
| 130 | int minIndex = -1; |
| 131 | |
| 132 | // find the closest attachment point |
| 133 | for (int a=0; a < int(anchors.size()); ++a) |
| 134 | { |
| 135 | Vec4& attachment = ((Vec4*)particles)[anchors[a]]; |
| 136 | |
| 137 | float distSqr = LengthSq(Vec3(particle)-Vec3(attachment)); |
| 138 | if (distSqr < minSqrDist) |
| 139 | { |
| 140 | minSqrDist = distSqr; |
| 141 | minIndex = anchors[a]; |
nothing calls this directly
no test coverage detected