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_GEOMUTILS_PX_MESH_QUERY
15#define PX_PHYSICS_GEOMUTILS_PX_MESH_QUERY
16
17/** \addtogroup geomutils
18 @{
19*/
20
21#include "common/PxPhysXCommonConfig.h"
22#include "PxQueryReport.h"
23
24#ifndef PX_DOXYGEN
25namespace physx
26{
27#endif
28
29class PxGeometry;
30class PxConvexMeshGeometry;
31class PxTriangleMeshGeometry;
32class PxHeightFieldGeometry;
33
34class PxTriangle;
35
36class PxMeshQuery
37{
38public:
39
40 /**
41 \brief Retrieves triangle data from a triangle ID.
42
43 This function can be used together with #findOverlapTriangleMesh() to retrieve triangle properties.
44
45 \param[in] triGeom Geometry of the triangle mesh to extract the triangle from.
46 \param[in] transform Transform for the triangle mesh
47 \param[in] triangleIndex The index of the triangle to retrieve.
48 \param[out] triangle Triangle points in world space.
49 \param[out] vertexIndices Returned vertex indices for given triangle
50 \param[out] adjacencyIndices Returned 3 triangle adjacency internal face indices (0xFFFFFFFF if no adjacency). The mesh must be cooked with cooking param buildTriangleAdjacencies enabled.
51
52 @see PxTriangle PxTriangleFlags PxTriangleID findOverlapTriangleMesh()
53 */
54 PX_PHYSX_COMMON_API static void getTriangle(const PxTriangleMeshGeometry& triGeom, const PxTransform& transform, PxTriangleID triangleIndex, PxTriangle& triangle, PxU32* vertexIndices=NULL, PxU32* adjacencyIndices=NULL);
55
56
57 /**
58 \brief Retrieves triangle data from a triangle ID.
59
60 This function can be used together with #findOverlapHeightField() to retrieve triangle properties.
61
62 \param[in] hfGeom Geometry of the height field to extract the triangle from.
63 \param[in] transform Transform for the height field.
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 triangle indices (0xFFFFFFFF if no adjacency).
68
69 @see PxTriangle PxTriangleFlags PxTriangleID findOverlapHeightField()
70 */
71 PX_PHYSX_COMMON_API static void getTriangle(const PxHeightFieldGeometry& hfGeom, const PxTransform& transform, PxTriangleID triangleIndex, PxTriangle& triangle, PxU32* vertexIndices=NULL, PxU32* adjacencyIndices=NULL);
72
73
74 /**
75 \brief Find the mesh triangles which touch the specified geometry object.
76
77 Returned triangle indices can be used with #getTriangle() to retrieve the triangle properties.
78
79 \param[in] geom The geometry object to test for mesh triangle overlaps. Supported geometries are #PxSphereGeometry, #PxCapsuleGeometry and #PxBoxGeometry
80 \param[in] geomPose Pose of the geometry object
81 \param[in] meshGeom The triangle mesh geometry to check overlap against
82 \param[in] meshPose Pose of the triangle mesh
83 \param[out] results Indices of overlapping triangles
84 \param[in] maxResults Size of 'results' buffer
85 \param[in] startIndex Index of first result to be retrieved. Previous indices are skipped.
86 \param[out] overflow True if a buffer overflow occured
87 \return Number of overlaps found, i.e. number of elements written to the results buffer
88
89 @see PxTriangleMeshGeometry getTriangle()
90 */
91 PX_PHYSX_COMMON_API static PxU32 findOverlapTriangleMesh( const PxGeometry& geom, const PxTransform& geomPose,
92 const PxTriangleMeshGeometry& meshGeom, const PxTransform& meshPose,
93 PxU32* results, PxU32 maxResults, PxU32 startIndex, bool& overflow);
94
95 /**
96 \brief Find the height field triangles which touch the specified geometry object.
97
98 Returned triangle indices can be used with #getTriangle() to retrieve the triangle properties.
99
100 \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.
101 \param[in] geomPose Pose of the geometry object
102 \param[in] hfGeom The height field geometry to check overlap against
103 \param[in] hfPose Pose of the height field
104 \param[out] results Indices of overlapping triangles
105 \param[in] maxResults Size of 'results' buffer
106 \param[in] startIndex Index of first result to be retrieved. Previous indices are skipped.
107 \param[out] overflow True if a buffer overflow occured
108 \return Number of overlaps found, i.e. number of elements written to the results buffer
109
110 @see PxHeightFieldGeometry getTriangle()
111 */
112 PX_PHYSX_COMMON_API static PxU32 findOverlapHeightField(const PxGeometry& geom, const PxTransform& geomPose,
113 const PxHeightFieldGeometry& hfGeom, const PxTransform& hfPose,
114 PxU32* results, PxU32 maxResults, PxU32 startIndex, bool& overflow);
115
116 /**
117 \brief Sweep a specified geometry object in space and test for collision with a set of given triangles.
118
119 This function simply sweeps input geometry against each input triangle. This is an O(N) operation with N = number of input triangles.
120 It does not use any particular acceleration structure.
121
122 \param[in] unitDir Normalized direction of the sweep.
123 \param[in] distance Sweep distance. Needs to be larger than 0. Clamped to PX_MAX_SWEEP_DISTANCE.
124 \param[in] geom The geometry object to sweep. Supported geometries are #PxSphereGeometry, #PxCapsuleGeometry and #PxBoxGeometry
125 \param[in] pose Pose of the geometry object to sweep.
126 \param[in] triangleCount Number of specified triangles
127 \param[in] triangles Array of triangles to sweep against
128 \param[out] sweepHit The sweep hit information. See the notes below for limitations about returned results.
129 \param[in] hintFlags Specification of the kind of information to retrieve on hit. Combination of #PxHitFlag flags. See the notes below for limitations about supported flags.
130 \param[in] cachedIndex Cached triangle index for subsequent calls. Cached triangle is tested first. Optional parameter.
131 \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.
132 \param[in] doubleSided Counterpart of PxMeshGeometryFlag::eDOUBLE_SIDED for input triangles.
133 \return True if the swept geometry object hits the specified triangles
134
135 \note Only the following geometry types are currently supported: PxSphereGeometry, PxCapsuleGeometry, PxBoxGeometry
136 \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.
137 \note This function returns a single closest hit across all the input triangles. Multiple hits are not supported.
138 \note Only PxHitFlag::eASSUME_NO_INITIAL_OVERLAP, PxHitFlag::ePRECISE_SWEEP and PxHitFlag::eMESH_BOTH_SIDES are supported in hintFlags.
139 \note Unlike scene queries the validity flags in sweepHit are not set by this call and only eDISTANCE and eNORMAL fields are always defined.
140 \note ePOSITION is only defined when there is no initial overlap (sweepHit.hadInitialOverlap() == false)
141 \note The returned normal for initially overlapping sweeps is set to -unitDir.
142 \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.
143 \note The returned PxSweepHit::actor and PxSweepHit::shape pointers are not filled.
144 \note The inflation parameter is not compatible with PxHitFlag::ePRECISE_SWEEP.
145
146 @see PxTriangle PxSweepHit PxGeometry PxTransform
147 */
148 PX_PHYSX_COMMON_API static bool sweep(const PxVec3& unitDir,
149 const PxReal distance,
150 const PxGeometry& geom,
151 const PxTransform& pose,
152 PxU32 triangleCount,
153 const PxTriangle* triangles,
154 PxSweepHit& sweepHit,
155 PxHitFlags hintFlags = PxHitFlag::eDEFAULT,
156 const PxU32* cachedIndex = NULL,
157 const PxReal inflation = 0.0f,
158 bool doubleSided = false);
159};
160
161
162#ifndef PX_DOXYGEN
163}
164#endif
165
166/** @} */
167#endif
168