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

Function NvFlexExtCreateInstance

extensions/flexExtContainer.cpp:620–685  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

618
619
620NvFlexExtInstance* NvFlexExtCreateInstance(NvFlexExtContainer* c, NvFlexExtParticleData* particleData, const NvFlexExtAsset* asset, const float* transform, float vx, float vy, float vz, int phase, float invMassScale)
621{
622 const int numParticles = asset->numParticles;
623
624 // check if asset will fit
625 if (int(c->mFreeList.size()) < numParticles)
626 return NULL;
627
628 NvFlexExtInstance* inst = new NvFlexExtInstance();
629
630 inst->asset = asset;
631 inst->triangleIndex = -1;
632 inst->shapeIndex = -1;
633 inst->inflatableIndex = -1;
634 inst->userData = NULL;
635 inst->numParticles = numParticles;
636
637 assert(inst->numParticles <= asset->maxParticles);
638
639 // allocate particles for instance
640 inst->particleIndices = new int[asset->maxParticles];
641 int n = NvFlexExtAllocParticles(c, numParticles, &inst->particleIndices[0]);
642 assert(n == numParticles);
643 (void)n;
644
645 c->mInstances.push_back(inst);
646
647 const Matrix44 xform(transform);
648
649 for (int i=0; i < numParticles; ++i)
650 {
651 const int index = inst->particleIndices[i];
652
653 // add transformed particles to the locked particle data
654 ((Vec4*)(particleData->particles))[index] = xform*Vec4(Vec3(&asset->particles[i*4]), 1.0f);
655 ((Vec4*)(particleData->particles))[index].w = asset->particles[i*4+3]*invMassScale;
656 ((Vec4*)(particleData->restParticles))[index] = Vec4(&asset->particles[i*4]);
657
658 ((Vec3*)(particleData->velocities))[index] = Vec3(vx, vy, vz);
659 ((int*)(particleData->phases))[index] = phase;
660 ((Vec4*)(particleData->normals))[index] = Vec4(0.0f);
661 }
662
663 const int numShapes = asset->numShapes;
664
665 // allocate memory for shape transforms
666 Vec3* shapeTranslations = new Vec3[numShapes];
667 Quat* shapeRotations = new Quat[numShapes];
668
669 Quat rotation = Quat(Matrix33(xform.GetAxis(0), xform.GetAxis(1), xform.GetAxis(2)));
670
671 for (int i=0; i < numShapes; ++i)
672 {
673 shapeTranslations[i] = Vec3(xform*Vec4(asset->shapeCenters[i*3+0], asset->shapeCenters[i*3+1], asset->shapeCenters[i*3+2], 1.0));
674 shapeRotations[i] = rotation;
675 }
676
677 inst->shapeTranslations = (float*)shapeTranslations;

Callers

nothing calls this directly

Calls 4

NvFlexExtAllocParticlesFunction · 0.85
sizeMethod · 0.80
push_backMethod · 0.80
Matrix33Class · 0.50

Tested by

no test coverage detected