| 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_TRIANGLEMESH |
| 15 | #define PX_PHYSICS_GEOMUTILS_NX_TRIANGLEMESH |
| 16 | /** \addtogroup geomutils |
| 17 | @{ */ |
| 18 | |
| 19 | #include "foundation/PxVec3.h" |
| 20 | #include "foundation/PxBounds3.h" |
| 21 | #include "common/PxPhysXCommonConfig.h" |
| 22 | #include "common/PxBase.h" |
| 23 | |
| 24 | #ifndef PX_DOXYGEN |
| 25 | namespace physx |
| 26 | { |
| 27 | #endif |
| 28 | |
| 29 | /** |
| 30 | \brief Flags for the mesh geometry properties. |
| 31 | |
| 32 | Used in ::PxTriangleMeshFlags. |
| 33 | */ |
| 34 | struct PxTriangleMeshFlag |
| 35 | { |
| 36 | enum Enum |
| 37 | { |
| 38 | e16_BIT_INDICES = (1<<1), //!< The triangle mesh has 16bits vertex indices. |
| 39 | eADJACENCY_INFO = (1<<2), //!< The triangle mesh has adjacency information build. |
| 40 | |
| 41 | PX_DEPRECATED eHAS_16BIT_TRIANGLE_INDICES = e16_BIT_INDICES, |
| 42 | PX_DEPRECATED eHAS_ADJACENCY_INFO = eADJACENCY_INFO |
| 43 | }; |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | \brief collection of set bits defined in PxTriangleMeshFlag. |
| 48 | |
| 49 | @see PxTriangleMeshFlag |
| 50 | */ |
| 51 | typedef PxFlags<PxTriangleMeshFlag::Enum,PxU8> PxTriangleMeshFlags; |
| 52 | PX_FLAGS_OPERATORS(PxTriangleMeshFlag::Enum,PxU8) |
| 53 | |
| 54 | /** |
| 55 | |
| 56 | \brief A triangle mesh, also called a 'polygon soup'. |
| 57 | |
| 58 | It is represented as an indexed triangle list. There are no restrictions on the |
| 59 | triangle data. |
| 60 | |
| 61 | To avoid duplicating data when you have several instances of a particular |
| 62 | mesh positioned differently, you do not use this class to represent a |
| 63 | mesh object directly. Instead, you create an instance of this mesh via |
| 64 | the PxTriangleMeshGeometry and PxShape classes. |
| 65 | |
| 66 | <h3>Creation</h3> |
| 67 | |
| 68 | To create an instance of this class call PxPhysics::createTriangleMesh(), |
| 69 | and release() to delete it. This is only possible |
| 70 | once you have released all of its PxShape instances. |
| 71 | |
| 72 | |
| 73 | <h3>Visualizations:</h3> |
| 74 | \li #PxVisualizationParameter::eCOLLISION_AABBS |
| 75 | \li #PxVisualizationParameter::eCOLLISION_SHAPES |
| 76 | \li #PxVisualizationParameter::eCOLLISION_AXES |
| 77 | \li #PxVisualizationParameter::eCOLLISION_FNORMALS |
| 78 | \li #PxVisualizationParameter::eCOLLISION_EDGES |
| 79 | |
| 80 | @see PxTriangleMeshDesc PxTriangleMeshGeometry PxShape PxPhysics.createTriangleMesh() |
| 81 | */ |
| 82 | |
| 83 | class PxTriangleMesh : public PxBase |
| 84 | { |
| 85 | public: |
| 86 | /** |
| 87 | \brief Returns the number of vertices. |
| 88 | \return number of vertices |
| 89 | @see getVertices() |
| 90 | */ |
| 91 | PX_PHYSX_COMMON_API virtual PxU32 getNbVertices() const = 0; |
| 92 | |
| 93 | /** |
| 94 | \brief Returns the vertices. |
| 95 | \return array of vertices |
| 96 | @see getNbVertices() |
| 97 | */ |
| 98 | PX_PHYSX_COMMON_API virtual const PxVec3* getVertices() const = 0; |
| 99 | |
| 100 | /** |
| 101 | \brief Returns the number of triangles. |
| 102 | \return number of triangles |
| 103 | @see getTriangles() getTrianglesRemap() |
| 104 | */ |
| 105 | PX_PHYSX_COMMON_API virtual PxU32 getNbTriangles() const = 0; |
| 106 | |
| 107 | /** |
| 108 | \brief Returns the triangle indices. |
| 109 | |
| 110 | The indices can be 16 or 32bit depending on the number of triangles in the mesh. |
| 111 | Call getTriangleMeshFlags() to know if the indices are 16 or 32 bits. |
| 112 | |
| 113 | The number of indices is the number of triangles * 3. |
| 114 | |
| 115 | \return array of triangles |
| 116 | @see getNbTriangles() getTriangleMeshFlags() getTrianglesRemap() |
| 117 | */ |
| 118 | PX_PHYSX_COMMON_API virtual const void* getTriangles() const = 0; |
| 119 | |
| 120 | /** |
| 121 | \brief Reads the PxTriangleMesh flags. |
| 122 | |
| 123 | See the list of flags #PxTriangleMeshFlag |
| 124 | |
| 125 | \return The values of the PxTriangleMesh flags. |
| 126 | |
| 127 | @see PxTriangleMesh |
| 128 | */ |
| 129 | PX_PHYSX_COMMON_API virtual PxTriangleMeshFlags getTriangleMeshFlags() const = 0; |
| 130 | |
| 131 | /** |
| 132 | \brief Returns the triangle remapping table. |
| 133 | |
| 134 | The triangles are internally sorted according to various criteria. Hence the internal triangle order |
| 135 | does not always match the original (user-defined) order. The remapping table helps finding the old |
| 136 | indices knowing the new ones: |
| 137 | |
| 138 | remapTable[ internalTriangleIndex ] = originalTriangleIndex |
| 139 | |
| 140 | \return the remapping table (or NULL if 'PxCookingParams::suppressTriangleMeshRemapTable' has been used) |
| 141 | @see getNbTriangles() getTriangles() PxCookingParams::suppressTriangleMeshRemapTable |
| 142 | */ |
| 143 | PX_PHYSX_COMMON_API virtual const PxU32* getTrianglesRemap() const = 0; |
| 144 | |
| 145 | |
| 146 | /** |
| 147 | \brief Decrements the reference count of a triangle mesh and releases it if the new reference count is zero. |
| 148 | |
| 149 | The mesh is destroyed when the application's reference is released and all shapes referencing the mesh are destroyed. |
| 150 | |
| 151 | @see PxPhysics.createTriangleMesh() |
| 152 | */ |
| 153 | PX_PHYSX_COMMON_API virtual void release() = 0; |
| 154 | |
| 155 | /** |
| 156 | \brief Returns material table index of given triangle |
| 157 | |
| 158 | This function takes a post cooking triangle index. |
| 159 | |
| 160 | \param[in] triangleIndex (internal) index of desired triangle |
| 161 | \return Material table index, or 0xffff if no per-triangle materials are used |
| 162 | */ |
| 163 | PX_PHYSX_COMMON_API virtual PxMaterialTableIndex getTriangleMaterialIndex(PxTriangleID triangleIndex) const = 0; |
| 164 | |
| 165 | /** |
| 166 | \brief Returns the local-space (vertex space) AABB from the triangle mesh. |
| 167 | |
| 168 | \return local-space bounds |
| 169 | */ |
| 170 | PX_PHYSX_COMMON_API virtual PxBounds3 getLocalBounds() const = 0; |
| 171 | |
| 172 | /** |
| 173 | \brief Returns the reference count for shared meshes. |
| 174 | |
| 175 | At creation, the reference count of the mesh is 1. Every shape referencing this mesh increments the |
| 176 | count by 1. When the reference count reaches 0, and only then, the mesh gets destroyed automatically. |
| 177 | |
| 178 | \return the current reference count. |
| 179 | */ |
| 180 | PX_PHYSX_COMMON_API virtual PxU32 getReferenceCount() const = 0; |
| 181 | |
| 182 | PX_PHYSX_COMMON_API virtual const char* getConcreteTypeName() const { return "PxTriangleMesh" ; } |
| 183 | |
| 184 | protected: |
| 185 | PX_INLINE PxTriangleMesh(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {} |
| 186 | PX_INLINE PxTriangleMesh(PxBaseFlags baseFlags) : PxBase(baseFlags) {} |
| 187 | PX_PHYSX_COMMON_API virtual ~PxTriangleMesh() {} |
| 188 | PX_PHYSX_COMMON_API virtual bool isKindOf(const char* name) const { return !strcmp("PxTriangleMesh" , name) || PxBase::isKindOf(name); } |
| 189 | }; |
| 190 | |
| 191 | #ifndef PX_DOXYGEN |
| 192 | } // namespace physx |
| 193 | #endif |
| 194 | |
| 195 | /** @} */ |
| 196 | #endif |
| 197 | |