include/PxPBDParticleSystem.h
File members: include/PxPBDParticleSystem.h
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2024 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PBD_PARTICLE_SYSTEM_H
#define PX_PBD_PARTICLE_SYSTEM_H
#include "foundation/PxSimpleTypes.h"
#include "foundation/PxVec3.h"
#include "foundation/PxArray.h"
#include "cudamanager/PxCudaTypes.h"
#include "PxParticleSystemFlag.h"
#include "PxFiltering.h"
#include "PxActor.h"
#include "PxParticleSystem.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
#if PX_VC
#pragma warning(push)
#pragma warning(disable : 4435)
#endif
class PxCudaContextManager;
class PxGpuParticleSystem;
class PxParticleAndDiffuseBuffer;
class PxParticleBuffer;
template <typename Type>
struct PxGpuMirroredPointer
{
Type* mDevicePtr;
Type* mHostPtr;
PxGpuMirroredPointer(Type* devicePtr, Type* hostPtr) : mDevicePtr(devicePtr), mHostPtr(hostPtr) { }
};
class PxParticleSystemCallback
{
public:
virtual void onBegin(const PxGpuMirroredPointer<PxGpuParticleSystem>& gpuParticleSystem, CUstream stream) = 0;
virtual void onAdvance(const PxGpuMirroredPointer<PxGpuParticleSystem>& gpuParticleSystem, CUstream stream) = 0;
virtual void onPostSolve(const PxGpuMirroredPointer<PxGpuParticleSystem>& gpuParticleSystem, CUstream stream) = 0;
virtual ~PxParticleSystemCallback() {}
};
class PxMultiCallback : public PxParticleSystemCallback
{
private:
PxArray<PxParticleSystemCallback*> mCallbacks;
public:
PxMultiCallback() : mCallbacks(0) {}
virtual void onPostSolve(const PxGpuMirroredPointer<PxGpuParticleSystem>& gpuParticleSystem, CUstream stream) PX_OVERRIDE
{
for (PxU32 i = 0; i < mCallbacks.size(); ++i)
mCallbacks[i]->onPostSolve(gpuParticleSystem, stream);
}
virtual void onBegin(const PxGpuMirroredPointer<PxGpuParticleSystem>& gpuParticleSystem, CUstream stream) PX_OVERRIDE
{
for (PxU32 i = 0; i < mCallbacks.size(); ++i)
mCallbacks[i]->onBegin(gpuParticleSystem, stream);
}
virtual void onAdvance(const PxGpuMirroredPointer<PxGpuParticleSystem>& gpuParticleSystem, CUstream stream) PX_OVERRIDE
{
for (PxU32 i = 0; i < mCallbacks.size(); ++i)
mCallbacks[i]->onAdvance(gpuParticleSystem, stream);
}
bool addCallback(PxParticleSystemCallback* callback)
{
if (mCallbacks.find(callback) != mCallbacks.end())
return false;
mCallbacks.pushBack(callback);
return true;
}
bool removeCallback(const PxParticleSystemCallback* callback)
{
for (PxU32 i = 0; i < mCallbacks.size(); ++i)
{
if (mCallbacks[i] == callback)
{
mCallbacks.remove(i);
return true;
}
}
return false;
}
};
struct PxParticleFlag
{
enum Enum
{
eDISABLE_SELF_COLLISION = 1 << 0,
eDISABLE_RIGID_COLLISION = 1 << 1,
eFULL_DIFFUSE_ADVECTION = 1 << 2,
eENABLE_SPECULATIVE_CCD = 1 << 3
};
};
typedef PxFlags<PxParticleFlag::Enum, PxU32> PxParticleFlags;
struct PxParticleLockFlag
{
enum Enum
{
eLOCK_X = (1 << 0),
eLOCK_Y = (1 << 1),
eLOCK_Z = (1 << 2)
};
};
typedef PxFlags<PxParticleLockFlag::Enum, PxU8> PxParticleLockFlags;
PX_FLAGS_OPERATORS(PxParticleLockFlag::Enum, PxU8)
class PxPBDParticleSystem : public PxActor
{
public:
virtual ~PxPBDParticleSystem() {}
virtual void setSolverIterationCounts(PxU32 minPositionIters, PxU32 minVelocityIters = 1) = 0;
virtual void getSolverIterationCounts(PxU32& minPositionIters, PxU32& minVelocityIters) const = 0;
virtual PxFilterData getSimulationFilterData() const = 0;
virtual void setSimulationFilterData(const PxFilterData& data) = 0;
virtual void setParticleFlag(PxParticleFlag::Enum flag, bool val) = 0;
virtual void setParticleFlags(PxParticleFlags flags) = 0;
virtual PxParticleFlags getParticleFlags() const = 0;
virtual void setMaxDepenetrationVelocity(PxReal maxDepenetrationVelocity) = 0;
virtual PxReal getMaxDepenetrationVelocity() const = 0;
virtual void setMaxVelocity(PxReal maxVelocity) = 0;
virtual PxReal getMaxVelocity() const = 0;
virtual PxCudaContextManager* getCudaContextManager() const = 0;
virtual void setRestOffset(PxReal restOffset) = 0;
virtual PxReal getRestOffset() const = 0;
virtual void setContactOffset(PxReal contactOffset) = 0;
virtual PxReal getContactOffset() const = 0;
virtual void setParticleContactOffset(PxReal particleContactOffset) = 0;
virtual PxReal getParticleContactOffset() const = 0;
virtual void setSolidRestOffset(PxReal solidRestOffset) = 0;
virtual PxReal getSolidRestOffset() const = 0;
PX_DEPRECATED virtual void addRigidAttachment(PxRigidActor* actor) = 0;
PX_DEPRECATED virtual void removeRigidAttachment(PxRigidActor* actor) = 0;
PX_DEPRECATED virtual void enableCCD(bool enable) = 0;
virtual PxParticleLockFlags getParticleLockFlags() const = 0;
virtual void setParticleLockFlag(PxParticleLockFlag::Enum flag, bool value) = 0;
virtual void setParticleLockFlags(PxParticleLockFlags flags) = 0;
virtual PxU32 createPhase(PxPBDMaterial* material, PxParticlePhaseFlags flags) = 0;
virtual PxU32 getNbParticleMaterials() const = 0;
virtual PxU32 getParticleMaterials(PxPBDMaterial** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const = 0;
virtual void setParticleSystemCallback(PxParticleSystemCallback* callback) = 0;
virtual PxParticleSystemCallback* getParticleSystemCallback() const = 0;
virtual void addParticleBuffer(PxParticleBuffer* particleBuffer) = 0;
virtual void removeParticleBuffer(PxParticleBuffer* particleBuffer) = 0;
virtual PxU32 getGpuParticleSystemIndex() = 0;
virtual void setWind(const PxVec3& wind) = 0;
virtual PxVec3 getWind() const = 0;
virtual void setFluidBoundaryDensityScale(PxReal fluidBoundaryDensityScale) = 0;
virtual PxReal getFluidBoundaryDensityScale() const = 0;
virtual void setFluidRestOffset(PxReal fluidRestOffset) = 0;
virtual PxReal getFluidRestOffset() const = 0;
virtual void setGridSizeX(PxU32 gridSizeX) = 0;
virtual PxU32 getGridSizeX() const = 0;
virtual void setGridSizeY(PxU32 gridSizeY) = 0;
virtual PxU32 getGridSizeY() const = 0;
virtual void setGridSizeZ(PxU32 gridSizeZ) = 0;
virtual PxU32 getGridSizeZ() const = 0;
virtual const char* getConcreteTypeName() const PX_OVERRIDE { return "PxPBDParticleSystem"; }
protected:
PX_INLINE PxPBDParticleSystem(PxType concreteType, PxBaseFlags baseFlags) : PxActor(concreteType, baseFlags) {}
PX_INLINE PxPBDParticleSystem(PxBaseFlags baseFlags) : PxActor(baseFlags) {}
virtual bool isKindOf(const char* name) const PX_OVERRIDE { PX_IS_KIND_OF(name, "PxPBDParticleSystem", PxActor); }
};
#if PX_VC
#pragma warning(pop)
#endif
#if !PX_DOXYGEN
} // namespace physx
#endif
#endif