-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
240 lines (203 loc) · 8.57 KB
/
main.cpp
File metadata and controls
240 lines (203 loc) · 8.57 KB
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
//Projective Dynamics solver main function
//Standalone app for QuikDeform Maya plugin
//Developed by Josh Wolper and Yichen Shou
#include "Eigen/Eigen"
#include "global.h"
#include <iostream>
#include "QuikDeformer.h"
#include <chrono> // for testing function speed
#include "OBJGenerator.h"
using namespace Eigen;
using namespace std;
int main(){
//SIM PARAMETERS
double h = 1e-2; //timestep
int iter = 1; // solverIterations
double mass = 1; //mass of each point
int fr = 24; // frame rate
double vx = 0;
double vy = 0; //init initial velocity direction and magnitude
double vz = 0;
bool printsOn = false;
double seconds = 5; //how long to run sim
string outputFilepath = "../Output/";
//WIND PARAMETERS
double wx = 0; //wind direction
double wy = 0;
double wz = -1;
double windMag = 20; //wind magnitude
double windAmp = 1;
double windPeriod = 0.5;
bool windOsc = true; //whether the wind oscillates or is constant
//Weight PARAMETERS
double E = 800;
double nu = 0.3;
double lame_lambda = E * nu / (((double)1 + nu) * ((double)1 - (double)2 * nu));
double lame_mu = E / ((double)2 * ((double)1 + nu));
double tetStrainWeight = 2 * lame_mu;
double triangleStrainWeight = tetStrainWeight;
double volumeWeight = 3 * lame_lambda;
cout << "Strain Weight is: " << tetStrainWeight << endl;
string objectFile;
string nodeFile;
string eleFile;
string faceFile;
int indexBase;
bool scaleModel;
//CHANGE THESE PARAMS WHEN CHANGING MODELS!!!
int whichObject = 5;
bool gravityOn = true;
bool volumetric = false; //whether this is a thin shell or volumetric
bool windOn = true;
if(whichObject == 0){
//Tet with 1 tet --> INDEX BASE IS 1
cout << "Processing volumetric tetrahedron model:" << endl;
indexBase = 1;
nodeFile = "../Models/tet.1.node";
eleFile = "../Models/tet.1.ele";
faceFile = "../Models/tet.1.face";
scaleModel = false;
} else if (whichObject == 1){
//Cube with 6 tets --> INDEX BASE IS 1
cout << "Processing volumetric cube model:" << endl;
indexBase = 1;
nodeFile = "../Models/cube.1.node";
eleFile = "../Models/cube.1.ele";
faceFile = "../Models/cube.1.face";
scaleModel = false;
} else if (whichObject == 2){
//Icosahedron with 16 tets --> INDEX BASE IS 0
cout << "Processing volumetric icosahedron model:" << endl;
indexBase = 0;
nodeFile = "../Models/icosahedron.1.node";
eleFile = "../Models/icosahedron.1.ele";
faceFile = "../Models/icosahedron.1.face";
scaleModel = false;
} else if (whichObject == 3){
//Tetgen weird box shape 600 tets --> INDEX BASE IS 1
cout << "Processing volumetric box with hole model:" << endl;
indexBase = 1;
nodeFile = "../tetgen1.5.1-beta1/example.1.node";
eleFile = "../tetgen1.5.1-beta1/example.1.ele";
faceFile = "../tetgen1.5.1-beta1/example.1.face";
scaleModel = false;
} else if (whichObject == 4){
//Sphere with 2064 tets --> INDEX BASE IS 0
cout << "Processing volumetric sphere model:" << endl;
indexBase = 0;
nodeFile = "../Models/sphere.1.node";
eleFile = "../Models/sphere.1.ele";
faceFile = "../Models/sphere.1.face";
scaleModel = true;
} else if(whichObject == 5) {
cout << "Processing cloth model:" << endl;
indexBase = 1;
objectFile = "../Models/cloth.obj";
double vertexDist = 0.5;
int width = 10;
int height = 10;
OBJGeneratorMode mode = OBJGeneratorMode::vertical;
double startHeight = 6;
OBJGenerator::generateClothOBJ(objectFile, vertexDist, width, height, mode, startHeight); //make the cloth to be used
scaleModel = false;
} else if(whichObject == 6){
cout << "Processing single triangle model:" << endl;
indexBase = 1;
objectFile = "../Models/triangle.obj";
scaleModel = false;
} else if(whichObject == 7){
cout << "Processing square model (2 tris):" << endl;
indexBase = 1;
objectFile = "../Models/square.obj";
scaleModel = false;
} else {
cout << "Failed to choose a case so basic tetrahedron selected" << endl;
//Tet with 1 tet --> INDEX BASE IS 1
indexBase = 1;
nodeFile = "../Models/tet.1.node";
eleFile = "../Models/tet.1.ele";
faceFile = "../Models/tet.1.face";
scaleModel = false;
}
//---------DEFINE COLLISION PLANES------------//
//Define some collision planes
vector<Vector3d> pCenters;
vector<double> pLengths;
vector<double> pWidths;
vector<Vector3d> pNormals;
double frictionCoeff = 0.4;
//Plane centers
pCenters.push_back(Vector3d(0,0,0)); //ground plane
//pCenters.push_back(Vector3d(5,0,0)); //right wall plane (90 deg)
//Plane normals
pNormals.push_back(Vector3d(0,1,0));
//pNormals.push_back(Vector3d(-1,0,0));
//---------CONSTRUCT AND RUN SIMULATOR-----------//
if(volumetric){
//---------CONSTRUCTOR--------//
QuikDeformer quikDeformer(nodeFile, eleFile, faceFile, h, iter, fr, mass, vx, vy, vz, gravityOn, volumetric, indexBase, scaleModel);
//------PRINT MATRICES-------//
//quikDeformer.printMatrices();
//-------ADD COLLISION PLANES-------//
quikDeformer.addCollisionPlanes(pCenters, pLengths, pWidths, pNormals, frictionCoeff);
//-----ADD STRAIN CONSTRAINTS-------//
quikDeformer.add3DStrainConstraints(tetStrainWeight);
//------ADD POSITION CONSTRAINTS------//
//int posConstraintIndex = 0;
//double posConstraintW = 100000;
//quikDeformer.addPositionConstraint(posConstraintW, posConstraintIndex);
//------ADD WIND EFFECTS--------------//
if(windOn){
quikDeformer.addWind(wx, wy, wz, windMag, windOsc, windAmp, windPeriod);
}
//-------RANDOMIZE VERTICES TEST----------//
//quikDeformer.randomizeVertices();
//---------RUN SIMULATION--------------//
quikDeformer.runSimulation(seconds, outputFilepath, printsOn);
}
else if(!volumetric){
//---------CONSTRUCTOR--------//
QuikDeformer quikDeformer(objectFile, h, iter, fr, mass, vx, vy, vz, gravityOn, volumetric, indexBase);
//------PRINT MATRICES-------//
//quikDeformer.printMatrices();
//-------ADD COLLISION PLANES-------//
quikDeformer.addCollisionPlanes(pCenters, pLengths, pWidths, pNormals, frictionCoeff);
//-----ADD STRAIN CONSTRAINTS-------//
quikDeformer.add2DStrainConstraints(triangleStrainWeight);
//------ADD POSITION CONSTRAINTS------//
double posConstraintW = 100000;
/*
quikDeformer.addPositionConstraint(posConstraintW, 0);
quikDeformer.addPositionConstraint(posConstraintW, 11);
quikDeformer.addPositionConstraint(posConstraintW, 22);
quikDeformer.addPositionConstraint(posConstraintW, 33);
quikDeformer.addPositionConstraint(posConstraintW, 44);
quikDeformer.addPositionConstraint(posConstraintW, 55);
quikDeformer.addPositionConstraint(posConstraintW, 66);
quikDeformer.addPositionConstraint(posConstraintW, 77);
quikDeformer.addPositionConstraint(posConstraintW, 88);
quikDeformer.addPositionConstraint(posConstraintW, 99);
quikDeformer.addPositionConstraint(posConstraintW, 110);
*/
quikDeformer.addPositionConstraint(posConstraintW, 0);
quikDeformer.addPositionConstraint(posConstraintW, 1);
quikDeformer.addPositionConstraint(posConstraintW, 2);
quikDeformer.addPositionConstraint(posConstraintW, 3);
quikDeformer.addPositionConstraint(posConstraintW, 4);
quikDeformer.addPositionConstraint(posConstraintW, 5);
quikDeformer.addPositionConstraint(posConstraintW, 6);
quikDeformer.addPositionConstraint(posConstraintW, 7);
quikDeformer.addPositionConstraint(posConstraintW, 8);
quikDeformer.addPositionConstraint(posConstraintW, 9);
quikDeformer.addPositionConstraint(posConstraintW, 10);
//------ADD WIND EFFECTS--------------//
if(windOn){
quikDeformer.addWind(wx, wy, wz, windMag, windOsc, windAmp, windPeriod);
}
//-------RANDOMIZE VERTICES TEST----------//
//quikDeformer.randomizeVertices();
//---------RUN SIMULATION--------------//
quikDeformer.runSimulation(seconds, outputFilepath, printsOn);
}
return 0;
}