include/PxSceneQuerySystem.h

File members: include/PxSceneQuerySystem.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_SCENE_QUERY_SYSTEM_H
#define PX_SCENE_QUERY_SYSTEM_H

#include "foundation/PxSimpleTypes.h"
#include "foundation/PxBitMap.h"
#include "foundation/PxTransform.h"
#include "PxSceneQueryDesc.h"
#include "PxQueryReport.h"
#include "PxQueryFiltering.h"
#include "geometry/PxGeometryQueryFlags.h"

#if !PX_DOXYGEN
namespace physx
{
#endif

    class PxBaseTask;
    class PxRenderOutput;
    class PxGeometry;
    class PxRigidActor;
    class PxShape;
    class PxBVH;
    class PxPruningStructure;

    enum PxScenePrunerIndex
    {
        PX_SCENE_PRUNER_STATIC      = 0,
        PX_SCENE_PRUNER_DYNAMIC     = 1,
        PX_SCENE_COMPOUND_PRUNER    = 0xffffffff
    };

    class PxSceneQuerySystemBase
    {
        protected:
                        PxSceneQuerySystemBase()    {}
        virtual         ~PxSceneQuerySystemBase()   {}

        public:

        //\{

        virtual void    setDynamicTreeRebuildRateHint(PxU32 dynamicTreeRebuildRateHint) = 0;

        virtual PxU32   getDynamicTreeRebuildRateHint() const = 0;

        virtual void    forceRebuildDynamicTree(PxU32 prunerIndex)  = 0;

        virtual void    setUpdateMode(PxSceneQueryUpdateMode::Enum updateMode)  = 0;

        virtual PxSceneQueryUpdateMode::Enum    getUpdateMode() const   = 0;

        virtual PxU32   getStaticTimestamp()    const   = 0;

        virtual void    flushUpdates()  = 0;

        virtual bool    raycast(const PxVec3& origin, const PxVec3& unitDir, const PxReal distance,
                                PxRaycastCallback& hitCall, PxHitFlags hitFlags = PxHitFlag::eDEFAULT,
                                const PxQueryFilterData& filterData = PxQueryFilterData(), PxQueryFilterCallback* filterCall = NULL,
                                const PxQueryCache* cache = NULL, PxGeometryQueryFlags queryFlags = PxGeometryQueryFlag::eDEFAULT) const = 0;

        virtual bool    sweep(  const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance,
                                PxSweepCallback& hitCall, PxHitFlags hitFlags = PxHitFlag::eDEFAULT,
                                const PxQueryFilterData& filterData = PxQueryFilterData(), PxQueryFilterCallback* filterCall = NULL,
                                const PxQueryCache* cache = NULL, const PxReal inflation = 0.0f, PxGeometryQueryFlags queryFlags = PxGeometryQueryFlag::eDEFAULT) const = 0;

        virtual bool    overlap(const PxGeometry& geometry, const PxTransform& pose, PxOverlapCallback& hitCall,
                                const PxQueryFilterData& filterData = PxQueryFilterData(), PxQueryFilterCallback* filterCall = NULL,
                                const PxQueryCache* cache = NULL, PxGeometryQueryFlags queryFlags = PxGeometryQueryFlag::eDEFAULT) const = 0;
        //\}
    };

    class PxSceneSQSystem : public PxSceneQuerySystemBase
    {
        protected:
                    PxSceneSQSystem()   {}
        virtual     ~PxSceneSQSystem()  {}

        public:

        //\{

        PX_FORCE_INLINE void    setSceneQueryUpdateMode(PxSceneQueryUpdateMode::Enum updateMode)    { setUpdateMode(updateMode);    }

        PX_FORCE_INLINE PxSceneQueryUpdateMode::Enum    getSceneQueryUpdateMode()   const   { return getUpdateMode();   }

        PX_FORCE_INLINE PxU32   getSceneQueryStaticTimestamp()  const   { return getStaticTimestamp();  }

        PX_FORCE_INLINE void    flushQueryUpdates() { flushUpdates();   }

        PX_FORCE_INLINE void    forceDynamicTreeRebuild(bool rebuildStaticStructure, bool rebuildDynamicStructure)
        {
            if(rebuildStaticStructure)
                forceRebuildDynamicTree(PX_SCENE_PRUNER_STATIC);
            if(rebuildDynamicStructure)
                forceRebuildDynamicTree(PX_SCENE_PRUNER_DYNAMIC);
        }

        virtual PxPruningStructureType::Enum getStaticStructure() const = 0;

        virtual PxPruningStructureType::Enum getDynamicStructure() const = 0;

        virtual void    sceneQueriesUpdate(PxBaseTask* completionTask = NULL, bool controlSimulation = true)    = 0;

        virtual bool    checkQueries(bool block = false) = 0;

        virtual bool    fetchQueries(bool block = false)    = 0;
        //\}
    };

    typedef PxU32   PxSQCompoundHandle;
    typedef PxU32   PxSQPrunerHandle;
    typedef void*   PxSQBuildStepHandle;

    class PxSceneQuerySystem : public PxSceneQuerySystemBase
    {
        protected:
                        PxSceneQuerySystem()    {}
        virtual         ~PxSceneQuerySystem()   {}
        public:

        virtual void    release()   = 0;

        virtual void    acquireReference()  = 0;

        virtual void    preallocate(PxU32 prunerIndex, PxU32 nbShapes)  = 0;

        virtual void    flushMemory()   = 0;

        virtual void    addSQShape( const PxRigidActor& actor, const PxShape& shape, const PxBounds3& bounds,
                                    const PxTransform& transform, const PxSQCompoundHandle* compoundHandle=NULL, bool hasPruningStructure=false)    = 0;

        virtual void    removeSQShape(const PxRigidActor& actor, const PxShape& shape)  = 0;

        virtual void    updateSQShape(const PxRigidActor& actor, const PxShape& shape, const PxTransform& transform)    = 0;

        virtual PxSQCompoundHandle  addSQCompound(const PxRigidActor& actor, const PxShape** shapes, const PxBVH& bvh, const PxTransform* transforms)   = 0;

        virtual void    removeSQCompound(PxSQCompoundHandle compoundHandle) = 0;

        virtual void    updateSQCompound(PxSQCompoundHandle compoundHandle, const PxTransform& compoundTransform)   = 0;

        virtual void    shiftOrigin(const PxVec3& shift)    = 0;

        virtual void    visualize(PxU32 prunerIndex, PxRenderOutput& out)   const   = 0;

        virtual void    merge(const PxPruningStructure& pruningStructure)   = 0;

        virtual PxSQPrunerHandle    getHandle(const PxRigidActor& actor, const PxShape& shape, PxU32& prunerIndex)  const   = 0;

        virtual void    sync(PxU32 prunerIndex, const PxSQPrunerHandle* handles, const PxU32* indices, const PxBounds3* bounds, const PxTransform32* transforms, PxU32 count, const PxBitMap& ignoredIndices)   = 0;

        virtual void    finalizeUpdates()   = 0;

        virtual PxSQBuildStepHandle prepareSceneQueryBuildStep(PxU32 prunerIndex)   = 0;

        virtual void    sceneQueryBuildStep(PxSQBuildStepHandle handle) = 0;
    };

#if !PX_DOXYGEN
} // namespace physx
#endif

#endif