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_CLOTHMESHDESC
15#define PX_PHYSICS_NX_CLOTHMESHDESC
16/** \addtogroup cooking
17@{
18*/
19
20#include "common/PxPhysXCommonConfig.h"
21#include "geometry/PxSimpleTriangleMesh.h"
22
23#ifndef PX_DOXYGEN
24namespace physx
25{
26#endif
27
28/**
29\brief Descriptor class for a cloth mesh.
30
31@see PxCooking.cookClothMesh()
32
33*/
34class PxClothMeshDesc
35{
36public:
37
38 /**
39 \brief Pointer to first vertex point.
40 */
41 PxBoundedData points;
42
43 /**
44 \brief Determines whether particle is simulated or static.
45 A positive value denotes that the particle is being simulated, zero denotes a static particle.
46 This data is used to generate tether and zero stretch constraints.
47 If invMasses.data is null, all particles are assumed to be simulated
48 and no tether and zero stretch constraints are being generated.
49 */
50 PxBoundedData invMasses;
51
52 /**
53 \brief Pointer to the first triangle.
54
55 These are triplets of 0 based indices:
56 vert0 vert1 vert2
57 vert0 vert1 vert2
58 vert0 vert1 vert2
59 ...
60
61 where vert* is either a 32 or 16 bit unsigned integer. There are a total of 3*count indices.
62 The stride determines the byte offset to the next index triple.
63
64 This is declared as a void pointer because it is actually either an PxU16 or a PxU32 pointer.
65 */
66 PxBoundedData triangles;
67
68 /**
69 \brief Pointer to the first quad.
70
71 These are quadruples of 0 based indices:
72 vert0 vert1 vert2 vert3
73 vert0 vert1 vert2 vert3
74 vert0 vert1 vert2 vert3
75 ...
76
77 where vert* is either a 32 or 16 bit unsigned integer. There are a total of 4*count indices.
78 The stride determines the byte offset to the next index quadruple.
79
80 This is declared as a void pointer because it is actually either an PxU16 or a PxU32 pointer.
81 */
82 PxBoundedData quads;
83
84 /**
85 \brief Flags bits, combined from values of the enum ::PxMeshFlag
86 */
87 PxMeshFlags flags;
88
89 /**
90 \brief constructor sets to default.
91 */
92 PX_INLINE PxClothMeshDesc();
93 /**
94 \brief (re)sets the structure to the default.
95 */
96 PX_INLINE void setToDefault();
97 /**
98 \brief Returns true if the descriptor is valid.
99 \return True if the current settings are valid
100 */
101 PX_INLINE bool isValid() const;
102};
103
104PX_INLINE PxClothMeshDesc::PxClothMeshDesc() //constructor sets to default
105{
106}
107
108PX_INLINE void PxClothMeshDesc::setToDefault()
109{
110 *this = PxClothMeshDesc();
111}
112
113PX_INLINE bool PxClothMeshDesc::isValid() const
114{
115 if(points.count < 3) //at least 1 trig's worth of points
116 return false;
117 if(points.count > 0xffff && flags & PxMeshFlag::e16_BIT_INDICES)
118 return false;
119 if(!points.data)
120 return false;
121 if(points.stride < sizeof(PxVec3)) //should be at least one point's worth of data
122 return false;
123
124 if(invMasses.data && invMasses.stride < sizeof(float))
125 return false;
126 if(invMasses.data && invMasses.count != points.count)
127 return false;
128
129 if (!triangles.count && !quads.count) // no support for non-indexed mesh
130 return false;
131 if (triangles.count && !triangles.data)
132 return false;
133 if (quads.count && !quads.data)
134 return false;
135
136 PxU32 indexSize = (flags & PxMeshFlag::e16_BIT_INDICES) ? sizeof(PxU16) : sizeof(PxU32);
137 if(triangles.count && triangles.stride < indexSize*3)
138 return false;
139 if(quads.count && quads.stride < indexSize*4)
140 return false;
141
142 return true;
143}
144
145#ifndef PX_DOXYGEN
146} // namespace physx
147#endif
148
149/** @} */
150#endif
151