29#ifndef GU_QUERY_SYSTEM_H
30#define GU_QUERY_SYSTEM_H
32#include "foundation/PxUserAllocated.h"
33#include "foundation/PxBitMap.h"
34#include "foundation/PxArray.h"
35#include "foundation/PxMutex.h"
36#include "foundation/PxBounds3.h"
38#include "GuActorShapeMap.h"
63 virtual bool processPruner(PxU32 prunerIndex)
const = 0;
66 typedef PxU32 PrunerInfo;
67 PX_FORCE_INLINE PrunerInfo createPrunerInfo(PxU32 prunerIndex,
bool isDynamic) {
return (prunerIndex << 1) | PxU32(isDynamic); }
68 PX_FORCE_INLINE PxU32 getPrunerIndex(PrunerInfo info) {
return PxU32(info)>>1; }
69 PX_FORCE_INLINE PxU32 getDynamic(PrunerInfo info) {
return PxU32(info) & 1; }
71 PX_FORCE_INLINE ActorShapeData createActorShapeData(PrunerInfo info, PrunerHandle h) {
return (ActorShapeData(h) << 32) | ActorShapeData(info); }
72 PX_FORCE_INLINE PrunerInfo getPrunerInfo(ActorShapeData data) {
return PrunerInfo(data); }
73 PX_FORCE_INLINE PrunerHandle getPrunerHandle(ActorShapeData data) {
return PrunerHandle(data >> 32); }
75 #define INVALID_ACTOR_SHAPE_DATA PxU64(-1)
87 void addToDirtyList(PrunerHandle handle, PxU32 dynamic,
const PxTransform& transform,
const PxBounds3* userBounds=NULL);
88 void removeFromDirtyList(PrunerHandle handle);
89 bool processDirtyList(
const Adapter& adapter,
float inflation);
109 PX_PHYSX_COMMON_API
QuerySystem(PxU64 contextID,
float inflation,
const Adapter& adapter,
bool usesTreeOfPruners=
false);
114 PX_FORCE_INLINE PxU32 getStaticTimestamp()
const {
return mStaticTimestamp; }
116 PX_PHYSX_COMMON_API PxU32 addPruner(Pruner* pruner, PxU32 preallocated);
117 PX_PHYSX_COMMON_API
void removePruner(PxU32 prunerIndex);
118 PX_FORCE_INLINE PxU32 getNbPruners()
const {
return mPrunerExt.size(); }
119 PX_FORCE_INLINE const Pruner* getPruner(PxU32 index)
const {
return mPrunerExt[index]->mPruner; }
120 PX_FORCE_INLINE Pruner* getPruner(PxU32 index) {
return mPrunerExt[index]->mPruner; }
122 PX_PHYSX_COMMON_API ActorShapeData addPrunerShape(
const PrunerPayload& payload, PxU32 prunerIndex,
bool dynamic,
const PxTransform& transform,
const PxBounds3* userBounds=NULL);
123 PX_PHYSX_COMMON_API
void removePrunerShape(ActorShapeData data, PrunerPayloadRemovalCallback* removalCallback);
124 PX_PHYSX_COMMON_API
void updatePrunerShape(ActorShapeData data,
bool immediately,
const PxTransform& transform,
const PxBounds3* userBounds=NULL);
126 PX_PHYSX_COMMON_API
const PrunerPayload& getPayloadData(ActorShapeData data, PrunerPayloadData* ppd=NULL)
const;
128 PX_PHYSX_COMMON_API
void commitUpdates();
129 PX_PHYSX_COMMON_API
void update(
bool buildStep,
bool commit);
130 PX_PHYSX_COMMON_API
void sync(PxU32 prunerIndex,
const PrunerHandle* handles,
const PxU32* boundsIndices,
const PxBounds3* bounds,
const PxTransform32* transforms, PxU32 count);
132 PX_PHYSX_COMMON_API
void flushMemory();
134 PX_PHYSX_COMMON_API
void raycast(
const PxVec3& origin,
const PxVec3& unitDir,
float& inOutDistance, PrunerRaycastCallback& cb,
const PrunerFilter* prunerFilter)
const;
135 PX_PHYSX_COMMON_API
void overlap(
const ShapeData& queryVolume, PrunerOverlapCallback& cb,
const PrunerFilter* prunerFilter)
const;
136 PX_PHYSX_COMMON_API
void sweep(
const ShapeData& queryVolume,
const PxVec3& unitDir,
float& inOutDistance, PrunerRaycastCallback& cb,
const PrunerFilter* prunerFilter)
const;
138 PxU32 startCustomBuildstep();
139 void customBuildstep(PxU32 index);
140 void finishCustomBuildstep();
142 void createTreeOfPruners();
144 const Adapter& mAdapter;
145 PxArray<PrunerExt*> mPrunerExt;
146 PxArray<PxU32> mDirtyPruners;
147 PxArray<PxU32> mFreePruners;
149 Gu::BVH* mTreeOfPruners;
151 const PxU64 mContextID;
152 PxU32 mStaticTimestamp;
153 const float mInflation;
157 volatile bool mPrunerNeedsUpdating;
158 volatile bool mTimestampNeedsUpdating;
159 const bool mUsesTreeOfPruners;
161 void processDirtyLists();
162 PX_FORCE_INLINE void invalidateStaticTimestamp() { mStaticTimestamp++; }
164 PX_NOCOPY(QuerySystem)
170#include "geometry/PxGeometryHit.h"
171#include "geometry/PxSphereGeometry.h"
172#include "geometry/PxCapsuleGeometry.h"
173#include "geometry/PxBoxGeometry.h"
174#include "geometry/PxConvexMeshGeometry.h"
175#include "GuCachedFuncs.h"
176#include "GuCapsule.h"
180#pragma warning(disable: 4355 )
203 const GeomRaycastTable& mCachedRaycastFuncs;
207 const PxU32 mMaxLocalHits;
208 const PxHitFlags mHitFlags;
216 mFilterCB (filterCB),
217 mCachedRaycastFuncs (funcs),
220 mLocalHits (localHits),
221 mMaxLocalHits (maxLocalHits),
222 mHitFlags (hitFlags),
236 PX_ASSERT(payloads && transforms);
240 PxHitFlags filteredHitFlags = mHitFlags;
241 const PxGeometry* shapeGeom = mFilterCB.validatePayload(payload, filteredHitFlags);
245 const RaycastFunc func = mCachedRaycastFuncs[shapeGeom->
getType()];
246 const PxU32 nbHits = func(*shapeGeom, transforms[primIndex], mOrigin, mDir, aDist, filteredHitFlags, mMaxLocalHits, mLocalHits,
sizeof(
PxGeomRaycastHit), mContext);
247 if(!nbHits || !reportHits(payload, nbHits, mLocalHits))
258 mClosestHit = localHit;
259 mClosestPayload = payload;
287 const GeomOverlapTable* mCachedFuncs;
294 mFilterCB (filterCB),
295 mCachedFuncs (funcs),
296 mGeometry (geometry),
308 PX_ASSERT(payloads && transforms);
312 const PxGeometry* shapeGeom = mFilterCB.validatePayload(payload, mUnused);
313 if(!shapeGeom || !Gu::overlap(mGeometry, mPose, *shapeGeom, transforms[primIndex], mCachedFuncs, mContext))
316 return reportHit(payload);
328 PX_ASSERT(queryGeom.
getType()==PxGeometryType::eBOX);
330 const SweepBoxFunc func = precise ? sf.preciseBoxMap[geom.
getType()] : sf.boxMap[geom.
getType()];
331 return PxU32(func(geom, pose,
static_cast<const PxBoxGeometry&
>(queryGeom), queryPose, queryVolume.getGuBox(), unitDir, distance, sweepHit, hitFlags, inflation,
context));
341 PX_ASSERT(queryGeom.
getType()==PxGeometryType::eSPHERE);
346 const Capsule worldCapsule(queryPose.p, queryPose.p, sphereGeom.
radius);
348 const SweepCapsuleFunc func = precise ? sf.preciseCapsuleMap[geom.
getType()] : sf.capsuleMap[geom.
getType()];
349 return PxU32(func(geom, pose, capsuleGeom, queryPose, worldCapsule, unitDir, distance, sweepHit, hitFlags, inflation,
context));
359 PX_ASSERT(queryGeom.
getType()==PxGeometryType::eCAPSULE);
361 const SweepCapsuleFunc func = precise ? sf.preciseCapsuleMap[geom.
getType()] : sf.capsuleMap[geom.
getType()];
362 return PxU32(func(geom, pose,
static_cast<const PxCapsuleGeometry&
>(queryGeom), queryPose, queryVolume.getGuCapsule(), unitDir, distance, sweepHit, hitFlags, inflation,
context));
372 PX_ASSERT(queryGeom.
getType()==PxGeometryType::eCONVEXMESH);
373 const SweepConvexFunc func = sf.convexMap[geom.
getType()];
374 return PxU32(func(geom, pose,
static_cast<const PxConvexMeshGeometry&
>(queryGeom), queryPose, unitDir, distance, sweepHit, hitFlags, inflation,
context));
386 template<
class ShapeCast>
397 const PxHitFlags mHitFlags;
407 mFilterCB (filterCB),
408 mCachedFuncs (funcs),
409 mGeometry (geometry),
411 mQueryVolume (queryVolume),
413 mHitFlags (hitFlags),
422 PX_ASSERT(payloads && transforms);
426 PxHitFlags filteredHitFlags = mHitFlags;
427 const PxGeometry* shapeGeom = mFilterCB.validatePayload(payload, filteredHitFlags);
433 const float inflation = 0.0f;
434 const PxU32 retVal = ShapeCast::sweep(mCachedFuncs, *shapeGeom, transforms[primIndex], mGeometry, mPose, mQueryVolume, mDir, aDist, mLocalHit, filteredHitFlags, inflation, mContext);
436 if(!retVal || !reportHit(payload, mLocalHit))
446 mClosestHit = mLocalHit;
447 mClosestPayload = payload;
Definition GuQuerySystem.h:49
Represents a capsule.
Definition GuCapsule.h:47
Definition GuQuerySystem.h:58
Definition GuQuerySystem.h:78
Definition GuBounds.h:115
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
Class representing the geometry of a box.
Definition PxBoxGeometry.h:49
Class representing the geometry of a capsule.
Definition PxCapsuleGeometry.h:54
Convex mesh geometry class.
Definition PxConvexMeshGeometry.h:79
A geometry object.
Definition PxGeometry.h:79
PX_CUDA_CALLABLE PX_FORCE_INLINE PxGeometryType::Enum getType() const
Returns the type of the geometry.
Definition PxGeometry.h:85
A class representing the geometry of a sphere.
Definition PxSphereGeometry.h:48
PxReal radius
The radius of the sphere.
Definition PxSphereGeometry.h:88
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition GuQuerySystem.h:323
Definition GuQuerySystem.h:354
Definition GuQuerySystem.h:367
Definition GuQuerySystem.h:284
Definition GuQuerySystem.h:268
Definition GuQuerySystem.h:200
Definition GuQuerySystem.h:276
Definition GuQuerySystem.h:388
Definition GuQuerySystem.h:379
Definition GuSweepTests.h:101
Definition GuQuerySystem.h:192
Definition GuPrunerPayload.h:43
Definition GuQuerySystem.h:99
Definition GuQuerySystem.h:81
Definition GuQuerySystem.h:336
Stores results of raycast queries.
Definition PxGeometryHit.h:151
Stores results of sweep queries.
Definition PxGeometryHit.h:175
@ eANY_HIT
Definition PxGeometryHit.h:65
@ ePRECISE_SWEEP
Definition PxGeometryHit.h:72
PxF32 distance
Distance to hit.
Definition PxGeometryHit.h:136
A per-thread context passed to low-level query functions.
Definition PxGeometryQueryContext.h:52