include/PxParticleSystem.h
File members: include/PxParticleSystem.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-2023 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_PARTICLE_SYSTEM_H
#define PX_PARTICLE_SYSTEM_H
#include "foundation/PxSimpleTypes.h"
#include "PxActor.h"
#include "PxFiltering.h"
#include "PxParticleSystemFlag.h"
#include "foundation/PxArray.h"
#include "cudamanager/PxCudaTypes.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;
class PxParticleMaterial;
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
};
};
typedef PxFlags<PxParticleFlag::Enum, PxU32> PxParticleFlags;
class PxParticleSystem : public PxActor
{
public:
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() = 0;
virtual void setMaxVelocity(PxReal maxVelocity) = 0;
virtual PxReal getMaxVelocity() = 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;
virtual void addRigidAttachment(PxRigidActor* actor) = 0;
virtual void removeRigidAttachment(PxRigidActor* actor) = 0;
virtual void enableCCD(bool enable) = 0;
virtual PxU32 createPhase(PxParticleMaterial* material, PxParticlePhaseFlags flags) = 0;
virtual PxU32 getNbParticleMaterials() const = 0;
virtual PxU32 getParticleMaterials(PxParticleMaterial** 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;
protected:
virtual ~PxParticleSystem() {}
PX_INLINE PxParticleSystem(PxType concreteType, PxBaseFlags baseFlags) : PxActor(concreteType, baseFlags) {}
PX_INLINE PxParticleSystem(PxBaseFlags baseFlags) : PxActor(baseFlags) {}
virtual bool isKindOf(const char* name) const PX_OVERRIDE { PX_IS_KIND_OF(name, "PxParticleSystem", PxActor); }
};
#if PX_VC
#pragma warning(pop)
#endif
#if !PX_DOXYGEN
} // namespace physx
#endif
#endif