Skip to content

Commit f4596a9

Browse files
author
Jan Bender
committed
- added collision demos
- added collision detection based on distance functions - added collision handling for rigid and deformable bodies - added SceneGenerator.py to generate new scenarios easily by simple Python scripting - added scene loader demo - added scene loader based on json - high resolution visualization mesh can be attached to a deformable body
1 parent 38960c4 commit f4596a9

File tree

109 files changed

+197372
-3373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+197372
-3373
lines changed

Changelog.txt

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
1.5.0
2+
- added SceneGenerator.py to generate new scenarios easily by simple Python scripting
3+
- added scene loader demo
4+
- added scene loader based on json
5+
- added collision demos
6+
- added collision detection based on distance functions
7+
- added collision handling for rigid and deformable bodies
8+
- high resolution visualization mesh can be attached to a deformable body
19
- added support for Mac OS X
210
- added shader support
311
- added automatic computation of inertia tensor for arbitrary triangle meshes

Common/Common.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef COMMON_H
2+
#define COMMON_H
3+
4+
#include <Eigen/Dense>
5+
6+
#define USE_DOUBLE
7+
8+
#ifdef USE_DOUBLE
9+
typedef double Real;
10+
11+
#define REAL_MAX DBL_MAX
12+
#define REAL_MIN DBL_MIN
13+
#else
14+
typedef float Real;
15+
16+
#define REAL_MAX FLT_MAX
17+
#define REAL_MIN FLT_MIN
18+
#endif
19+
20+
namespace PBD
21+
{
22+
using Vector2r = Eigen::Matrix<Real, 2, 1>;
23+
using Vector3r = Eigen::Matrix<Real, 3, 1>;
24+
using Vector4r = Eigen::Matrix<Real, 4, 1>;
25+
using Matrix2r = Eigen::Matrix<Real, 2, 2>;
26+
using Matrix3r = Eigen::Matrix<Real, 3, 3>;
27+
using Matrix4r = Eigen::Matrix<Real, 4, 4>;
28+
using AlignedBox2r = Eigen::AlignedBox<Real, 2>;
29+
using AlignedBox3r = Eigen::AlignedBox<Real, 3>;
30+
using AngleAxisr = Eigen::AngleAxis<Real>;
31+
using Quaternionr = Eigen::Quaternion<Real>;
32+
}
33+
34+
#endif

Demos/BarDemo/CMakeLists.txt

+4-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
set(SIMULATION_LINK_LIBRARIES AntTweakBar glew PositionBasedDynamics)
2-
set(SIMULATION_DEPENDENCIES AntTweakBar glew PositionBasedDynamics)
1+
set(SIMULATION_LINK_LIBRARIES AntTweakBar glew PositionBasedDynamics Simulation)
2+
set(SIMULATION_DEPENDENCIES AntTweakBar glew PositionBasedDynamics Simulation)
33

