RavEngine
Loading...
Searching...
No Matches
GuSweepMesh.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 GU_SWEEP_MESH_H
30#define GU_SWEEP_MESH_H
31
32#include "GuMidphaseInterface.h"
33#include "GuVecConvexHull.h"
34
35namespace physx
36{
37
38namespace Gu
39{
40 // PT: intermediate class containing shared bits of code & members
41 struct SweepShapeMeshHitCallback : MeshHitCallback<PxGeomRaycastHit>
42 {
43 SweepShapeMeshHitCallback(CallbackMode::Enum mode, const PxHitFlags& hitFlags, bool flipNormal, float distCoef);
44
45 const PxHitFlags mHitFlags;
46 bool mStatus; // Default is false, set to true if a valid hit is found. Stays true once true.
47 bool mInitialOverlap; // Default is false, set to true if an initial overlap hit is found. Reset for each hit.
48 bool mFlipNormal; // If negative scale is used we need to flip normal
49 PxReal mDistCoeff; // dist coeff from unscaled to scaled distance
50
51 void operator=(const SweepShapeMeshHitCallback&) {}
52 };
53
55 {
56 PxGeomSweepHit& mSweepHit;
57 const PxMat34& mVertexToWorldSkew;
58 const PxReal mTrueSweepDistance; // max sweep distance that can be used
59 PxReal mBestAlignmentValue; // best alignment value for triangle normal
60 PxReal mBestDist; // best distance, not the same as sweepHit.distance, can be shorter by epsilon
61 const Capsule& mCapsule;
62 const PxVec3& mUnitDir;
63 const bool mMeshDoubleSided; // PT: true if PxMeshGeometryFlag::eDOUBLE_SIDED
64 const bool mIsSphere;
65
66 SweepCapsuleMeshHitCallback(PxGeomSweepHit& sweepHit, const PxMat34& worldMatrix, PxReal distance, bool meshDoubleSided,
67 const Capsule& capsule, const PxVec3& unitDir, const PxHitFlags& hitFlags, bool flipNormal, float distCoef);
68
69 virtual PxAgain processHit(const PxGeomRaycastHit& aHit, const PxVec3& v0, const PxVec3& v1, const PxVec3& v2, PxReal& shrunkMaxT, const PxU32*);
70
71 // PT: TODO: unify these operators
72 void operator=(const SweepCapsuleMeshHitCallback&) {}
73
74 bool finalizeHit( PxGeomSweepHit& sweepHit, const Capsule& lss, const PxTriangleMeshGeometry& triMeshGeom,
75 const PxTransform& pose, bool isDoubleSided) const;
76 };
77
78#if PX_VC
79 #pragma warning(push)
80 #pragma warning( disable : 4324 ) // Padding was added at the end of a structure because of a __declspec(align) value.
81#endif
82
84 {
85 const PxMat34Padded& mMeshToBox;
86 PxReal mDist, mDist0;
87 physx::aos::FloatV mDistV;
88 const Box& mBox;
89 const PxVec3& mLocalDir;
90 const PxVec3& mWorldUnitDir;
91 PxReal mInflation;
92 PxTriangle mHitTriangle;
93 physx::aos::Vec3V mMinClosestA;
94 physx::aos::Vec3V mMinNormal;
95 physx::aos::Vec3V mLocalMotionV;
96 PxU32 mMinTriangleIndex;
97 PxVec3 mOneOverDir;
98 const bool mBothTriangleSidesCollide; // PT: true if PxMeshGeometryFlag::eDOUBLE_SIDED || PxHitFlag::eMESH_BOTH_SIDES
99
100 SweepBoxMeshHitCallback(CallbackMode::Enum mode_, const PxMat34Padded& meshToBox, PxReal distance, bool bothTriangleSidesCollide,
101 const Box& box, const PxVec3& localMotion, const PxVec3& localDir, const PxVec3& unitDir,
102 const PxHitFlags& hitFlags, const PxReal inflation, bool flipNormal, float distCoef);
103
104 virtual ~SweepBoxMeshHitCallback() {}
105
106 virtual PxAgain processHit(const PxGeomRaycastHit& meshHit, const PxVec3& lp0, const PxVec3& lp1, const PxVec3& lp2, PxReal& shrinkMaxT, const PxU32*);
107
108 bool finalizeHit( PxGeomSweepHit& sweepHit, const PxTriangleMeshGeometry& triMeshGeom, const PxTransform& pose,
109 const PxTransform& boxTransform, const PxVec3& localDir,
110 bool meshBothSides, bool isDoubleSided) const;
111
112 private:
114 };
115
117 {
118 PxTriangle mHitTriangle;
119 ConvexHullV mConvexHull;
120 physx::aos::PxMatTransformV mMeshToConvex;
121 physx::aos::PxTransformV mConvexPoseV;
122 const Cm::FastVertex2ShapeScaling& mMeshScale;
123 PxGeomSweepHit mSweepHit; // stores either the closest or any hit depending on value of mAnyHit
124 physx::aos::FloatV mInitialDistance;
125 physx::aos::Vec3V mConvexSpaceDir; // convexPose.rotateInv(-unit*distance)
126 PxVec3 mUnitDir;
127 PxVec3 mMeshSpaceUnitDir;
128 PxReal mInflation;
129 const bool mAnyHit;
130 const bool mBothTriangleSidesCollide; // PT: true if PxMeshGeometryFlag::eDOUBLE_SIDED || PxHitFlag::eMESH_BOTH_SIDES
131
132 SweepConvexMeshHitCallback( const ConvexHullData& hull, const PxMeshScale& convexScale, const Cm::FastVertex2ShapeScaling& meshScale,
133 const PxTransform& convexPose, const PxTransform& meshPose,
134 const PxVec3& unitDir, const PxReal distance, PxHitFlags hitFlags, const bool bothTriangleSidesCollide, const PxReal inflation,
135 const bool anyHit, float distCoef);
136
137 virtual ~SweepConvexMeshHitCallback() {}
138
139 virtual PxAgain processHit(const PxGeomRaycastHit& hit, const PxVec3& av0, const PxVec3& av1, const PxVec3& av2, PxReal& shrunkMaxT, const PxU32*);
140
141 bool finalizeHit(PxGeomSweepHit& sweepHit, const PxTriangleMeshGeometry& meshGeom, const PxTransform& pose,
142 const PxConvexMeshGeometry& convexGeom, const PxTransform& convexPose,
143 const PxVec3& unitDir, PxReal inflation,
144 bool isMtd, bool meshBothSides, bool isDoubleSided, bool bothTriangleSidesCollide);
145
146 private:
148 };
149
150#if PX_VC
151 #pragma warning(pop)
152#endif
153
154}
155}
156
157#endif
Definition CmScaling.h:61
Represents an oriented bounding box.
Definition GuBox.h:72
Represents a capsule.
Definition GuCapsule.h:47
Definition GuVecConvexHull.h:184
Convex mesh geometry class.
Definition PxConvexMeshGeometry.h:79
A padded version of PxMat34, to safely load its data using SIMD.
Definition PxMat34.h:263
Definition PxMat34.h:50
A class expressing a nonuniform scaling transformation.
Definition PxMeshScale.h:69
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
Triangle mesh geometry class.
Definition PxTriangleMeshGeometry.h:81
Triangle class.
Definition PxTriangle.h:47
3 Element vector class.
Definition PxVec3.h:50
Definition PxVecTransform.h:200
Definition PxVecTransform.h:43
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
bool PxAgain
Describes query behavior after returning a partial query result via a callback.
Definition PxQueryReport.h:78
Definition GuConvexMeshData.h:109
Definition GuMidphaseInterface.h:61
Definition GuSweepMesh.h:84
Definition GuSweepMesh.h:55
Definition GuSweepMesh.h:117
Definition GuSweepMesh.h:42
Stores results of raycast queries.
Definition PxGeometryHit.h:151
Stores results of sweep queries.
Definition PxGeometryHit.h:175
Definition PxVecMathAoSScalar.h:52
Definition PxVecMathAoSScalar.h:77