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_CONVEXMESH
32#define PX_PHYSICS_GEOMUTILS_NX_CONVEXMESH
33/** \addtogroup geomutils
34 @{
35*/
36
37#include "foundation/Px.h"
38#include "common/PxBase.h"
39
40#if !PX_DOXYGEN
41namespace physx
42{
43#endif
44
45/**
46\brief Polygon data
47
48Plane format: (mPlane[0],mPlane[1],mPlane[2]).dot(x) + mPlane[3] = 0
49With the normal outward-facing from the hull.
50*/
51struct PxHullPolygon
52{
53 PxReal mPlane[4]; //!< Plane equation for this polygon
54 PxU16 mNbVerts; //!< Number of vertices/edges in the polygon
55 PxU16 mIndexBase; //!< Offset in index buffer
56};
57
58/**
59\brief A convex mesh.
60
61Internally represented as a list of convex polygons. The number
62of polygons is limited to 256.
63
64To avoid duplicating data when you have several instances of a particular
65mesh positioned differently, you do not use this class to represent a
66convex object directly. Instead, you create an instance of this mesh via
67the PxConvexMeshGeometry and PxShape classes.
68
69<h3>Creation</h3>
70
71To create an instance of this class call PxPhysics::createConvexMesh(),
72and PxConvexMesh::release() to delete it. This is only possible
73once you have released all of its #PxShape instances.
74
75<h3>Visualizations:</h3>
76\li #PxVisualizationParameter::eCOLLISION_AABBS
77\li #PxVisualizationParameter::eCOLLISION_SHAPES
78\li #PxVisualizationParameter::eCOLLISION_AXES
79\li #PxVisualizationParameter::eCOLLISION_FNORMALS
80\li #PxVisualizationParameter::eCOLLISION_EDGES
81
82@see PxConvexMeshDesc PxPhysics.createConvexMesh()
83*/
84class PxConvexMesh : public PxBase
85{
86public:
87
88 /**
89 \brief Returns the number of vertices.
90 \return Number of vertices.
91 @see getVertices()
92 */
93 PX_PHYSX_COMMON_API virtual PxU32 getNbVertices() const = 0;
94
95 /**
96 \brief Returns the vertices.
97 \return Array of vertices.
98 @see getNbVertices()
99 */
100 PX_PHYSX_COMMON_API virtual const PxVec3* getVertices() const = 0;
101
102 /**
103 \brief Returns the index buffer.
104 \return Index buffer.
105 @see getNbPolygons() getPolygonData()
106 */
107 PX_PHYSX_COMMON_API virtual const PxU8* getIndexBuffer() const = 0;
108
109 /**
110 \brief Returns the number of polygons.
111 \return Number of polygons.
112 @see getIndexBuffer() getPolygonData()
113 */
114 PX_PHYSX_COMMON_API virtual PxU32 getNbPolygons() const = 0;
115
116 /**
117 \brief Returns the polygon data.
118 \param[in] index Polygon index in [0 ; getNbPolygons()[.
119 \param[out] data Polygon data.
120 \return True if success.
121 @see getIndexBuffer() getNbPolygons()
122 */
123 PX_PHYSX_COMMON_API virtual bool getPolygonData(PxU32 index, PxHullPolygon& data) const = 0;
124
125 /**
126 \brief Decrements the reference count of a convex mesh and releases it if the new reference count is zero.
127
128 @see PxPhysics.createConvexMesh() PxConvexMeshGeometry PxShape
129 */
130 PX_PHYSX_COMMON_API virtual void release() = 0;
131
132 /**
133 \brief Returns the reference count of a convex mesh.
134
135 At creation, the reference count of the convex mesh is 1. Every shape referencing this convex mesh increments the
136 count by 1. When the reference count reaches 0, and only then, the convex mesh gets destroyed automatically.
137
138 \return the current reference count.
139 */
140 PX_PHYSX_COMMON_API virtual PxU32 getReferenceCount() const = 0;
141
142 /**
143 \brief Acquires a counted reference to a convex mesh.
144
145 This method increases the reference count of the convex mesh by 1. Decrement the reference count by calling release()
146 */
147 PX_PHYSX_COMMON_API virtual void acquireReference() = 0;
148
149 /**
150 \brief Returns the mass properties of the mesh assuming unit density.
151
152 The following relationship holds between mass and volume:
153
154 mass = volume * density
155
156 The mass of a unit density mesh is equal to its volume, so this function returns the volume of the mesh.
157
158 Similarly, to obtain the localInertia of an identically shaped object with a uniform density of d, simply multiply the
159 localInertia of the unit density mesh by d.
160
161 \param[out] mass The mass of the mesh assuming unit density.
162 \param[out] localInertia The inertia tensor in mesh local space assuming unit density.
163 \param[out] localCenterOfMass Position of center of mass (or centroid) in mesh local space.
164 */
165 PX_PHYSX_COMMON_API virtual void getMassInformation(PxReal& mass, PxMat33& localInertia, PxVec3& localCenterOfMass) const = 0;
166
167 /**
168 \brief Returns the local-space (vertex space) AABB from the convex mesh.
169
170 \return local-space bounds
171 */
172 PX_PHYSX_COMMON_API virtual PxBounds3 getLocalBounds() const = 0;
173
174 PX_PHYSX_COMMON_API virtual const char* getConcreteTypeName() const { return "PxConvexMesh"; }
175
176 /**
177 \brief This method decides whether a convex mesh is gpu compatible. If the total number of vertices are more than 64 or any number of vertices in a polygon is more than 32, or
178 convex hull data was not cooked with GPU data enabled during cooking or was loaded from a serialized collection, the convex hull is incompatible with GPU collision detection. Otherwise
179 it is compatible.
180
181 \return True if the convex hull is gpu compatible
182 */
183 PX_PHYSX_COMMON_API virtual bool isGpuCompatible() const = 0;
184
185protected:
186 PX_INLINE PxConvexMesh(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {}
187 PX_INLINE PxConvexMesh(PxBaseFlags baseFlags) : PxBase(baseFlags) {}
188 PX_PHYSX_COMMON_API virtual ~PxConvexMesh() {}
189 PX_PHYSX_COMMON_API virtual bool isKindOf(const char* name) const { return !::strcmp(s1: "PxConvexMesh", s2: name) || PxBase::isKindOf(superClass: name); }
190};
191
192#if !PX_DOXYGEN
193} // namespace physx
194#endif
195
196/** @} */
197#endif
198

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