44
if(WIN32)
55
set(SIMULATION_LINK_LIBRARIES freeglut opengl32.lib glu32.lib ${SIMULATION_LINK_LIBRARIES})
@@ -19,7 +19,8 @@ add_executable(BarDemo
1919
main.cpp
2020

2121
${VIS_FILES}
22-
${PROJECT_PATH}/Demos/Utils/Config.h
22+
${PROJECT_PATH}/Common/Common.h
23+
${PROJECT_PATH}/Demos/Common/Config.h
2324
${PROJECT_PATH}/Demos/Utils/IndexedFaceMesh.cpp
2425
${PROJECT_PATH}/Demos/Utils/IndexedFaceMesh.h
2526
${PROJECT_PATH}/Demos/Utils/IndexedTetMesh.cpp
@@ -28,21 +29,6 @@ add_executable(BarDemo
2829
${PROJECT_PATH}/Demos/Utils/Utilities.h
2930
${PROJECT_PATH}/Demos/Utils/VolumeIntegration.cpp
3031
${PROJECT_PATH}/Demos/Utils/VolumeIntegration.h
31-
${PROJECT_PATH}/Demos/Simulation/TimeManager.cpp
32-
${PROJECT_PATH}/Demos/Simulation/TimeManager.h
33-
${PROJECT_PATH}/Demos/Simulation/RigidBodyGeometry.cpp
34-
${PROJECT_PATH}/Demos/Simulation/RigidBodyGeometry.h
35-
${PROJECT_PATH}/Demos/Simulation/RigidBody.h
36-
${PROJECT_PATH}/Demos/Simulation/Constraints.cpp
37-
${PROJECT_PATH}/Demos/Simulation/Constraints.h
38-
${PROJECT_PATH}/Demos/Simulation/TetModel.cpp
39-
${PROJECT_PATH}/Demos/Simulation/TetModel.h
40-
${PROJECT_PATH}/Demos/Simulation/TriangleModel.cpp
41-
${PROJECT_PATH}/Demos/Simulation/TriangleModel.h
42-
${PROJECT_PATH}/Demos/Simulation/TimeStepController.cpp
43-
${PROJECT_PATH}/Demos/Simulation/TimeStepController.h
44-
${PROJECT_PATH}/Demos/Simulation/SimulationModel.cpp
45-
${PROJECT_PATH}/Demos/Simulation/SimulationModel.h
4632

4733
CMakeLists.txt
4834
)

Demos/BarDemo/main.cpp

+29-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "Demos/Utils/Config.h"
1+
#include "Demos/Common/Config.h"
22
#include "Demos/Visualization/MiniGL.h"
33
#include "Demos/Visualization/Selection.h"
44
#include "GL/glut.h"
@@ -48,9 +48,10 @@ TimeStepController sim;
4848
const unsigned int width = 30;
4949
const unsigned int depth = 5;
5050
const unsigned int height = 5;
51+
short simulationMethod = 2;
5152
bool doPause = true;
5253
std::vector<unsigned int> selectedParticles;
53-
Eigen::Vector3f oldMousePos;
54+
Vector3r oldMousePos;
5455
Shader *shader;
5556
string exePath;
5657
string dataPath;
@@ -75,17 +76,17 @@ int main( int argc, char **argv )
7576
buildModel ();
7677

7778
MiniGL::setClientSceneFunc(render);
78-
MiniGL::setViewport (40.0f, 0.1f, 500.0f, Vector3f (5.0, -10.0, 30.0), Vector3f (5.0, 0.0, 0.0));
79+
MiniGL::setViewport (40.0f, 0.1f, 500.0f, Vector3r (5.0, 10.0, 30.0), Vector3r (5.0, 0.0, 0.0));
7980

8081
TwAddVarRW(MiniGL::getTweakBar(), "Pause", TW_TYPE_BOOLCPP, &doPause, " label='Pause' group=Simulation key=SPACE ");
81-
TwAddVarCB(MiniGL::getTweakBar(), "TimeStepSize", TW_TYPE_FLOAT, setTimeStep, getTimeStep, &model, " label='Time step size' min=0.0 max = 0.1 step=0.001 precision=4 group=Simulation ");
82+
TwAddVarCB(MiniGL::getTweakBar(), "TimeStepSize", TW_TYPE_REAL, setTimeStep, getTimeStep, &model, " label='Time step size' min=0.0 max = 0.1 step=0.001 precision=4 group=Simulation ");
8283
TwType enumType = TwDefineEnum("VelocityUpdateMethodType", NULL, 0);
8384
TwAddVarCB(MiniGL::getTweakBar(), "VelocityUpdateMethod", enumType, setVelocityUpdateMethod, getVelocityUpdateMethod, &sim, " label='Velocity update method' enum='0 {First Order Update}, 1 {Second Order Update}' group=Simulation");
8485
TwType enumType2 = TwDefineEnum("SimulationMethodType", NULL, 0);
85-
TwAddVarCB(MiniGL::getTweakBar(), "SimulationMethod", enumType2, setSimulationMethod, getSimulationMethod, &sim,
86+
TwAddVarCB(MiniGL::getTweakBar(), "SimulationMethod", enumType2, setSimulationMethod, getSimulationMethod, &simulationMethod,
8687
" label='Simulation method' enum='0 {None}, 1 {Volume constraints}, 2 {FEM based PBD}, 3 {Strain based dynamics (no inversion handling)}, 4 {Shape matching (no inversion handling)}' group=Simulation");
87-
TwAddVarCB(MiniGL::getTweakBar(), "Stiffness", TW_TYPE_FLOAT, setStiffness, getStiffness, &model, " label='Stiffness' min=0.0 step=0.1 precision=4 group='Simulation' ");
88-
TwAddVarCB(MiniGL::getTweakBar(), "PoissonRatio", TW_TYPE_FLOAT, setPoissonRatio, getPoissonRatio, &model, " label='Poisson ratio XY' min=0.0 step=0.1 precision=4 group='Simulation' ");
88+
TwAddVarCB(MiniGL::getTweakBar(), "Stiffness", TW_TYPE_REAL, setStiffness, getStiffness, &model, " label='Stiffness' min=0.0 step=0.1 precision=4 group='Simulation' ");
89+
TwAddVarCB(MiniGL::getTweakBar(), "PoissonRatio", TW_TYPE_REAL, setPoissonRatio, getPoissonRatio, &model, " label='Poisson ratio XY' min=0.0 step=0.1 precision=4 group='Simulation' ");
8990
TwAddVarCB(MiniGL::getTweakBar(), "NormalizeStretch", TW_TYPE_BOOL32, setNormalizeStretch, getNormalizeStretch, &model, " label='Normalize stretch' group='Strain based dynamics' ");
9091
TwAddVarCB(MiniGL::getTweakBar(), "NormalizeShear", TW_TYPE_BOOL32, setNormalizeShear, getNormalizeShear, &model, " label='Normalize shear' group='Strain based dynamics' ");
9192

@@ -132,12 +133,12 @@ void reset()
132133

133134
void mouseMove(int x, int y)
134135
{
135-
Eigen::Vector3f mousePos;
136+
Vector3r mousePos;
136137
MiniGL::unproject(x, y, mousePos);
137-
const Eigen::Vector3f diff = mousePos - oldMousePos;
138+
const Vector3r diff = mousePos - oldMousePos;
138139

139140
TimeManager *tm = TimeManager::getCurrent();
140-
const float h = tm->getTimeStepSize();
141+
const Real h = tm->getTimeStepSize();
141142

142143
ParticleData &pd = model.getParticles();
143144
for (unsigned int j = 0; j < selectedParticles.size(); j++)
@@ -178,7 +179,7 @@ void timeStep ()
178179

179180
void buildModel ()
180181
{
181-
TimeManager::getCurrent ()->setTimeStepSize (0.005f);
182+
TimeManager::getCurrent ()->setTimeStepSize (0.005);
182183

183184
createMesh();
184185
}
@@ -207,8 +208,9 @@ void renderTetModels()
207208

208209
for (unsigned int i = 0; i < model.getTetModels().size(); i++)
209210
{
210-
const IndexedFaceMesh &visMesh = model.getTetModels()[i]->getVisMesh();
211-
Visualization::drawMesh(pd, visMesh, surfaceColor);
211+
TetModel *tetModel = model.getTetModels()[i];
212+
const IndexedFaceMesh &surfaceMesh = tetModel->getSurfaceMesh();
213+
Visualization::drawMesh(pd, surfaceMesh, tetModel->getIndexOffset(), surfaceColor);
212214
}
213215
if (shader)
214216
shader->end();
@@ -235,14 +237,14 @@ void render ()
235237

236238
void createMesh()
237239
{
238-
Eigen::Vector3f points[width*height*depth];
240+
Vector3r points[width*height*depth];
239241
for (unsigned int i = 0; i < width; i++)
240242
{
241243
for (unsigned int j = 0; j < height; j++)
242244
{
243245
for (unsigned int k = 0; k < depth; k++)
244246
{
245-
points[i*height*depth + j*depth + k] = 0.3f*Eigen::Vector3f((float)i, (float)j, (float)k);
247+
points[i*height*depth + j*depth + k] = 0.3*Vector3r((Real)i, (Real)j, (Real)k);
246248
}
247249
}
248250
}
@@ -314,7 +316,7 @@ void createMesh()
314316
const unsigned int nTets = model.getTetModels()[cm]->getParticleMesh().numTets();
315317
const unsigned int *tets = model.getTetModels()[cm]->getParticleMesh().getTets().data();
316318
const IndexedTetMesh::VertexTets *vTets = model.getTetModels()[cm]->getParticleMesh().getVertexTets().data();
317-
if (sim.getSimulationMethod() == 1)
319+
if (simulationMethod == 1)
318320
{
319321
const unsigned int offset = model.getTetModels()[cm]->getIndexOffset();
320322
const unsigned int nEdges = model.getTetModels()[cm]->getParticleMesh().numEdges();
@@ -337,9 +339,8 @@ void createMesh()
337339
model.addVolumeConstraint(v1, v2, v3, v4);
338340
}
339341
}
340-
else if (sim.getSimulationMethod() == 2)
342+
else if (simulationMethod == 2)
341343
{
342-
const unsigned int offset = model.getTetModels()[cm]->getIndexOffset();
343344
TetModel::ParticleMesh &mesh = model.getTetModels()[cm]->getParticleMesh();
344345
for (unsigned int i = 0; i < nTets; i++)
345346
{
@@ -351,9 +352,8 @@ void createMesh()
351352
model.addFEMTetConstraint(v1, v2, v3, v4);
352353
}
353354
}
354-
else if (sim.getSimulationMethod() == 3)
355+
else if (simulationMethod == 3)
355356
{
356-
const unsigned int offset = model.getTetModels()[cm]->getIndexOffset();
357357
TetModel::ParticleMesh &mesh = model.getTetModels()[cm]->getParticleMesh();
358358
for (unsigned int i = 0; i < nTets; i++)
359359
{
@@ -365,9 +365,8 @@ void createMesh()
365365
model.addStrainTetConstraint(v1, v2, v3, v4);
366366
}
367367
}
368-
else if (sim.getSimulationMethod() == 4)
368+
else if (simulationMethod == 4)
369369
{
370-
const unsigned int offset = model.getTetModels()[cm]->getIndexOffset();
371370
TetModel::ParticleMesh &mesh = model.getTetModels()[cm]->getParticleMesh();
372371
for (unsigned int i = 0; i < nTets; i++)
373372
{
@@ -388,35 +387,35 @@ void createMesh()
388387

389388
void TW_CALL setTimeStep(const void *value, void *clientData)
390389
{
391-
const float val = *(const float *)(value);
390+
const Real val = *(const Real *)(value);
392391
TimeManager::getCurrent()->setTimeStepSize(val);
393392
}
394393

395394
void TW_CALL getTimeStep(void *value, void *clientData)
396395
{
397-
*(float *)(value) = TimeManager::getCurrent()->getTimeStepSize();
396+
*(Real *)(value) = TimeManager::getCurrent()->getTimeStepSize();
398397
}
399398

400399
void TW_CALL setStiffness(const void *value, void *clientData)
401400
{
402-
const float val = *(const float *)(value);
401+
const Real val = *(const Real *)(value);
403402
((SimulationModel*) clientData)->setSolidStiffness(val);
404403
}
405404

406405
void TW_CALL getStiffness(void *value, void *clientData)
407406
{
408-
*(float *)(value) = ((SimulationModel*)clientData)->getSolidStiffness();
407+
*(Real *)(value) = ((SimulationModel*)clientData)->getSolidStiffness();
409408
}
410409

411410
void TW_CALL setPoissonRatio(const void *value, void *clientData)
412411
{
413-
const float val = *(const float *)(value);
412+
const Real val = *(const Real *)(value);
414413
((SimulationModel*)clientData)->setSolidPoissonRatio(val);
415414
}
416415

417416
void TW_CALL getPoissonRatio(void *value, void *clientData)
418417
{
419-
*(float *)(value) = ((SimulationModel*)clientData)->getSolidPoissonRatio();
418+
*(Real *)(value) = ((SimulationModel*)clientData)->getSolidPoissonRatio();
420419
}
421420

422421
void TW_CALL setNormalizeStretch(const void *value, void *clientData)
@@ -444,13 +443,13 @@ void TW_CALL getNormalizeShear(void *value, void *clientData)
444443
void TW_CALL setSimulationMethod(const void *value, void *clientData)
445444
{
446445
const short val = *(const short *)(value);
447-
((TimeStepController*)clientData)->setSimulationMethod((unsigned int)val);
446+
*((short*)clientData) = val;
448447
reset();
449448
}
450449

451450
void TW_CALL getSimulationMethod(void *value, void *clientData)
452451
{
453-
*(short *)(value) = (short)((TimeStepController*)clientData)->getSimulationMethod();
452+
*(short *)(value) = *((short*)clientData);
454453
}
455454

456455
void TW_CALL setVelocityUpdateMethod(const void *value, void *clientData)

Demos/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
include(Visualization/CMakeLists.txt)
22
add_definitions(-DPBD_DATA_PATH="../data")
33

4-
subdirs(BarDemo ClothDemo FluidDemo RigidBodyDemos CouplingDemos GenericConstraintsDemos)
4+
subdirs(Simulation BarDemo ClothDemo DistanceFieldDemos FluidDemo RigidBodyDemos CouplingDemos GenericConstraintsDemos SceneLoaderDemo)
55

Demos/ClothDemo/CMakeLists.txt

+6-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
set(SIMULATION_LINK_LIBRARIES AntTweakBar glew PositionBasedDynamics)
2-
set(SIMULATION_DEPENDENCIES AntTweakBar glew PositionBasedDynamics)
1+
set(SIMULATION_LINK_LIBRARIES AntTweakBar glew PositionBasedDynamics Simulation)
2+
set(SIMULATION_DEPENDENCIES AntTweakBar glew PositionBasedDynamics Simulation)
33

44
if(WIN32)
55
set(SIMULATION_LINK_LIBRARIES freeglut opengl32.lib glu32.lib ${SIMULATION_LINK_LIBRARIES})
@@ -18,31 +18,17 @@ endif()
1818
add_executable(ClothDemo
1919
main.cpp
2020

21-
${VIS_FILES}
22-
${PROJECT_PATH}/Demos/Utils/Config.h
21+
${VIS_FILES}
22+
${PROJECT_PATH}/Common/Common.h
23+
${PROJECT_PATH}/Demos/Common/Config.h
2324
${PROJECT_PATH}/Demos/Utils/IndexedFaceMesh.cpp
2425
${PROJECT_PATH}/Demos/Utils/IndexedFaceMesh.h
2526
${PROJECT_PATH}/Demos/Utils/IndexedTetMesh.cpp
26-
${PROJECT_PATH}/Demos/Utils/IndexedTetMesh.h
27+
${PROJECT_PATH}/Demos/Utils/IndexedTetMesh.h
2728
${PROJECT_PATH}/Demos/Utils/Utilities.cpp
2829
${PROJECT_PATH}/Demos/Utils/Utilities.h
2930
${PROJECT_PATH}/Demos/Utils/VolumeIntegration.cpp
3031
${PROJECT_PATH}/Demos/Utils/VolumeIntegration.h
31-
${PROJECT_PATH}/Demos/Simulation/TimeManager.cpp
32-
${PROJECT_PATH}/Demos/Simulation/TimeManager.h
33-
${PROJECT_PATH}/Demos/Simulation/RigidBodyGeometry.cpp
34-
${PROJECT_PATH}/Demos/Simulation/RigidBodyGeometry.h
35-
${PROJECT_PATH}/Demos/Simulation/RigidBody.h
36-
${PROJECT_PATH}/Demos/Simulation/Constraints.cpp
37-
${PROJECT_PATH}/Demos/Simulation/Constraints.h
38-
${PROJECT_PATH}/Demos/Simulation/TetModel.cpp
39-
${PROJECT_PATH}/Demos/Simulation/TetModel.h
40-
${PROJECT_PATH}/Demos/Simulation/TriangleModel.cpp
41-
${PROJECT_PATH}/Demos/Simulation/TriangleModel.h
42-
${PROJECT_PATH}/Demos/Simulation/TimeStepController.cpp
43-
${PROJECT_PATH}/Demos/Simulation/TimeStepController.h
44-
${PROJECT_PATH}/Demos/Simulation/SimulationModel.cpp
45-
${PROJECT_PATH}/Demos/Simulation/SimulationModel.h
4632

4733
CMakeLists.txt
4834
)

0 commit comments

Comments
 (0)