include/PxSoftBody.h

File members: include/PxSoftBody.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_SOFT_BODY_H
#define PX_SOFT_BODY_H

#include "PxFEMParameter.h"
#include "PxActor.h"
#include "PxConeLimitedConstraint.h"
#include "PxSoftBodyFlag.h"

#if !PX_DOXYGEN
namespace physx
{
#endif

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

    class PxCudaContextManager;
    class PxTetrahedronMesh;
    class PxSoftBodyAuxData;
    class PxFEMCloth;
    class PxParticleBuffer;

    #define PX_MAX_NB_SOFTBODY_TET 0x000fffff

    #define PX_MAX_TETID PX_MAX_NB_SOFTBODY_TET

    #define PX_MAX_NB_SOFTBODY 0xfff

    struct PxSoftBodyFlag
    {
        enum Enum
        {
            eDISABLE_SELF_COLLISION = 1 << 0,
            eCOMPUTE_STRESS_TENSOR = 1 << 1,
            eENABLE_CCD = 1 << 2,
            eDISPLAY_SIM_MESH = 1 << 3,
            eKINEMATIC = 1 << 4,
            ePARTIALLY_KINEMATIC = 1 << 5
        };
    };

    typedef PxFlags<PxSoftBodyFlag::Enum, PxU32> PxSoftBodyFlags;

    class PxSoftBody : public PxActor
    {
    public:

        virtual                         ~PxSoftBody() {}

        virtual     void                setSoftBodyFlag(PxSoftBodyFlag::Enum flag, bool val) = 0;

        virtual     void                setSoftBodyFlags(PxSoftBodyFlags flags) = 0;

        virtual     PxSoftBodyFlags     getSoftBodyFlag() const = 0;

        virtual     void                setParameter(PxFEMParameters parameters) = 0;

        virtual PxFEMParameters         getParameter() const = 0;

        virtual     PxVec4*             getPositionInvMassBufferD() = 0;

        virtual     PxVec4*             getRestPositionBufferD() = 0;

        virtual     PxVec4*             getSimPositionInvMassBufferD() = 0;

        virtual     PxVec4*             getSimVelocityBufferD() = 0;

        virtual     void                markDirty(PxSoftBodyDataFlags flags) = 0;

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

        virtual     PxCudaContextManager*   getCudaContextManager() const = 0;

        virtual     void                setWakeCounter(PxReal wakeCounterValue) = 0;

        virtual     PxReal              getWakeCounter() const = 0;

        virtual     bool                isSleeping() const = 0;

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

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

        virtual     PxShape*            getShape() = 0;

        virtual PxTetrahedronMesh*      getCollisionMesh() = 0;

        virtual const PxTetrahedronMesh* getCollisionMesh() const = 0;

        virtual PxTetrahedronMesh*      getSimulationMesh() = 0;

        virtual const PxTetrahedronMesh* getSimulationMesh() const = 0;

        virtual PxSoftBodyAuxData* getSoftBodyAuxData() = 0;

        virtual const PxSoftBodyAuxData* getSoftBodyAuxData() const = 0;

        virtual     bool                attachShape(PxShape& shape) = 0;

        virtual     bool                attachSimulationMesh(PxTetrahedronMesh& simulationMesh, PxSoftBodyAuxData& softBodyAuxData) = 0;

        virtual     void                detachShape() = 0;

        virtual     void                detachSimulationMesh() = 0;

        virtual     void                release() = 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(PxSoftBody* otherSoftBody, PxU32 otherTetIdx, PxU32 tetIdx1) = 0;

        PX_DEPRECATED   virtual     void    removeSoftBodyFilter(PxSoftBody* otherSoftBody, PxU32 otherTetIdx, PxU32 tetIdx1) = 0;

        PX_DEPRECATED   virtual     void    addSoftBodyFilters(PxSoftBody* otherSoftBody, PxU32* otherTetIndices, PxU32* tetIndices, PxU32 tetIndicesSize) = 0;

        PX_DEPRECATED   virtual     void    removeSoftBodyFilters(PxSoftBody* otherSoftBody, PxU32* otherTetIndices, PxU32* tetIndices, PxU32 tetIndicesSize) = 0;

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

        PX_DEPRECATED   virtual     void    removeSoftBodyAttachment(PxSoftBody* softbody0, PxU32 handle) = 0;

        PX_DEPRECATED   virtual     void    addClothFilter(PxFEMCloth* cloth, PxU32 triIdx, PxU32 tetIdx) = 0;

        PX_DEPRECATED   virtual     void    removeClothFilter(PxFEMCloth* cloth, PxU32 triIdx, PxU32 tetIdx) = 0;

        PX_DEPRECATED   virtual     void    addVertClothFilter(PxFEMCloth* cloth, PxU32 vertIdx, PxU32 tetIdx) = 0;

        PX_DEPRECATED   virtual     void    removeVertClothFilter(PxFEMCloth* cloth, PxU32 vertIdx, PxU32 tetIdx) = 0;

        PX_DEPRECATED   virtual     PxU32   addClothAttachment(PxFEMCloth* cloth, PxU32 triIdx, const PxVec4& triBarycentric, PxU32 tetIdx, const PxVec4& tetBarycentric,
                                            PxConeLimitedConstraint* constraint = NULL, PxReal constraintOffset = 0.0f) = 0;

        PX_DEPRECATED   virtual     void    removeClothAttachment(PxFEMCloth* cloth, PxU32 handle) = 0;

        virtual     PxBounds3       getWorldBounds(float inflation = 1.01f) const = 0;

        virtual     PxU32           getGpuSoftBodyIndex() = 0;

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

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

    PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec4 PxConfigureSoftBodyKinematicTarget(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 PxConfigureSoftBodyKinematicTarget(const PxVec3& target, bool isActive)
    {
        return PxConfigureSoftBodyKinematicTarget(PxVec4(target, 0.0f), isActive);
    }

#if PX_VC
#pragma warning(pop)
#endif

#if !PX_DOXYGEN
} // namespace physx
#endif

#endif