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_NX_TRIANGLEMESH
32#define PX_PHYSICS_GEOMUTILS_NX_TRIANGLEMESH
33/** \addtogroup geomutils
34@{ */
35
36#include "foundation/PxVec3.h"
37#include "foundation/PxBounds3.h"
38#include "common/PxPhysXCommonConfig.h"
39#include "common/PxBase.h"
40
41#if !PX_DOXYGEN
42namespace physx
43{
44#endif
45
46/**
47\brief Enables the dynamic rtree mesh feature. It is recommended to use this feature for scene queries only.
48@see PxTriangleMesh::getVerticesForModification
49@see PxTriangleMesh::refitBVH
50*/
51#define PX_ENABLE_DYNAMIC_MESH_RTREE 1
52
53/**
54\brief Mesh midphase structure. This enum is used to select the desired acceleration structure for midphase queries
55 (i.e. raycasts, overlaps, sweeps vs triangle meshes).
56
57 The PxMeshMidPhase::eBVH33 structure is the one used in recent PhysX versions (up to PhysX 3.3). It has great performance and is
58 supported on all platforms.
59
60 The PxMeshMidPhase::eBVH34 structure is a revisited implementation introduced in PhysX 3.4. It can be significantly faster both
61 in terms of cooking performance and runtime performance, but it is currently only available on platforms supporting the
62 SSE2 instuction set.
63*/
64struct PxMeshMidPhase
65{
66 enum Enum
67 {
68 eBVH33 = 0, //!< Default midphase mesh structure, as used up to PhysX 3.3
69 eBVH34 = 1, //!< New midphase mesh structure, introduced in PhysX 3.4
70
71 eLAST
72 };
73};
74
75/**
76\brief Flags for the mesh geometry properties.
77
78Used in ::PxTriangleMeshFlags.
79*/
80struct PxTriangleMeshFlag
81{
82 enum Enum
83 {
84 e16_BIT_INDICES = (1<<1), //!< The triangle mesh has 16bits vertex indices.
85 eADJACENCY_INFO = (1<<2) //!< The triangle mesh has adjacency information build.
86 };
87};
88
89/**
90\brief collection of set bits defined in PxTriangleMeshFlag.
91
92@see PxTriangleMeshFlag
93*/
94typedef PxFlags<PxTriangleMeshFlag::Enum,PxU8> PxTriangleMeshFlags;
95PX_FLAGS_OPERATORS(PxTriangleMeshFlag::Enum,PxU8)
96
97/**
98
99\brief A triangle mesh, also called a 'polygon soup'.
100
101It is represented as an indexed triangle list. There are no restrictions on the
102triangle data.
103
104To avoid duplicating data when you have several instances of a particular
105mesh positioned differently, you do not use this class to represent a
106mesh object directly. Instead, you create an instance of this mesh via
107the PxTriangleMeshGeometry and PxShape classes.
108
109<h3>Creation</h3>
110
111To create an instance of this class call PxPhysics::createTriangleMesh(),
112and release() to delete it. This is only possible
113once you have released all of its PxShape instances.
114
115
116<h3>Visualizations:</h3>
117\li #PxVisualizationParameter::eCOLLISION_AABBS
118\li #PxVisualizationParameter::eCOLLISION_SHAPES
119\li #PxVisualizationParameter::eCOLLISION_AXES
120\li #PxVisualizationParameter::eCOLLISION_FNORMALS
121\li #PxVisualizationParameter::eCOLLISION_EDGES
122
123@see PxTriangleMeshDesc PxTriangleMeshGeometry PxShape PxPhysics.createTriangleMesh()
124*/
125
126class PxTriangleMesh : public PxBase
127{
128 public:
129 /**
130 \brief Returns the number of vertices.
131 \return number of vertices
132 @see getVertices()
133 */
134 virtual PxU32 getNbVertices() const = 0;
135
136 /**
137 \brief Returns the vertices.
138 \return array of vertices
139 @see getNbVertices()
140 */
141 virtual const PxVec3* getVertices() const = 0;
142
143#if PX_ENABLE_DYNAMIC_MESH_RTREE
144 /**
145 \brief Returns all mesh vertices for modification.
146
147 This function will return the vertices of the mesh so that their positions can be changed in place.
148 After modifying the vertices you must call refitBVH for the refitting to actually take place.
149 This function maintains the old mesh topology (triangle indices).
150
151 \return inplace vertex coordinates for each existing mesh vertex.
152
153 \note works only for PxMeshMidPhase::eBVH33
154 \note Size of array returned is equal to the number returned by getNbVertices().
155 \note This function operates on cooked vertex indices.
156 \note This means the index mapping and vertex count can be different from what was provided as an input to the cooking routine.
157 \note To achieve unchanged 1-to-1 index mapping with orignal mesh data (before cooking) please use the following cooking flags:
158 \note eWELD_VERTICES = 0, eDISABLE_CLEAN_MESH = 1.
159 \note It is also recommended to make sure that a call to validateTriangleMesh returns true if mesh cleaning is disabled.
160 @see getNbVertices()
161 @see refitBVH()
162 */
163 virtual PxVec3* getVerticesForModification() = 0;
164
165 /**
166 \brief Refits BVH for mesh vertices.
167
168 This function will refit the mesh BVH to correctly enclose the new positions updated by getVerticesForModification.
169 Mesh BVH will not be reoptimized by this function so significantly different new positions will cause significantly reduced performance.
170
171 \return New bounds for the entire mesh.
172
173 \note works only for PxMeshMidPhase::eBVH33
174 \note PhysX does not keep a mapping from the mesh to mesh shapes that reference it.
175 \note Call PxShape::setGeometry on each shape which references the mesh, to ensure that internal data structures are updated to reflect the new geometry.
176 \note PxShape::setGeometry does not guarantee correct/continuous behavior when objects are resting on top of old or new geometry.
177 \note It is also recommended to make sure that a call to validateTriangleMesh returns true if mesh cleaning is disabled.
178 \note Active edges information will be lost during refit, the rigid body mesh contact generation might not perform as expected.
179 @see getNbVertices()
180 @see getVerticesForModification()
181 */
182 virtual PxBounds3 refitBVH() = 0;
183#endif // PX_ENABLE_DYNAMIC_MESH_RTREE
184
185 /**
186 \brief Returns the number of triangles.
187 \return number of triangles
188 @see getTriangles() getTrianglesRemap()
189 */
190 virtual PxU32 getNbTriangles() const = 0;
191
192 /**
193 \brief Returns the triangle indices.
194
195 The indices can be 16 or 32bit depending on the number of triangles in the mesh.
196 Call getTriangleMeshFlags() to know if the indices are 16 or 32 bits.
197
198 The number of indices is the number of triangles * 3.
199
200 \return array of triangles
201 @see getNbTriangles() getTriangleMeshFlags() getTrianglesRemap()
202 */
203 virtual const void* getTriangles() const = 0;
204
205 /**
206 \brief Reads the PxTriangleMesh flags.
207
208 See the list of flags #PxTriangleMeshFlag
209
210 \return The values of the PxTriangleMesh flags.
211
212 @see PxTriangleMesh
213 */
214 virtual PxTriangleMeshFlags getTriangleMeshFlags() const = 0;
215
216 /**
217 \brief Returns the triangle remapping table.
218
219 The triangles are internally sorted according to various criteria. Hence the internal triangle order
220 does not always match the original (user-defined) order. The remapping table helps finding the old
221 indices knowing the new ones:
222
223 remapTable[ internalTriangleIndex ] = originalTriangleIndex
224
225 \return the remapping table (or NULL if 'PxCookingParams::suppressTriangleMeshRemapTable' has been used)
226 @see getNbTriangles() getTriangles() PxCookingParams::suppressTriangleMeshRemapTable
227 */
228 virtual const PxU32* getTrianglesRemap() const = 0;
229
230
231 /**
232 \brief Decrements the reference count of a triangle mesh and releases it if the new reference count is zero.
233
234 @see PxPhysics.createTriangleMesh()
235 */
236 virtual void release() = 0;
237
238 /**
239 \brief Returns material table index of given triangle
240
241 This function takes a post cooking triangle index.
242
243 \param[in] triangleIndex (internal) index of desired triangle
244 \return Material table index, or 0xffff if no per-triangle materials are used
245 */
246 virtual PxMaterialTableIndex getTriangleMaterialIndex(PxTriangleID triangleIndex) const = 0;
247
248 /**
249 \brief Returns the local-space (vertex space) AABB from the triangle mesh.
250
251 \return local-space bounds
252 */
253 virtual PxBounds3 getLocalBounds() const = 0;
254
255 /**
256 \brief Returns the reference count for shared meshes.
257
258 At creation, the reference count of the mesh is 1. Every shape referencing this mesh increments the
259 count by 1. When the reference count reaches 0, and only then, the mesh gets destroyed automatically.
260
261 \return the current reference count.
262 */
263 virtual PxU32 getReferenceCount() const = 0;
264
265 /**
266 \brief Acquires a counted reference to a triangle mesh.
267
268 This method increases the reference count of the triangle mesh by 1. Decrement the reference count by calling release()
269 */
270 virtual void acquireReference() = 0;
271
272protected:
273 PX_INLINE PxTriangleMesh(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {}
274 PX_INLINE PxTriangleMesh(PxBaseFlags baseFlags) : PxBase(baseFlags) {}
275 virtual ~PxTriangleMesh() {}
276
277 virtual bool isKindOf(const char* name) const { return !::strcmp(s1: "PxTriangleMesh", s2: name) || PxBase::isKindOf(superClass: name); }
278};
279
280/**
281
282\brief A triangle mesh containing the PxMeshMidPhase::eBVH33 structure.
283
284@see PxMeshMidPhase
285*/
286class PxBVH33TriangleMesh : public PxTriangleMesh
287{
288 public:
289protected:
290 PX_INLINE PxBVH33TriangleMesh(PxType concreteType, PxBaseFlags baseFlags) : PxTriangleMesh(concreteType, baseFlags) {}
291 PX_INLINE PxBVH33TriangleMesh(PxBaseFlags baseFlags) : PxTriangleMesh(baseFlags) {}
292 virtual ~PxBVH33TriangleMesh() {}
293 virtual bool isKindOf(const char* name) const { return !::strcmp(s1: "PxBVH33TriangleMesh", s2: name) || PxTriangleMesh::isKindOf(name); }
294};
295
296/**
297
298\brief A triangle mesh containing the PxMeshMidPhase::eBVH34 structure.
299
300@see PxMeshMidPhase
301*/
302class PxBVH34TriangleMesh : public PxTriangleMesh
303{
304 public:
305protected:
306 PX_INLINE PxBVH34TriangleMesh(PxType concreteType, PxBaseFlags baseFlags) : PxTriangleMesh(concreteType, baseFlags) {}
307 PX_INLINE PxBVH34TriangleMesh(PxBaseFlags baseFlags) : PxTriangleMesh(baseFlags) {}
308 virtual ~PxBVH34TriangleMesh() {}
309 virtual bool isKindOf(const char* name) const { return !::strcmp(s1: "PxBVH34TriangleMesh", s2: name) || PxTriangleMesh::isKindOf(name); }
310};
311
312#if !PX_DOXYGEN
313} // namespace physx
314#endif
315
316/** @} */
317#endif
318

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