| 43 | } |
| 44 | |
| 45 | int NvFlexExtCreateWeldedMeshIndices(const float* vertices, int numVertices, int* uniqueIndices, int* originalToUniqueMap, float threshold) |
| 46 | { |
| 47 | memset(originalToUniqueMap, -1, numVertices*sizeof(int)); |
| 48 | |
| 49 | const Vec3* positions = (const Vec3*)vertices; |
| 50 | |
| 51 | // use a sweep and prune style search to accelerate neighbor finding |
| 52 | std::vector<Key> keys; |
| 53 | for (int i=0; i < numVertices; i++) |
| 54 | keys.push_back(Key(i, positions[i].z)); |
| 55 | |
| 56 | std::sort(keys.begin(), keys.end()); |
| 57 | |
| 58 | int uniqueCount = 0; |
| 59 | |
| 60 | // sweep keys to find matching verts |
| 61 | for (int i=0; i < numVertices; ++i) |
| 62 | { |
| 63 | // we are a duplicate, skip |
| 64 | if (originalToUniqueMap[keys[i].index] != -1) |
| 65 | continue; |
| 66 | |
| 67 | // scan forward until no vertex can be closer than threshold |
| 68 | for (int j=i+1; j < numVertices && (keys[j].depth-keys[i].depth) <= threshold; ++j) |
| 69 | { |
| 70 | float distance = Length(Vector3(positions[keys[i].index])-Vector3(positions[keys[j].index])); |
| 71 | |
| 72 | if (distance <= threshold) |
| 73 | originalToUniqueMap[keys[j].index] = uniqueCount; |
| 74 | } |
| 75 | |
| 76 | originalToUniqueMap[keys[i].index] = uniqueCount; |
| 77 | |
| 78 | uniqueIndices[uniqueCount++] = keys[i].index; |
| 79 | } |
| 80 | |
| 81 | return uniqueCount; |
| 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 | { |