RavEngine
Loading...
Searching...
No Matches
NpPvdSceneQueryCollector.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 NP_PVD_SCENEQUERYCOLLECTOR_H
30#define NP_PVD_SCENEQUERYCOLLECTOR_H
31
32#include "geometry/PxGeometryHelpers.h"
33#include "PxFiltering.h"
34#include "PxQueryReport.h"
35#include "PxQueryFiltering.h"
36
37#include "foundation/PxArray.h"
38#include "foundation/PxMutex.h"
39
40#if PX_SUPPORT_PVD
41
42namespace physx
43{
44namespace Vd
45{
46 class PvdSceneClient;
47
48 struct QueryID { enum Enum {
49 QUERY_RAYCAST_ANY_OBJECT,
50 QUERY_RAYCAST_CLOSEST_OBJECT,
51 QUERY_RAYCAST_ALL_OBJECTS,
52
53 QUERY_OVERLAP_SPHERE_ALL_OBJECTS,
54 QUERY_OVERLAP_AABB_ALL_OBJECTS,
55 QUERY_OVERLAP_OBB_ALL_OBJECTS,
56 QUERY_OVERLAP_CAPSULE_ALL_OBJECTS,
57 QUERY_OVERLAP_CONVEX_ALL_OBJECTS,
58
59 QUERY_LINEAR_OBB_SWEEP_CLOSEST_OBJECT,
60 QUERY_LINEAR_CAPSULE_SWEEP_CLOSEST_OBJECT,
61 QUERY_LINEAR_CONVEX_SWEEP_CLOSEST_OBJECT
62 }; };
63
64struct PvdReference
65{
66 PX_FORCE_INLINE PvdReference() {}
67 PX_FORCE_INLINE PvdReference(const char* arrayName, PxU32 baseIndex, PxU32 count) : mArrayName(arrayName), mBaseIndex(baseIndex), mCount(count) {}
68
69 const char* mArrayName;
70 PxU32 mBaseIndex;
71 PxU32 mCount;
72};
73
74struct PvdRaycast
75{
76 PxU32 mType;
77 PxFilterData mFilterData;
78 PxU32 mFilterFlags;
79 PxVec3 mOrigin;
80 PxVec3 mUnitDir;
81 PxReal mDistance;
82 PvdReference mHits;
83};
84
85struct PvdOverlap
86{
87 PxU32 mType;
88 PxFilterData mFilterData;
89 PxU32 mFilterFlags;
90 PxTransform mPose;
91 PvdReference mGeometries;
92 PvdReference mHits;
93};
94
95struct PvdSweep
96{
97 PxU32 mType;
98 PxU32 mFilterFlags;
99 PxVec3 mUnitDir;
100 PxReal mDistance;
101 PvdReference mGeometries;
102 PvdReference mPoses;
103 PvdReference mFilterData;
104 PvdReference mHits;
105};
106
107struct PvdSqHit
108{
109 const void* mShape;
110 const void* mActor;
111 PxU32 mFaceIndex;
112 PxU32 mFlags;
113 PxVec3 mImpact;
114 PxVec3 mNormal;
115 PxF32 mDistance;
116 PxF32 mU;
117 PxF32 mV;
118
119 PvdSqHit()
120 {
121 setDefaults(0xFFFFffff, NULL, NULL);
122 }
123
124 explicit PvdSqHit(const PxOverlapHit& hit)
125 {
126 setDefaults(hit.faceIndex, hit.shape, hit.actor);
127 }
128
129 explicit PvdSqHit(const PxRaycastHit& hit)
130 {
131 setDefaults(hit.faceIndex, hit.shape, hit.actor);
132
133 mImpact = hit.position;
134 mNormal = hit.normal;
135 mDistance = hit.distance;
136 mFlags = hit.flags;
137 mU = hit.u;
138 mV = hit.v;
139 }
140
141 explicit PvdSqHit(const PxSweepHit& hit)
142 {
143 setDefaults(hit.faceIndex, hit.shape, hit.actor);
144
145 mImpact = hit.position;
146 mNormal = hit.normal;
147 mDistance = hit.distance;
148 mFlags = hit.flags;
149 }
150
151 private:
152 void setDefaults(PxU32 faceIndex, const void* shape, const void* actor)
153 {
154 mShape = shape;
155 mActor = actor;
156 mFaceIndex = faceIndex;
157 mFlags = 0;
158 mImpact = mNormal = PxVec3(0.0f);
159 mDistance = mU = mV = 0.0f;
160 }
161};
162
163template <class T>
164class NamedArray : public PxArray<T>
165{
166 public:
167 NamedArray(const char* names[2]) { mNames[0] = names[0]; mNames[1] = names[1]; }
168
169 const char* mNames[2];
170};
171
172class PvdSceneQueryCollector
173{
174 PX_NOCOPY(PvdSceneQueryCollector)
175public:
176 PvdSceneQueryCollector(Vd::PvdSceneClient* pvd, bool isBatched);
177 ~PvdSceneQueryCollector() {}
178
179 void clear()
180 {
181 PxMutex::ScopedLock lock(mMutex);
182
183 mAccumulatedRaycastQueries.clear();
184 mAccumulatedOverlapQueries.clear();
185 mAccumulatedSweepQueries.clear();
186 mPvdSqHits.clear();
187 mPoses.clear();
188 mFilterData.clear();
189 }
190
191 void clearGeometryArrays()
192 {
193 mGeometries0.clear();
194 mGeometries1.clear();
195 }
196
197 void release();
198
199 void raycast(const PxVec3& origin, const PxVec3& unitDir, PxReal distance, const PxRaycastHit* hit, PxU32 hitsNum, const PxQueryFilterData& filterData, bool multipleHits);
200 void sweep(const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, PxReal distance, const PxSweepHit* hit, PxU32 hitsNum, const PxQueryFilterData& filterData, bool multipleHits);
201 void overlapMultiple(const PxGeometry& geometry, const PxTransform& pose, const PxOverlapHit* hit, PxU32 hitsNum, const PxQueryFilterData& filterData);
202
203 PX_FORCE_INLINE PxMutex& getLock() { return mMutex; }
204
205 template <class T>
206 PX_FORCE_INLINE const char* getArrayName(const NamedArray<T>& namedArray) const { return namedArray.mNames[mIsBatched]; }
207
208 PX_FORCE_INLINE const NamedArray<PxGeometryHolder>& getGeometries(PxU32 index) const { return index ? mGeometries1 : mGeometries0; }
209 PX_FORCE_INLINE NamedArray<PxGeometryHolder>& getGeometries(PxU32 index) { return index ? mGeometries1 : mGeometries0; }
210
211 PX_FORCE_INLINE const NamedArray<PxGeometryHolder>& getCurrentFrameGeometries() const { return getGeometries(mInUse); }
212 PX_FORCE_INLINE const NamedArray<PxGeometryHolder>& getPrevFrameGeometries() const { return getGeometries(mInUse ^ 1); }
213
214 void prepareNextFrameGeometries()
215 {
216 mInUse ^= 1;
217 getGeometries(mInUse).clear();
218 }
219
220 NamedArray<PvdRaycast> mAccumulatedRaycastQueries;
221 NamedArray<PvdSweep> mAccumulatedSweepQueries;
222 NamedArray<PvdOverlap> mAccumulatedOverlapQueries;
223 NamedArray<PvdSqHit> mPvdSqHits;
224 NamedArray<PxTransform> mPoses;
225 NamedArray<PxFilterData> mFilterData;
226
227private:
228 Vd::PvdSceneClient* mPVD;
229 PxMutex mMutex;
230 NamedArray<PxGeometryHolder>mGeometries0;
231 NamedArray<PxGeometryHolder>mGeometries1;
232 PxU32 mInUse;
233 const bool mIsBatched;
234};
235}
236}
237
238#endif // PX_SUPPORT_PVD
239
240#endif // NP_PVD_SCENEQUERYCOLLECTOR_H
#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