Program Listing for include/PxFiltering.h

↰ Return to documentation for include/PxFiltering.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-2022 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_FILTERING_H
#define PX_FILTERING_H

#include "PxPhysXConfig.h"
#include "foundation/PxFlags.h"

#if !PX_DOXYGEN
namespace physx
{
#endif

class PxActor;
class PxShape;

static const PxU32 INVALID_FILTER_PAIR_INDEX = 0xffffffff;

struct PxPairFlag
{
    enum Enum
    {
        eSOLVE_CONTACT                      = (1<<0),

        eMODIFY_CONTACTS                    = (1<<1),

        eNOTIFY_TOUCH_FOUND                 = (1<<2),

        eNOTIFY_TOUCH_PERSISTS              = (1<<3),

        eNOTIFY_TOUCH_LOST                  = (1<<4),

        eNOTIFY_TOUCH_CCD                   = (1<<5),

        eNOTIFY_THRESHOLD_FORCE_FOUND       = (1<<6),

        eNOTIFY_THRESHOLD_FORCE_PERSISTS    = (1<<7),

        eNOTIFY_THRESHOLD_FORCE_LOST        = (1<<8),

        eNOTIFY_CONTACT_POINTS              = (1<<9),

        eDETECT_DISCRETE_CONTACT            = (1<<10),

        eDETECT_CCD_CONTACT                 = (1<<11),

        ePRE_SOLVER_VELOCITY                = (1<<12),

        ePOST_SOLVER_VELOCITY               = (1<<13),

        eCONTACT_EVENT_POSE                 = (1<<14),

        eNEXT_FREE                          = (1<<15),

        eCONTACT_DEFAULT                    = eSOLVE_CONTACT | eDETECT_DISCRETE_CONTACT,

        eTRIGGER_DEFAULT                    = eNOTIFY_TOUCH_FOUND | eNOTIFY_TOUCH_LOST | eDETECT_DISCRETE_CONTACT
    };
};

typedef PxFlags<PxPairFlag::Enum, PxU16> PxPairFlags;
PX_FLAGS_OPERATORS(PxPairFlag::Enum, PxU16)




struct PxFilterFlag
{
    enum Enum
    {
        eKILL               = (1<<0),

        eSUPPRESS           = (1<<1),

        eCALLBACK           = (1<<2),

        eNOTIFY             = (1<<3) | eCALLBACK,

        eDEFAULT = 0
    };
};

typedef PxFlags<PxFilterFlag::Enum, PxU16> PxFilterFlags;
PX_FLAGS_OPERATORS(PxFilterFlag::Enum, PxU16)



struct PxFilterData
{
//= ATTENTION! =====================================================================================
// Changing the data layout of this class breaks the binary serialization format.  See comments for
// PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData
// function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
// accordingly.
//==================================================================================================

    PX_INLINE PxFilterData(const PxEMPTY)
    {
    }

    PX_INLINE PxFilterData()
    {
        word0 = word1 = word2 = word3 = 0;
    }

    PX_INLINE PxFilterData(const PxFilterData& fd) : word0(fd.word0), word1(fd.word1), word2(fd.word2), word3(fd.word3) {}

    PX_INLINE PxFilterData(PxU32 w0, PxU32 w1, PxU32 w2, PxU32 w3) : word0(w0), word1(w1), word2(w2), word3(w3) {}

    PX_INLINE void setToDefault()
    {
        *this = PxFilterData();
    }

    PX_INLINE void operator = (const PxFilterData& fd)
    {
        word0 = fd.word0;
        word1 = fd.word1;
        word2 = fd.word2;
        word3 = fd.word3;
    }

    PX_INLINE bool operator == (const PxFilterData& a) const
    {
        return a.word0 == word0 && a.word1 == word1 && a.word2 == word2 && a.word3 == word3;
    }

    PX_INLINE bool operator != (const PxFilterData& a) const
    {
        return !(a == *this);
    }

    PxU32 word0;
    PxU32 word1;
    PxU32 word2;
    PxU32 word3;
};


struct PxFilterObjectType
{
    enum Enum
    {
        eRIGID_STATIC,

        eRIGID_DYNAMIC,

        eARTICULATION,

        ePARTICLESYSTEM,

        eSOFTBODY,

        eFEMCLOTH,

        eHAIRSYSTEM,

        eMAX_TYPE_COUNT = 16,

        eUNDEFINED = eMAX_TYPE_COUNT-1
    };
};


// For internal use only
struct PxFilterObjectFlag
{
    enum Enum
    {
        eKINEMATIC      = (1<<4),
        eTRIGGER        = (1<<5)
    };
};


typedef PxU32 PxFilterObjectAttributes;


PX_INLINE PxFilterObjectType::Enum PxGetFilterObjectType(PxFilterObjectAttributes attr)
{
    return PxFilterObjectType::Enum(attr & (PxFilterObjectType::eMAX_TYPE_COUNT-1));
}


PX_INLINE bool PxFilterObjectIsKinematic(PxFilterObjectAttributes attr)
{
    return (attr & PxFilterObjectFlag::eKINEMATIC) != 0;
}


PX_INLINE bool PxFilterObjectIsTrigger(PxFilterObjectAttributes attr)
{
    return (attr & PxFilterObjectFlag::eTRIGGER) != 0;
}

typedef PxFilterFlags (*PxSimulationFilterShader)
    (PxFilterObjectAttributes attributes0, PxFilterData filterData0,
     PxFilterObjectAttributes attributes1, PxFilterData filterData1,
     PxPairFlags& pairFlags, const void* constantBlock, PxU32 constantBlockSize);



class PxSimulationFilterCallback
{
public:

    virtual     PxFilterFlags   pairFound(  PxU32 pairID,
        PxFilterObjectAttributes attributes0, PxFilterData filterData0, const PxActor* a0, const PxShape* s0,
        PxFilterObjectAttributes attributes1, PxFilterData filterData1, const PxActor* a1, const PxShape* s1,
        PxPairFlags& pairFlags) = 0;

    virtual     void            pairLost(   PxU32 pairID,
        PxFilterObjectAttributes attributes0,
        PxFilterData filterData0,
        PxFilterObjectAttributes attributes1,
        PxFilterData filterData1,
        bool objectRemoved) = 0;

    virtual     bool            statusChange(PxU32& pairID, PxPairFlags& pairFlags, PxFilterFlags& filterFlags) = 0;

protected:
    virtual                     ~PxSimulationFilterCallback() {}
};

struct PxPairFilteringMode
{
    enum Enum
    {
        eKEEP,

        eSUPPRESS,

        eKILL,

        eDEFAULT = eSUPPRESS
    };
};

struct PxParticleRigidFilterPair
{
    PxU64 mID0;
    PxU64 mID1;

    PX_CUDA_CALLABLE bool operator<(const PxParticleRigidFilterPair& other) const
    {
        if(mID0 < other.mID0)
            return true;
        if(mID0 == other.mID0 && mID1 < other.mID1)
            return true;
        return false;
    }

    PX_CUDA_CALLABLE bool operator>(const PxParticleRigidFilterPair& other) const
    {
        if(mID0 > other.mID0)
            return true;
        if(mID0 == other.mID0 && mID1 > other.mID1)
            return true;
        return false;
    }

    PX_CUDA_CALLABLE bool operator==(const PxParticleRigidFilterPair& other) const
    {
        return (mID0 == other.mID0 && mID1 == other.mID1);
    }
};


#if !PX_DOXYGEN
} // namespace physx
#endif

#endif