11
11
#include " Utils/Timing.h"
12
12
#include " Utils/FileSystem.h"
13
13
#include " Demos/Common/DemoBase.h"
14
- #include " Demos/Common/TweakBarParameters.h"
15
14
#include " Simulation/Simulation.h"
16
15
17
16
@@ -30,30 +29,13 @@ void buildModel ();
30
29
void createMesh ();
31
30
void render ();
32
31
void reset ();
33
- void TW_CALL setSimulationMethod (const void *value, void *clientData);
34
- void TW_CALL getSimulationMethod (void *value, void *clientData);
35
- void TW_CALL setStiffness (const void * value, void * clientData);
36
- void TW_CALL getStiffness (void * value, void * clientData);
37
- void TW_CALL setPoissonRatio (const void * value, void * clientData);
38
- void TW_CALL getPoissonRatio (void * value, void * clientData);
39
- void TW_CALL setVolumeStiffness (const void * value, void * clientData);
40
- void TW_CALL getVolumeStiffness (void * value, void * clientData);
41
- void TW_CALL setNormalizeStretch (const void * value, void * clientData);
42
- void TW_CALL getNormalizeStretch (void * value, void * clientData);
43
- void TW_CALL setNormalizeShear (const void * value, void * clientData);
44
- void TW_CALL getNormalizeShear (void * value, void * clientData);
45
32
46
33
47
34
DemoBase *base;
48
35
const unsigned int width = 30 ;
49
36
const unsigned int depth = 5 ;
50
37
const unsigned int height = 5 ;
51
- short simulationMethod = 2 ;
52
- Real stiffness = 1.0 ;
53
- Real poissonRatio = 0.3 ;
54
- bool normalizeStretch = false ;
55
- bool normalizeShear = false ;
56
- Real volumeStiffness = 1.0 ;
38
+
57
39
58
40
// main
59
41
int main ( int argc, char **argv )
@@ -71,21 +53,14 @@ int main( int argc, char **argv )
71
53
72
54
base->createParameterGUI ();
73
55
56
+ // reset simulation when solid simulation method has changed
57
+ model->setSolidSimulationMethodChangedCallback ([&]() { reset (); });
58
+
74
59
// OpenGL
75
60
MiniGL::setClientIdleFunc (timeStep);
76
61
MiniGL::addKeyFunc (' r' , reset);
77
62
MiniGL::setClientSceneFunc (render);
78
63
MiniGL::setViewport (40 .0f , 0 .1f , 500 .0f , Vector3r (5.0 , 10.0 , 30.0 ), Vector3r (5.0 , 0.0 , 0.0 ));
79
-
80
- TwType enumType2 = TwDefineEnum (" SimulationMethodType" , NULL , 0 );
81
- TwAddVarCB (MiniGL::getTweakBar (), " SimulationMethod" , enumType2, setSimulationMethod, getSimulationMethod, &simulationMethod,
82
- " label='Simulation method' enum='0 {None}, 1 {Volume constraints}, 2 {FEM based PBD}, 3 {FEM based XPBD}, \
83
- 4 {Strain based dynamics (no inversion handling)}, 5 {Shape matching (no inversion handling)}, 6 {XPBD volume constraints}' group=Simulation" );
84
- TwAddVarCB (MiniGL::getTweakBar (), " stiffness" , TW_TYPE_REAL, setStiffness, getStiffness, model, " label='Stiffness' min=0.0 step=0.1 precision=4 group='Solid' " );
85
- TwAddVarCB (MiniGL::getTweakBar (), " poissonRatio" , TW_TYPE_REAL, setPoissonRatio, getPoissonRatio, model, " label='Poisson ratio' min=0.0 step=0.1 precision=4 group='Solid' " );
86
- TwAddVarCB (MiniGL::getTweakBar (), " normalizeStretch" , TW_TYPE_BOOL32, setNormalizeStretch, getNormalizeStretch, model, " label='Normalize stretch' group='Solid' " );
87
- TwAddVarCB (MiniGL::getTweakBar (), " normalizeShear" , TW_TYPE_BOOL32, setNormalizeShear, getNormalizeShear, model, " label='Normalize shear' group='Solid' " );
88
- TwAddVarCB (MiniGL::getTweakBar (), " volumeStiffness" , TW_TYPE_REAL, setVolumeStiffness, getVolumeStiffness, model, " label='Volume stiffness' min=0.0 step=0.1 precision=4 group='Solid' " );
89
64
MiniGL::mainLoop ();
90
65
base->cleanup ();
91
66
@@ -128,6 +103,8 @@ void timeStep ()
128
103
START_TIMING (" SimStep" );
129
104
Simulation::getCurrent ()->getTimeStep ()->step (*model);
130
105
STOP_TIMING_AVG;
106
+
107
+ base->step ();
131
108
}
132
109
133
110
for (unsigned int i = 0 ; i < model->getTetModels ().size (); i++)
@@ -167,19 +144,19 @@ void createMesh()
167
144
}
168
145
169
146
// init constraints
170
- stiffness = 1.0 ;
171
- if (simulationMethod == 3 )
172
- stiffness = 1000000 ;
173
- if (simulationMethod == 6 )
174
- stiffness = 100000 ;
175
-
176
- volumeStiffness = 1.0 ;
177
- if (simulationMethod == 6 )
178
- volumeStiffness = 100000 ;
147
+ model-> setSolidStiffness ( 1.0 ) ;
148
+ if (model-> getSolidSimulationMethod () == 3 )
149
+ model-> setSolidStiffness ( 1000000 ) ;
150
+ if (model-> getSolidSimulationMethod () == 6 )
151
+ model-> setSolidStiffness ( 100000 ) ;
152
+
153
+ model-> setSolidVolumeStiffness ( 1.0 ) ;
154
+ if (model-> getSolidSimulationMethod () == 6 )
155
+ model-> setSolidVolumeStiffness ( 100000 ) ;
179
156
for (unsigned int cm = 0 ; cm < model->getTetModels ().size (); cm++)
180
157
{
181
- model->addSolidConstraints (model->getTetModels ()[cm], simulationMethod, stiffness,
182
- poissonRatio, volumeStiffness, normalizeStretch, normalizeShear );
158
+ model->addSolidConstraints (model->getTetModels ()[cm], model-> getSolidSimulationMethod (), model-> getSolidStiffness (),
159
+ model-> getSolidPoissonRatio (), model-> getSolidVolumeStiffness (), model-> getSolidNormalizeStretch (), model-> getSolidNormalizeShear () );
183
160
184
161
model->getTetModels ()[cm]->updateMeshNormals (pd);
185
162
@@ -188,77 +165,3 @@ void createMesh()
188
165
}
189
166
}
190
167
191
- void TW_CALL setSimulationMethod (const void *value, void *clientData)
192
- {
193
- const short val = *(const short *)(value);
194
- *((short *)clientData) = val;
195
- reset ();
196
- }
197
-
198
- void TW_CALL getSimulationMethod (void *value, void *clientData)
199
- {
200
- *(short *)(value) = *((short *)clientData);
201
- }
202
-
203
- void TW_CALL setStiffness (const void * value, void * clientData)
204
- {
205
- stiffness = *(const Real*)(value);
206
- ((SimulationModel*)clientData)->setConstraintValue <FEMTetConstraint, Real, &FEMTetConstraint::m_stiffness>(stiffness);
207
- ((SimulationModel*)clientData)->setConstraintValue <XPBD_FEMTetConstraint, Real, &XPBD_FEMTetConstraint::m_stiffness>(stiffness);
208
- ((SimulationModel*)clientData)->setConstraintValue <StrainTetConstraint, Real, &StrainTetConstraint::m_stretchStiffness>(stiffness);
209
- ((SimulationModel*)clientData)->setConstraintValue <StrainTetConstraint, Real, &StrainTetConstraint::m_shearStiffness>(stiffness);
210
- ((SimulationModel*)clientData)->setConstraintValue <DistanceConstraint, Real, &DistanceConstraint::m_stiffness>(stiffness);
211
- ((SimulationModel*)clientData)->setConstraintValue <DistanceConstraint_XPBD, Real, &DistanceConstraint_XPBD::m_stiffness>(stiffness);
212
- ((SimulationModel*)clientData)->setConstraintValue <ShapeMatchingConstraint, Real, &ShapeMatchingConstraint::m_stiffness>(stiffness);
213
- }
214
-
215
- void TW_CALL getStiffness (void * value, void * clientData)
216
- {
217
- *(Real*)(value) = stiffness;
218
- }
219
-
220
- void TW_CALL setVolumeStiffness (const void * value, void * clientData)
221
- {
222
- volumeStiffness = *(const Real*)(value);
223
- ((SimulationModel*)clientData)->setConstraintValue <VolumeConstraint, Real, &VolumeConstraint::m_stiffness>(volumeStiffness);
224
- ((SimulationModel*)clientData)->setConstraintValue <VolumeConstraint_XPBD, Real, &VolumeConstraint_XPBD::m_stiffness>(volumeStiffness);
225
- }
226
-
227
- void TW_CALL getVolumeStiffness (void * value, void * clientData)
228
- {
229
- *(Real*)(value) = volumeStiffness;
230
- }
231
-
232
- void TW_CALL getPoissonRatio (void * value, void * clientData)
233
- {
234
- *(Real*)(value) = poissonRatio;
235
- }
236
-
237
- void TW_CALL setPoissonRatio (const void * value, void * clientData)
238
- {
239
- poissonRatio = *(const Real*)(value);
240
- ((SimulationModel*)clientData)->setConstraintValue <FEMTetConstraint, Real, &FEMTetConstraint::m_poissonRatio>(poissonRatio);
241
- ((SimulationModel*)clientData)->setConstraintValue <XPBD_FEMTetConstraint, Real, &XPBD_FEMTetConstraint::m_poissonRatio>(poissonRatio);
242
- }
243
-
244
- void TW_CALL getNormalizeStretch (void * value, void * clientData)
245
- {
246
- *(bool *)(value) = normalizeStretch;
247
- }
248
-
249
- void TW_CALL setNormalizeStretch (const void * value, void * clientData)
250
- {
251
- normalizeStretch = *(const Real*)(value);
252
- ((SimulationModel*)clientData)->setConstraintValue <StrainTetConstraint, bool , &StrainTetConstraint::m_normalizeStretch>(normalizeStretch);
253
- }
254
-
255
- void TW_CALL getNormalizeShear (void * value, void * clientData)
256
- {
257
- *(bool *)(value) = normalizeShear;
258
- }
259
-
260
- void TW_CALL setNormalizeShear (const void * value, void * clientData)
261
- {
262
- normalizeShear = *(const Real*)(value);
263
- ((SimulationModel*)clientData)->setConstraintValue <StrainTetConstraint, bool , &StrainTetConstraint::m_normalizeShear>(normalizeShear);
264
- }
0 commit comments