1//
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions
4// are met:
5// * Redistributions of source code must retain the above copyright
6// notice, this list of conditions and the following disclaimer.
7// * Redistributions in binary form must reproduce the above copyright
8// notice, this list of conditions and the following disclaimer in the
9// documentation and/or other materials provided with the distribution.
10// * Neither the name of NVIDIA CORPORATION nor the names of its
11// contributors may be used to endorse or promote products derived
12// from this software without specific prior written permission.
13//
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
15// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25//
26// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
27// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29
30
31#ifndef PX_PHYSICS_GEOMUTILS_PX_MESH_QUERY
32#define PX_PHYSICS_GEOMUTILS_PX_MESH_QUERY
33
34/** \addtogroup geomutils
35 @{
36*/
37
38#include "common/PxPhysXCommonConfig.h"
39#include "PxQueryReport.h"
40
41#if !PX_DOXYGEN
42namespace physx
43{
44#endif
45
46class PxGeometry;
47class PxConvexMeshGeometry;
48class PxTriangleMeshGeometry;
49class PxHeightFieldGeometry;
50
51class PxTriangle;
52
53class PxMeshQuery
54{
55public:
56
57 /**
58 \brief Retrieves triangle data from a triangle ID.
59
60 This function can be used together with #findOverlapTriangleMesh() to retrieve triangle properties.
61
62 \param[in] triGeom Geometry of the triangle mesh to extract the triangle from.
63 \param[in] transform Transform for the triangle mesh
64 \param[in] triangleIndex The index of the triangle to retrieve.
65 \param[out] triangle Triangle points in world space.
66 \param[out] vertexIndices Returned vertex indices for given triangle
67 \param[out] adjacencyIndices Returned 3 triangle adjacency internal face indices (0xFFFFFFFF if no adjacency). The mesh must be cooked with cooking param buildTriangleAdjacencies enabled.
68
69 \note This function will flip the triangle normal whenever triGeom.scale.hasNegativeDeterminant() is true.
70
71 @see PxTriangle PxTriangleFlags PxTriangleID findOverlapTriangleMesh()
72 */
73 PX_PHYSX_COMMON_API static void getTriangle(const PxTriangleMeshGeometry& triGeom, const PxTransform& transform, PxTriangleID triangleIndex, PxTriangle& triangle, PxU32* vertexIndices=NULL, PxU32* adjacencyIndices=NULL);
74
75
76 /**
77 \brief Retrieves triangle data from a triangle ID.
78
79 This function can be used together with #findOverlapHeightField() to retrieve triangle properties.
80
81 \param[in] hfGeom Geometry of the height field to extract the triangle from.
82 \param[in] transform Transform for the height field.
83 \param[in] triangleIndex The index of the triangle to retrieve.
84 \param[out] triangle Triangle points in world space.
85 \param[out] vertexIndices Returned vertex indices for given triangle
86 \param[out] adjacencyIndices Returned 3 triangle adjacency triangle indices (0xFFFFFFFF if no adjacency).
87
88 \note This function will flip the triangle normal whenever triGeom.scale.hasNegativeDeterminant() is true.
89 \note TriangleIndex is an index used in internal format, which does have an index out of the bounds in last row.
90 To traverse all tri indices in the HF, the following code can be applied:
91 for (PxU32 row = 0; row < (nbRows - 1); row++)
92 {
93 for (PxU32 col = 0; col < (nbCols - 1); col++)
94 {
95 for (PxU32 k = 0; k < 2; k++)
96 {
97 const PxU32 triIndex = 2 * (row*nbCols + col) + k;
98 ....
99 }
100 }
101 }
102 @see PxTriangle PxTriangleFlags PxTriangleID findOverlapHeightField()
103 */
104 PX_PHYSX_COMMON_API static void getTriangle(const PxHeightFieldGeometry& hfGeom, const PxTransform& transform, PxTriangleID triangleIndex, PxTriangle& triangle, PxU32* vertexIndices=NULL, PxU32* adjacencyIndices=NULL);
105
106
107 /**
108 \brief Find the mesh triangles which touch the specified geometry object.
109
110 Returned triangle indices can be used with #getTriangle() to retrieve the triangle properties.
111
112 \param[in] geom The geometry object to test for mesh triangle overlaps. Supported geometries are #PxSphereGeometry, #PxCapsuleGeometry and #PxBoxGeometry
113 \param[in] geomPose Pose of the geometry object
114 \param[in] meshGeom The triangle mesh geometry to check overlap against
115 \param[in] meshPose Pose of the triangle mesh
116 \param[out] results Indices of overlapping triangles
117 \param[in] maxResults Size of 'results' buffer
118 \param[in] startIndex Index of first result to be retrieved. Previous indices are skipped.
119 \param[out] overflow True if a buffer overflow occurred
120 \return Number of overlaps found, i.e. number of elements written to the results buffer
121
122 @see PxTriangleMeshGeometry getTriangle()
123 */
124 PX_PHYSX_COMMON_API static PxU32 findOverlapTriangleMesh( const PxGeometry& geom, const PxTransform& geomPose,
125 const PxTriangleMeshGeometry& meshGeom, const PxTransform& meshPose,
126 PxU32* results, PxU32 maxResults, PxU32 startIndex, bool& overflow);
127
128 /**
129 \brief Find the height field triangles which touch the specified geometry object.
130
131 Returned triangle indices can be used with #getTriangle() to retrieve the triangle properties.
132
133 \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.
134 \param[in] geomPose Pose of the geometry object
135 \param[in] hfGeom The height field geometry to check overlap against
136 \param[in] hfPose Pose of the height field
137 \param[out] results Indices of overlapping triangles
138 \param[in] maxResults Size of 'results' buffer
139 \param[in] startIndex Index of first result to be retrieved. Previous indices are skipped.
140 \param[out] overflow True if a buffer overflow occurred
141 \return Number of overlaps found, i.e. number of elements written to the results buffer
142
143 @see PxHeightFieldGeometry getTriangle()
144 */
145 PX_PHYSX_COMMON_API static PxU32 findOverlapHeightField(const PxGeometry& geom, const PxTransform& geomPose,
146 const PxHeightFieldGeometry& hfGeom, const PxTransform& hfPose,
147 PxU32* results, PxU32 maxResults, PxU32 startIndex, bool& overflow);
148
149
150 /**
151 \brief Sweep a specified geometry object in space and test for collision with a set of given triangles.
152
153 This function simply sweeps input geometry against each input triangle, in the order they are given.
154 This is an O(N) operation with N = number of input triangles. It does not use any particular acceleration structure.
155
156 \param[in] unitDir Normalized direction of the sweep.
157 \param[in] distance Sweep distance. Needs to be larger than 0. Clamped to PX_MAX_SWEEP_DISTANCE.
158 \param[in] geom The geometry object to sweep. Supported geometries are #PxSphereGeometry, #PxCapsuleGeometry and #PxBoxGeometry
159 \param[in] pose Pose of the geometry object to sweep.
160 \param[in] triangleCount Number of specified triangles
161 \param[in] triangles Array of triangles to sweep against
162 \param[out] sweepHit The sweep hit information. See the notes below for limitations about returned results.
163 \param[in] hitFlags Specification of the kind of information to retrieve on hit. Combination of #PxHitFlag flags. See the notes below for limitations about supported flags.
164 \param[in] cachedIndex Cached triangle index for subsequent calls. Cached triangle is tested first. Optional parameter.
165 \param[in] inflation This parameter creates a skin around the swept geometry which increases its extents for sweeping. The sweep will register a hit as soon as the skin touches a shape, and will return the corresponding distance and normal.
166 \param[in] doubleSided Counterpart of PxMeshGeometryFlag::eDOUBLE_SIDED for input triangles.
167 \return True if the swept geometry object hits the specified triangles
168
169 \note Only the following geometry types are currently supported: PxSphereGeometry, PxCapsuleGeometry, PxBoxGeometry
170 \note If a shape from the scene is already overlapping with the query shape in its starting position, the hit is returned unless eASSUME_NO_INITIAL_OVERLAP was specified.
171 \note This function returns a single closest hit across all the input triangles. Multiple hits are not supported.
172 \note Supported hitFlags are PxHitFlag::eDEFAULT, PxHitFlag::eASSUME_NO_INITIAL_OVERLAP, PxHitFlag::ePRECISE_SWEEP, PxHitFlag::eMESH_BOTH_SIDES, PxHitFlag::eMESH_ANY.
173 \note ePOSITION is only defined when there is no initial overlap (sweepHit.hadInitialOverlap() == false)
174 \note The returned normal for initially overlapping sweeps is set to -unitDir.
175 \note Otherwise the returned normal is the front normal of the triangle even if PxHitFlag::eMESH_BOTH_SIDES is set.
176 \note The returned PxSweepHit::faceIndex parameter will hold the index of the hit triangle in input array, i.e. the range is [0; triangleCount). For initially overlapping sweeps, this is the index of overlapping triangle.
177 \note The returned PxSweepHit::actor and PxSweepHit::shape pointers are not filled.
178 \note The inflation parameter is not compatible with PxHitFlag::ePRECISE_SWEEP.
179
180 @see PxTriangle PxSweepHit PxGeometry PxTransform
181 */
182 PX_PHYSX_COMMON_API static bool sweep(const PxVec3& unitDir,
183 const PxReal distance,
184 const PxGeometry& geom,
185 const PxTransform& pose,
186 PxU32 triangleCount,
187 const PxTriangle* triangles,
188 PxSweepHit& sweepHit,
189 PxHitFlags hitFlags = PxHitFlag::eDEFAULT,
190 const PxU32* cachedIndex = NULL,
191 const PxReal inflation = 0.0f,
192 bool doubleSided = false);
193};
194
195
196#if !PX_DOXYGEN
197}
198#endif
199
200/** @} */
201#endif
202

source code of qtquick3dphysics/src/3rdparty/PhysX/include/geometry/PxMeshQuery.h