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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
|
//
// 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_AUTHORING_H
#define CLOTHING_AUTHORING_H
#include "PxPreprocessor.h"
#if PX_WINDOWS_FAMILY
#include "ApexDefs.h"
#include "PxMath.h"
#include "PxMat33.h"
#include "PxMat44.h"
#include "PxCpuDispatcher.h"
#include <nvparameterized/NvSerializer.h>
#include <IProgressListener.h>
#include <UserRenderResourceManager.h>
#include <UserRenderVertexBufferDesc.h>
#include <nvparameterized/NvParameterized.h>
#include <clothing/ClothingAsset.h>
#include <AutoGeometry.h>
#include <vector>
#include <map>
namespace physx
{
class PxScene;
class PxMaterial;
class PxRigidStatic;
namespace pvdsdk
{
class PxPvd;
}
class PxCpuDispatcher;
}
namespace nvidia
{
namespace apex
{
class ApexSDK;
class RenderDebugInterface;
class Renderable;
class Scene;
class ResourceCallback;
class UserRenderResourceManager;
class RenderMeshAssetAuthoring;
class ModuleClothing;
class ClothingActor;
class ClothingAsset;
class ClothingAssetAuthoring;
class ClothingPhysicalMesh;
class ClothingPreview;
class ClothingUserRecompute;
class ClothingPlane;
struct ClothingMeshSkinningMap;
}
}
namespace Samples
{
class MaterialList;
class TriangleMesh;
class SkeletalAnim;
}
namespace SharedTools
{
class MeshPainter;
class ClothingAuthoring
{
public:
class ErrorCallback
{
public:
void reportErrorPrintf(const char* label, const char* fmt, ...);
virtual void reportError(const char* label, const char* message) = 0;
};
class NotificationCallback
{
public:
virtual void notifyRestart() = 0;
virtual void notifyInputMeshLoaded() = 0;
virtual void notifyMeshPos(const physx::PxVec3&) = 0;
};
struct BrushMode
{
enum Enum
{
PaintFlat,
PaintVolumetric,
Smooth,
};
};
struct CollisionVolume
{
CollisionVolume() : boneIndex(-1), parentIndex(-1), transform(physx::PxIdentity), meshVolume(0.0f),
capsuleHeight(0.0f), capsuleRadius(0.0f), shapeOffset(physx::PxIdentity), inflation(0.0f) {}
void draw(nvidia::apex::RenderDebugInterface* batcher, Samples::SkeletalAnim* anim, bool wireframe, float simulationScale);
int boneIndex;
int parentIndex;
std::string boneName;
physx::PxTransform transform;
std::vector<physx::PxVec3> vertices;
std::vector<uint32_t> indices;
float meshVolume;
float capsuleHeight;
float capsuleRadius;
physx::PxTransform shapeOffset;
float inflation;
};
ClothingAuthoring(
nvidia::apex::ApexSDK* apexSDK,
nvidia::apex::ModuleClothing* moduleClothing,
nvidia::apex::ResourceCallback* resourceCallback,
nvidia::apex::UserRenderResourceManager* renderResourceManager,
ClothingAuthoring::ErrorCallback* errorCallback,
nvidia::PxPvd* pvd = NULL,
nvidia::apex::RenderDebugInterface* renderDebug = NULL
);
virtual ~ClothingAuthoring();
void addNotifyCallback(NotificationCallback* callback);
void setMaterialList(Samples::MaterialList* list);
void releasePhysX();
void connectPVD(bool toggle);
int getNumParameters() const;
bool getParameter(unsigned int i, std::string& name, std::string& type, std::string& val) const;
bool setParameter(std::string& name, std::string& type, std::string& val);
// state information
bool getAndClearNeedsRedraw()
{
bool temp = mState.needsRedraw;
mState.needsRedraw = false;
return temp;
}
bool getAndClearNeedsRestart()
{
bool temp = mState.needsRestart;
mState.needsRestart = false;
return temp;
}
bool getAndClearManualAnimation()
{
bool temp = mState.manualAnimation;
mState.manualAnimation = false;
return temp;
}
void setManualAnimation(bool on)
{
mState.manualAnimation = on;
}
struct AuthoringState
{
enum Enum
{
None = 0,
MeshLoaded,
SubmeshSelectionChanged,
PaintingChanged,
RenderMeshAssetCreated,
PhysicalCustomMeshCreated,
PhysicalClothMeshCreated,
ClothingAssetCreated,
};
};
AuthoringState::Enum getAuthoringState() const
{
return mState.authoringState;
}
bool createDefaultMaterialLibrary();
bool addMaterialLibrary(const char* name, NvParameterized::Interface* newInterface);
void removeMaterialLibrary(const char* name);
void addMaterialToLibrary(const char* libName, const char* matName);
void removeMaterialFromLibrary(const char* libName, const char* matName);
void selectMaterial(const char* libName, const char* matName);
void clearMaterialLibraries();
const char* getSelectedMaterialLibrary() const
{
return mState.selectedMaterialLibrary.c_str();
}
const char* getSelectedMaterial() const
{
return mState.selectedMaterial.c_str();
}
physx::PxBounds3 getSimulationBounds() const
{
return mState.apexBounds;
}
physx::PxBounds3 getCombinedSimulationBounds() const;
size_t getNumMaterialLibraries() const
{
return mState.materialLibraries.size();
}
NvParameterized::Interface* getMaterialLibrary(unsigned int libraryIndex) const;
bool setMaterialLibrary(unsigned int libraryIndex, NvParameterized::Interface* data);
const char* getMaterialLibraryName(unsigned int libraryIndex) const;
unsigned int getNumMaterials(unsigned int libraryIndex) const;
const char* getMaterialName(unsigned int libraryIndex, unsigned int materialIndex) const;
float getDrawWindTime() const
{
return mState.drawWindTime;
}
const physx::PxVec3& getWindOrigin() const
{
return mState.windOrigin;
}
const physx::PxVec3& getWindTarget() const
{
return mState.windTarget;
}
// dirty information
void setMaxDistancePaintingDirty(bool dirty)
{
mDirty.maxDistancePainting |= dirty;
}
bool getAndClearMaxDistancePaintingDirty()
{
bool temp = mDirty.maxDistancePainting;
mDirty.maxDistancePainting = false;
return temp;
}
bool getAndClearGroundPlaneDirty()
{
bool temp = mDirty.groundPlane;
mDirty.groundPlane = false;
return temp;
}
bool getAndClearGravityDirty()
{
bool temp = mDirty.gravity;
mDirty.gravity = false;
return temp;
}
bool getAndClearWorkspaceDirty()
{
bool temp = mDirty.workspace;
mDirty.workspace = false;
return temp;
}
void setSimulationValueScale(float v)
{
mState.simulationValuesScale = v;
}
float getSimulationValueScale() const
{
return mState.simulationValuesScale;
}
void setGravityValueScale(float v)
{
mState.gravityValueScale = v;
}
float getGravityValueScale() const
{
return mState.gravityValueScale;
}
// simulation objects
size_t getNumSimulationAssets() const
{
return mSimulation.assets.size();
}
size_t getNumTriangleMeshes() const
{
return mSimulation.actors.size();
}
Samples::TriangleMesh* getTriangleMesh(size_t index)
{
return mSimulation.actors[index].triangleMesh;
}
const physx::PxMat44& getTriangleMeshPose(size_t index) const;
size_t getNumActors() const
{
return mSimulation.actors.size() * mSimulation.assets.size();
}
size_t getNumSimulationActors() const;
nvidia::apex::ClothingActor* getSimulationActor(size_t index);
nvidia::apex::Renderable* getSimulationRenderable(size_t index);
void initMeshSkinningData();
nvidia::apex::ClothingMeshSkinningMap* getMeshSkinningMap(size_t index, uint32_t lod, uint32_t& mapSize, nvidia::apex::RenderMeshAsset*& renderMeshAsset);
void setActorCount(int count, bool addToCommandQueue);
int getActorCount() const
{
return mSimulation.actorCount;
}
float getActorScale(size_t index);
void setMatrices(const physx::PxMat44& viewMatrix, const physx::PxMat44& projectionMatrix);
void startCreateApexScene();
bool addAssetToScene(nvidia::apex::ClothingAsset* asset, nvidia::apex::IProgressListener* progress, unsigned int totalNumAssets = 1);
void handleGravity();
void finishCreateApexScene(bool recomputeScale);
void startSimulation();
void stopSimulation();
void restartSimulation();
bool updateCCT(float deltaT);
void stepsUntilPause(int steps);
unsigned int getFrameNumber() const
{
return mSimulation.frameNumber;
}
int getMaxLodValue() const;
nvidia::apex::Scene* getApexScene() const
{
return mSimulation.apexScene;
}
#if PX_PHYSICS_VERSION_MAJOR == 3
physx::PxScene* getPhysXScene() const
{
return mSimulation.physxScene;
}
#endif
bool isPaused() const
{
return mSimulation.paused;
}
// Meshes
bool loadInputMesh(const char* filename, bool allowConversion, bool silentOnError, bool recurseIntoApx);
bool loadAnimation(const char* filename, std::string& error);
NvParameterized::Interface* extractRMA(NvParameterized::Handle& param);
bool saveInputMeshToXml(const char* filename);
bool saveInputMeshToEzm(const char* filename);
void setInputMeshFilename(const char* filename)
{
mDirty.workspace |= mMeshes.inputMeshFilename.compare(filename) != 0;
mMeshes.inputMeshFilename = filename;
}
const char* getInputMeshFilename() const
{
return mMeshes.inputMeshFilename.c_str();
}
void selectSubMesh(int subMeshNr, bool on);
bool hasTangentSpaceGenerated()
{
return mMeshes.tangentSpaceGenerated;
}
bool loadCustomPhysicsMesh(const char* filename);
const char* getCustomPhysicsMeshFilename() const
{
return mMeshes.customPhysicsMeshFilename.empty() ? NULL : mMeshes.customPhysicsMeshFilename.c_str();
}
void clearCustomPhysicsMesh();
Samples::TriangleMesh* getInputMesh()
{
return mMeshes.inputMesh;
}
Samples::SkeletalAnim* getSkeleton()
{
return mMeshes.skeleton;
}
Samples::TriangleMesh* getCustomPhysicsMesh()
{
return mMeshes.customPhysicsMesh;
}
Samples::TriangleMesh* getGroundMesh()
{
PX_ASSERT(mMeshes.groundMesh);
return mMeshes.groundMesh;
}
// modify mesh
int subdivideSubmesh(int subMeshNumber);
size_t getNumSubdivisions()
{
return mMeshes.subdivideHistory.size();
}
int getSubdivisionSubmesh(int index)
{
return mMeshes.subdivideHistory[(uint32_t)index].submesh;
}
int getSubdivisionSize(int index)
{
return mMeshes.subdivideHistory[(uint32_t)index].subdivision;
}
void renameSubMeshMaterial(size_t submesh, const char* newName);
void generateInputTangentSpace();
// painting
MeshPainter* getPainter()
{
return mMeshes.painter;
}
void paint(const physx::PxVec3& rayOrigin, const physx::PxVec3& rayDirection, bool execute, bool leftButton, bool rightButton);
void floodPainting(bool invalid);
void smoothPainting(int numIterations);
void updatePainter();
void setPainterIndexBufferRange();
void updatePaintingColors();
bool getMaxDistancePaintValues(const float*& values, int& numValues, int& byteStride);
float getAbsolutePaintingScalingMaxDistance();
float getAbsolutePaintingScalingCollisionFactor();
void initGroundMesh(const char* resourceDir);
// modify animation
void setAnimationPose(int position);
void setBindPose();
void setAnimationTime(float t);
float getAnimationTime() const;
bool updateAnimation();
void skinMeshes(Samples::SkeletalAnim* anim);
// collision volumes
void clearCollisionVolumes();
unsigned int generateCollisionVolumes(bool useCapsule, bool commandMode, bool dirtyOnly);
CollisionVolume* addCollisionVolume(bool useCapsule, unsigned int boneIndex, bool createFromMesh);
size_t getNumCollisionVolumes() const
{
return mMeshes.collisionVolumes.size();
}
CollisionVolume* getCollisionVolume(int index);
bool deleteCollisionVolume(int index);
void drawCollisionVolumes(bool wireframe) const;
// Authoring objecst
size_t getNumRenderMeshAssets()
{
return (uint32_t)mConfig.cloth.numGraphicalLods;
}
nvidia::apex::RenderMeshAssetAuthoring* getRenderMeshAsset(int index);
nvidia::apex::ClothingPhysicalMesh* getClothMesh(int index, nvidia::apex::IProgressListener* progress);
void simplifyClothMesh(float factor);
int getNumClothTriangles() const;
nvidia::apex::ClothingPhysicalMesh* getPhysicalMesh();
nvidia::apex::ClothingAssetAuthoring* getClothingAsset(nvidia::apex::IProgressListener* progress);
// configuration.UI
void setZAxisUp(bool z);
bool getZAxisUp() const
{
return mConfig.ui.zAxisUp;
}
void setSpotLight(bool s)
{
mDirty.workspace |= mConfig.ui.spotLight != s;
mConfig.ui.spotLight = s;
}
bool getSpotLight() const
{
return mConfig.ui.spotLight;
}
void setSpotLightShadow(bool s)
{
mDirty.workspace |= mConfig.ui.spotLightShadow != s;
mConfig.ui.spotLightShadow = s;
}
bool getSpotLightShadow() const
{
return mConfig.ui.spotLightShadow;
}
// configuration.mesh
void setSubmeshSubdiv(int value)
{
mDirty.workspace |= mConfig.mesh.originalMeshSubdivision != value;
mConfig.mesh.originalMeshSubdivision = value;
}
int getSubmeshSubdiv() const
{
return mConfig.mesh.originalMeshSubdivision;
}
void setEvenOutVertexDegrees(bool on)
{
mDirty.workspace |= mConfig.mesh.evenOutVertexDegrees != on;
mConfig.mesh.evenOutVertexDegrees = on;
}
bool getEvenOutVertexDegrees() const
{
return mConfig.mesh.evenOutVertexDegrees;
}
void setCullMode(nvidia::apex::RenderCullMode::Enum mode);
nvidia::apex::RenderCullMode::Enum getCullMode() const
{
return (nvidia::apex::RenderCullMode::Enum)mConfig.mesh.cullMode;
}
void setTextureUvOrigin(nvidia::apex::TextureUVOrigin::Enum origin);
nvidia::apex::TextureUVOrigin::Enum getTextureUvOrigin() const
{
return (nvidia::apex::TextureUVOrigin::Enum)mConfig.mesh.textureUvOrigin;
}
// configuration.Apex
void setParallelCpuSkinning(bool s)
{
mDirty.workspace |= mConfig.apex.parallelCpuSkinning != s;
mConfig.apex.parallelCpuSkinning = s;
mDirty.clothingActorFlags = true;
}
bool getParallelCpuSkinning() const
{
return mConfig.apex.parallelCpuSkinning;
}
void setRecomputeNormals(bool r)
{
mDirty.workspace |= mConfig.apex.recomputeNormals != r;
mConfig.apex.recomputeNormals = r;
mDirty.clothingActorFlags = true;
}
bool getRecomputeNormals() const
{
return mConfig.apex.recomputeNormals;
}
void setRecomputeTangents(bool r)
{
mDirty.workspace |= mConfig.apex.recomputeTangents != r;
mConfig.apex.recomputeTangents = r;
mDirty.clothingActorFlags = true;
}
bool getRecomputeTangents() const
{
return mConfig.apex.recomputeTangents;
}
void setCorrectSimulationNormals(bool c)
{
mConfig.apex.correctSimulationNormals = c;
mDirty.clothingActorFlags = true;
}
bool getCorrectSimulationNormals() const
{
return mConfig.apex.correctSimulationNormals;
}
void setUseMorphTargets(bool on)
{
mState.needsRestart |= mConfig.apex.useMorphTargetTest != on;
mConfig.apex.useMorphTargetTest = on;
}
bool getUseMorphTargets() const
{
return mConfig.apex.useMorphTargetTest;
}
void setForceEmbedded(bool on)
{
mDirty.workspace |= mConfig.apex.forceEmbedded != on;
mConfig.apex.forceEmbedded = on;
mState.needsRestart = true;
}
bool getForceEmbedded()
{
return mConfig.apex.forceEmbedded;
}
// configuration.tempMeshes.Cloth
void setClothNumGraphicalLods(int numLods)
{
mDirty.workspace |= mConfig.cloth.numGraphicalLods != numLods;
mConfig.cloth.numGraphicalLods = numLods;
setAuthoringState(AuthoringState::RenderMeshAssetCreated, false);
}
int getClothNumGraphicalLods() const
{
return mConfig.cloth.numGraphicalLods;
}
void setClothSimplifySL(int simplification)
{
mDirty.workspace |= mConfig.cloth.simplify != simplification;
mConfig.cloth.simplify = simplification;
setAuthoringState(AuthoringState::RenderMeshAssetCreated, false);
}
int getClothSimplifySL() const
{
return mConfig.cloth.simplify;
}
void setCloseCloth(bool close)
{
mDirty.workspace |= mConfig.cloth.close != close;
mConfig.cloth.close = close;
setAuthoringState(AuthoringState::RenderMeshAssetCreated, false);
}
bool getCloseCloth() const
{
return mConfig.cloth.close;
}
void setSlSubdivideCloth(bool subdivide)
{
mDirty.workspace |= mConfig.cloth.subdivide != subdivide;
mConfig.cloth.subdivide = subdivide;
setAuthoringState(AuthoringState::RenderMeshAssetCreated, false);
}
bool getSlSubdivideCloth() const
{
return mConfig.cloth.subdivide;
}
void setClothMeshSubdiv(int subdivision)
{
mDirty.workspace |= mConfig.cloth.subdivision != subdivision;
mConfig.cloth.subdivision = subdivision;
setAuthoringState(AuthoringState::RenderMeshAssetCreated, false);
}
int getClothMeshSubdiv() const
{
return mConfig.cloth.subdivision;
}
// configuration.collisionVolumes
void setCollisionVolumeUsePaintChannel(bool on)
{
mDirty.workspace |= mConfig.collisionVolumes.usePaintingChannel != on;
mConfig.collisionVolumes.usePaintingChannel = on;
}
bool getCollisionVolumeUsePaintChannel() const
{
return mConfig.collisionVolumes.usePaintingChannel;
}
// configuration.painting
void setBrushMode(BrushMode::Enum mode)
{
mDirty.workspace |= mConfig.painting.brushMode != mode;
mConfig.painting.brushMode = mode;
}
BrushMode::Enum getBrushMode() const
{
return (BrushMode::Enum)mConfig.painting.brushMode;
}
void setFalloffExponent(float exp)
{
mDirty.workspace |= mConfig.painting.falloffExponent != exp;
mConfig.painting.falloffExponent = exp;
mState.needsRedraw = true;
}
float getFalloffExponent() const
{
return mConfig.painting.falloffExponent;
}
void setPaintingChannel(int channel);
int getPaintingChannel() const
{
return mConfig.painting.channel;
}
void setPaintingValue(float val, float vmin, float vmax);
float getPaintingValue() const
{
return mConfig.painting.value;
}
float getPaintingValueMin() const
{
return mConfig.painting.valueMin;
}
float getPaintingValueMax() const
{
return mConfig.painting.valueMax;
}
void setPaintingValueFlag(unsigned int flags);
unsigned int getPaintingValueFlag() const
{
return (uint32_t)mConfig.painting.valueFlag;
}
void setBrushRadius(int radius)
{
mDirty.workspace |= mConfig.painting.brushRadius != radius;
mConfig.painting.brushRadius = radius;
}
int getBrushRadius() const
{
return mConfig.painting.brushRadius;
}
void setPaintingScalingMaxDistance(float scaling)
{
mDirty.workspace |= mConfig.painting.scalingMaxdistance != scaling;
mConfig.painting.scalingMaxdistance = scaling;
mDirty.maxDistancePainting = true;
mDirty.clothingActorFlags = true;
setAuthoringState(AuthoringState::PaintingChanged, false);
}
float getPaintingScalingMaxDistance() const
{
return mConfig.painting.scalingMaxdistance;
}
void setPaintingScalingCollisionFactor(float scaling)
{
mDirty.workspace |= mConfig.painting.scalingCollisionFactor != scaling;
mConfig.painting.scalingCollisionFactor = scaling;
mDirty.clothingActorFlags = true;
setAuthoringState(AuthoringState::PaintingChanged, false);
}
float getPaintingScalingCollisionFactor() const
{
return mConfig.painting.scalingCollisionFactor;
}
void setMaxDistanceScale(float scale)
{
mDirty.maxDistanceScale |= mConfig.painting.maxDistanceScale != scale;
mConfig.painting.maxDistanceScale = scale;
}
float getMaxDistanceScale() const
{
return mConfig.painting.maxDistanceScale;
}
void setMaxDistanceScaleMultipliable(bool multipliable)
{
mDirty.maxDistanceScale |= mConfig.painting.maxDistanceScaleMultipliable != multipliable;
mConfig.painting.maxDistanceScaleMultipliable = multipliable;
}
bool getMaxDistanceScaleMultipliable() const
{
return mConfig.painting.maxDistanceScaleMultipliable;
}
// configuration.setMeshes
void setDeriveNormalsFromBones(bool on)
{
mDirty.workspace |= mConfig.setMeshes.deriveNormalsFromBones != on;
mConfig.setMeshes.deriveNormalsFromBones = on;
}
bool getDeriveNormalsFromBones() const
{
return mConfig.setMeshes.deriveNormalsFromBones;
}
// configuration.simulation
void setSimulationFrequency(int freq)
{
mDirty.workspace |= mConfig.simulation.frequency != (float)freq;
mConfig.simulation.frequency = (float)freq;
}
int getSimulationFrequency() const
{
return (int)mConfig.simulation.frequency;
}
void setGravity(int gravity)
{
mDirty.workspace |= mConfig.simulation.gravity != gravity;
mConfig.simulation.gravity = gravity;
mDirty.gravity = true;
}
int getGravity() const
{
return mConfig.simulation.gravity;
}
void setGroundplane(int v)
{
mDirty.workspace |= mConfig.simulation.groundplane != v;
mConfig.simulation.groundplane = v;
mDirty.groundPlane = true;
}
int getGroundplane() const
{
return mConfig.simulation.groundplane;
}
void setGroundplaneEnabled(bool on)
{
mDirty.workspace |= mConfig.simulation.groundplaneEnabled != on;
mConfig.simulation.groundplaneEnabled = on;
mDirty.groundPlane = true;
}
bool getGroundplaneEnabled() const
{
return mConfig.simulation.groundplaneEnabled;
}
void setBudgetPercent(int p)
{
p = physx::PxClamp(p, 0, 100);
mConfig.simulation.budgetPercent = p;
}
int getBudgetPercent() const
{
return mConfig.simulation.budgetPercent;
}
void setInterCollisionDistance(float distance)
{
mDirty.workspace |= mConfig.simulation.interCollisionDistance != distance;
mConfig.simulation.interCollisionDistance = distance;
}
float getInterCollisionDistance() const
{
return mConfig.simulation.interCollisionDistance;
}
void setInterCollisionStiffness(float stiffness)
{
mDirty.workspace |= mConfig.simulation.interCollisionStiffness != stiffness;
mConfig.simulation.interCollisionStiffness = stiffness;
}
float getInterCollisionStiffness() const
{
return mConfig.simulation.interCollisionStiffness;
}
void setInterCollisionIterations(int iterations)
{
mDirty.workspace |= mConfig.simulation.interCollisionIterations != iterations;
mConfig.simulation.interCollisionIterations = iterations;
}
int getInterCollisionIterations() const
{
return mConfig.simulation.interCollisionIterations;
}
void setBlendTime(float time)
{
mDirty.workspace |= mConfig.simulation.blendTime != time;
mConfig.simulation.blendTime = time;
mDirty.blendTime = true;
}
float getBlendTime() const
{
return mConfig.simulation.blendTime;
}
void setPressure(float p)
{
mDirty.workspace |= mConfig.simulation.pressure != p;
mConfig.simulation.pressure = p;
mDirty.pressure = true;
}
float getPressure() const
{
return mConfig.simulation.pressure;
}
void setLodOverwrite(int lod)
{
mDirty.workspace |= mConfig.simulation.lodOverwrite != lod;
mConfig.simulation.lodOverwrite = lod;
}
int getLodOverwrite() const
{
return mConfig.simulation.lodOverwrite;
}
void setWindDirection(int w)
{
mDirty.workspace |= mConfig.simulation.windDirection != w;
mConfig.simulation.windDirection = w;
mState.drawWindTime = 3.0f;
}
int getWindDirection() const
{
return mConfig.simulation.windDirection;
}
void setWindElevation(int w)
{
mDirty.workspace |= mConfig.simulation.windElevation != w;
mConfig.simulation.windElevation = w;
mState.drawWindTime = 3.0f;
}
int getWindElevation() const
{
return mConfig.simulation.windElevation;
}
void setWindVelocity(int w)
{
mDirty.workspace |= mConfig.simulation.windVelocity != w;
mConfig.simulation.windVelocity = w;
mState.drawWindTime = 3.0f;
}
int getWindVelocity() const
{
return mConfig.simulation.windVelocity;
}
void setGpuSimulation(bool gpuSimulation)
{
mDirty.workspace |= mConfig.simulation.gpuSimulation != gpuSimulation;
mConfig.simulation.gpuSimulation = gpuSimulation;
mState.needsRestart = true;
}
bool getGpuSimulation() const
{
return mConfig.simulation.gpuSimulation;
}
void setMeshSkinningInApp(bool meshSkinningInApp)
{
mConfig.simulation.meshSkinningInApp = meshSkinningInApp;
mState.needsRestart = true;
}
bool getMeshSkinningInApp() const
{
return mConfig.simulation.meshSkinningInApp;
}
void setFallbackSkinning(bool fallbackSkinning)
{
mDirty.workspace |= mConfig.simulation.fallbackSkinning != fallbackSkinning;
mConfig.simulation.fallbackSkinning = fallbackSkinning;
mState.needsRestart = true;
}
bool getFallbackSkinning() const
{
return mConfig.simulation.fallbackSkinning;
}
void setCCTSpeed(float speed)
{
mConfig.simulation.CCTSpeed = speed;
}
float getCCTSpeed() const
{
return mConfig.simulation.CCTSpeed;
}
void setTimingNoise(float noise)
{
mConfig.simulation.timingNoise = noise;
}
float getTimingNoise() const
{
return mConfig.simulation.timingNoise;
}
void setScaleFactor(float factor)
{
mDirty.workspace |= mConfig.simulation.scaleFactor != factor;
mState.needsRestart |= mConfig.simulation.scaleFactor != factor;
mConfig.simulation.scaleFactor = factor;
}
float getScaleFactor() const
{
return mConfig.simulation.scaleFactor;
}
void setPvdDebug(bool on)
{
mDirty.workspace |= mConfig.simulation.pvdDebug != on;
mState.needsReconnect |= mConfig.simulation.pvdProfile != on;
mConfig.simulation.pvdDebug = on;
}
bool getPvdDebug() const
{
return mConfig.simulation.pvdDebug;
}
void setPvdProfile(bool on)
{
mDirty.workspace |= mConfig.simulation.pvdProfile != on;
mState.needsReconnect |= mConfig.simulation.pvdProfile != on;
mConfig.simulation.pvdProfile = on;
}
bool getPvdProfile() const
{
return mConfig.simulation.pvdProfile;
}
void setPvdMemory(bool on)
{
mDirty.workspace |= mConfig.simulation.pvdMemory != on;
mState.needsReconnect |= mConfig.simulation.pvdMemory != on;
mConfig.simulation.pvdMemory = on;
}
bool getPvdMemory() const
{
return mConfig.simulation.pvdMemory;
}
void setCCTDirection(const physx::PxVec3& direction)
{
mSimulation.CCTDirection = direction;
}
void setCCTRotation(const physx::PxVec3 rotation)
{
mSimulation.CCTRotationDelta = rotation;
}
void setGraphicalLod(int lod)
{
mDirty.workspace |= mConfig.simulation.graphicalLod != lod;
mConfig.simulation.graphicalLod = lod;
}
int getGraphicalLod() const
{
return mConfig.simulation.graphicalLod;
}
void setUsePreview(bool on)
{
mState.needsRestart |= mSimulation.actors.size() > 0;
mConfig.simulation.usePreview = on;
}
bool getUsePreview() const
{
return mConfig.simulation.usePreview;
}
void setLocalSpaceSim(bool on)
{
mDirty.workspace |= mConfig.simulation.localSpaceSim != on;
mState.needsRestart |= mConfig.simulation.localSpaceSim != on;
mConfig.simulation.localSpaceSim = on;
}
bool getLocalSpaceSim() const
{
return mConfig.simulation.localSpaceSim;
}
// configuration.animation
void setShowSkinnedPose(bool on)
{
mConfig.animation.showSkinnedPose = on;
}
bool getShowSkinnedPose()
{
return mConfig.animation.showSkinnedPose;
}
void setAnimation(int animation);
int getAnimation() const
{
return mConfig.animation.selectedAnimation;
}
void setAnimationSpeed(int s)
{
mDirty.workspace |= mConfig.animation.speed != s;
mConfig.animation.speed = s;
}
int getAnimationSpeed() const
{
return mConfig.animation.speed;
}
void setAnimationTimes(float val)
{
mConfig.animation.time = val;
}
float getAnimationTimes() const
{
return mConfig.animation.time;
}
void stepAnimationTimes(float animStep);
bool clampAnimation(float& time, bool stoppable, bool loop, float minTime, float maxTime);
void setLoopAnimation(bool on)
{
mDirty.workspace |= mConfig.animation.loop != on;
mConfig.animation.loop = on;
}
bool getLoopAnimation() const
{
return mConfig.animation.loop;
}
void setLockRootbone(bool on)
{
mDirty.workspace |= mConfig.animation.lockRootbone != on;
mConfig.animation.lockRootbone = on;
mState.manualAnimation = true;
}
bool getLockRootbone() const
{
return mConfig.animation.lockRootbone;
}
void setAnimationContinuous(bool on)
{
mDirty.workspace |= mConfig.animation.continuous != on;
mConfig.animation.continuous = on;
}
bool getAnimationContinuous() const
{
return mConfig.animation.continuous;
}
void setUseGlobalPoseMatrices(bool on)
{
mDirty.workspace |= mConfig.animation.useGlobalPoseMatrices != on;
mState.needsRestart = mConfig.animation.useGlobalPoseMatrices != on;
mConfig.animation.useGlobalPoseMatrices = on;
}
bool getUseGlobalPoseMatrices() const
{
return mConfig.animation.useGlobalPoseMatrices;
}
void setApplyGlobalPoseInApp(bool on)
{
mDirty.workspace |= mConfig.animation.applyGlobalPoseInApp != on;
mState.needsRestart = mConfig.animation.applyGlobalPoseInApp != on;
mConfig.animation.applyGlobalPoseInApp = on;
}
bool getApplyGlobalPoseInApp() const
{
return mConfig.animation.applyGlobalPoseInApp;
}
void setAnimationCrop(float min, float max);
// configuration.deformable
void setDeformableThickness(float value)
{
mDirty.workspace |= mConfig.deformable.thickness != value;
mConfig.deformable.thickness = value;
mConfig.deformable.drawThickness = true;
}
float getDeformableThickness() const
{
return mConfig.deformable.thickness;
}
void setDrawDeformableThickness(bool on)
{
mConfig.deformable.drawThickness = on;
}
bool getDrawDeformableThickness() const
{
return mConfig.deformable.drawThickness;
}
void setDeformableVirtualParticleDensity(float val)
{
mDirty.workspace |= mConfig.deformable.virtualParticleDensity != val;
mConfig.deformable.virtualParticleDensity = val;
}
float getDeformableVirtualParticleDensity() const
{
return mConfig.deformable.virtualParticleDensity;
}
void setDeformableHierarchicalLevels(int value)
{
mDirty.workspace |= mConfig.deformable.hierarchicalLevels != value;
mConfig.deformable.hierarchicalLevels = value;
}
int getDeformableHierarchicalLevels() const
{
return mConfig.deformable.hierarchicalLevels;
}
void setDeformableDisableCCD(bool on)
{
mDirty.workspace |= mConfig.deformable.disableCCD != on;
mConfig.deformable.disableCCD = on;
}
bool getDeformableDisableCCD() const
{
return mConfig.deformable.disableCCD;
}
void setDeformableTwowayInteraction(bool on)
{
mDirty.workspace |= mConfig.deformable.twowayInteraction != on;
mConfig.deformable.twowayInteraction = on;
}
bool getDeformableTwowayInteraction() const
{
return mConfig.deformable.twowayInteraction;
}
void setDeformableUntangling(bool on)
{
mDirty.workspace |= mConfig.deformable.untangling != on;
mConfig.deformable.untangling = on;
}
bool getDeformableUntangling() const
{
return mConfig.deformable.untangling;
}
void setDeformableRestLengthScale(float scale)
{
mDirty.workspace |= mConfig.deformable.restLengthScale != scale;
mConfig.deformable.restLengthScale = scale;
}
float getDeformableRestLengthScale() const
{
return mConfig.deformable.restLengthScale;
}
// init configuration
void resetTempConfiguration();
void initConfiguration();
void prepareConfiguration();
size_t getNumCommands() const
{
return mRecordCommands.size();
}
int getCommandFrameNumber(size_t index) const
{
return mRecordCommands[index].frameNumber;
}
const char* getCommandString(size_t index) const
{
return mRecordCommands[index].command.c_str();
}
void addCommand(const char* command, int frameNumber = -2);
void clearCommands();
// file IO
bool loadParameterized(const char* filename, physx::PxFileBuf* filebuffer, NvParameterized::Serializer::DeserializedData& deserializedData, bool silent = false);
bool saveParameterized(const char* filename, physx::PxFileBuf* filebuffer, const NvParameterized::Interface** pInterfaces, unsigned int numInterfaces);
void clearLoadedActorDescs();
protected:
std::vector<NvParameterized::Interface*> mLoadedActorDescs;
std::vector<float> mMaxTimesteps;
std::vector<int> mMaxIterations;
std::vector<int> mTimestepMethods;
std::vector<float> mDts;
std::vector<physx::PxVec3> mGravities;
unsigned int mCurrentActorDesc;
private:
NvParameterized::Serializer::SerializeType extensionToType(const char* filename) const;
bool parameterizedError(NvParameterized::Serializer::ErrorType errorType, const char* filename);
void setAuthoringState(AuthoringState::Enum authoringState, bool allowAdvance);
// internal methods
HACD::AutoGeometry* createAutoGeometry();
void addCollisionVolumeInternal(HACD::SimpleHull* hull, bool useCapsule);
void createRenderMeshAssets();
void createCustomMesh();
void createClothMeshes(nvidia::apex::IProgressListener* progress);
void createClothingAsset(nvidia::apex::IProgressListener* progress);
void updateDeformableParameters();
struct CurrentState
{
bool needsRedraw;
bool needsRestart;
bool needsReconnect;
bool manualAnimation;
AuthoringState::Enum authoringState;
float simulationValuesScale;
float gravityValueScale;
typedef std::map<std::string, NvParameterized::Interface*> tMaterialLibraries;
tMaterialLibraries materialLibraries;
std::string selectedMaterialLibrary;
std::string selectedMaterial;
physx::PxVec3 windOrigin;
physx::PxVec3 windTarget;
float drawWindTime;
physx::PxBounds3 apexBounds;
int currentFrameNumber;
void init()
{
needsRedraw = false;
needsRestart = false;
needsReconnect = false;
manualAnimation = false;
authoringState = AuthoringState::None;
simulationValuesScale = 1.0f;
gravityValueScale = 0.0f;
for (tMaterialLibraries::iterator it = materialLibraries.begin(); it != materialLibraries.end(); ++it)
{
it->second->destroy();
}
materialLibraries.clear();
selectedMaterialLibrary.clear();
selectedMaterial.clear();
windOrigin = physx::PxVec3(0.0f);
windTarget = physx::PxVec3(0.0f);
drawWindTime = 0;
apexBounds.setEmpty();
currentFrameNumber = -1;
}
};
CurrentState mState;
struct DirtyFlags
{
bool maxDistancePainting;
bool maxDistanceScale;
bool clothingActorFlags;
bool groundPlane;
bool gravity;
bool blendTime;
bool pressure;
bool workspace;
void init()
{
maxDistancePainting = false;
maxDistanceScale = false;
clothingActorFlags = false;
groundPlane = false;
gravity = false;
blendTime = false;
pressure = false;
workspace = false;
}
};
DirtyFlags mDirty;
struct Simulation
{
struct ClothingActor
{
ClothingActor() : scale(1.0f), triangleMesh(NULL)
{
initPose = physx::PxMat44(physx::PxIdentity);
currentPose = physx::PxMat44(physx::PxIdentity);
}
physx::PxMat44 initPose;
physx::PxMat44 currentPose;
float scale;
Samples::TriangleMesh* triangleMesh;
std::vector<nvidia::apex::ClothingActor*> actors;
std::vector<nvidia::apex::ClothingPreview*> previews;
std::vector<nvidia::apex::ClothingPlane*> actorGroundPlanes;
};
physx::PxCpuDispatcher* cpuDispatcher;
nvidia::apex::Scene* apexScene;
nvidia::apex::AssetPreviewScene* previewScene;
physx::PxCudaContextManager* cudaContextManager;
physx::PxScene* physxScene;
physx::PxMaterial* physxMaterial;
bool running;
struct ClothingAsset
{
ClothingAsset(nvidia::apex::ClothingAsset* _apexAsset) : apexAsset(_apexAsset) {}
void releaseRenderMeshAssets();
nvidia::apex::ClothingAsset* apexAsset;
std::vector<short> remapToSkeleton;
std::vector<std::vector<nvidia::apex::ClothingMeshSkinningMap> > meshSkinningMaps;
std::vector<nvidia::apex::RenderMeshAsset*> renderMeshAssets;
};
std::vector<ClothingAsset> assets;
bool clearAssets;
int actorCount;
std::vector<ClothingActor> actors;
bool paused;
physx::PxRigidStatic* groundPlane;
unsigned int stepsUntilPause;
unsigned int frameNumber;
physx::PxMat44 CCTPose;
physx::PxVec3 CCTDirection;
physx::PxVec3 CCTRotationDelta;
void init()
{
cpuDispatcher = NULL;
apexScene = NULL;
cudaContextManager = NULL;
physxScene = NULL;
physxMaterial = NULL;
groundPlane = NULL;
running = false;
clearAssets = true;
actorCount = 1;
paused = false;
stepsUntilPause = 0;
frameNumber = 0;
CCTPose = physx::PxMat44(physx::PxIdentity);
CCTDirection = physx::PxVec3(0.0f);
CCTRotationDelta = physx::PxVec3(0.0f);
}
void clear();
};
Simulation mSimulation;
struct Meshes
{
Samples::TriangleMesh* inputMesh;
std::string inputMeshFilename;
MeshPainter* painter;
Samples::TriangleMesh* customPhysicsMesh;
std::string customPhysicsMeshFilename;
Samples::TriangleMesh* groundMesh;
Samples::SkeletalAnim* skeleton;
Samples::SkeletalAnim* skeletonBehind;
std::vector<int> skeletonRemap;
std::vector<CollisionVolume> collisionVolumes;
bool tangentSpaceGenerated;
struct SubdivideHistoryItem
{
int submesh;
int subdivision;
};
std::vector<SubdivideHistoryItem> subdivideHistory;
struct SubmeshMaterialRename
{
int submesh;
std::string newName;
};
void init()
{
inputMesh = NULL;
//inputMeshFilename.clear();
painter = NULL;
customPhysicsMesh = NULL;
customPhysicsMeshFilename.clear();
groundMesh = NULL;
skeleton = NULL;
skeletonBehind = NULL;
skeletonRemap.clear();
collisionVolumes.clear();
subdivideHistory.clear();
tangentSpaceGenerated = false;
}
void clear(nvidia::apex::UserRenderResourceManager* rrm, nvidia::apex::ResourceCallback* rcb, bool groundAsWell);
};
Meshes mMeshes;
struct AuthoringObjects
{
std::vector<nvidia::apex::RenderMeshAssetAuthoring*> renderMeshAssets;
std::vector<nvidia::apex::ClothingPhysicalMesh*> physicalMeshes;
nvidia::apex::ClothingAssetAuthoring* clothingAssetAuthoring;
void init()
{
renderMeshAssets.clear();
physicalMeshes.clear();
clothingAssetAuthoring = NULL;
}
void clear();
};
AuthoringObjects mAuthoringObjects;
// configuration
std::map<std::string, float*> mFloatConfiguration;
std::map<std::string, float*> mFloatConfigurationOld;
std::map<std::string, int*> mIntConfiguration;
std::map<std::string, int*> mIntConfigurationOld;
std::map<std::string, bool*> mBoolConfiguration;
std::map<std::string, bool*> mBoolConfigurationOld;
struct configUI
{
bool zAxisUp;
bool spotLight;
bool spotLightShadow;
void init()
{
zAxisUp = false;
spotLight = false;
spotLightShadow = true;
}
};
struct configMesh
{
int originalMeshSubdivision;
bool evenOutVertexDegrees;
int cullMode;
int textureUvOrigin;
int physicalMeshType;
void init()
{
originalMeshSubdivision = 10;
evenOutVertexDegrees = false;
cullMode = nvidia::apex::RenderCullMode::NONE;
textureUvOrigin = nvidia::apex::TextureUVOrigin::ORIGIN_TOP_LEFT;
physicalMeshType = 0;
}
};
struct configApex
{
bool parallelCpuSkinning;
bool recomputeNormals;
bool recomputeTangents;
bool correctSimulationNormals;
bool useMorphTargetTest;
bool forceEmbedded;
void init()
{
parallelCpuSkinning = true;
recomputeNormals = false;
recomputeTangents = false;
correctSimulationNormals = true;
useMorphTargetTest = false;
forceEmbedded = false;
}
};
struct configCloth
{
int numGraphicalLods;
int simplify;
bool close;
bool subdivide;
int subdivision;
void init()
{
numGraphicalLods = 1;
simplify = 40;
close = false;
subdivide = false;
subdivision = 40;
}
};
struct configCollisionVolumes
{
bool usePaintingChannel;
void init()
{
usePaintingChannel = false;
}
};
struct configPainting
{
int brushMode;
float falloffExponent;
int channel;
float value;
float valueMin;
float valueMax;
int valueFlag;
int brushRadius;
float scalingMaxdistance;
float scalingCollisionFactor;
float maxDistanceScale;
bool maxDistanceScaleMultipliable;
void init()
{
brushMode = BrushMode::PaintFlat;
falloffExponent = 1.0f;
channel = 4; // NUM_CHANNELS
value = 1.0f;
valueMin = 0.0f;
valueMax = 1.0f;
valueFlag = 1;
brushRadius = 50;
scalingMaxdistance = 1.0f;
scalingCollisionFactor = 1.0f;
maxDistanceScale = 1.0f;
maxDistanceScaleMultipliable = true;
}
};
struct configSetMeshes
{
bool deriveNormalsFromBones;
void init()
{
deriveNormalsFromBones = false;
}
};
struct configSimulation
{
float frequency;
int gravity;
int groundplane;
bool groundplaneEnabled;
int budgetPercent;
float interCollisionDistance;
float interCollisionStiffness;
int interCollisionIterations;
float blendTime;
float pressure;
int lodOverwrite;
int windDirection;
int windElevation;
int windVelocity;
bool gpuSimulation;
bool meshSkinningInApp;
bool fallbackSkinning;
float CCTSpeed;
int graphicalLod;
bool usePreview;
float timingNoise;
float scaleFactor;
bool localSpaceSim;
bool pvdDebug;
bool pvdProfile;
bool pvdMemory;
void init()
{
frequency = 50.0f;
gravity = 10;
groundplane = 0;
groundplaneEnabled = true;
budgetPercent = 100;
interCollisionDistance = 0.1f;
interCollisionStiffness = 1.0f;
interCollisionIterations = 1;
blendTime = 1.0f;
pressure = -1.0f;
lodOverwrite = -1;
windDirection = 0;
windElevation = 0;
windVelocity = -1;
gpuSimulation = true;
meshSkinningInApp = false;
fallbackSkinning = false;
CCTSpeed = 0.0f;
graphicalLod = 0;
usePreview = false;
timingNoise = 0.0f;
scaleFactor = 1.0f;
localSpaceSim = true;
pvdDebug = true;
pvdProfile = true;
pvdMemory = false;
}
};
struct configAnimation
{
bool showSkinnedPose; // can overwrite mAnimatio>0 for the non-simulating part
int selectedAnimation; // 0 and negative mean no animation (use negative to switch off and remember which one)
int speed;
float time;
bool loop;
bool lockRootbone;
bool continuous;
bool useGlobalPoseMatrices;
bool applyGlobalPoseInApp;
float cropMin;
float cropMax;
void init()
{
showSkinnedPose = false;
selectedAnimation = -1;
speed = 100;
time = 0.0f;
loop = true;
lockRootbone = false;
continuous = false;
useGlobalPoseMatrices = true;
applyGlobalPoseInApp = false;
cropMin = 0.0f;
cropMax = 1000000.0f;
}
};
struct configDeformable
{
float thickness;
bool drawThickness;
float virtualParticleDensity;
int hierarchicalLevels;
bool disableCCD;
bool twowayInteraction;
bool untangling;
float restLengthScale;
void init()
{
thickness = 0.01f;
drawThickness = false;
virtualParticleDensity = 0.0f;
hierarchicalLevels = 0;
disableCCD = false;
twowayInteraction = false;
untangling = false;
restLengthScale = 1.0f;
}
};
struct Configuration
{
configUI ui;
configMesh mesh;
configApex apex;
configCloth cloth;
configCollisionVolumes collisionVolumes;
configPainting painting;
configSetMeshes setMeshes;
configSimulation simulation;
configAnimation animation;
configDeformable deformable;
void init()
{
ui.init();
mesh.init();
apex.init();
cloth.init();
collisionVolumes.init();
painting.init();
setMeshes.init();
simulation.init();
animation.init();
deformable.init();
}
};
Configuration mConfig;
struct Command
{
int frameNumber;
std::string command;
};
std::vector<Command> mRecordCommands;
protected:
// APEX
nvidia::apex::ApexSDK* _mApexSDK;
nvidia::apex::ModuleClothing* _mModuleClothing;
nvidia::apex::RenderDebugInterface* _mApexRenderDebug;
nvidia::apex::ResourceCallback* _mResourceCallback;
nvidia::apex::UserRenderResourceManager* _mRenderResourceManager;
Samples::MaterialList* _mMaterialList;
nvidia::PxPvd* mPvd;
// Callback
ErrorCallback* _mErrorCallback;
std::vector<NotificationCallback*> _mNotifyCallbacks;
};
} // namespace SharedTools
#endif //PX_WINDOWS_FAMILY
#endif //CLOTHING_AUTHORING_H
|