| 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_NX_TRIANGLEMESH_GEOMETRY |
| 15 | #define PX_PHYSICS_NX_TRIANGLEMESH_GEOMETRY |
| 16 | /** \addtogroup geomutils |
| 17 | @{ |
| 18 | */ |
| 19 | #include "geometry/PxGeometry.h" |
| 20 | #include "geometry/PxMeshScale.h" |
| 21 | #include "common/PxCoreUtilityTypes.h" |
| 22 | |
| 23 | #ifndef PX_DOXYGEN |
| 24 | namespace physx |
| 25 | { |
| 26 | #endif |
| 27 | |
| 28 | class PxTriangleMesh; |
| 29 | |
| 30 | |
| 31 | /** |
| 32 | \brief Some flags to control the simulated behavior of the mesh geometry. |
| 33 | |
| 34 | Used in ::PxMeshGeometryFlags. |
| 35 | */ |
| 36 | struct PxMeshGeometryFlag |
| 37 | { |
| 38 | enum Enum |
| 39 | { |
| 40 | eDOUBLE_SIDED = (1<<1) //!< Meshes with this flag set are treated as double-sided. |
| 41 | //!< This flag is currently only used for raycasts and sweeps (it is ignored for overlap queries). |
| 42 | //!< For detailed specifications of this flag for meshes and heightfields please refer to the Geometry Query section of the user guide. |
| 43 | }; |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | \brief collection of set bits defined in PxMeshGeometryFlag. |
| 48 | |
| 49 | @see PxMeshGeometryFlag |
| 50 | */ |
| 51 | typedef PxFlags<PxMeshGeometryFlag::Enum,PxU8> PxMeshGeometryFlags; |
| 52 | PX_FLAGS_OPERATORS(PxMeshGeometryFlag::Enum,PxU8) |
| 53 | |
| 54 | /** |
| 55 | \brief Triangle mesh geometry class. |
| 56 | |
| 57 | This class unifies a mesh object with a scaling transform, and |
| 58 | lets the combined object be used anywhere a PxGeometry is needed. |
| 59 | |
| 60 | The scaling is a transform along arbitrary axes contained in the scale object. |
| 61 | The vertices of the mesh in geometry (or shape) space is the |
| 62 | PxMeshScale::toMat33() transform, multiplied by the vertex space vertices |
| 63 | in the PxConvexMesh object. |
| 64 | */ |
| 65 | class PxTriangleMeshGeometry : public PxGeometry |
| 66 | { |
| 67 | public: |
| 68 | PX_INLINE PxTriangleMeshGeometry() : |
| 69 | PxGeometry(PxGeometryType::eTRIANGLEMESH), |
| 70 | triangleMesh(NULL) |
| 71 | { } |
| 72 | |
| 73 | PX_INLINE PxTriangleMeshGeometry(PxTriangleMesh* mesh, |
| 74 | const PxMeshScale& scaling = PxMeshScale(), |
| 75 | PxMeshGeometryFlags flags = PxMeshGeometryFlags()) : |
| 76 | PxGeometry(PxGeometryType::eTRIANGLEMESH), |
| 77 | scale(scaling), |
| 78 | meshFlags(flags), |
| 79 | triangleMesh(mesh) |
| 80 | { } |
| 81 | |
| 82 | /** |
| 83 | \brief Returns true if the geometry is valid. |
| 84 | |
| 85 | \return True if the current settings are valid. |
| 86 | |
| 87 | \note A valid triangle mesh has a positive scale value in each direction (scale.scale.x > 0, scale.scale.y > 0, scale.scale.z > 0). |
| 88 | It is illegal to call PxRigidActor::createShape and PxPhysics::createShape with a triangle mesh that has zero extents in any direction. |
| 89 | |
| 90 | @see PxRigidActor::createShape, PxPhysics::createShape |
| 91 | */ |
| 92 | PX_INLINE bool isValid() const; |
| 93 | |
| 94 | public: |
| 95 | PxMeshScale scale; //!< The scaling transformation. |
| 96 | |
| 97 | PxMeshGeometryFlags meshFlags; //!< Some flags to control the simulated behavior of the mesh geometry. |
| 98 | PxPadding<3> paddingFromFlags; //!< padding for mesh flags |
| 99 | |
| 100 | PxTriangleMesh* triangleMesh; //!< A reference to the mesh object. |
| 101 | }; |
| 102 | |
| 103 | |
| 104 | PX_INLINE bool PxTriangleMeshGeometry::isValid() const |
| 105 | { |
| 106 | if (mType != PxGeometryType::eTRIANGLEMESH) |
| 107 | return false; |
| 108 | if (!scale.scale.isFinite() || !scale.rotation.isUnit()) |
| 109 | return false; |
| 110 | if (scale.scale.x <= 0.0f || scale.scale.y <= 0.0f || scale.scale.z <= 0.0f) |
| 111 | return false; |
| 112 | if (!triangleMesh) |
| 113 | return false; |
| 114 | |
| 115 | return true; |
| 116 | } |
| 117 | |
| 118 | #ifndef PX_DOXYGEN |
| 119 | } // namespace physx |
| 120 | #endif |
| 121 | |
| 122 | /** @} */ |
| 123 | #endif |
| 124 | |