-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathiGameMeshView.cpp
339 lines (266 loc) · 10.1 KB
/
iGameMeshView.cpp
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
#include "iGameMeshView.h"
iGameMeshView::iGameMeshView(QWidget* parent) :QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->btnLastMesh, SIGNAL(clicked(bool)), this, SLOT(LastMesh()));
connect(ui->btnNextMesh, SIGNAL(clicked(bool)), this, SLOT(NextMesh()));
///样条
//打开和保存
connect(ui->btnOpenCurve, SIGNAL(clicked(bool)), this, SLOT(OpenNurbs()));
connect(ui->btnOpenSurface, SIGNAL(clicked(bool)), this, SLOT(OpenNurbs()));
connect(ui->btnOpenVolume, SIGNAL(clicked(bool)), this, SLOT(OpenNurbs()));
connect(ui->btnSaveCurve, SIGNAL(clicked(bool)), this, SLOT(SaveNurbs()));
connect(ui->btnSaveSurface, SIGNAL(clicked(bool)), this, SLOT(SaveNurbs()));
connect(ui->btnSaveVolume, SIGNAL(clicked(bool)), this, SLOT(SaveNurbs()));
///todo: 通过控制点生成文件
//curveControlCnt,curveControlDegree_u
//surfaceControlCnt_u,surfaceControlCnt_v,surfaceControlDegree_u,surfaceControlDegree_v
//volumeControlCnt_u,volumeControlCnt_v,volumeControlCnt_w,volumeControlDegree_u,volumeControlDegree_v,volumeControlDegree_w
connect(ui->bthGenerateCurve, SIGNAL(clicked(bool)), this, SLOT(CreateNurbsCurve()));
connect(ui->bthGenrateSurface, SIGNAL(clicked(bool)), this, SLOT(CreateNurbsSurface()));
connect(ui->bthGenrateVolume,SIGNAL(clicked(bool)),this, SLOT(CreateNurbsVolume()));
// 点选和切割操作
connect(ui->rtnModelView, SIGNAL(clicked(bool)), this, SLOT(setModelView()));
connect(ui->rtnPickItem, SIGNAL(clicked(bool)), this, SLOT(setPickItem()));
connect(ui->rtnModelCut, SIGNAL(clicked(bool)), this, SLOT(setModelCut()));
connect(ui->rtnPickPoint, SIGNAL(clicked(bool)), this, SLOT(setPickPoint()));
connect(ui->rtnPickEdge, SIGNAL(clicked(bool)), this, SLOT(setPickEdge()));
connect(ui->rtnPickFace, SIGNAL(clicked(bool)), this, SLOT(setPickFace()));
connect(ui->rtnPickCell, SIGNAL(clicked(bool)), this, SLOT(setPickCell()));
connect(ui->btnPickRemoveAll, SIGNAL(clicked(bool)), this, SLOT(removeSelectedAll()));
connect(ui->btnToCut, SIGNAL(clicked(bool)), this, SLOT(cutModel()));
connect(ui->btnRemoveLine, SIGNAL(clicked(bool)), this, SLOT(removeLine()));
//绘制样式
connect(ui->viewpoints,SIGNAL (clicked (bool)),this,SLOT (ViewStylePoints ()));
connect(ui->viewlines,SIGNAL (clicked (bool)),this,SLOT (ViewStyleLines ()));
connect(ui->viewfill,SIGNAL (clicked (bool)),this,SLOT (ViewStyleFill ()));
connect(ui->viewflatfill, SIGNAL(clicked(bool)), this, SLOT(ViewStyleFlatFill()));
connect(ui->viewclear, SIGNAL(clicked(bool)), this, SLOT(ViewClear()));
connect(ui->viewlight, SIGNAL(clicked(bool)), this, SLOT(ViewLight()));
connect(ui->viewnormal, SIGNAL(clicked(bool)), this, SLOT(ViewNormal()));
connect(ui->ckbSurfaceGrid, SIGNAL(clicked(bool)), this, SLOT(ChangeSurfaceGrid()));
connect(ui->ckbFaceCull, SIGNAL(clicked(bool)), this, SLOT(ChangeFaceCull()));
connect(ui->ckbCoordCircle, SIGNAL(clicked(bool)), this, SLOT(ChangeCoordCircle()));
//x,y,z切割
connect(ui->ckbCutPlane, SIGNAL(clicked(bool)), this, SLOT(ChangeCutFlag()));
connect(ui->cutPlaneX, SIGNAL(valueChanged(int)), this, SLOT(UpdateCutXYZ()));
connect(ui->cutPlaneY, SIGNAL(valueChanged(int)), this, SLOT(UpdateCutXYZ()));
connect(ui->cutPlaneZ, SIGNAL(valueChanged(int)), this, SLOT(UpdateCutXYZ()));
// 信息监视器
ui->openGLWidget->setShowInfo([&]() {
PrintMeshInfo();
});
}
iGameMeshView::~iGameMeshView (void){
}
bool iGameMeshView::OpenNurbs(void) {
QString filePath = QFileDialog::getOpenFileName(this, tr("Load file"), tr(""), tr("XmlFiles(*.xml)"));
if (filePath.isEmpty())
return false;
else {
ui->openGLWidget->loadNurbsGeo(filePath.toStdString());
std::string filename = filePath.toStdString();
int beg = filename.find_last_of('/');
filePath = QString::fromStdString(filename.substr(++beg, filename.length()));
return true;
}
}
bool iGameMeshView::CreateNurbsCurve(void) {
std::vector<int> cc{ ui->curveControlCnt->value() };
std::vector<int> dd{ui->curveControlDegree->value()};
ui->openGLWidget->creatNurbs(cc, dd);
return true;
}
bool iGameMeshView::CreateNurbsSurface(void) {
std::vector<int> cc{ ui->surfaceControlCnt_u->value(), ui->surfaceControlCnt_v->value() };
std::vector<int> dd{ ui->surfaceControlDegree_u->value(),ui->surfaceControlDegree_v->value()};
ui->openGLWidget->creatNurbs(cc, dd);
return true;
}
bool iGameMeshView::CreateNurbsVolume(void) {
std::vector<int> cc{ ui->volumeControlCnt_u->value(), ui->volumeControlCnt_v->value(), ui->volumeControlCnt_w->value() };
std::vector<int> dd{ ui->volumeControlDegree_u->value(), ui->volumeControlDegree_v->value(), ui->volumeControlDegree_w->value() };
ui->openGLWidget->creatNurbs(cc, dd);
return true;
}
bool iGameMeshView::SaveNurbs(void) {
QString fileName = QFileDialog::getSaveFileName(this, tr("Save model file:"), tr("untitled"), tr("XmlFiles(*.xml)"));
if (!fileName.isEmpty())
{
assert(ui->openGLWidget);
std::string filename = fileName.toStdString();
ui->openGLWidget->saveNurbsGeo(filename);
int beg = filename.find_last_of('/');
fileName = QString::fromStdString(filename.substr(++beg, filename.length()));
return true;
}
return false;
}
bool iGameMeshView::OpenMesh(void) {
return false;
}
bool iGameMeshView::SaveMesh(void)
{
return false;
}
bool iGameMeshView::LastMesh(void) {
ui->openGLWidget->changeCurrentMeshToLast();
return true;
}
bool iGameMeshView::NextMesh(void) {
ui->openGLWidget->changeCurrentMeshToNext();
return true;
}
bool iGameMeshView::CopyMesh(void) {
if (ui->openGLWidget->copyMesh()) ui->info->printString("copy mesh success");
else ui->info->printString("copy mesh fail, triMesh is nullptr");
return true;
}
bool iGameMeshView::RecoverMesh(void) {
if (ui->openGLWidget->recoverMesh()) ui->info->printString("recover mesh success");
else ui->info->printString("recover mesh fail, copyTriMesh is nullptr");
return true;
}
bool iGameMeshView::AddNoise(void) {
if (!ui->openGLWidget->hasMesh()) return false;
QtConcurrent::run([&](){
ui->info->printString("add noise success");});
return true;
}
bool iGameMeshView::MotorcycleGraphs(void) {
if (!ui->openGLWidget->hasMesh()) return false;
return true;
}
bool iGameMeshView::MeshAlgorithm1(void) {
if (!ui->openGLWidget->hasMesh()) return false;
ui->info->printString("custom Algorithm1");
return true;
}
bool iGameMeshView::MeshAlgorithm2(void) {
if (!ui->openGLWidget->hasMesh()) return false;
ui->info->printString("custom Algorithm1");
return true;
}
bool iGameMeshView::MeshAlgorithm3(void) {
if (!ui->openGLWidget->hasMesh()) return false;
ui->info->printString("custom Algorithm1");
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool iGameMeshView::ViewStylePoints (){
ui->openGLWidget->SetDrawMode (ModelDraw::POINTS);
ui->openGLWidget->makeCurrent ();
return true;
}
bool iGameMeshView::ViewStyleLines (){
ui->openGLWidget->SetDrawMode (ModelDraw::FLATLINES);
ui->openGLWidget->makeCurrent ();
return true;
}
bool iGameMeshView::ViewStyleFill (){
ui->openGLWidget->SetDrawMode (ModelDraw::FILL);
ui->openGLWidget->makeCurrent ();
return true;
}
bool iGameMeshView::ViewStyleFlatFill() {
ui->openGLWidget->SetDrawMode(ModelDraw::FLATFILL);
ui->openGLWidget->makeCurrent();
return true;
}
bool iGameMeshView::ViewClear() {
ui->openGLWidget->clearMesh();
return true;
}
bool iGameMeshView::ViewLight() {
ui->openGLWidget->SetColorMode(ModelDraw::LIGHT);
return true;
}
bool iGameMeshView::ViewNormal() {
ui->openGLWidget->SetColorMode(ModelDraw::NORMAL);
return true;
}
bool iGameMeshView::ChangeSurfaceGrid() {
ui->openGLWidget->changeSurfaceGrid();
return true;
}
bool iGameMeshView::ChangeFaceCull() {
ui->openGLWidget->changeFaceCull();
return true;
}
bool iGameMeshView::ChangeCoordCircle() {
ui->openGLWidget->changeCoordCircle();
return true;
}
void iGameMeshView::PrintMeshInfo() {
}
bool iGameMeshView::setModelView() {
ui->openGLWidget->setEditModel(ModelDraw::MODELVIEW);
ui->info->printString("Edit Mode: Model View");
return true;
}
bool iGameMeshView::setPickItem() {
ui->openGLWidget->setEditModel(ModelDraw::PICKITEM);
ui->info->printString("Edit Mode: Pick Item");
return true;
}
bool iGameMeshView::setModelCut() {
ui->openGLWidget->setEditModel(ModelDraw::MODELCUT);
ui->info->printString("Edit Mode: Model Cut");
return true;
}
bool iGameMeshView::setPickPoint() {
ui->openGLWidget->setPickType(ModelDraw::PickPoint);
ui->info->printString("Pick : Point");
return true;
}
bool iGameMeshView::setPickEdge() {
ui->openGLWidget->setPickType(ModelDraw::PickEdge);
ui->info->printString("Pick : Edge");
update();
return true;
}
bool iGameMeshView::setPickFace() {
ui->openGLWidget->setPickType(ModelDraw::PickFace);
ui->info->printString("Pick : Face");
return true;
}
bool iGameMeshView::setPickCell() {
ui->openGLWidget->setPickType(ModelDraw::PickCell);
ui->info->printString("Pick : Cell");
return true;
}
bool iGameMeshView::removeSelectedAll() {
ui->openGLWidget->removeSelectedAll();
return true;
}
bool iGameMeshView::cutModel() {
//ui->openGLWidget->toCutModel();
return true;
}
bool iGameMeshView::removeLine() {
//ui->openGLWidget->removeCutLine();
return true;
}
bool iGameMeshView::ChangeCutFlag() {
if (ui->ckbCutPlane->isChecked()) {
ui->info->printString("enable cut plane");
UpdateCutXYZ();// 会自动更新 drawdata
}
else {
ui->info->printString("disable cut plane");
ui->openGLWidget->updateCutFlag(false);
}
update();
return true;
}
bool iGameMeshView::UpdateCutXYZ() {
ui->openGLWidget->cutX = (ui->cutPlaneX->value() / 100.f);
ui->openGLWidget->cutY = (ui->cutPlaneY->value() / 100.f);
ui->openGLWidget->cutZ = (ui->cutPlaneZ->value() / 100.f);
if (ui->ckbCutPlane->isChecked()) ui->openGLWidget->updateCutFlag(true);
else ui->openGLWidget->updateCutFlag(false);
printf("cut rate: %.2f, %.2f, %.2f\n", ui->openGLWidget->cutX, ui->openGLWidget->cutY, ui->openGLWidget->cutZ);
//ui->info->printString("update cut plane success");
return true;
}