Monday, December 5, 2022
HomeGame DevelopmentPhysX 5.1 particles don't collide with inflexible dynamic actors

PhysX 5.1 particles don’t collide with inflexible dynamic actors


I am presently utilizing PhysX 5.1 for a recreation that I am growing. Though every part appears to work positive I am unable to get the particles to collide with inflexible dynamic actors (Field form). Be aware that the particles collide with one another. Right here is the code taken from the snippets with the particles for fluids examples :

// Materials setup
PxPBDMaterial* defaultMat = mPhysics->createPBDMaterial(0.05f, 0.05f, 0.f, 0.001f, 0.5f, 0.005f, 0.01f, 0.f, 0.f);

defaultMat->setViscosity(0.001f);
defaultMat->setSurfaceTension(0.00704f);
defaultMat->setCohesion(0.0704f);
defaultMat->setVorticityConfinement(10.f);

PxPBDParticleSystem* particleSystem = mPhysics->createPBDParticleSystem(*mCudaContextManager, 96);

// Common particle system setting
const PxU32 maxParticles = numX * numY * numZ;
const PxReal restOffset = 0.5f * particleSpacing / 0.6f;
const PxReal solidRestOffset = restOffset;
const PxReal fluidRestOffset = restOffset * 0.6f;
const PxReal particleMass = fluidDensity * 1.333f * 3.14159f * particleSpacing * particleSpacing * particleSpacing;
particleSystem->setRestOffset(restOffset);
particleSystem->setContactOffset(restOffset + 0.01f);
particleSystem->setParticleContactOffset(PxMax(solidRestOffset + 0.01f, fluidRestOffset / 0.6f));
particleSystem->setSolidRestOffset(solidRestOffset);
particleSystem->setFluidRestOffset(fluidRestOffset);
particleSystem->enableCCD(false);
particleSystem->setParticleFlag(PxParticleFlag::eDISABLE_RIGID_COLLISION, false);
particleSystem->setParticleFlag(PxParticleFlag::eDISABLE_SELF_COLLISION, false);

mScene->addActor(*particleSystem);

// Create particles and add them to the particle system
const PxU32 particlePhase = particleSystem->createPhase(defaultMat, PxParticlePhaseFlags(PxParticlePhaseFlag::eParticlePhaseFluid | PxParticlePhaseFlag::eParticlePhaseSelfCollide));

PxU32* part = mCudaContextManager->allocPinnedHostBuffer<PxU32>(maxParticles);
PxVec4* positionInvMass = mCudaContextManager->allocPinnedHostBuffer<PxVec4>(maxParticles);
PxVec4* velocity = mCudaContextManager->allocPinnedHostBuffer<PxVec4>(maxParticles);

PxReal x = place.x;
PxReal y = place.y;
PxReal z = place.z;
PxReal maxY = y;
PxReal maxZ = z;

for (PxU32 i = 0; i < numX; ++i)
{
    for (PxU32 j = 0; j < numY; ++j)
    {
        for (PxU32 okay = 0; okay < numZ; ++okay)
        {
            const PxU32 index = i * (numY * numZ) + j * numZ + okay;

            PxVec4 pos(x, y, z, 1.0f / particleMass);
            part[index] = particlePhase;
            positionInvMass[index] = pos;
            velocity[index] = PxVec4(0.0f);

            z += particleSpacing;
        }
        maxZ = z - particleSpacing;
        z = place.z;
        y += particleSpacing;
    }
    maxY = y - particleSpacing;
    y = place.y;
    x += particleSpacing;
}


ExtGpu::PxParticleAndDiffuseBufferDesc bufferDesc;
bufferDesc.maxParticles = maxParticles;
bufferDesc.numActiveParticles = maxParticles;

bufferDesc.positions = positionInvMass;
bufferDesc.velocities = velocity;
bufferDesc.phases = part;

auto particleBuffer = physx::ExtGpu::PxCreateAndPopulateParticleBuffer(bufferDesc, mCudaContextManager);
particleSystem->addParticleBuffer(particleBuffer);

mCudaContextManager->freePinnedHostBuffer(positionInvMass);
mCudaContextManager->freePinnedHostBuffer(velocity);
mCudaContextManager->freePinnedHostBuffer(part);

return particleBuffer;

Am I setting one thing fallacious right here? Any solutions on find out how to make the particles really collide with the field geometries?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments