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_SIMPLETRIANGLEMESH |
15 | #define PX_PHYSICS_GEOMUTILS_NX_SIMPLETRIANGLEMESH |
16 | /** \addtogroup geomutils |
17 | @{ |
18 | */ |
19 | |
20 | #include "foundation/PxVec3.h" |
21 | #include "foundation/PxFlags.h" |
22 | #include "common/PxCoreUtilityTypes.h" |
23 | #include "common/PxPhysXCommonConfig.h" |
24 | |
25 | #ifndef PX_DOXYGEN |
26 | namespace physx |
27 | { |
28 | #endif |
29 | |
30 | /** |
31 | \brief Enum with flag values to be used in PxSimpleTriangleMesh::flags. |
32 | */ |
33 | struct PxMeshFlag |
34 | { |
35 | enum Enum |
36 | { |
37 | /** |
38 | \brief Specifies if the SDK should flip normals. |
39 | |
40 | The PhysX libraries assume that the face normal of a triangle with vertices [a,b,c] can be computed as: |
41 | edge1 = b-a |
42 | edge2 = c-a |
43 | face_normal = edge1 x edge2. |
44 | |
45 | Note: This is the same as a counterclockwise winding in a right handed coordinate system or |
46 | alternatively a clockwise winding order in a left handed coordinate system. |
47 | |
48 | If this does not match the winding order for your triangles, raise the below flag. |
49 | */ |
50 | eFLIPNORMALS = (1<<0), |
51 | e16_BIT_INDICES = (1<<1) //<! Denotes the use of 16-bit vertex indices |
52 | }; |
53 | }; |
54 | |
55 | /** |
56 | \brief collection of set bits defined in PxMeshFlag. |
57 | |
58 | @see PxMeshFlag |
59 | */ |
60 | typedef PxFlags<PxMeshFlag::Enum,PxU16> PxMeshFlags; |
61 | PX_FLAGS_OPERATORS(PxMeshFlag::Enum,PxU16) |
62 | |
63 | |
64 | /** |
65 | \brief A structure describing a triangle mesh. |
66 | */ |
67 | class PxSimpleTriangleMesh |
68 | { |
69 | public: |
70 | |
71 | /** |
72 | \brief Pointer to first vertex point. |
73 | */ |
74 | PxBoundedData points; |
75 | |
76 | /** |
77 | \brief Pointer to first triangle. |
78 | |
79 | Caller may add triangleStrideBytes bytes to the pointer to access the next triangle. |
80 | |
81 | These are triplets of 0 based indices: |
82 | vert0 vert1 vert2 |
83 | vert0 vert1 vert2 |
84 | vert0 vert1 vert2 |
85 | ... |
86 | |
87 | where vertex is either a 32 or 16 bit unsigned integer. There are numTriangles*3 indices. |
88 | |
89 | This is declared as a void pointer because it is actually either an PxU16 or a PxU32 pointer. |
90 | */ |
91 | PxBoundedData triangles; |
92 | |
93 | /** |
94 | \brief Flags bits, combined from values of the enum ::PxMeshFlag |
95 | */ |
96 | PxMeshFlags flags; |
97 | |
98 | /** |
99 | \brief constructor sets to default. |
100 | */ |
101 | PX_INLINE PxSimpleTriangleMesh(); |
102 | /** |
103 | \brief (re)sets the structure to the default. |
104 | */ |
105 | PX_INLINE void setToDefault(); |
106 | /** |
107 | \brief returns true if the current settings are valid |
108 | */ |
109 | PX_INLINE bool isValid() const; |
110 | }; |
111 | |
112 | |
113 | PX_INLINE PxSimpleTriangleMesh::PxSimpleTriangleMesh() |
114 | { |
115 | } |
116 | |
117 | PX_INLINE void PxSimpleTriangleMesh::setToDefault() |
118 | { |
119 | *this = PxSimpleTriangleMesh(); |
120 | } |
121 | |
122 | PX_INLINE bool PxSimpleTriangleMesh::isValid() const |
123 | { |
124 | // Check geometry |
125 | if(points.count > 0xffff && flags & PxMeshFlag::e16_BIT_INDICES) |
126 | return false; |
127 | if(!points.data) |
128 | return false; |
129 | if(points.stride < sizeof(PxVec3)) //should be at least one point's worth of data |
130 | return false; |
131 | |
132 | // Check topology |
133 | // The triangles pointer is not mandatory |
134 | if(triangles.data) |
135 | { |
136 | // Indexed mesh |
137 | PxU32 limit = (flags & PxMeshFlag::e16_BIT_INDICES) ? sizeof(PxU16)*3 : sizeof(PxU32)*3; |
138 | if(triangles.stride < limit) |
139 | return false; |
140 | } |
141 | return true; |
142 | } |
143 | |
144 | #ifndef PX_DOXYGEN |
145 | } // namespace physx |
146 | #endif |
147 | |
148 | /** @} */ |
149 | #endif |
150 | |