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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
//
// 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_ASSET_AUTHORING_IMPL_H
#define CLOTHING_ASSET_AUTHORING_IMPL_H
#include "ClothingAssetAuthoring.h"
#include "ClothingAssetImpl.h"
#include "ClothingGraphicalLodParameters.h"
#include "ApexAssetAuthoring.h"
#include "ReadCheck.h"
#include "WriteCheck.h"
#ifndef WITHOUT_APEX_AUTHORING
namespace nvidia
{
namespace clothing
{
class ClothingPhysicalMeshImpl;
class ClothingAssetAuthoringImpl : public ClothingAssetAuthoring, public ApexAssetAuthoring, public ClothingAssetImpl
{
public:
APEX_RW_LOCKABLE_BOILERPLATE
ClothingAssetAuthoringImpl(ModuleClothingImpl* module, ResourceList& list, const char* name);
ClothingAssetAuthoringImpl(ModuleClothingImpl* module, ResourceList& list);
ClothingAssetAuthoringImpl(ModuleClothingImpl* module, ResourceList& list, NvParameterized::Interface* params, const char* name);
// from AssetAuthoring
virtual const char* getName(void) const
{
return ClothingAssetImpl::getName();
}
virtual const char* getObjTypeName() const
{
return CLOTHING_AUTHORING_TYPE_NAME;
}
virtual bool prepareForPlatform(nvidia::apex::PlatformTag);
virtual void setToolString(const char* toolName, const char* toolVersion, uint32_t toolChangelist)
{
ApexAssetAuthoring::setToolString(toolName, toolVersion, toolChangelist);
}
// from ApexInterface
virtual void release();
// from ClothingAssetAuthoring
virtual void setDefaultConstrainCoefficients(const ClothingConstrainCoefficients& coeff)
{
WRITE_ZONE();
mDefaultConstrainCoefficients = coeff;
}
virtual void setInvalidConstrainCoefficients(const ClothingConstrainCoefficients& coeff)
{
WRITE_ZONE();
mInvalidConstrainCoefficients = coeff;
}
virtual void setMeshes(uint32_t lod, RenderMeshAssetAuthoring* asset, ClothingPhysicalMesh* mesh,
float normalResemblance = 90, bool ignoreUnusedVertices = true,
IProgressListener* progress = NULL);
virtual bool addPlatformToGraphicalLod(uint32_t lod, PlatformTag platform);
virtual bool removePlatform(uint32_t lod, PlatformTag platform);
virtual uint32_t getNumPlatforms(uint32_t lod) const;
virtual PlatformTag getPlatform(uint32_t lod, uint32_t i) const;
virtual uint32_t getNumLods() const;
virtual int32_t getLodValue(uint32_t lod) const;
virtual void clearMeshes();
virtual ClothingPhysicalMesh* getClothingPhysicalMesh(uint32_t graphicalLod) const;
virtual void setBoneInfo(uint32_t boneIndex, const char* boneName, const PxMat44& bindPose, int32_t parentIndex);
virtual void setRootBone(const char* boneName);
virtual uint32_t addBoneConvex(const char* boneName, const PxVec3* positions, uint32_t numPositions);
virtual uint32_t addBoneConvex(uint32_t boneIndex, const PxVec3* positions, uint32_t numPositions);
virtual void addBoneCapsule(const char* boneName, float capsuleRadius, float capsuleHeight, const PxMat44& localPose);
virtual void addBoneCapsule(uint32_t boneIndex, float capsuleRadius, float capsuleHeight, const PxMat44& localPose);
virtual void clearBoneActors(const char* boneName);
virtual void clearBoneActors(uint32_t boneIndex);
virtual void clearAllBoneActors();
virtual void setCollision(const char** boneNames, float* radii, PxVec3* localPositions,
uint32_t numSpheres, uint16_t* pairs, uint32_t numPairs);
virtual void setCollision(uint32_t* boneIndices, float* radii, PxVec3* localPositions, uint32_t numSpheres,
uint16_t* pairs, uint32_t numPairs);
virtual void clearCollision();
virtual void setSimulationHierarchicalLevels(uint32_t levels)
{
WRITE_ZONE();
mParams->simulation.hierarchicalLevels = levels;
clearCooked();
}
virtual void setSimulationThickness(float thickness)
{
WRITE_ZONE();
mParams->simulation.thickness = thickness;
}
virtual void setSimulationVirtualParticleDensity(float density)
{
WRITE_ZONE();
PX_ASSERT(density >= 0.0f);
PX_ASSERT(density <= 1.0f);
mParams->simulation.virtualParticleDensity = PxClamp(density, 0.0f, 1.0f);
}
virtual void setSimulationSleepLinearVelocity(float sleep)
{
WRITE_ZONE();
mParams->simulation.sleepLinearVelocity = sleep;
}
virtual void setSimulationGravityDirection(const PxVec3& gravity)
{
WRITE_ZONE();
mParams->simulation.gravityDirection = gravity.getNormalized();
}
virtual void setSimulationDisableCCD(bool disable)
{
WRITE_ZONE();
mParams->simulation.disableCCD = disable;
}
virtual void setSimulationTwowayInteraction(bool enable)
{
WRITE_ZONE();
mParams->simulation.twowayInteraction = enable;
}
virtual void setSimulationUntangling(bool enable)
{
WRITE_ZONE();
mParams->simulation.untangling = enable;
}
virtual void setSimulationRestLengthScale(float scale)
{
WRITE_ZONE();
mParams->simulation.restLengthScale = scale;
}
virtual void setExportScale(float scale)
{
WRITE_ZONE();
mExportScale = scale;
}
virtual void applyTransformation(const PxMat44& transformation, float scale, bool applyToGraphics, bool applyToPhysics);
virtual void updateBindPoses(const PxMat44* newBindPoses, uint32_t newBindPosesCount, bool isInternalOrder, bool collisionMaintainWorldPose);
virtual void setDeriveNormalsFromBones(bool enable)
{
WRITE_ZONE();
mDeriveNormalsFromBones = enable;
}
virtual NvParameterized::Interface* getMaterialLibrary();
virtual bool setMaterialLibrary(NvParameterized::Interface* materialLibrary, uint32_t materialIndex, bool transferOwnership);
virtual NvParameterized::Interface* getRenderMeshAssetAuthoring(uint32_t lodLevel) const;
// parameterization
NvParameterized::Interface* getNvParameterized() const
{
return mParams;
}
virtual NvParameterized::Interface* releaseAndReturnNvParameterizedInterface();
// from NvParameterized::SerializationCallback
virtual void preSerialize(void* userData);
// from ApexAssetAuthoring
virtual void setToolString(const char* toolString);
// internal
void destroy();
virtual bool setBoneBindPose(uint32_t boneIndex, const PxMat44& bindPose);
virtual bool getBoneBindPose(uint32_t boneIndex, PxMat44& bindPose) const;
private:
// bones
uint32_t addBoneConvexInternal(uint32_t boneIndex, const PxVec3* positions, uint32_t numPositions);
void addBoneCapsuleInternal(uint32_t boneIndex, float capsuleRadius, float capsuleHeight, const PxMat44& localPose);
void clearBoneActorsInternal(int32_t internalBoneIndex);
void compressBones() const;
void compressBoneCollision();
void collectBoneIndices(uint32_t numVertices, const uint16_t* boneIndices, const float* boneWeights, uint32_t numBonesPerVertex) const;
void updateMappingAuthoring(ClothingGraphicalLodParameters& graphLod, RenderMeshAssetIntl* renderMeshAssetCopy,
RenderMeshAssetAuthoringIntl* renderMeshAssetOrig, float normalResemblance,
bool ignoreUnusedVertices, IProgressListener* progress);
void sortSkinMapB(SkinClothMapB* skinClothMap, uint32_t skinClothMapSize, uint32_t* immediateClothMap, uint32_t immediateClothMapSize);
void setupPhysicalMesh(ClothingPhysicalMeshParameters& physicalMeshParameters) const;
bool checkSetMeshesInput(uint32_t lod, ClothingPhysicalMesh* nxPhysicalMesh, uint32_t& graphicalLodIndexTest);
void sortPhysicalMeshes();
// mesh reordering
void sortDeformableIndices(ClothingPhysicalMeshImpl& physicalMesh);
bool getGraphicalLodIndex(uint32_t lod, uint32_t& graphicalLodIndex) const;
uint32_t addGraphicalLod(uint32_t lod);
// cooking
void clearCooked();
// access
bool addGraphicalMesh(RenderMeshAssetAuthoring* renderMesh, uint32_t graphicalLodIndex);
Array<ClothingPhysicalMeshImpl*> mPhysicalMeshesInput;
float mExportScale;
bool mDeriveNormalsFromBones;
bool mOwnsMaterialLibrary;
ClothingConstrainCoefficients mDefaultConstrainCoefficients;
ClothingConstrainCoefficients mInvalidConstrainCoefficients;
const char* mPreviousCookedType;
ApexSimpleString mRootBoneName;
void initParams();
// immediate cloth: 1-to-1 mapping from physical to rendering mesh (except for LOD)
bool generateImmediateClothMap(const AbstractMeshDescription* targetMeshes, uint32_t numTargetMeshes,
ClothingPhysicalMeshParametersNS::PhysicalMesh_Type& physicalMesh,
uint32_t* masterFlags, float epsilon, uint32_t& numNotFoundVertices,
float normalResemblance, ParamArray<uint32_t>& result, IProgressListener* progress) const;
bool generateSkinClothMap(const AbstractMeshDescription* targetMeshes, uint32_t numTargetMeshes,
ClothingPhysicalMeshParametersNS::PhysicalMesh_Type& physicalMesh, uint32_t* masterFlags,
uint32_t* immediateMap, uint32_t numEmptyInImmediateMap, ParamArray<SkinClothMap>& result,
float& offsetAlongNormal, bool integrateImmediateMap, IProgressListener* progress) const;
void removeMaxDistance0Mapping(ClothingGraphicalLodParameters& graphicalLod, RenderMeshAssetIntl* renderMeshAsset) const;
bool generateTetraMap(const AbstractMeshDescription* targetMeshes, uint32_t numTargetMeshes,
ClothingPhysicalMeshParametersNS::PhysicalMesh_Type& physicalMesh, uint32_t* masterFlags,
ParamArray<ClothingGraphicalLodParametersNS::TetraLink_Type>& result, IProgressListener* progress) const;
float computeBaryError(float baryX, float baryY) const;
float computeTriangleError(const TriangleWithNormals& triangle, const PxVec3& normal) const;
bool hasTangents(const RenderMeshAssetIntl& rma);
uint32_t getMaxNumGraphicalVertsActive(const ClothingGraphicalLodParameters& graphicalLod, uint32_t submeshIndex);
bool isMostlyImmediateSkinned(const RenderMeshAssetIntl& rma, const ClothingGraphicalLodParameters& graphicalLod);
bool conditionalMergeMapping(const RenderMeshAssetIntl& rma, ClothingGraphicalLodParameters& graphicalLod);
};
}
} // namespace nvidia
#endif // WITHOUT_APEX_AUTHORING
#endif // CLOTHING_ASSET_AUTHORING_IMPL_H
|