RavEngine
Loading...
Searching...
No Matches
PxBVH.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_BVH_H
30#define PX_BVH_H
35#include "common/PxBase.h"
36#include "foundation/PxTransform.h"
37#include "foundation/PxBounds3.h"
38#include "geometry/PxGeometryQueryFlags.h"
39#include "geometry/PxReportCallback.h"
40
41#if !PX_DOXYGEN
42namespace physx
43{
44#endif
45
46class PxGeometry;
47
62class PxBVH : public PxBase
63{
64public:
65
77 PX_DEPRECATED virtual PxU32 raycast(const PxVec3& origin, const PxVec3& unitDir, PxReal maxDist, PxU32 maxHits, PxU32* PX_RESTRICT rayHits) const = 0;
78
90 PX_DEPRECATED virtual PxU32 sweep(const PxBounds3& aabb, const PxVec3& unitDir, PxReal maxDist, PxU32 maxHits, PxU32* PX_RESTRICT sweepHits) const = 0;
91
101 PX_DEPRECATED virtual PxU32 overlap(const PxBounds3& aabb, PxU32 maxHits, PxU32* PX_RESTRICT overlapHits) const = 0;
102
104 {
105 RaycastCallback() {}
106 virtual ~RaycastCallback() {}
107
108 // Reports one raycast or sweep hit.
109 // boundsIndex [in] Index of touched bounds
110 // distance [in/out] Impact distance. Shrinks the ray if written out.
111 // return false to abort the query
112 virtual bool reportHit(PxU32 boundsIndex, PxReal& distance) = 0;
113 };
114
116 {
117 OverlapCallback() {}
118 virtual ~OverlapCallback() {}
119
120 // Reports one overlap hit.
121 // boundsIndex [in] Index of touched bounds
122 // return false to abort the query
123 virtual bool reportHit(PxU32 boundsIndex) = 0;
124 };
125
127 {
129 virtual ~TraversalCallback() {}
130
131 // Reports one visited node.
132 // bounds [in] node bounds
133 // return true to continue traversing this branch
134 virtual bool visitNode(const PxBounds3& bounds) = 0;
135
136 // Reports one validated leaf node. Called on leaf nodes after visitNode returns true on them.
137 // nbPrims [in] number of primitives in the node
138 // prims [in] primitives in the node (nbPrims entries)
139 // return false to abort the query
140 virtual bool reportLeaf(PxU32 nbPrims, const PxU32* prims) = 0;
141 };
142
153 virtual bool raycast(const PxVec3& origin, const PxVec3& unitDir, float maxDist, RaycastCallback& cb, PxGeometryQueryFlags queryFlags = PxGeometryQueryFlag::eDEFAULT) const = 0;
154
166 virtual bool sweep(const PxGeometry& geom, const PxTransform& pose, const PxVec3& unitDir, float maxDist, RaycastCallback& cb, PxGeometryQueryFlags queryFlags = PxGeometryQueryFlag::eDEFAULT) const = 0;
167
177 virtual bool overlap(const PxGeometry& geom, const PxTransform& pose, OverlapCallback& cb, PxGeometryQueryFlags queryFlags = PxGeometryQueryFlag::eDEFAULT) const = 0;
178
196 virtual bool cull(PxU32 nbPlanes, const PxPlane* planes, OverlapCallback& cb, PxGeometryQueryFlags queryFlags = PxGeometryQueryFlag::eDEFAULT) const = 0;
197
209 virtual PxU32 getNbBounds() const = 0;
210
218 virtual const PxBounds3* getBounds() const = 0;
219
230 {
231 return const_cast<PxBounds3*>(getBounds());
232 }
233
250 virtual void refit() = 0;
251
269 virtual bool updateBounds(PxU32 boundsIndex, const PxBounds3& newBounds) = 0;
270
279 virtual void partialRefit() = 0;
280
290 virtual bool traverse(TraversalCallback& cb) const = 0;
291
292 virtual const char* getConcreteTypeName() const { return "PxBVH"; }
293protected:
294 PX_INLINE PxBVH(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {}
295 PX_INLINE PxBVH(PxBaseFlags baseFlags) : PxBase(baseFlags) {}
296 virtual ~PxBVH() {}
297
298 virtual bool isKindOf(const char* name) const { return !::strcmp("PxBVH", name) || PxBase::isKindOf(name); }
299};
300
301 struct PxGeomIndexPair;
302
315 PX_C_EXPORT PX_PHYSX_COMMON_API bool PX_CALL_CONV PxFindOverlap(PxReportCallback<PxGeomIndexPair>& callback, const PxBVH& bvh0, const PxBVH& bvh1);
316
318
321 typedef PX_DEPRECATED PxBVH PxBVHStructure;
323
324#if !PX_DOXYGEN
325} // namespace physx
326#endif
327
329#endif
Class representing a bounding volume hierarchy.
Definition PxBVH.h:63
virtual PxU32 getNbBounds() const =0
Returns the number of bounds in the BVH.
virtual bool traverse(TraversalCallback &cb) const =0
Generic BVH traversal function.
virtual void refit()=0
Refit the BVH.
virtual PX_DEPRECATED PxU32 raycast(const PxVec3 &origin, const PxVec3 &unitDir, PxReal maxDist, PxU32 maxHits, PxU32 *PX_RESTRICT rayHits) const =0
Raycast test against a BVH.
virtual bool cull(PxU32 nbPlanes, const PxPlane *planes, OverlapCallback &cb, PxGeometryQueryFlags queryFlags=PxGeometryQueryFlag::eDEFAULT) const =0
Frustum culling test against a BVH.
virtual bool sweep(const PxGeometry &geom, const PxTransform &pose, const PxVec3 &unitDir, float maxDist, RaycastCallback &cb, PxGeometryQueryFlags queryFlags=PxGeometryQueryFlag::eDEFAULT) const =0
Sweep test against a BVH.
virtual bool raycast(const PxVec3 &origin, const PxVec3 &unitDir, float maxDist, RaycastCallback &cb, PxGeometryQueryFlags queryFlags=PxGeometryQueryFlag::eDEFAULT) const =0
Raycast test against a BVH.
virtual bool updateBounds(PxU32 boundsIndex, const PxBounds3 &newBounds)=0
Update single bounds.
virtual PX_DEPRECATED PxU32 overlap(const PxBounds3 &aabb, PxU32 maxHits, PxU32 *PX_RESTRICT overlapHits) const =0
AABB overlap test against a BVH.
virtual const char * getConcreteTypeName() const
Returns string name of dynamic type.
Definition PxBVH.h:292
virtual PX_DEPRECATED PxU32 sweep(const PxBounds3 &aabb, const PxVec3 &unitDir, PxReal maxDist, PxU32 maxHits, PxU32 *PX_RESTRICT sweepHits) const =0
Sweep test against a BVH.
PX_FORCE_INLINE PxBounds3 * getBoundsForModification()
Retrieve the bounds in the BVH.
Definition PxBVH.h:229
virtual bool isKindOf(const char *name) const
Returns whether a given type name matches with the type of this instance.
Definition PxBVH.h:298
virtual void partialRefit()=0
Refits subset of marked nodes.
virtual bool overlap(const PxGeometry &geom, const PxTransform &pose, OverlapCallback &cb, PxGeometryQueryFlags queryFlags=PxGeometryQueryFlag::eDEFAULT) const =0
Overlap test against a BVH.
virtual const PxBounds3 * getBounds() const =0
Retrieve the read-only bounds in the BVH.
Base class for objects that can be members of a PxCollection.
Definition PxBase.h:73
virtual bool isKindOf(const char *superClass) const
Returns whether a given type name matches with the type of this instance.
Definition PxBase.h:179
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
A geometry object.
Definition PxGeometry.h:79
Representation of a plane.
Definition PxPlane.h:49
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
3 Element vector class.
Definition PxVec3.h:50
#define PX_RESTRICT
Definition PxPreprocessor.h:355
#define PX_CALL_CONV
Definition PxPreprocessor.h:299
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
#define PX_DEPRECATED
Definition PxPreprocessor.h:418
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_DEPRECATED PxBVH PxBVHStructure
Definition PxPhysics.h:73
PX_C_EXPORT PX_PHYSX_COMMON_API bool PX_CALL_CONV PxFindOverlap(PxReportCallback< PxGeomIndexPair > &callback, const PxBVH &bvh0, const PxBVH &bvh1)
BVH-vs-BVH overlap test.
Definition GuBVH.cpp:950
Definition PxBVH.h:116
Definition PxBVH.h:104
Definition PxBVH.h:127