aboutsummaryrefslogtreecommitdiff
path: root/APEX_1.4/include/clothing/ClothingPhysicalMesh.h
blob: 5d60b818f968eb6d9072fe20319b448adb230adf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of NVIDIA CORPORATION nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2018 NVIDIA Corporation. All rights reserved.



#ifndef CLOTHING_PHYSICAL_MESH_H
#define CLOTHING_PHYSICAL_MESH_H

#include "ApexInterface.h"
#include "IProgressListener.h"

namespace nvidia
{
namespace apex
{


/**
\brief Constrain coefficients of the physical mesh vertices
*/
struct ClothingConstrainCoefficients
{
	float maxDistance; ///< \brief Maximum distance a vertex is allowed to move
	float collisionSphereRadius; ///< \brief Backstop sphere radius
	float collisionSphereDistance; ///< \brief Backstop sphere distance
};


PX_PUSH_PACK_DEFAULT

/**
\brief Contains the data for handing out statistics about a ClothingPhysicalMesh
*/
struct ClothingPhysicalMeshStats
{
	/// the number of bytes allocated for the physical mesh
	uint32_t	totalBytes;
	/// the number of vertices
	uint32_t	numVertices;
	/// the number of indices
	uint32_t	numIndices;
};


/**
\brief Holder for a physical mesh, this can be generated through various ways (see single- and multi-layered clothing) or hand crafted
*/
class ClothingPhysicalMesh : public ApexInterface
{
public:
	/**
	\brief returns the number of vertices
	*/
	virtual uint32_t getNumVertices() const = 0;

	/**
	\brief returns the number of simulated vertices
	*/
	virtual uint32_t getNumSimulatedVertices() const = 0;

	/**
	\brief returns the number of vertices with zero max distance
	*/
	virtual uint32_t getNumMaxDistance0Vertices() const = 0;

	/**
	\brief returns the number of indices
	*/
	virtual uint32_t getNumIndices() const = 0;

	/**
	\brief returns the number of simulated indices
	*/
	virtual uint32_t getNumSimulatedIndices() const = 0;

	/**
	\brief writes the indices to a destination buffer

	\param [out] indexDestination	destination buffer where to write the indices
	\param [in] byteStride			stride of the destination buffer
	\param [in] numIndices			number of indices the buffer can hold. This can be smaller than getNumIndices()
	*/
	virtual void getIndices(void* indexDestination, uint32_t byteStride, uint32_t numIndices) const = 0;

	/**
	\brief returns whether the mesh is built out of tetrahedra or triangles
	*/
	virtual bool isTetrahedralMesh() const = 0;

	/**
	\brief This will simplify the current mesh.

	\param [in] subdivisions	used to derive the maximal length a new edge can get.<br>
								Divide the bounding box diagonal by this value to get the maximal edge length for newly created edges<br>
								Use 0 to not restrict the maximal edge length
	\param [in] maxSteps		The maximum number of edges to be considered for simplification.<br>
								Use 0 to turn off
	\param [in] maxError		The maximal quadric error an edge can cause to be considered simplifyable.<br>
								Use any value < 0 to turn off
	\param [in] progress		Callback class that will be fired every now and then to update a progress bar in the gui.
	\return The number of edges collapsed
	*/
	virtual void simplify(uint32_t subdivisions, int32_t maxSteps, float maxError, IProgressListener* progress) = 0;

	/**
	\brief Create a physical mesh from scratch

	Overwrites all vertices/indices, and invalidates all misc vertex buffers. vertices must be PxVec3 and indices uint32_t.
	If driveChannels is NULL, all vertices are assigned to all drive channels (initialized to 0xffffffff)
	*/
	virtual void setGeometry(bool tetraMesh, uint32_t numVertices, uint32_t vertexByteStride, const void* vertices,	const uint32_t* driveChannels, 
							uint32_t numIndices, uint32_t indexByteStride, const void* indices) = 0;

	// direct access to specific buffers
	/**
	\brief writes the indices into a user specified buffer.

	Returns false if the buffer doesn't exist.
	The buffer must be bigger than sizeof(uint32_t) * getNumIndices()
	*/
	virtual bool getIndices(uint32_t* indices, uint32_t byteStride) const = 0;

	/**
	\brief Writes the vertex positions into a user specified buffer.

	Returns false if the buffer doesn't exist.
	The buffer must be bigger than sizeof(PxVec3) * getNumVertices()
	*/
	virtual bool getVertices(PxVec3* vertices, uint32_t byteStride) const = 0;

	/**
	\brief Writes the normals into a user specified buffer.

	Returns false if the buffer doesn't exist.
	The buffer must be bigger than sizeof(PxVec3) * getNumVertices()
	*/
	virtual bool getNormals(PxVec3* normals, uint32_t byteStride) const = 0;

	/**
	\brief Returns the number of bones per vertex.
	*/
	virtual uint32_t getNumBonesPerVertex() const = 0;

	/**
	\brief Writes the bone indices into a user specified buffer.

	Returns false if the buffer doesn't exist.
	The buffer must be bigger than sizeof(uint16_t) * getNumVertices() * getNumBonesPerVertex().
	(numBonesPerVertex is the same as in the graphical mesh for LOD 0)

	The bytestride is applied only after writing numBonesPerVertex and thus must be >= sizoef(uint16_t) * numBonesPerVertex
	*/
	virtual bool getBoneIndices(uint16_t* boneIndices, uint32_t byteStride) const = 0;

	/**
	\brief Writes the bone weights into a user specified buffer.

	Returns false if the buffer doesn't exist.
	The buffer must be bigger than sizeof(float) * getNumVertices() * getNumBonesPerVertex().
	(numBonesPerVertex is the same as in the graphical mesh for LOD 0)
	The bytestride is applied only after writing numBonesPerVertex and thus must be >= sizoef(float) * numBonesPerVertex
	*/
	virtual bool getBoneWeights(float* boneWeights, uint32_t byteStride) const = 0;

	/**
	\brief Allocates and initializes the drive channels (master flags) of the physics mesh.

	This allows to set the drive channels directly on the physics mesh.
	*/
	virtual void allocateMasterFlagsBuffer() = 0;

	/**
	\brief Returns the masterFlag buffer pointer in order to edit the values.

	This allows to set values directly on the physics mesh.
	*/
	virtual uint32_t* getMasterFlagsBuffer() = 0;

	/**
	\brief Allocates and initializes the constrain coefficients of the physics mesh.

	This allows to set the constrain coefficients like maxDistance directly on the physics mesh.
	If this is not called by the authoring tool, the constrain coefficients are read from the
	graphical mesh.
	*/
	virtual void allocateConstrainCoefficientBuffer() = 0;

	/**
	\brief Returns the constrain coefficient buffer pointer in order to edit the values.

	This allows to set the constrain coefficients like maxDistance directly on the physics mesh.
	*/
	virtual ClothingConstrainCoefficients* getConstrainCoefficientBuffer() const = 0;

	/**
	\brief Writes the cloth constrain coefficients into a user specified buffer.

	Returns false if the buffer doesn't exist. The buffer must be bigger than sizeof(ClothingConstrainCoefficients) * getNumVertices().
	*/
	virtual bool getConstrainCoefficients(ClothingConstrainCoefficients* coeffs, uint32_t byteStride) const = 0;

	/**
	\brief Returns stats (sizes, counts) for the asset.  See ClothingPhysicalMeshStats.
	*/
	virtual void getStats(ClothingPhysicalMeshStats& stats) const = 0;

};

PX_POP_PACK

}
} // namespace nvidia

#endif // CLOTHING_PHYSICAL_MESH_H