include/PxDeformableVolume.h

File members: include/PxDeformableVolume.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_DEFORMABLE_VOLUME_H
#define PX_DEFORMABLE_VOLUME_H

#include "PxDeformableBody.h"
#include "PxDeformableVolumeFlag.h"
#include "PxConeLimitedConstraint.h"

#if !PX_DOXYGEN
namespace physx
{
#endif

#if PX_VC
#pragma warning(push)
#pragma warning(disable : 4435)
#endif

class PxCudaContextManager;
class PxTetrahedronMesh;
class PxDeformableVolumeAuxData;
class PxDeformableSurface;
class PxParticleBuffer;

#define PX_MAX_NB_DEFORMABLE_VOLUME_TET 0x000fffff

#define PX_MAX_NB_DEFORMABLE_VOLUME 0xfff

class PxDeformableVolume : public PxDeformableBody
{
public:

    virtual     void                        setDeformableVolumeFlag(PxDeformableVolumeFlag::Enum flag, bool val) = 0;

    virtual     void                        setDeformableVolumeFlags(PxDeformableVolumeFlags flags) = 0;

    virtual     PxDeformableVolumeFlags     getDeformableVolumeFlags() const = 0;

    virtual     void                        setSelfCollisionStressTolerance(const PxReal selfCollisionStressTolerance) = 0;

    virtual     PxReal                      getSelfCollisionStressTolerance() const = 0;

    virtual     PxVec4*                     getPositionInvMassBufferD() = 0;

    virtual     PxVec4*                     getRestPositionBufferD() = 0;

    virtual     PxVec4*                     getSimPositionInvMassBufferD() = 0;

    virtual     PxVec4*                     getSimVelocityBufferD() = 0;

    virtual     void                        markDirty(PxDeformableVolumeDataFlags flags) = 0;

    virtual     void                        setKinematicTargetBufferD(const PxVec4* positions) = 0;

    PX_DEPRECATED virtual void              setKinematicTargetBufferD(const PxVec4* positions, PxDeformableVolumeFlags flags) = 0;

    virtual     bool                        attachSimulationMesh(PxTetrahedronMesh& simulationMesh, PxDeformableVolumeAuxData& deformableVolumeAuxData) = 0;

    virtual     void                        detachSimulationMesh() = 0;

    virtual     PxTetrahedronMesh*          getSimulationMesh() = 0;

    virtual     const PxTetrahedronMesh*    getSimulationMesh() const = 0;

    virtual     PxTetrahedronMesh*          getCollisionMesh() = 0;

    virtual     const PxTetrahedronMesh*    getCollisionMesh() const = 0;

    virtual     PxDeformableVolumeAuxData*  getDeformableVolumeAuxData() = 0;

    virtual     const PxDeformableVolumeAuxData*
                                            getDeformableVolumeAuxData() const = 0;

    virtual     PxU32                       getGpuDeformableVolumeIndex() = 0;

    virtual     const char*                 getConcreteTypeName() const PX_OVERRIDE PX_FINAL { return "PxDeformableVolume"; }

    PX_DEPRECATED PX_FORCE_INLINE void setSoftBodyFlag(PxDeformableVolumeFlag::Enum flag, bool val) { return setDeformableVolumeFlag(flag, val); }

    PX_DEPRECATED PX_FORCE_INLINE void setSoftBodyFlags(PxDeformableVolumeFlags flags) { return setDeformableVolumeFlags(flags); }

    PX_DEPRECATED PX_FORCE_INLINE PxDeformableVolumeFlags getSoftBodyFlag() const { return getDeformableVolumeFlags(); }

    PX_DEPRECATED PX_FORCE_INLINE PxDeformableVolumeAuxData* getSoftBodyAuxData() { return getDeformableVolumeAuxData(); }

    PX_DEPRECATED PX_FORCE_INLINE const PxDeformableVolumeAuxData* getSoftBodyAuxData() const { return getDeformableVolumeAuxData(); }

    PX_DEPRECATED virtual       void    setSolverIterationCounts(PxU32 minPositionIters, PxU32 minVelocityIters = 1) = 0;

    PX_DEPRECATED virtual       void    getSolverIterationCounts(PxU32& minPositionIters, PxU32& minVelocityIters) const = 0;

    PX_DEPRECATED   virtual     void    addParticleFilter(PxPBDParticleSystem* particlesystem, const PxParticleBuffer* buffer, PxU32 particleId, PxU32 tetId) = 0;

