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