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_CONVEXMESH_GEOMETRY |
15 | #define PX_PHYSICS_NX_CONVEXMESH_GEOMETRY |
16 | /** \addtogroup geomutils |
17 | @{ |
18 | */ |
19 | #include "geometry/PxGeometry.h" |
20 | #include "geometry/PxMeshScale.h" |
21 | |
22 | #ifndef PX_DOXYGEN |
23 | namespace physx |
24 | { |
25 | #endif |
26 | |
27 | class PxConvexMesh; |
28 | |
29 | /** |
30 | \brief Convex mesh geometry class. |
31 | |
32 | This class unifies a convex mesh object with a scaling transform, and |
33 | lets the combined object be used anywhere a PxGeometry is needed. |
34 | |
35 | The scaling is a transform along arbitrary axes contained in the scale object. |
36 | The vertices of the mesh in geometry (or shape) space is the |
37 | PxMeshScale::toMat33() transform, multiplied by the vertex space vertices |
38 | in the PxConvexMesh object. |
39 | */ |
40 | class PxConvexMeshGeometry : public PxGeometry |
41 | { |
42 | public: |
43 | /** |
44 | \brief Default constructor. |
45 | |
46 | Creates an empty object with a NULL mesh and identity scale. |
47 | */ |
48 | PX_INLINE PxConvexMeshGeometry() : |
49 | PxGeometry(PxGeometryType::eCONVEXMESH), |
50 | scale(PxMeshScale(1.0f)), |
51 | convexMesh(NULL) |
52 | {} |
53 | |
54 | /** |
55 | \brief Constructor. |
56 | \param[in] mesh The Mesh pointer. May be NULL, though this will not make the object valid for shape construction. |
57 | \param[in] scaling The scale factor. |
58 | \ |
59 | */ |
60 | PX_INLINE PxConvexMeshGeometry(PxConvexMesh* mesh, |
61 | const PxMeshScale& scaling = PxMeshScale()) : |
62 | PxGeometry(PxGeometryType::eCONVEXMESH), |
63 | scale(scaling), |
64 | convexMesh(mesh) |
65 | {} |
66 | |
67 | /** |
68 | \brief Returns true if the geometry is valid. |
69 | |
70 | \return True if the current settings are valid for shape creation. |
71 | |
72 | \note A valid convex mesh has a positive scale value in each direction (scale.x > 0, scale.y > 0, scale.z > 0). |
73 | It is illegal to call PxRigidActor::createShape and PxPhysics::createShape with a convex that has zero extent in any direction. |
74 | |
75 | @see PxRigidActor::createShape, PxPhysics::createShape |
76 | */ |
77 | PX_INLINE bool isValid() const; |
78 | |
79 | public: |
80 | |
81 | /** |
82 | \brief Scale factor that transforms from vertex space to shape space. |
83 | */ |
84 | PxMeshScale scale; |
85 | /** |
86 | \brief The mesh data in vertex space. |
87 | */ |
88 | PxConvexMesh* convexMesh; |
89 | }; |
90 | |
91 | |
92 | PX_INLINE bool PxConvexMeshGeometry::isValid() const |
93 | { |
94 | if (mType != PxGeometryType::eCONVEXMESH) |
95 | return false; |
96 | if (!scale.scale.isFinite() || !scale.rotation.isUnit()) |
97 | return false; |
98 | if (scale.scale.x <= 0.0f || scale.scale.y <= 0.0f || scale.scale.z <= 0.0f) |
99 | return false; |
100 | if (!convexMesh) |
101 | return false; |
102 | |
103 | return true; |
104 | } |
105 | |
106 | #ifndef PX_DOXYGEN |
107 | } // namespace physx |
108 | #endif |
109 | |
110 | /** @} */ |
111 | #endif |
112 | |