29#include "GuSweepTriangleUtils.h"
30#include "GuSweepBoxTriangle_FeatureBased.h"
31#include "GuSweepBoxTriangle_SAT.h"
32#include "GuBV4_BoxOverlap_Internal.h"
43 BV4_ALIGN16(
PxVec3p mCenterOrMinCoeff_PaddedAligned);
44 BV4_ALIGN16(
PxVec3p mExtentsOrMaxCoeff_PaddedAligned);
45 #ifndef GU_BV4_USE_SLABS
46 BV4_ALIGN16(
PxVec3p mData2_PaddedAligned);
47 BV4_ALIGN16(
PxVec3p mFDir_PaddedAligned);
48 BV4_ALIGN16(
PxVec3p mData_PaddedAligned);
49 BV4_ALIGN16(
PxVec3p mLocalDir_PaddedAligned);
51 BV4_ALIGN16(
PxVec3p mOrigin_Padded);
54 #include "GuBV4_AABBAABBSweepTest.h"
56 #include "GuBV4_BoxBoxOverlapTest.h"
59#include "GuBV4_BoxSweep_Params.h"
61static PX_FORCE_INLINE Vec4V multiply3x3V(
const Vec4V p,
const PxMat33& mat_Padded)
63 const FloatV xxxV = V4GetX(p);
64 const FloatV yyyV = V4GetY(p);
65 const FloatV zzzV = V4GetZ(p);
67 Vec4V ResV = V4Scale(V4LoadU_Safe(&mat_Padded.column0.x), xxxV);
68 ResV = V4Add(ResV, V4Scale(V4LoadU_Safe(&mat_Padded.column1.x), yyyV));
69 ResV = V4Add(ResV, V4Scale(V4LoadU_Safe(&mat_Padded.column2.x), zzzV));
75static bool triBoxSweep(BoxSweepParams*
PX_RESTRICT params, PxU32 primIndex,
bool nodeSorting=
true)
77 PxU32 VRef0, VRef1, VRef2;
78 getVertexReferences(VRef0, VRef1, VRef2, primIndex, params->mTris32, params->mTris16);
80 const PxVec3& p0 = params->mVerts[VRef0];
81 const PxVec3& p1 = params->mVerts[VRef1];
82 const PxVec3& p2 = params->mVerts[VRef2];
87 const float dp0 = p0.
dot(params->mLocalDir_Padded);
88 const float dp1 = p1.dot(params->mLocalDir_Padded);
89 const float dp2 = p2.dot(params->mLocalDir_Padded);
91 float TriMin =
PxMin(dp0, dp1);
92 TriMin =
PxMin(TriMin, dp2);
94 if(TriMin >= params->mOffset + params->mStabbedFace.mDistance)
98 PxTrianglePadded triBoxSpace;
99 const Vec4V transModelToBoxV = V4LoadU_Safe(¶ms->mTModelToBox_Padded.x);
100 const Vec4V v0V = V4Add(multiply3x3V(V4LoadU_Safe(&p0.x), params->mRModelToBox_Padded), transModelToBoxV);
101 V4StoreU_Safe(v0V, &triBoxSpace.verts[0].x);
102 const Vec4V v1V = V4Add(multiply3x3V(V4LoadU_Safe(&p1.x), params->mRModelToBox_Padded), transModelToBoxV);
103 V4StoreU_Safe(v1V, &triBoxSpace.verts[1].x);
104 const Vec4V v2V = V4Add(multiply3x3V(V4LoadU_Safe(&p2.x), params->mRModelToBox_Padded), transModelToBoxV);
105 V4StoreU_Safe(v2V, &triBoxSpace.verts[2].x);
108 if(
triBoxSweepTestBoxSpace_inlined(triBoxSpace, params->mOriginalExtents_Padded, params->mOriginalDir_Padded*params->mStabbedFace.mDistance, params->mOneOverDir_Padded, 1.0f, Dist, params->mBackfaceCulling))
111 Dist *= params->mStabbedFace.mDistance;
112 params->mOneOverDir_Padded = params->mOneOverOriginalDir / Dist;
113 params->mStabbedFace.mDistance = Dist;
114 params->mStabbedFace.mTriangleID = primIndex;
116 params->mP0 = triBoxSpace.verts[0];
117 params->mP1 = triBoxSpace.verts[1];
118 params->mP2 = triBoxSpace.verts[2];
125#ifdef SWEEP_AABB_IMPL
126 #ifndef GU_BV4_USE_SLABS
127 setupRayData(params, Dist, params->mOrigin_Padded, params->mLocalDir_PaddedAligned);
130 params->ShrinkOBB(Dist);
140class LeafFunction_BoxSweepClosest
145 PxU32 nbToGo = getNbPrimitives(primIndex);
148 triBoxSweep(params, primIndex);
154class LeafFunction_BoxSweepAny
159 PxU32 nbToGo = getNbPrimitives(primIndex);
162 if(triBoxSweep(params, primIndex))
173static PX_FORCE_INLINE bool computeImpactData(
const Box& box,
const PxVec3& dir, SweepHit*
PX_RESTRICT hit,
const BoxSweepParams*
PX_RESTRICT params,
bool isDoubleSided,
bool meshBothSides)
175 if(params->mStabbedFace.mTriangleID==PX_INVALID_U32)
180 const float t = params->mStabbedFace.mDistance;
181 hit->mTriangleID = params->mStabbedFace.mTriangleID;
186 hit->mPos = PxVec3(0.0f);
192 const PxTriangle triInBoxSpace(params->mP0, params->mP1, params->mP2);
193 PxHitFlags outFlags = PxHitFlag::Enum(0);
194 computeBoxLocalImpact(hit->mPos, hit->mNormal, outFlags, box, params->mOriginalDir_Padded, triInBoxSpace, PxHitFlag::ePOSITION|PxHitFlag::eNORMAL, isDoubleSided, meshBothSides, t);
200template<
class ParamsT>
203 params->mStabbedFace.mTriangleID = PX_INVALID_U32;
204 setupParamsFlags(params, flags);
206 setupMeshPointersAndQuantizedCoeffs(params, mesh, tree);
208 prepareSweepData(localBox, localDir, maxDist, params);
210#ifdef SWEEP_AABB_IMPL
211 params->mOrigin_Padded = localBox.center;
212 #ifndef GU_BV4_USE_SLABS
213 params->mLocalDir_PaddedAligned = localDir;
214 setupRayData(params, maxDist, localBox.center, localDir);
219#ifdef GU_BV4_USE_SLABS
220 #include "GuBV4_Slabs.h"
222#ifdef SWEEP_AABB_IMPL
223 #include "GuBV4_ProcessStreamOrdered_SegmentAABB_Inflated.h"
224 #include "GuBV4_ProcessStreamNoOrder_SegmentAABB_Inflated.h"
225 #ifdef GU_BV4_USE_SLABS
226 #include "GuBV4_Slabs_KajiyaNoOrder.h"
227 #include "GuBV4_Slabs_KajiyaOrdered.h"
230 #include "GuBV4_ProcessStreamOrdered_OBBOBB.h"
231 #include "GuBV4_ProcessStreamNoOrder_OBBOBB.h"
232 #ifdef GU_BV4_USE_SLABS
233 #include "GuBV4_Slabs_SwizzledNoOrder.h"
234 #include "GuBV4_Slabs_SwizzledOrdered.h"
238#ifdef SWEEP_AABB_IMPL
239 #define GU_BV4_PROCESS_STREAM_RAY_NO_ORDER
240 #define GU_BV4_PROCESS_STREAM_RAY_ORDERED
242 #define GU_BV4_PROCESS_STREAM_NO_ORDER
243 #define GU_BV4_PROCESS_STREAM_ORDERED
245#include "GuBV4_Internal.h"
247#ifdef SWEEP_AABB_IMPL
248PxIntBool Sweep_AABB_BV4(
const Box& localBox,
const PxVec3& localDir,
float maxDist,
const BV4Tree& tree, SweepHit*
PX_RESTRICT hit, PxU32 flags)
250PxIntBool Sweep_OBB_BV4(
const Box& localBox,
const PxVec3& localDir,
float maxDist,
const BV4Tree& tree, SweepHit*
PX_RESTRICT hit, PxU32 flags)
253 const SourceMesh*
PX_RESTRICT mesh =
static_cast<const SourceMesh*
>(tree.mMeshInterface);
255 BoxSweepParams Params;
256 setupBoxSweepParams(&Params, localBox, localDir, maxDist, &tree, mesh, flags);
260#ifdef SWEEP_AABB_IMPL
261 if(Params.mEarlyExit)
262 processStreamRayNoOrder<1, LeafFunction_BoxSweepAny>(tree, &Params);
264 processStreamRayOrdered<1, LeafFunction_BoxSweepClosest>(tree, &Params);
266 if(Params.mEarlyExit)
267 processStreamNoOrder<LeafFunction_BoxSweepAny>(tree, &Params);
269 processStreamOrdered<LeafFunction_BoxSweepClosest>(tree, &Params);
273 doBruteForceTests<LeafFunction_BoxSweepAny, LeafFunction_BoxSweepClosest>(mesh->getNbTriangles(), &Params);
275 return computeImpactData(localBox, localDir, hit, &Params, (flags & QUERY_MODIFIER_DOUBLE_SIDED)!=0, (flags & QUERY_MODIFIER_MESH_BOTH_SIDES)!=0);
284 struct BoxSweepParamsCB : BoxSweepParams
290 const PxMat44* mWorldm_Aligned;
293 SweepUnlimitedCallback mCallback;
299class LeafFunction_BoxSweepCB
304 PxU32 nbToGo = getNbPrimitives(primIndex);
307 if(triBoxSweep(params, primIndex, params->mNodeSorting))
312 const bool b = computeImpactData(params->mBoxCB, params->mDirCB, &hit, params, (params->mFlags & QUERY_MODIFIER_DOUBLE_SIDED)!=0, (params->mFlags & QUERY_MODIFIER_MESH_BOTH_SIDES)!=0);
316 if(b && params->mWorldm_Aligned)
320 hit.mPos = params->mWorldm_Aligned->transform(hit.mPos);
321 hit.mNormal = params->mWorldm_Aligned->rotate(hit.mNormal);
324 reportUnlimitedCallbackHit(params, hit);
338#ifdef SWEEP_AABB_IMPL
339void Sweep_AABB_BV4_CB(
const Box& localBox,
const PxVec3& localDir,
float maxDist,
const BV4Tree& tree,
const PxMat44*
PX_RESTRICT worldm_Aligned, SweepUnlimitedCallback callback,
void* userData, PxU32 flags,
bool nodeSorting)
341void Sweep_OBB_BV4_CB(
const Box& localBox,
const PxVec3& localDir,
float maxDist,
const BV4Tree& tree,
const PxMat44*
PX_RESTRICT worldm_Aligned, SweepUnlimitedCallback callback,
void* userData, PxU32 flags,
bool nodeSorting)
344 const SourceMesh*
PX_RESTRICT mesh =
static_cast<const SourceMesh*
>(tree.mMeshInterface);
346 BoxSweepParamsCB Params;
347 Params.mBoxCB = localBox;
348 Params.mDirCB = localDir;
349 Params.mWorldm_Aligned = worldm_Aligned;
350 Params.mFlags = flags;
352 Params.mCallback = callback;
353 Params.mUserData = userData;
354 Params.mMaxDist = maxDist;
355 Params.mNodeSorting = nodeSorting;
356 setupBoxSweepParams(&Params, localBox, localDir, maxDist, &tree, mesh, flags);
358 PX_ASSERT(!Params.mEarlyExit);
364#ifdef SWEEP_AABB_IMPL
365 processStreamRayOrdered<1, LeafFunction_BoxSweepCB>(tree, &Params);
367 processStreamOrdered<LeafFunction_BoxSweepCB>(tree, &Params);
372#ifdef SWEEP_AABB_IMPL
373 processStreamRayNoOrder<1, LeafFunction_BoxSweepCB>(tree, &Params);
375 processStreamNoOrder<LeafFunction_BoxSweepCB>(tree, &Params);
380 doBruteForceTests<LeafFunction_BoxSweepCB, LeafFunction_BoxSweepCB>(mesh->getNbTriangles(), &Params);
392struct GenericSweepParamsCB : BoxSweepParams
394 MeshSweepCallback mCallback;
398class LeafFunction_BoxSweepClosestCB
403 PxU32 nbToGo = getNbPrimitives(prim_index);
417 PxU32 VRef0, VRef1, VRef2;
418 getVertexReferences(VRef0, VRef1, VRef2, prim_index, params->mTris32, params->mTris16);
420 const PxVec3& p0 = params->mVerts[VRef0];
421 const PxVec3& p1 = params->mVerts[VRef1];
422 const PxVec3& p2 = params->mVerts[VRef2];
425 const float dp0 = p0.
dot(params->mLocalDir_Padded);
426 const float dp1 = p1.dot(params->mLocalDir_Padded);
427 const float dp2 = p2.dot(params->mLocalDir_Padded);
429 float TriMin =
PxMin(dp0, dp1);
430 TriMin =
PxMin(TriMin, dp2);
432 if(TriMin < params->mOffset + params->mStabbedFace.mDistance)
435 float Dist = params->mStabbedFace.mDistance;
436 if((params->mCallback)(params->mUserData, p0, p1, p2, prim_index, Dist))
439 if(Dist<params->mStabbedFace.mDistance)
441 params->mStabbedFace.mDistance = Dist;
442 params->mStabbedFace.mTriangleID = prim_index;
443#ifdef SWEEP_AABB_IMPL
444 #ifndef GU_BV4_USE_SLABS
445 setupRayData(params, Dist, params->mOrigin_Padded, params->mLocalDir_PaddedAligned);
448 params->ShrinkOBB(Dist);
458class LeafFunction_BoxSweepAnyCB
463 PxU32 nbToGo = getNbPrimitives(prim_index);
466 PxU32 VRef0, VRef1, VRef2;
467 getVertexReferences(VRef0, VRef1, VRef2, prim_index, params->mTris32, params->mTris16);
469 const PxVec3& p0 = params->mVerts[VRef0];
470 const PxVec3& p1 = params->mVerts[VRef1];
471 const PxVec3& p2 = params->mVerts[VRef2];
475 float Dist = params->mStabbedFace.mDistance;
476 if((params->mCallback)(params->mUserData, p0, p1, p2, prim_index, Dist))
488#ifdef SWEEP_AABB_IMPL
489void GenericSweep_AABB_CB(
const Box& localBox,
const PxVec3& localDir,
float maxDist,
const BV4Tree& tree, MeshSweepCallback callback,
void* userData, PxU32 flags)
491void GenericSweep_OBB_CB(
const Box& localBox,
const PxVec3& localDir,
float maxDist,
const BV4Tree& tree, MeshSweepCallback callback,
void* userData, PxU32 flags)
494 const SourceMesh*
PX_RESTRICT mesh =
static_cast<const SourceMesh*
>(tree.mMeshInterface);
496 GenericSweepParamsCB Params;
497 Params.mCallback = callback;
498 Params.mUserData = userData;
499 setupBoxSweepParams(&Params, localBox, localDir, maxDist, &tree, mesh, flags);
503#ifdef SWEEP_AABB_IMPL
504 if(Params.mEarlyExit)
505 processStreamRayNoOrder<1, LeafFunction_BoxSweepAnyCB>(tree, &Params);
507 processStreamRayOrdered<1, LeafFunction_BoxSweepClosestCB>(tree, &Params);
509 if(Params.mEarlyExit)
510 processStreamNoOrder<LeafFunction_BoxSweepAnyCB>(tree, &Params);
512 processStreamOrdered<LeafFunction_BoxSweepClosestCB>(tree, &Params);
516 doBruteForceTests<LeafFunction_BoxSweepAnyCB, LeafFunction_BoxSweepClosestCB>(mesh->getNbTriangles(), &Params);
A padded version of PxVec3, to safely load its data using SIMD.
Definition PxVec3.h:392
PX_CUDA_CALLABLE PX_FORCE_INLINE Type dot(const PxVec3T &v) const
returns the scalar product of this and other.
Definition PxVec3.h:274
#define PX_RESTRICT
Definition PxPreprocessor.h:355
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
PX_FORCE_INLINE int triBoxSweepTestBoxSpace_inlined(const PxTriangle &tri, const PxVec3 &extents, const PxVec3 &dir, const PxVec3 &oneOverDir, float tmax, float &toi, PxU32 doBackfaceCulling)
Inlined version of triBoxSweepTestBoxSpace. See that other function for comments.
Definition GuSweepBoxTriangle_SAT.h:201
PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMin(T a, T b)
The return value is the lesser of the two specified values.
Definition PxMath.h:88
Definition GuBV4_BoxSweep_Internal.h:42