1/*
2 * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 */
10// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12
13
14#ifndef PX_PHYSICS_EXTENSIONS_TRIANGLE_MESH_H
15#define PX_PHYSICS_EXTENSIONS_TRIANGLE_MESH_H
16/** \addtogroup extensions
17 @{
18*/
19
20#include "PxPhysXConfig.h"
21#include "common/PxPhysXCommonConfig.h"
22
23#ifndef PX_DOXYGEN
24namespace physx
25{
26#endif
27
28class PxGeometry;
29class PxTriangleMeshGeometry;
30class PxHeightFieldGeometry;
31
32 /**
33 \brief Utility class to find mesh triangles touched by a specified geometry object.
34
35 This class is a helper calling PxMeshQuery::findOverlapTriangleMesh or PxMeshQuery::findOverlapHeightField under the hood,
36 while taking care of necessary memory management issues.
37
38 PxMeshQuery::findOverlapTriangleMesh and PxMeshQuery::findOverlapHeightField are the "raw" functions operating on user-provided fixed-size
39 buffers. These functions abort with an error code in case of buffer overflow. PxMeshOverlapUtil is a convenient helper function checking
40 this error code, and resizing buffers appropriately, until the desired call succeeds.
41
42 Returned triangle indices are stored within the class, and can be used with PxMeshQuery::getTriangle() to retrieve the triangle properties.
43 */
44 class PxMeshOverlapUtil
45 {
46 public:
47 PxMeshOverlapUtil();
48 ~PxMeshOverlapUtil();
49 /**
50 \brief Find the mesh triangles which touch the specified geometry object.
51
52 \param[in] geom The geometry object to test for mesh triangle overlaps. Supported geometries are #PxSphereGeometry, #PxCapsuleGeometry and #PxBoxGeometry
53 \param[in] geomPose Pose of the geometry object
54 \param[in] meshGeom The triangle mesh geometry to check overlap against
55 \param[in] meshPose Pose of the triangle mesh
56 \return Number of overlaps found. Triangle indices can then be accessed through the #getResults() function.
57
58 @see PxGeometry PxTransform PxTriangleMeshGeometry PxMeshQuery::findOverlapTriangleMesh
59 */
60 PxU32 findOverlap(const PxGeometry& geom, const PxTransform& geomPose, const PxTriangleMeshGeometry& meshGeom, const PxTransform& meshPose);
61
62 /**
63 \brief Find the height field triangles which touch the specified geometry object.
64
65 \param[in] geom The geometry object to test for height field overlaps. Supported geometries are #PxSphereGeometry, #PxCapsuleGeometry and #PxBoxGeometry. The sphere and capsule queries are currently conservative estimates.
66 \param[in] geomPose Pose of the geometry object
67 \param[in] hfGeom The height field geometry to check overlap against
68 \param[in] hfPose Pose of the height field
69 \return Number of overlaps found. Triangle indices can then be accessed through the #getResults() function.
70
71 @see PxGeometry PxTransform PxHeightFieldGeometry PxMeshQuery::findOverlapHeightField
72 */
73 PxU32 findOverlap(const PxGeometry& geom, const PxTransform& geomPose, const PxHeightFieldGeometry& hfGeom, const PxTransform& hfPose);
74
75 /**
76 \brief Retrieves array of triangle indices after a findOverlap call.
77 \return Indices of touched triangles
78 */
79 PX_FORCE_INLINE const PxU32* getResults() const { return mResultsMemory; }
80
81 /**
82 \brief Retrieves number of triangle indices after a findOverlap call.
83 \return Number of touched triangles
84 */
85 PX_FORCE_INLINE PxU32 getNbResults() const { return mNbResults; }
86
87 private:
88 PxU32* mResultsMemory;
89 PxU32 mResults[64];
90 PxU32 mNbResults;
91 PxU32 mMaxNbResults;
92 };
93
94 /** \brief DEPRECATED typedef for backward compatibility with PhysX 3.2. */
95 typedef PxMeshOverlapUtil PxFindOverlapTriangleMeshUtil;
96
97
98 /**
99 \brief Computes an approximate minimum translational distance (MTD) between a geometry object and a mesh.
100
101 This iterative function computes an approximate vector that can be used to depenetrate a geom object
102 from a triangle mesh. Returned depenetration vector should be applied to 'geom', to get out of the mesh.
103
104 The function works best when the amount of overlap between the geom object and the mesh is small. If the
105 geom object's center goes inside the mesh, backface culling usually kicks in, no overlap is detected,
106 and the function does not compute an MTD vector.
107
108 The function early exits if no overlap is detected after a depenetration attempt. This means that if
109 maxIter = N, the code will attempt at most N iterations but it might exit earlier if depenetration has
110 been successful. Usually N = 4 gives good results.
111
112 \param[in] maxIter Max number of iterations before returning.
113 \param[in] geom The geometry object
114 \param[in] geomPose Pose for the geometry object
115 \param[in] meshGeom The mesh geometry
116 \param[in] meshPose Pose for the mesh
117 \param[out] nb Number of depenetrations attempts performed during the call. 0 means no overlap has been detected.
118
119 \return Approximate depenetration vector
120
121 @see PxGeometry PxTransform PxTriangleMeshGeometry
122 */
123 PxVec3 PxComputeMeshPenetration(PxU32 maxIter, const PxGeometry& geom, const PxTransform& geomPose, const PxTriangleMeshGeometry& meshGeom, const PxTransform& meshPose, PxU32& nb);
124
125 /**
126 \brief Computes an approximate minimum translational distance (MTD) between a geometry object and a heightfield.
127
128 This iterative function computes an approximate vector that can be used to depenetrate a geom object
129 from a heightfield. Returned depenetration vector should be applied to 'geom', to get out of the heightfield.
130
131 The function works best when the amount of overlap between the geom object and the mesh is small. If the
132 geom object's center goes inside the heightfield, backface culling usually kicks in, no overlap is detected,
133 and the function does not compute an MTD vector.
134
135 The function early exits if no overlap is detected after a depenetration attempt. This means that if
136 maxIter = N, the code will attempt at most N iterations but it might exit earlier if depenetration has
137 been successful. Usually N = 4 gives good results.
138
139 \param[in] maxIter Max number of iterations before returning.
140 \param[in] geom The geometry object
141 \param[in] geomPose Pose for the geometry object
142 \param[in] heightFieldGeom The heightfield geometry
143 \param[in] heightFieldPose Pose for the heightfield
144 \param[out] nb Number of depenetrations attempts performed during the call. 0 means no overlap has been detected.
145
146 \return Approximate depenetration vector
147
148 @see PxGeometry PxTransform PxHeightFieldGeometry
149 */
150 PxVec3 PxComputeHeightFieldPenetration(PxU32 maxIter, const PxGeometry& geom, const PxTransform& geomPose, const PxHeightFieldGeometry& heightFieldGeom, const PxTransform& heightFieldPose, PxU32& nb);
151
152#ifndef PX_DOXYGEN
153} // namespace physx
154#endif
155
156/** @} */
157#endif
158