MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/FleX / NvFlexExtCreateSoftFromMesh

Function NvFlexExtCreateSoftFromMesh

extensions/flexExtSoft.cpp:510–618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

508// API methods
509
510NvFlexExtAsset* NvFlexExtCreateSoftFromMesh(const float* vertices, int numVertices, const int* indices, int numIndices, float particleSpacing, float volumeSampling, float surfaceSampling, float clusterSpacing, float clusterRadius, float clusterStiffness, float linkRadius, float linkStiffness, float globalStiffness)
511{
512 // construct asset definition
513 NvFlexExtAsset* asset = new NvFlexExtAsset();
514
515 // create particle sampling
516 std::vector<Vec3> samples;
517 SampleMesh((Vec3*)vertices, numVertices, indices, numIndices, particleSpacing, volumeSampling, surfaceSampling, samples);
518
519 const int numParticles = int(samples.size());
520
521 std::vector<int> clusterIndices;
522 std::vector<int> clusterOffsets;
523 std::vector<Vec3> clusterPositions;
524 std::vector<float> clusterCoefficients;
525
526 // priority (not currently used)
527 std::vector<float> priority(numParticles);
528 for (int i = 0; i < int(priority.size()); ++i)
529 priority[i] = 0.0f;
530
531 // cluster particles into shape matching groups
532 int numClusters = CreateClusters(&samples[0], &priority[0], int(samples.size()), clusterOffsets, clusterIndices, clusterPositions, clusterSpacing, clusterRadius);
533
534 // assign all clusters the same stiffness
535 clusterCoefficients.resize(numClusters, clusterStiffness);
536
537 // create links between clusters
538 if (linkRadius > 0.0f)
539 {
540 std::vector<int> springIndices;
541 std::vector<float> springLengths;
542 std::vector<float> springStiffness;
543
544 // create links between particles
545 int numLinks = CreateLinks(&samples[0], int(samples.size()), springIndices, springLengths, springStiffness, linkRadius, linkStiffness);
546
547 // assign links
548 if (numLinks)
549 {
550 asset->springIndices = new int[numLinks * 2];
551 memcpy(asset->springIndices, &springIndices[0], sizeof(int)*springIndices.size());
552
553 asset->springCoefficients = new float[numLinks];
554 memcpy(asset->springCoefficients, &springStiffness[0], sizeof(float)*numLinks);
555
556 asset->springRestLengths = new float[numLinks];
557 memcpy(asset->springRestLengths, &springLengths[0], sizeof(float)*numLinks);
558
559 asset->numSprings = numLinks;
560 }
561 }
562
563 // add an additional global cluster with stiffness = globalStiffness
564 if (globalStiffness > 0.0f)
565 {
566 numClusters += 1;
567 clusterCoefficients.push_back(globalStiffness);

Callers 2

CreateSoftBodyMethod · 0.85
CreatePlasticBodyMethod · 0.85

Calls 6

sizeMethod · 0.80
resizeMethod · 0.80
push_backMethod · 0.80
SampleMeshFunction · 0.70
CreateClustersFunction · 0.70
CreateLinksFunction · 0.70

Tested by

no test coverage detected