[1378] | 1 | #ifndef NX_COLLISION_NXCONVEXMESHDESC
|
---|
| 2 | #define NX_COLLISION_NXCONVEXMESHDESC
|
---|
| 3 | /*----------------------------------------------------------------------------*\
|
---|
| 4 | |
|
---|
| 5 | | Public Interface to NovodeX Technology
|
---|
| 6 | |
|
---|
| 7 | | www.novodex.com
|
---|
| 8 | |
|
---|
| 9 | \*----------------------------------------------------------------------------*/
|
---|
| 10 | /** \addtogroup physics
|
---|
| 11 | @{
|
---|
| 12 | */
|
---|
| 13 |
|
---|
| 14 | #include "NxConvexMesh.h"
|
---|
| 15 |
|
---|
| 16 | /**
|
---|
| 17 | \brief Flags which describe the format and behavior of a convex mesh.
|
---|
| 18 | */
|
---|
| 19 | enum NxConvexFlags
|
---|
| 20 | {
|
---|
| 21 | /**
|
---|
| 22 | The Nx libraries assume that the face normal of a triangle with vertices [a,b,c] can be computed as:
|
---|
| 23 | edge1 = b-a
|
---|
| 24 | edge2 = c-a
|
---|
| 25 | face_normal = edge1 x edge2.
|
---|
| 26 |
|
---|
| 27 | Note: this is the same as counterclockwise winding in a right handed graphics coordinate system.
|
---|
| 28 |
|
---|
| 29 | If this does not match the winding order for your triangles, raise the below flag.
|
---|
| 30 | */
|
---|
| 31 | NX_CF_FLIPNORMALS = (1<<0), //<! Used to flip the normals if the winding order is reversed.
|
---|
| 32 | NX_CF_16_BIT_INDICES = (1<<1), //<! Denotes the use of 16-bit vertex indices
|
---|
| 33 | NX_CF_COMPUTE_CONVEX = (1<<2), //<! Automatically recomputes the hull from the vertices
|
---|
| 34 |
|
---|
| 35 | /**
|
---|
| 36 | \brief Inflates the convex object according to skin width
|
---|
| 37 |
|
---|
| 38 | This flag is now assumed by default.
|
---|
| 39 |
|
---|
| 40 | If the old behavior is required the NX_CF_USE_LEGACY_COOKER flag can be used.
|
---|
| 41 |
|
---|
| 42 | \note This flag is only used in combination with NX_CF_COMPUTE_CONVEX.
|
---|
| 43 |
|
---|
| 44 | @see NxCookingParams NX_CF_USE_LEGACY_COOKER
|
---|
| 45 | */
|
---|
| 46 | NX_CF_INFLATE_CONVEX = (1<<3),
|
---|
| 47 |
|
---|
| 48 | /**
|
---|
| 49 | \brief Uses legacy hull algorithm, which doesn't inflate convex according to skin width
|
---|
| 50 |
|
---|
| 51 | See NxCookingParams
|
---|
| 52 | */
|
---|
| 53 | NX_CF_USE_LEGACY_COOKER = (1<<4), //!< Use the legacy convex hull algorithm.
|
---|
| 54 | //!< Note that this is only used in combination with NX_CF_COMPUTE_CONVEX.
|
---|
| 55 | };
|
---|
| 56 |
|
---|
| 57 | typedef NxVec3 NxPoint;
|
---|
| 58 |
|
---|
| 59 | /**
|
---|
| 60 | \brief Descriptor class for #NxConvexMesh.
|
---|
| 61 |
|
---|
| 62 | @see NxConvexMesh NxConvexShape NxPhysicsSDK.createConvexMesh()
|
---|
| 63 |
|
---|
| 64 | */
|
---|
| 65 | class NxConvexMeshDesc
|
---|
| 66 | {
|
---|
| 67 | public:
|
---|
| 68 |
|
---|
| 69 | /**
|
---|
| 70 | \brief Number of vertices.
|
---|
| 71 |
|
---|
| 72 | <b>Default:</b> 0
|
---|
| 73 |
|
---|
| 74 | <b>Platform:</b>
|
---|
| 75 | \li PC SW: Yes
|
---|
| 76 | \li PPU : Yes
|
---|
| 77 | \li PS3 : Yes
|
---|
| 78 | \li XB360: Yes
|
---|
| 79 | */
|
---|
| 80 | NxU32 numVertices;
|
---|
| 81 |
|
---|
| 82 | /**
|
---|
| 83 | \brief Number of triangles.
|
---|
| 84 |
|
---|
| 85 | <b>Default:</b> 0
|
---|
| 86 |
|
---|
| 87 | <b>Platform:</b>
|
---|
| 88 | \li PC SW: Yes
|
---|
| 89 | \li PPU : Yes
|
---|
| 90 | \li PS3 : Yes
|
---|
| 91 | \li XB360: Yes
|
---|
| 92 | */
|
---|
| 93 | NxU32 numTriangles;
|
---|
| 94 |
|
---|
| 95 | /**
|
---|
| 96 | \brief Offset between vertex points in bytes.
|
---|
| 97 |
|
---|
| 98 | <b>Default:</b> 0
|
---|
| 99 |
|
---|
| 100 | <b>Platform:</b>
|
---|
| 101 | \li PC SW: Yes
|
---|
| 102 | \li PPU : Yes
|
---|
| 103 | \li PS3 : Yes
|
---|
| 104 | \li XB360: Yes
|
---|
| 105 | */
|
---|
| 106 | NxU32 pointStrideBytes;
|
---|
| 107 |
|
---|
| 108 | /**
|
---|
| 109 | \brief Offset between triangles in bytes.
|
---|
| 110 |
|
---|
| 111 | <b>Default:</b> 0
|
---|
| 112 |
|
---|
| 113 | <b>Platform:</b>
|
---|
| 114 | \li PC SW: Yes
|
---|
| 115 | \li PPU : Yes
|
---|
| 116 | \li PS3 : Yes
|
---|
| 117 | \li XB360: Yes
|
---|
| 118 | */
|
---|
| 119 | NxU32 triangleStrideBytes;
|
---|
| 120 |
|
---|
| 121 | /**
|
---|
| 122 | \brief Pointer to array of vertex positions.
|
---|
| 123 | Pointer to first vertex point. Caller may add pointStrideBytes bytes to the pointer to access the next point.
|
---|
| 124 |
|
---|
| 125 | <b>Default:</b> NULL
|
---|
| 126 |
|
---|
| 127 | <b>Platform:</b>
|
---|
| 128 | \li PC SW: Yes
|
---|
| 129 | \li PPU : Yes
|
---|
| 130 | \li PS3 : Yes
|
---|
| 131 | \li XB360: Yes
|
---|
| 132 | */
|
---|
| 133 | const void* points;
|
---|
| 134 |
|
---|
| 135 | /**
|
---|
| 136 | \brief Pointer to array of triangle inices.
|
---|
| 137 | <p>Pointer to first triangle. Caller may add triangleStrideBytes bytes to the pointer to access the next triangle.</p>
|
---|
| 138 | <p><pre>These are triplets of 0 based indices:
|
---|
| 139 | vert0 vert1 vert2
|
---|
| 140 | vert0 vert1 vert2
|
---|
| 141 | vert0 vert1 vert2
|
---|
| 142 | ...</pre></p>
|
---|
| 143 |
|
---|
| 144 | <p>Where vertex is either a 32 or 16 bit unsigned integer. There are numTriangles*3 indices.</p>
|
---|
| 145 |
|
---|
| 146 | <p>This is declared as a void pointer because it is actually either an NxU16 or a NxU32 pointer.</p>
|
---|
| 147 |
|
---|
| 148 | <b>Default:</b> NULL
|
---|
| 149 |
|
---|
| 150 | <b>Platform:</b>
|
---|
| 151 | \li PC SW: Yes
|
---|
| 152 | \li PPU : Yes
|
---|
| 153 | \li PS3 : Yes
|
---|
| 154 | \li XB360: Yes
|
---|
| 155 | */
|
---|
| 156 | const void* triangles;
|
---|
| 157 |
|
---|
| 158 | /**
|
---|
| 159 | \brief Flags bits, combined from values of the enum ::NxConvexFlags
|
---|
| 160 |
|
---|
| 161 | <b>Default:</b> 0
|
---|
| 162 |
|
---|
| 163 | <b>Platform:</b>
|
---|
| 164 | \li PC SW: Yes
|
---|
| 165 | \li PPU : Partial
|
---|
| 166 | \li PS3 : Yes
|
---|
| 167 | \li XB360: Yes
|
---|
| 168 | */
|
---|
| 169 | NxU32 flags;
|
---|
| 170 |
|
---|
| 171 | /**
|
---|
| 172 | \brief constructor sets to default.
|
---|
| 173 | */
|
---|
| 174 | NX_INLINE NxConvexMeshDesc();
|
---|
| 175 | /**
|
---|
| 176 | \brief (re)sets the structure to the default.
|
---|
| 177 | */
|
---|
| 178 | NX_INLINE void setToDefault();
|
---|
| 179 | /**
|
---|
| 180 | \brief Returns true if the descriptor is valid.
|
---|
| 181 |
|
---|
| 182 | \return True if the current settings are valid
|
---|
| 183 | */
|
---|
| 184 | NX_INLINE bool isValid() const;
|
---|
| 185 | };
|
---|
| 186 |
|
---|
| 187 | NX_INLINE NxConvexMeshDesc::NxConvexMeshDesc() //constructor sets to default
|
---|
| 188 | {
|
---|
| 189 | setToDefault();
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | NX_INLINE void NxConvexMeshDesc::setToDefault()
|
---|
| 193 | {
|
---|
| 194 | numVertices = 0;
|
---|
| 195 | numTriangles = 0;
|
---|
| 196 | pointStrideBytes = 0;
|
---|
| 197 | triangleStrideBytes = 0;
|
---|
| 198 | points = NULL;
|
---|
| 199 | triangles = NULL;
|
---|
| 200 | flags = 0;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | NX_INLINE bool NxConvexMeshDesc::isValid() const
|
---|
| 204 | {
|
---|
| 205 | // Check geometry
|
---|
| 206 | if(numVertices < 3 || //at least 1 trig's worth of points
|
---|
| 207 | (numVertices > 0xffff && flags & NX_CF_16_BIT_INDICES))
|
---|
| 208 | return false;
|
---|
| 209 | if(!points)
|
---|
| 210 | return false;
|
---|
| 211 | if(pointStrideBytes < sizeof(NxPoint)) //should be at least one point's worth of data
|
---|
| 212 | return false;
|
---|
| 213 |
|
---|
| 214 | // Check topology
|
---|
| 215 | // The triangles pointer is not mandatory: the vertex cloud is enough to define the convex hull.
|
---|
| 216 | if(triangles)
|
---|
| 217 | {
|
---|
| 218 | // Indexed mesh
|
---|
| 219 | if(numTriangles < 2) //some algos require at least 2 trigs
|
---|
| 220 | return false;
|
---|
| 221 | if(flags & NX_CF_16_BIT_INDICES)
|
---|
| 222 | {
|
---|
| 223 | if((triangleStrideBytes < sizeof(NxU16)*3))
|
---|
| 224 | return false;
|
---|
| 225 | }
|
---|
| 226 | else
|
---|
| 227 | {
|
---|
| 228 | if((triangleStrideBytes < sizeof(NxU32)*3))
|
---|
| 229 | return false;
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 | else
|
---|
| 233 | {
|
---|
| 234 | // We can compute the hull from the vertices
|
---|
| 235 | if(!(flags & NX_CF_COMPUTE_CONVEX))
|
---|
| 236 | return false; // If the mesh is convex and we're not allowed to compute the hull,
|
---|
| 237 | // you have to provide it completely (geometry & topology).
|
---|
| 238 | }
|
---|
| 239 | return true;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 |
|
---|
| 243 | /** \cond */
|
---|
| 244 | //#ifdef NX_SUPPORT_INTERNAL_FACES
|
---|
| 245 | /**
|
---|
| 246 | <p>Descriptor class for NxConvexMesh.</p>
|
---|
| 247 |
|
---|
| 248 | <p>This version is used when the user can provide his own set of already-computed hull polygons. This also makes it
|
---|
| 249 | possible to mark each polygon as internal or not (which would have been painful to do with the original desc since
|
---|
| 250 | polygons are not explicitly defined there)</p>
|
---|
| 251 | */
|
---|
| 252 | class NxConvexMeshDesc2
|
---|
| 253 | {
|
---|
| 254 | public:
|
---|
| 255 | NxU32 numVertices; //!< Number of vertices.
|
---|
| 256 | NxU32 numPolygons; //!< Number of convex polygons.
|
---|
| 257 |
|
---|
| 258 | /**
|
---|
| 259 | \brief Pointer to array of vertex positions.
|
---|
| 260 | Pointer to first vertex point. Caller may add pointStrideBytes bytes to the pointer to access the next point.
|
---|
| 261 | */
|
---|
| 262 | const void* points;
|
---|
| 263 |
|
---|
| 264 | /**
|
---|
| 265 | <p>Polygon counts and indices(there are numPolygons polygons).</p>
|
---|
| 266 |
|
---|
| 267 | <p>
|
---|
| 268 | <pre>Format:-
|
---|
| 269 | Polygon 1 Index Count (NxU32)
|
---|
| 270 | Index 0 (NxU32)
|
---|
| 271 | Index 1
|
---|
| 272 | ...
|
---|
| 273 | Polygon 2 Index Count
|
---|
| 274 | Index 0
|
---|
| 275 | Index 1
|
---|
| 276 | ...</pre>
|
---|
| 277 | </p>
|
---|
| 278 |
|
---|
| 279 | */
|
---|
| 280 | const NxU32* polygons;
|
---|
| 281 |
|
---|
| 282 | /**
|
---|
| 283 | Internal flags relating to the this convex mesh.
|
---|
| 284 | */
|
---|
| 285 | const bool* internalFlags;
|
---|
| 286 |
|
---|
| 287 | /**
|
---|
| 288 | constructor sets to default.
|
---|
| 289 | */
|
---|
| 290 | NX_INLINE NxConvexMeshDesc2();
|
---|
| 291 | /**
|
---|
| 292 | (re)sets the structure to the default.
|
---|
| 293 | */
|
---|
| 294 | NX_INLINE void setToDefault();
|
---|
| 295 | /**
|
---|
| 296 | returns true if the current settings are valid
|
---|
| 297 | */
|
---|
| 298 | NX_INLINE bool isValid() const;
|
---|
| 299 | };
|
---|
| 300 |
|
---|
| 301 | NX_INLINE NxConvexMeshDesc2::NxConvexMeshDesc2() //constructor sets to default
|
---|
| 302 | {
|
---|
| 303 | setToDefault();
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | NX_INLINE void NxConvexMeshDesc2::setToDefault()
|
---|
| 307 | {
|
---|
| 308 | numVertices = 0;
|
---|
| 309 | numPolygons = 0;
|
---|
| 310 | points = NULL;
|
---|
| 311 | polygons = NULL;
|
---|
| 312 | internalFlags = NULL;
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | NX_INLINE bool NxConvexMeshDesc2::isValid() const
|
---|
| 316 | {
|
---|
| 317 | return true;
|
---|
| 318 | }
|
---|
| 319 | //#endif
|
---|
| 320 | /** \endcond */
|
---|
| 321 |
|
---|
| 322 | /** @} */
|
---|
| 323 | #endif
|
---|
| 324 |
|
---|
| 325 |
|
---|
| 326 | //AGCOPYRIGHTBEGIN
|
---|
| 327 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 328 | // Copyright © 2005 AGEIA Technologies.
|
---|
| 329 | // All rights reserved. www.ageia.com
|
---|
| 330 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 331 | //AGCOPYRIGHTEND
|
---|
| 332 |
|
---|