include/geometry/PxBVH.h

File members: include/geometry/PxBVH.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_BVH_H
#define PX_BVH_H

#include "common/PxBase.h"
#include "foundation/PxTransform.h"
#include "foundation/PxBounds3.h"
#include "geometry/PxGeometryQueryFlags.h"
#include "geometry/PxReportCallback.h"

#if !PX_DOXYGEN
namespace physx
{
#endif

class PxGeometry;

class PxBVH : public PxBase
{
public:

    struct RaycastCallback
    {
                        RaycastCallback()   {}
        virtual         ~RaycastCallback()  {}

        // Reports one raycast or sweep hit.
        // boundsIndex  [in]        Index of touched bounds
        // distance     [in/out]    Impact distance. Shrinks the ray if written out.
        // return false to abort the query
        virtual bool    reportHit(PxU32 boundsIndex, PxReal& distance) = 0;
    };

    struct OverlapCallback
    {
                        OverlapCallback()   {}
        virtual         ~OverlapCallback()  {}

        // Reports one overlap hit.
        // boundsIndex  [in] Index of touched bounds
        // return false to abort the query
        virtual bool    reportHit(PxU32 boundsIndex) = 0;
    };

    struct TraversalCallback
    {
                        TraversalCallback()     {}
        virtual         ~TraversalCallback()    {}

        // Reports one visited node.
        // bounds   [in] node bounds
        // return true to continue traversing this branch
        virtual bool    visitNode(const PxBounds3& bounds) = 0;

        // Reports one validated leaf node. Called on leaf nodes after visitNode returns true on them.
        // nbPrims  [in] number of primitives in the node
        // prims    [in] primitives in the node (nbPrims entries)
        // return false to abort the query
        virtual bool    reportLeaf(PxU32 nbPrims, const PxU32* prims) = 0;
    };

    virtual bool                raycast(const PxVec3& origin, const PxVec3& unitDir, float maxDist, RaycastCallback& cb, PxGeometryQueryFlags queryFlags = PxGeometryQueryFlag::eDEFAULT) const = 0;

    virtual bool                sweep(const PxGeometry& geom, const PxTransform& pose, const PxVec3& unitDir, float maxDist, RaycastCallback& cb, PxGeometryQueryFlags queryFlags = PxGeometryQueryFlag::eDEFAULT) const = 0;

    virtual bool                overlap(const PxGeometry& geom, const PxTransform& pose, OverlapCallback& cb, PxGeometryQueryFlags queryFlags = PxGeometryQueryFlag::eDEFAULT) const = 0;

    virtual bool                cull(PxU32 nbPlanes, const PxPlane* planes, OverlapCallback& cb, PxGeometryQueryFlags queryFlags = PxGeometryQueryFlag::eDEFAULT) const = 0;

    virtual PxU32               getNbBounds() const = 0;

    virtual const PxBounds3*    getBounds() const = 0;

    PX_FORCE_INLINE PxBounds3*  getBoundsForModification()
                                {
                                    return const_cast<PxBounds3*>(getBounds());
                                }

    virtual void                refit() = 0;

    virtual bool                updateBounds(PxU32 boundsIndex, const PxBounds3& newBounds) = 0;

    virtual void                partialRefit()  = 0;

    virtual bool                traverse(TraversalCallback& cb) const   = 0;

    virtual const char*         getConcreteTypeName() const { return "PxBVH";   }
protected:
    PX_INLINE                   PxBVH(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {}
    PX_INLINE                   PxBVH(PxBaseFlags baseFlags) : PxBase(baseFlags)                                    {}
    virtual                     ~PxBVH()                                                                            {}

    virtual bool                isKindOf(const char* name) const { PX_IS_KIND_OF(name, "PxBVH", PxBase); }
};

    struct PxGeomIndexPair;

    PX_C_EXPORT PX_PHYSX_COMMON_API bool PX_CALL_CONV PxFindOverlap(PxReportCallback<PxGeomIndexPair>& callback, const PxBVH& bvh0, const PxBVH& bvh1);

#if !PX_DOXYGEN
} // namespace physx
#endif

#endif