    PX_DEPRECATED   virtual     void    removeParticleFilter(PxPBDParticleSystem* particlesystem, const PxParticleBuffer* buffer, PxU32 particleId, PxU32 tetId) = 0;

    PX_DEPRECATED   virtual     PxU32   addParticleAttachment(PxPBDParticleSystem* particlesystem, const PxParticleBuffer* buffer, PxU32 particleId, PxU32 tetId, const PxVec4& barycentric) = 0;

    PX_DEPRECATED   virtual     void    removeParticleAttachment(PxPBDParticleSystem* particlesystem, PxU32 handle) = 0;

    PX_DEPRECATED   virtual     void    addRigidFilter(PxRigidActor* actor, PxU32 vertId) = 0;

    PX_DEPRECATED   virtual     void    removeRigidFilter(PxRigidActor* actor, PxU32 vertId) = 0;

    PX_DEPRECATED   virtual     PxU32   addRigidAttachment(PxRigidActor* actor, PxU32 vertId, const PxVec3& actorSpacePose, PxConeLimitedConstraint* constraint = NULL) = 0;

    PX_DEPRECATED   virtual     void    removeRigidAttachment(PxRigidActor* actor, PxU32 handle) = 0;

    PX_DEPRECATED   virtual     void    addTetRigidFilter(PxRigidActor* actor, PxU32 tetIdx) = 0;

    PX_DEPRECATED   virtual     void    removeTetRigidFilter(PxRigidActor* actor, PxU32 tetIdx) = 0;

    PX_DEPRECATED   virtual     PxU32   addTetRigidAttachment(PxRigidActor* actor, PxU32 tetIdx, const PxVec4& barycentric, const PxVec3& actorSpacePose, PxConeLimitedConstraint* constraint = NULL) = 0;

    PX_DEPRECATED   virtual     void    addSoftBodyFilter(PxDeformableVolume* otherDeformableVolume, PxU32 otherTetIdx, PxU32 tetIdx1) = 0;

    PX_DEPRECATED   virtual     void    removeSoftBodyFilter(PxDeformableVolume* otherDeformableVolume, PxU32 otherTetIdx, PxU32 tetIdx1) = 0;

    PX_DEPRECATED   virtual     void    addSoftBodyFilters(PxDeformableVolume* otherDeformableVolume, PxU32* otherTetIndices, PxU32* tetIndices, PxU32 tetIndicesSize) = 0;

    PX_DEPRECATED   virtual     void    removeSoftBodyFilters(PxDeformableVolume* otherDeformableVolume, PxU32* otherTetIndices, PxU32* tetIndices, PxU32 tetIndicesSize) = 0;

    PX_DEPRECATED   virtual     PxU32   addSoftBodyAttachment(PxDeformableVolume* deformableVolume0, PxU32 tetIdx0, const PxVec4& tetBarycentric0, PxU32 tetIdx1, const PxVec4& tetBarycentric1,
                                        PxConeLimitedConstraint* constraint = NULL, PxReal constraintOffset = 0.0f) = 0;

    PX_DEPRECATED   virtual     void    removeSoftBodyAttachment(PxDeformableVolume* deformableVolume0, PxU32 handle) = 0;

    PX_DEPRECATED PX_FORCE_INLINE PxU32 getGpuSoftBodyIndex() { return getGpuDeformableVolumeIndex(); }

protected:
    PX_INLINE                   PxDeformableVolume(PxType concreteType, PxBaseFlags baseFlags) : PxDeformableBody(concreteType, baseFlags) {}
    PX_INLINE                   PxDeformableVolume(PxBaseFlags baseFlags) : PxDeformableBody(baseFlags) {}
    virtual                     ~PxDeformableVolume() {}
    virtual     bool            isKindOf(const char* name) const PX_OVERRIDE { PX_IS_KIND_OF(name, "PxDeformableVolume", PxDeformableBody); }
};

PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec4 PxConfigureDeformableVolumeKinematicTarget(const PxVec4& target, bool isActive)
{
    PxVec4 result = target;
    if (isActive)
        result.w = 0.0f;
    else
    {
        //Any non-zero value will mark the target as inactive
        if (result.w == 0.0f)
            result.w = 1.0f;
    }
    return result;
}

PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec4 PxConfigureDeformableVolumeKinematicTarget(const PxVec3& target, bool isActive)
{
    return PxConfigureDeformableVolumeKinematicTarget(PxVec4(target, 0.0f), isActive);
}

#if PX_VC
#pragma warning(pop)
#endif

#if !PX_DOXYGEN
} // namespace physx
#endif

#endif // PX_DEFORMABLE_VOLUME_H