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_COLLISION_NXTRIANGLEMESHDESC
15#define PX_COLLISION_NXTRIANGLEMESHDESC
16/** \addtogroup cooking
17@{
18*/
19
20#include "PxPhysXConfig.h"
21#include "geometry/PxSimpleTriangleMesh.h"
22
23#ifndef PX_DOXYGEN
24namespace physx
25{
26#endif
27
28/**
29\brief Descriptor class for #PxTriangleMesh.
30
31Note that this class is derived from PxSimpleTriangleMesh which contains the members that describe the basic mesh.
32The mesh data is *copied* when an PxTriangleMesh object is created from this descriptor. After the call the
33user may discard the triangle data.
34
35@see PxTriangleMesh PxTriangleMeshGeometry PxShape
36*/
37class PxTriangleMeshDesc : public PxSimpleTriangleMesh
38{
39public:
40
41 /**
42 Optional pointer to first material index, or NULL. There are PxSimpleTriangleMesh::numTriangles indices in total.
43 Caller may add materialIndexStride bytes to the pointer to access the next triangle.
44
45 When a triangle mesh collides with another object, a material is required at the collision point.
46 If materialIndices is NULL, then the material of the PxShape instance is used.
47 Otherwise, if the point of contact is on a triangle with index i, then the material index is determined as:
48 PxMaterialTableIndex index = *(PxMaterialTableIndex *)(((PxU8*)materialIndices) + materialIndexStride * i);
49
50 If the contact point falls on a vertex or an edge, a triangle adjacent to the vertex or edge is selected, and its index
51 used to look up a material. The selection is arbitrary but consistent over time.
52
53 <b>Default:</b> NULL
54
55 @see materialIndexStride
56 */
57 PxTypedStridedData<PxMaterialTableIndex> materialIndices;
58
59 /**
60 \deprecated
61 The SDK computes convex edges of a mesh and use them for collision detection. This parameter allows you to
62 setup a tolerance for the convex edge detector.
63
64 <b>Range:</b> (0, PX_MAX_F32)<br>
65 <b>Default:</b> 0.001
66 */
67 PX_DEPRECATED PxReal convexEdgeThreshold;
68
69 /**
70 \brief Constructor sets to default.
71 */
72 PX_INLINE PxTriangleMeshDesc();
73
74 /**
75 \brief (re)sets the structure to the default.
76 */
77 PX_INLINE void setToDefault();
78
79 /**
80 \brief Returns true if the descriptor is valid.
81 \return true if the current settings are valid
82 */
83 PX_INLINE bool isValid() const;
84};
85
86PX_INLINE PxTriangleMeshDesc::PxTriangleMeshDesc() //constructor sets to default
87{
88 PxSimpleTriangleMesh::setToDefault();
89 convexEdgeThreshold = 0.001f;
90}
91
92PX_INLINE void PxTriangleMeshDesc::setToDefault()
93{
94 *this = PxTriangleMeshDesc();
95}
96
97PX_INLINE bool PxTriangleMeshDesc::isValid() const
98{
99 if(points.count < 3) //at least 1 trig's worth of points
100 return false;
101 if ((!triangles.data) && (points.count%3)) // Non-indexed mesh => we must ensure the geometry defines an implicit number of triangles // i.e. numVertices can't be divided by 3
102 return false;
103 //add more validity checks here
104 if (materialIndices.data && materialIndices.stride < sizeof(PxMaterialTableIndex))
105 return false;
106 return PxSimpleTriangleMesh::isValid();
107}
108
109#ifndef PX_DOXYGEN
110} // namespace physx
111#endif
112
113/** @} */
114#endif
115