1111#include " Utils/Timing.h"
1212#include " Utils/FileSystem.h"
1313#include " Demos/Common/DemoBase.h"
14- #include " Demos/Common/TweakBarParameters.h"
1514#include " Simulation/Simulation.h"
1615
1716
@@ -30,30 +29,13 @@ void buildModel ();
3029void createMesh ();
3130void render ();
3231void 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);
4532
4633
4734DemoBase *base;
4835const unsigned int width = 30 ;
4936const unsigned int depth = 5 ;
5037const 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+
5739
5840// main
5941int main ( int argc, char **argv )
@@ -71,21 +53,14 @@ int main( int argc, char **argv )
7153
7254 base->createParameterGUI ();
7355
56+ // reset simulation when solid simulation method has changed
57+ model->setSolidSimulationMethodChangedCallback ([&]() { reset (); });
58+
7459 // OpenGL
7560 MiniGL::setClientIdleFunc (timeStep);
7661 MiniGL::addKeyFunc (' r' , reset);
7762 MiniGL::setClientSceneFunc (render);
7863 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' " );
8964 MiniGL::mainLoop ();
9065 base->cleanup ();
9166
@@ -128,6 +103,8 @@ void timeStep ()
128103 START_TIMING (" SimStep" );
129104 Simulation::getCurrent ()->getTimeStep ()->step (*model);
130105 STOP_TIMING_AVG;
106+
107+ base->step ();
131108 }
132109
133110 for (unsigned int i = 0 ; i < model->getTetModels ().size (); i++)
@@ -167,19 +144,19 @@ void createMesh()
167144 }
168145
169146 // 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 ) ;
179156 for (unsigned int cm = 0 ; cm < model->getTetModels ().size (); cm++)
180157 {
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 () );
183160
184161 model->getTetModels ()[cm]->updateMeshNormals (pd);
185162
@@ -188,77 +165,3 @@ void createMesh()
188165 }
189166}
190167
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