1 | // generated by Fast Light User Interface Designer (fluid) version 2.0100 |
---|
2 | |
---|
3 | #include "GeoMeshViewUI.h" |
---|
4 | #include "resource.h" |
---|
5 | #include "GeoLodTreeConstructor.h" |
---|
6 | #include <string.h> |
---|
7 | |
---|
8 | using namespace Geometry; |
---|
9 | using namespace std; |
---|
10 | |
---|
11 | //------------------------------------------------------------------------- |
---|
12 | // Menu File Open Callback |
---|
13 | //------------------------------------------------------------------------- |
---|
14 | inline void GeoMeshViewUI::cb_menuFileOpen_i(fltk::Item*, void*) |
---|
15 | { |
---|
16 | // Sets menus application state to NONE. |
---|
17 | mApplicationState = NONE; |
---|
18 | |
---|
19 | // Loads a mesh file. |
---|
20 | openMeshFile(); |
---|
21 | |
---|
22 | // Deactive Lod strip visualization. |
---|
23 | geoMeshView->deactiveLodStrip(); |
---|
24 | |
---|
25 | // Deactive Lod tree visualization. |
---|
26 | geoMeshView->deactiveLodTree(); |
---|
27 | |
---|
28 | BuildLoadTextureSubMeshMenu(); |
---|
29 | |
---|
30 | // Repaint the window. |
---|
31 | mMainWindow->redraw(); |
---|
32 | } |
---|
33 | |
---|
34 | inline void GeoMeshViewUI::cb_menuFileLoadTexture_i(fltk::Item*, void*) |
---|
35 | { |
---|
36 | static char pattern[] = "*.{jpg|tga|png|bmp}"; |
---|
37 | |
---|
38 | fltk::FileChooser *fcho = new fltk::FileChooser("",pattern,fltk::FileChooser::CREATE,"Open image file"); |
---|
39 | fcho->exec(); |
---|
40 | char filename[256]=""; |
---|
41 | if (fcho->value()) |
---|
42 | { |
---|
43 | strcpy(filename,fcho->value()); |
---|
44 | geoMeshView->LoadTexture(filename); |
---|
45 | |
---|
46 | // For each submesh. |
---|
47 | for (int i = 0; i < mGeoMesh->mSubMeshCount; i++) |
---|
48 | { |
---|
49 | geoMeshView->changeTexFile(i,filename); |
---|
50 | } |
---|
51 | |
---|
52 | // Refresh mesh. |
---|
53 | geoMeshView->setMesh(mGeoMesh); |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | void GeoMeshViewUI::cb_menuFileLoadTexture(fltk::Item *o, void *v) |
---|
58 | { |
---|
59 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->parent()->user_data())) |
---|
60 | -> |
---|
61 | cb_menuFileLoadTexture_i(o,v); |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | inline void GeoMeshViewUI::cb_menuFileLoadTextureSubMesh_i( fltk::Item *item, |
---|
66 | void *) |
---|
67 | { |
---|
68 | fltk::FileChooser *fcho; |
---|
69 | |
---|
70 | static char pattern[] = "*.{jpg|tga|png|bmp}"; |
---|
71 | |
---|
72 | const char *label = item->label(); |
---|
73 | int isubmesh = label[strlen(label)-1]-48; |
---|
74 | |
---|
75 | fcho = new fltk::FileChooser("", |
---|
76 | pattern, |
---|
77 | fltk::FileChooser::CREATE, |
---|
78 | "Open image file"); |
---|
79 | fcho->exec(); |
---|
80 | |
---|
81 | char filename[256] = ""; |
---|
82 | |
---|
83 | if (fcho->value()) |
---|
84 | { |
---|
85 | strcpy(filename,fcho->value()); |
---|
86 | |
---|
87 | geoMeshView->changeTexFile(isubmesh,filename); |
---|
88 | |
---|
89 | // Refresh mesh. |
---|
90 | geoMeshView->setMesh(mGeoMesh); |
---|
91 | } |
---|
92 | |
---|
93 | } |
---|
94 | |
---|
95 | void GeoMeshViewUI::cb_menuFileLoadTextureSubMesh(fltk::Item *o, void *v) |
---|
96 | { |
---|
97 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->parent()->user_data())) |
---|
98 | -> |
---|
99 | cb_menuFileLoadTextureSubMesh_i(o,v); |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | //------------------------------------------------------------------------- |
---|
105 | // Repaint the FPS label. |
---|
106 | //------------------------------------------------------------------------- |
---|
107 | void GeoMeshViewUI::refreshFPS(int fps) |
---|
108 | { |
---|
109 | static char char_value[10]; |
---|
110 | |
---|
111 | // Translate the FPS count to a char value. |
---|
112 | sprintf(char_value,"FPS %d",fps); |
---|
113 | |
---|
114 | mFPS->label(char_value); |
---|
115 | |
---|
116 | // Repaint the window. |
---|
117 | mMainWindow->redraw(); |
---|
118 | } |
---|
119 | |
---|
120 | void GeoMeshViewUI::cb_menuFileOpen(fltk::Item* o, void* v) |
---|
121 | { |
---|
122 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
123 | -> |
---|
124 | cb_menuFileOpen_i(o,v); |
---|
125 | } |
---|
126 | |
---|
127 | //------------------------------------------------------------------------- |
---|
128 | // Save callback |
---|
129 | //------------------------------------------------------------------------- |
---|
130 | inline void GeoMeshViewUI::cb_menuFileSave_i(fltk::Item*, void*) |
---|
131 | { |
---|
132 | GeoMeshSaver *mesh_saver; |
---|
133 | |
---|
134 | // If there is a mesh object created. |
---|
135 | if (mGeoMesh != NULL) |
---|
136 | { |
---|
137 | // Create a mesh saver with mesh bounds. |
---|
138 | mesh_saver = new GeoMeshSaver(); |
---|
139 | |
---|
140 | // Save the file mesh. |
---|
141 | mesh_saver->save(mGeoMesh, mFileName); |
---|
142 | |
---|
143 | // Free memory. |
---|
144 | delete mesh_saver; |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | void GeoMeshViewUI::cb_menuFileSave(fltk::Item* o, void* v) |
---|
149 | { |
---|
150 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
151 | -> |
---|
152 | cb_menuFileSave_i(o,v); |
---|
153 | } |
---|
154 | |
---|
155 | //------------------------------------------------------------------------- |
---|
156 | // Save As Callback |
---|
157 | //------------------------------------------------------------------------- |
---|
158 | inline void GeoMeshViewUI::cb_menuFileSaveAs_i(fltk::Item*, void*) |
---|
159 | { |
---|
160 | fltk::FileChooser *fcho; |
---|
161 | GeoMeshSaver *mesh_saver; |
---|
162 | char file_name[255]; |
---|
163 | char message[255]; |
---|
164 | char *ptr; |
---|
165 | int answer_yes; |
---|
166 | |
---|
167 | // Initialize answer to yes. |
---|
168 | answer_yes = 1; |
---|
169 | |
---|
170 | if (mGeoMesh != NULL) |
---|
171 | { |
---|
172 | fcho = new fltk::FileChooser("", |
---|
173 | "*.mesh", |
---|
174 | fltk::FileChooser::CREATE, |
---|
175 | "Save Mesh as"); |
---|
176 | |
---|
177 | fcho->exec(); |
---|
178 | |
---|
179 | if (fcho->value()) |
---|
180 | { |
---|
181 | // Gets file name. |
---|
182 | strcpy(file_name,fcho->value()); |
---|
183 | |
---|
184 | // Cut extension. |
---|
185 | ptr = strtok(file_name,"."); |
---|
186 | |
---|
187 | // If has extension. |
---|
188 | if (ptr) |
---|
189 | { |
---|
190 | strcpy(file_name,ptr); |
---|
191 | } |
---|
192 | |
---|
193 | // Adds mesh extension. |
---|
194 | strcat(file_name,".mesh"); |
---|
195 | |
---|
196 | // If File Exists. |
---|
197 | if (fileExists(file_name)) |
---|
198 | { |
---|
199 | // Compose message. |
---|
200 | strcpy(message,"Do you want to replace "); |
---|
201 | strcat(message,filename_name(file_name)); |
---|
202 | strcat(message,"?"); |
---|
203 | |
---|
204 | // Question. |
---|
205 | answer_yes = fltk::ask(message); |
---|
206 | } |
---|
207 | |
---|
208 | // If answer yes to replace question |
---|
209 | // or if file not exists. |
---|
210 | if (answer_yes) |
---|
211 | { |
---|
212 | mesh_saver = new GeoMeshSaver(); |
---|
213 | |
---|
214 | // Debug. |
---|
215 | mGeoMesh = mGeoMesh->toSharedVertex(); |
---|
216 | //------------------------------------- |
---|
217 | |
---|
218 | mesh_saver->save(mGeoMesh,file_name); |
---|
219 | |
---|
220 | delete mesh_saver; |
---|
221 | } |
---|
222 | } |
---|
223 | // Repaint the window. |
---|
224 | mMainWindow->redraw(); |
---|
225 | |
---|
226 | delete fcho; |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | void GeoMeshViewUI::cb_menuFileSaveAs(fltk::Item* o, void* v) |
---|
231 | { |
---|
232 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
233 | -> |
---|
234 | cb_menuFileSaveAs_i(o,v); |
---|
235 | } |
---|
236 | |
---|
237 | //------------------------------------------------------------------------- |
---|
238 | // Mesh info callback |
---|
239 | //------------------------------------------------------------------------- |
---|
240 | inline void GeoMeshViewUI::cb_menuMeshInfo_i(fltk::Item*, void*) |
---|
241 | { |
---|
242 | // Show title. |
---|
243 | mProcessTitle->label("Mesh Info"); |
---|
244 | |
---|
245 | showMeshInfo(); |
---|
246 | mMainWindow->redraw(); |
---|
247 | } |
---|
248 | |
---|
249 | void GeoMeshViewUI::cb_menuMeshInfo(fltk::Item* o, void* v) |
---|
250 | { |
---|
251 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
252 | -> |
---|
253 | cb_menuMeshInfo_i(o,v); |
---|
254 | } |
---|
255 | |
---|
256 | //------------------------------------------------------------------------- |
---|
257 | // Mesh Export to OBJ callback |
---|
258 | //------------------------------------------------------------------------- |
---|
259 | inline void GeoMeshViewUI::cb_menuMeshExportOBJ_i(fltk::Item*, void*) |
---|
260 | { |
---|
261 | char *p; |
---|
262 | |
---|
263 | // Sets menus application state to NONE. |
---|
264 | mApplicationState = NONE; |
---|
265 | |
---|
266 | // Open file chooser dialog. |
---|
267 | p = fltk::file_chooser("Export to OBJ","*.obj",""); |
---|
268 | if (p && mGeoMesh) |
---|
269 | { |
---|
270 | mGeoMesh->exportToOBJ(p); |
---|
271 | } |
---|
272 | } |
---|
273 | |
---|
274 | void GeoMeshViewUI::cb_menuMeshExportOBJ(fltk::Item* o, void* v) |
---|
275 | { |
---|
276 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
277 | -> |
---|
278 | cb_menuMeshExportOBJ_i(o,v); |
---|
279 | } |
---|
280 | |
---|
281 | //------------------------------------------------------------------------- |
---|
282 | // Transform to Shared Vertex callback |
---|
283 | //------------------------------------------------------------------------- |
---|
284 | inline void GeoMeshViewUI::cb_menuTransformSharedVertex_i(fltk::Item*, void*) |
---|
285 | { |
---|
286 | Mesh *mesh_aux; |
---|
287 | |
---|
288 | // if the undo mesh is not initialized. |
---|
289 | if (mGeoMesh != NULL) |
---|
290 | { |
---|
291 | // Deletes the actual mesh. |
---|
292 | delete mUndoMesh; |
---|
293 | |
---|
294 | mUndoMesh = new Mesh(); |
---|
295 | |
---|
296 | // Restore the previous mesh. |
---|
297 | *mUndoMesh = *mGeoMesh; |
---|
298 | |
---|
299 | // Transform NoSV Mesh to a SV Mesh. |
---|
300 | mesh_aux = mGeoMesh->toSharedVertex(); |
---|
301 | |
---|
302 | // Deletes the mesh No Shared Vertex. |
---|
303 | delete mGeoMesh; |
---|
304 | |
---|
305 | // Gets the mesh Shared Vertex. |
---|
306 | mGeoMesh = mesh_aux; |
---|
307 | |
---|
308 | // Visualize the mesh stripified. |
---|
309 | geoMeshView->setMesh(mGeoMesh); |
---|
310 | |
---|
311 | // Refresh mesh information. |
---|
312 | showMeshInfo(); |
---|
313 | |
---|
314 | // Repaint the window. |
---|
315 | mMainWindow->redraw(); |
---|
316 | } |
---|
317 | } |
---|
318 | |
---|
319 | void GeoMeshViewUI::cb_menuFileTransformSharedVertex(fltk::Item* o, void* v) |
---|
320 | { |
---|
321 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
322 | -> |
---|
323 | cb_menuTransformSharedVertex_i(o,v); |
---|
324 | } |
---|
325 | |
---|
326 | //------------------------------------------------------------------------- |
---|
327 | // Quit Callback |
---|
328 | //------------------------------------------------------------------------- |
---|
329 | inline void GeoMeshViewUI::cb_menuFileQuit_i(fltk::Item*, void*) |
---|
330 | { |
---|
331 | delete this; |
---|
332 | } |
---|
333 | |
---|
334 | void GeoMeshViewUI::cb_menuFileQuit(fltk::Item* o, void* v) |
---|
335 | { |
---|
336 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
337 | -> |
---|
338 | cb_menuFileQuit_i(o,v); |
---|
339 | } |
---|
340 | |
---|
341 | //------------------------------------------------------------------------- |
---|
342 | // Undo Callback |
---|
343 | //------------------------------------------------------------------------- |
---|
344 | inline void GeoMeshViewUI::cb_menuEditUndo_i(fltk::Item*, void*) |
---|
345 | { |
---|
346 | // Undo the mesh changes. |
---|
347 | undo(); |
---|
348 | } |
---|
349 | |
---|
350 | void GeoMeshViewUI::cb_menuEditUndo(fltk::Item* o, void* v) |
---|
351 | { |
---|
352 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
353 | -> |
---|
354 | cb_menuEditUndo_i(o,v); |
---|
355 | } |
---|
356 | |
---|
357 | //------------------------------------------------------------------------- |
---|
358 | // Fit Callback |
---|
359 | //------------------------------------------------------------------------- |
---|
360 | inline void GeoMeshViewUI::cb_menuEditFit_i(fltk::Item*, void*) |
---|
361 | { |
---|
362 | geoMeshView->fit(); |
---|
363 | mMainWindow->redraw(); |
---|
364 | } |
---|
365 | |
---|
366 | void GeoMeshViewUI::cb_menuEditFit(fltk::Item* o, void* v) |
---|
367 | { |
---|
368 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
369 | -> |
---|
370 | cb_menuEditFit_i(o,v); |
---|
371 | } |
---|
372 | |
---|
373 | //------------------------------------------------------------------------- |
---|
374 | // Rotate Callback |
---|
375 | //------------------------------------------------------------------------- |
---|
376 | inline void GeoMeshViewUI::cb_menuEditRotate_i(fltk::Item *item, void*) |
---|
377 | { |
---|
378 | // If the item is activated. |
---|
379 | if (item->value()) |
---|
380 | { |
---|
381 | menuEditPan->clear_value(); |
---|
382 | geoMeshView->deactivePan(); |
---|
383 | |
---|
384 | geoMeshView->activeRotate(); |
---|
385 | } |
---|
386 | else |
---|
387 | { |
---|
388 | menuEditPan->set_value(); |
---|
389 | geoMeshView->activePan(); |
---|
390 | |
---|
391 | geoMeshView->deactiveRotate(); |
---|
392 | } |
---|
393 | |
---|
394 | // Repaint the main window. |
---|
395 | mMainWindow->redraw(); |
---|
396 | } |
---|
397 | |
---|
398 | void GeoMeshViewUI::cb_menuEditRotate(fltk::Item* o, void* v) |
---|
399 | { |
---|
400 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
401 | -> |
---|
402 | cb_menuEditRotate_i(o,v); |
---|
403 | } |
---|
404 | |
---|
405 | //------------------------------------------------------------------------- |
---|
406 | // Pan Callback |
---|
407 | //------------------------------------------------------------------------- |
---|
408 | inline void GeoMeshViewUI::cb_menuEditPan_i(fltk::Item *item, void*) |
---|
409 | { |
---|
410 | // If the item is activated. |
---|
411 | if (item->value()) |
---|
412 | { |
---|
413 | geoMeshView->activePan(); |
---|
414 | |
---|
415 | menuEditRotate->clear_value(); |
---|
416 | geoMeshView->deactiveRotate(); |
---|
417 | } |
---|
418 | else |
---|
419 | { |
---|
420 | geoMeshView->deactivePan(); |
---|
421 | |
---|
422 | menuEditRotate->set_value(); |
---|
423 | geoMeshView->activeRotate(); |
---|
424 | } |
---|
425 | |
---|
426 | // Repaint the main window. |
---|
427 | mMainWindow->redraw(); |
---|
428 | } |
---|
429 | |
---|
430 | void GeoMeshViewUI::cb_menuEditPan(fltk::Item* o, void* v) |
---|
431 | { |
---|
432 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
433 | -> |
---|
434 | cb_menuEditPan_i(o,v); |
---|
435 | } |
---|
436 | |
---|
437 | //------------------------------------------------------------------------- |
---|
438 | // Zoom Callback |
---|
439 | //------------------------------------------------------------------------- |
---|
440 | inline void GeoMeshViewUI::cb_menuEditZoom_i(fltk::Item*, void*) |
---|
441 | { |
---|
442 | } |
---|
443 | |
---|
444 | void GeoMeshViewUI::cb_menuEditZoom(fltk::Item* o, void* v) |
---|
445 | { |
---|
446 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
447 | -> |
---|
448 | cb_menuEditZoom_i(o,v); |
---|
449 | } |
---|
450 | |
---|
451 | //------------------------------------------------------------------------- |
---|
452 | // Wire Callback |
---|
453 | //------------------------------------------------------------------------- |
---|
454 | inline void GeoMeshViewUI::cb_menuRenderWire_i(fltk::Item *item, void*) |
---|
455 | { |
---|
456 | if (item->value()) |
---|
457 | { |
---|
458 | geoMeshView->activeWire(); |
---|
459 | } |
---|
460 | else |
---|
461 | { |
---|
462 | geoMeshView->deactiveWire(); |
---|
463 | } |
---|
464 | |
---|
465 | // Repaint the canvas. |
---|
466 | //geoMeshView->redraw(); |
---|
467 | |
---|
468 | // Repaint the main window. |
---|
469 | mMainWindow->redraw(); |
---|
470 | } |
---|
471 | |
---|
472 | void GeoMeshViewUI::cb_menuRenderWire(fltk::Item* o, void* v) |
---|
473 | { |
---|
474 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
475 | -> |
---|
476 | cb_menuRenderWire_i(o,v); |
---|
477 | } |
---|
478 | |
---|
479 | //------------------------------------------------------------------------- |
---|
480 | // Solid Callback |
---|
481 | //------------------------------------------------------------------------- |
---|
482 | inline void GeoMeshViewUI::cb_menuRenderSolid_i(fltk::Item *item, void*) |
---|
483 | { |
---|
484 | if (item->value()) |
---|
485 | { |
---|
486 | geoMeshView->activeSolid(); |
---|
487 | } |
---|
488 | else |
---|
489 | { |
---|
490 | geoMeshView->deactiveSolid(); |
---|
491 | } |
---|
492 | |
---|
493 | // Repaint the canvas. |
---|
494 | //geoMeshView->redraw(); |
---|
495 | |
---|
496 | // Repaint the main window. |
---|
497 | mMainWindow->redraw(); |
---|
498 | } |
---|
499 | |
---|
500 | void GeoMeshViewUI::cb_menuRenderSolid(fltk::Item* o, void* v) |
---|
501 | { |
---|
502 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
503 | -> |
---|
504 | cb_menuRenderSolid_i(o,v); |
---|
505 | } |
---|
506 | |
---|
507 | //------------------------------------------------------------------------- |
---|
508 | // Lighting Callback |
---|
509 | //------------------------------------------------------------------------- |
---|
510 | inline void GeoMeshViewUI::cb_menuRenderLighting_i(fltk::Item *item, void*) |
---|
511 | { |
---|
512 | if (item->value()) |
---|
513 | { |
---|
514 | geoMeshView->activeLighting(); |
---|
515 | } |
---|
516 | else |
---|
517 | { |
---|
518 | geoMeshView->deactiveLighting(); |
---|
519 | } |
---|
520 | |
---|
521 | // Repaint the main window. |
---|
522 | mMainWindow->redraw(); |
---|
523 | } |
---|
524 | |
---|
525 | void GeoMeshViewUI::cb_menuRenderLighting(fltk::Item* o, void* v) |
---|
526 | { |
---|
527 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
528 | -> |
---|
529 | cb_menuRenderLighting_i(o,v); |
---|
530 | } |
---|
531 | |
---|
532 | //------------------------------------------------------------------------- |
---|
533 | // CW callback |
---|
534 | //------------------------------------------------------------------------- |
---|
535 | inline void GeoMeshViewUI::cb_menuRenderCW_i(fltk::Item *item, void*) |
---|
536 | { |
---|
537 | // Clear the CCW state. |
---|
538 | menuRenderCCW->clear_value(); |
---|
539 | geoMeshView->deactiveCCW(); |
---|
540 | |
---|
541 | // If the item is activated. |
---|
542 | if (item->value()) |
---|
543 | { |
---|
544 | geoMeshView->activeCW(); |
---|
545 | } |
---|
546 | else |
---|
547 | { |
---|
548 | geoMeshView->deactiveCW(); |
---|
549 | } |
---|
550 | |
---|
551 | // Repaint the main window. |
---|
552 | mMainWindow->redraw(); |
---|
553 | } |
---|
554 | |
---|
555 | void GeoMeshViewUI::cb_menuRenderCW(fltk::Item* o, void* v) |
---|
556 | { |
---|
557 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
558 | -> |
---|
559 | cb_menuRenderCW_i(o,v); |
---|
560 | } |
---|
561 | |
---|
562 | //------------------------------------------------------------------------- |
---|
563 | // CCW callback |
---|
564 | //------------------------------------------------------------------------- |
---|
565 | inline void GeoMeshViewUI::cb_menuRenderCCW_i(fltk::Item *item, void*) |
---|
566 | { |
---|
567 | // Clear the CW state. |
---|
568 | menuRenderCW->clear_value(); |
---|
569 | geoMeshView->deactiveCW(); |
---|
570 | |
---|
571 | // If the item is activated. |
---|
572 | if (item->value()) |
---|
573 | { |
---|
574 | geoMeshView->activeCCW(); |
---|
575 | } |
---|
576 | else |
---|
577 | { |
---|
578 | geoMeshView->deactiveCCW(); |
---|
579 | } |
---|
580 | |
---|
581 | // Repaint the main window. |
---|
582 | mMainWindow->redraw(); |
---|
583 | } |
---|
584 | |
---|
585 | void GeoMeshViewUI::cb_menuRenderCCW(fltk::Item* o, void* v) |
---|
586 | { |
---|
587 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
588 | -> |
---|
589 | cb_menuRenderCCW_i(o,v); |
---|
590 | } |
---|
591 | |
---|
592 | //------------------------------------------------------------------------- |
---|
593 | // Flat callback |
---|
594 | //------------------------------------------------------------------------- |
---|
595 | inline void GeoMeshViewUI::cb_menuRenderFlat_i(fltk::Item*, void*) |
---|
596 | { |
---|
597 | // Deactive smooth flag. |
---|
598 | menuRenderSmooth->clear_value(); |
---|
599 | |
---|
600 | // Sets flat lighting. |
---|
601 | geoMeshView->flat(); |
---|
602 | |
---|
603 | // Repaint the main window. |
---|
604 | mMainWindow->redraw(); |
---|
605 | } |
---|
606 | |
---|
607 | void GeoMeshViewUI::cb_menuRenderFlat(fltk::Item* o, void* v) |
---|
608 | { |
---|
609 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
610 | -> |
---|
611 | cb_menuRenderFlat_i(o,v); |
---|
612 | } |
---|
613 | |
---|
614 | //------------------------------------------------------------------------- |
---|
615 | // Smooth Callback |
---|
616 | //------------------------------------------------------------------------- |
---|
617 | inline void GeoMeshViewUI::cb_menuRenderSmooth_i(fltk::Item*, void*) |
---|
618 | { |
---|
619 | // Deactive flat flag. |
---|
620 | menuRenderFlat->clear_value(); |
---|
621 | |
---|
622 | // Sets smooth lighting. |
---|
623 | geoMeshView->smooth(); |
---|
624 | |
---|
625 | // Repaint the main window. |
---|
626 | mMainWindow->redraw(); |
---|
627 | } |
---|
628 | |
---|
629 | void GeoMeshViewUI::cb_menuRenderSmooth(fltk::Item* o, void* v) |
---|
630 | { |
---|
631 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
632 | -> |
---|
633 | cb_menuRenderSmooth_i(o,v); |
---|
634 | } |
---|
635 | |
---|
636 | //------------------------------------------------------------------------- |
---|
637 | // Textures callback |
---|
638 | //------------------------------------------------------------------------- |
---|
639 | inline void GeoMeshViewUI::cb_menuRenderTextures_i(fltk::Item*, void*) |
---|
640 | { |
---|
641 | // Repaint the main window. |
---|
642 | mMainWindow->redraw(); |
---|
643 | if (geoMeshView->isTextureMappingEnabled()) |
---|
644 | geoMeshView->disableTextureMapping(); |
---|
645 | else |
---|
646 | geoMeshView->enableTextureMapping(); |
---|
647 | } |
---|
648 | |
---|
649 | void GeoMeshViewUI::cb_menuRenderTextures(fltk::Item* o, void* v) |
---|
650 | { |
---|
651 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
652 | -> |
---|
653 | cb_menuRenderTextures_i(o,v); |
---|
654 | } |
---|
655 | |
---|
656 | //------------------------------------------------------------------------- |
---|
657 | // Stripify Callback |
---|
658 | //------------------------------------------------------------------------- |
---|
659 | inline void GeoMeshViewUI::cb_menuStripify_i(fltk::Item*, void*) |
---|
660 | { |
---|
661 | // Show title. |
---|
662 | mProcessTitle->label("Stripify"); |
---|
663 | mProcessBar->position(0); |
---|
664 | |
---|
665 | // Hide the right panel. |
---|
666 | hideRightPanel(); |
---|
667 | |
---|
668 | // Show the stripify panel. |
---|
669 | showStripify(); |
---|
670 | |
---|
671 | // Sets menus application state to STRIPIFY. |
---|
672 | mApplicationState = STRIPIFY; |
---|
673 | |
---|
674 | // Repaint the window. |
---|
675 | mMainWindow->redraw(); |
---|
676 | } |
---|
677 | |
---|
678 | void GeoMeshViewUI::cb_menuStripify(fltk::Item* o, void* v) |
---|
679 | { |
---|
680 | ((GeoMeshViewUI*) (o->parent()->parent()->user_data())) |
---|
681 | -> |
---|
682 | cb_menuStripify_i(o,v); |
---|
683 | } |
---|
684 | |
---|
685 | //------------------------------------------------------------------------- |
---|
686 | // Simplify Callback |
---|
687 | //------------------------------------------------------------------------- |
---|
688 | inline void GeoMeshViewUI::cb_menuSimplify_i(fltk::ItemGroup*, void*) |
---|
689 | { |
---|
690 | } |
---|
691 | |
---|
692 | void GeoMeshViewUI::cb_menuSimplify(fltk::ItemGroup* o, void* v) |
---|
693 | { |
---|
694 | ((GeoMeshViewUI*) (o->parent()->parent()->user_data())) |
---|
695 | -> |
---|
696 | cb_menuSimplify_i(o,v); |
---|
697 | } |
---|
698 | |
---|
699 | //------------------------------------------------------------------------- |
---|
700 | // Edge collapse Callback |
---|
701 | //------------------------------------------------------------------------- |
---|
702 | inline void GeoMeshViewUI::cb_menuSimplifyEdgeCollapse_i(fltk::Item*, void*) |
---|
703 | { |
---|
704 | // Show title. |
---|
705 | mProcessTitle->label("Mesh Simplification"); |
---|
706 | mProcessBar->position(0); |
---|
707 | |
---|
708 | // Hide the right panel. |
---|
709 | hideRightPanel(); |
---|
710 | |
---|
711 | // Show the edge collapse panel. |
---|
712 | showEdgeCollapse(); |
---|
713 | |
---|
714 | // Sets menus application state to EDGE_COLLAPSE. |
---|
715 | mApplicationState = EDGE_COLLAPSE; |
---|
716 | |
---|
717 | // Repaint the window. |
---|
718 | mMainWindow->redraw(); |
---|
719 | |
---|
720 | } |
---|
721 | |
---|
722 | void GeoMeshViewUI::cb_menuSimplifyEdgeCollapse(fltk::Item* o, void* v) |
---|
723 | { |
---|
724 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
725 | -> |
---|
726 | cb_menuSimplifyEdgeCollapse_i(o,v); |
---|
727 | } |
---|
728 | |
---|
729 | //------------------------------------------------------------------------- |
---|
730 | // Leaves collapse Callback |
---|
731 | //------------------------------------------------------------------------- |
---|
732 | inline void GeoMeshViewUI::cb_menuSimplifyLeavesCollapse_i(fltk::Item*, void*) |
---|
733 | { |
---|
734 | // Show title. |
---|
735 | mProcessTitle->label("Leaves Simplification"); |
---|
736 | mProcessBar->position(0); |
---|
737 | |
---|
738 | // Hide the right panel. |
---|
739 | hideRightPanel(); |
---|
740 | |
---|
741 | // Show the leaves collapse panel. |
---|
742 | showLeavesCollapse(); |
---|
743 | |
---|
744 | // Sets menus application state to LEAVES_COLLAPSE. |
---|
745 | mApplicationState = LEAVES_COLLAPSE; |
---|
746 | |
---|
747 | // Repaint the window. |
---|
748 | mMainWindow->redraw(); |
---|
749 | } |
---|
750 | |
---|
751 | void GeoMeshViewUI::cb_menuSimplifyLeavesCollapse(fltk::Item* o, void* v) |
---|
752 | { |
---|
753 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
754 | -> |
---|
755 | cb_menuSimplifyLeavesCollapse_i(o,v); |
---|
756 | } |
---|
757 | |
---|
758 | //------------------------------------------------------------------------- |
---|
759 | // Tree select leaves simplification Callback |
---|
760 | //------------------------------------------------------------------------- |
---|
761 | inline void GeoMeshViewUI::cb_menuSelectLeaves_i(fltk::Item*, void*) |
---|
762 | { |
---|
763 | // Show title. |
---|
764 | mProcessTitle->label("Select Leaves"); |
---|
765 | |
---|
766 | showMeshInfo(); |
---|
767 | mButtonProcess->show(); |
---|
768 | mButtonProcess->activate(); |
---|
769 | mApplicationState = SELECT_LEAVES; |
---|
770 | } |
---|
771 | |
---|
772 | void GeoMeshViewUI::cb_menuSelectLeaves(fltk::Item* o, void* v) |
---|
773 | { |
---|
774 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
775 | -> |
---|
776 | cb_menuSelectLeaves_i(o,v); |
---|
777 | } |
---|
778 | |
---|
779 | //------------------------------------------------------------------------- |
---|
780 | // Auto Generate LodStrips Callback |
---|
781 | //------------------------------------------------------------------------- |
---|
782 | inline void GeoMeshViewUI::cb_menuLodStripsGenerate_i(fltk::Item*, void*) |
---|
783 | { |
---|
784 | // Show title. |
---|
785 | mProcessTitle->label("Generate LodStrips"); |
---|
786 | mProcessBar->position(0); |
---|
787 | mBuildBar->position(0); |
---|
788 | |
---|
789 | // Hide the right panel. |
---|
790 | hideRightPanel(); |
---|
791 | |
---|
792 | // Show the LodStrips panel. |
---|
793 | showAutoGenerateLodStrips(); |
---|
794 | |
---|
795 | // Sets menus application state to LODSTRIPS_AUTO. |
---|
796 | mApplicationState = LODSTRIPS_AUTO; |
---|
797 | |
---|
798 | // Repaint the window. |
---|
799 | mMainWindow->redraw(); |
---|
800 | } |
---|
801 | |
---|
802 | void GeoMeshViewUI::cb_menuLodStripsGenerate(fltk::Item* o, void* v) |
---|
803 | { |
---|
804 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
805 | -> |
---|
806 | cb_menuLodStripsGenerate_i(o,v); |
---|
807 | } |
---|
808 | |
---|
809 | //------------------------------------------------------------------------- |
---|
810 | // Auto Generate LodStrips Callback |
---|
811 | //------------------------------------------------------------------------- |
---|
812 | inline void GeoMeshViewUI::cb_menuLodTreesGenerate_i(fltk::Item*, void*) |
---|
813 | { |
---|
814 | // Show title. |
---|
815 | mProcessTitle->label("Generate LodTree"); |
---|
816 | mProcessBar->position(0); |
---|
817 | mBuildBar->position(0); |
---|
818 | |
---|
819 | // Hide the right panel. |
---|
820 | hideRightPanel(); |
---|
821 | |
---|
822 | // Show the LodStrips panel. |
---|
823 | showAutoGenerateLodTrees(); |
---|
824 | |
---|
825 | // Sets menus application state to LODSTRIPS_AUTO. |
---|
826 | mApplicationState = LODTREES_AUTO; |
---|
827 | |
---|
828 | // Repaint the window. |
---|
829 | mMainWindow->redraw(); |
---|
830 | } |
---|
831 | |
---|
832 | void GeoMeshViewUI::cb_menuLodTreesGenerate(fltk::Item* o, void* v) |
---|
833 | { |
---|
834 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
835 | -> |
---|
836 | cb_menuLodTreesGenerate_i(o,v); |
---|
837 | } |
---|
838 | |
---|
839 | |
---|
840 | //------------------------------------------------------------------------- |
---|
841 | // Visualize LodStrips Callback |
---|
842 | //------------------------------------------------------------------------- |
---|
843 | inline void GeoMeshViewUI::cb_menuLodStripsVisualize_i(fltk::Item*, void*) |
---|
844 | { |
---|
845 | // Sets menus application state to NONE. |
---|
846 | mApplicationState = NONE; |
---|
847 | |
---|
848 | // Deactive Lod strip visualization. |
---|
849 | geoMeshView->deactiveLodStrip(); |
---|
850 | geoMeshView->deactiveLodTree(); |
---|
851 | |
---|
852 | // Loads a mesh file. |
---|
853 | openMeshFile(); |
---|
854 | |
---|
855 | // If an object is loaded. |
---|
856 | if (mGeoMesh != NULL) |
---|
857 | { |
---|
858 | if (geoMeshLoader->GetLodStripsData()) |
---|
859 | { |
---|
860 | // Build lod strips library. |
---|
861 | setLodStripsLibrary(geoMeshLoader->GetLodStripsData(), mGeoMesh); |
---|
862 | |
---|
863 | // Sets the aplication mode. |
---|
864 | mApplicationState = VISUALIZE_LODSTRIPS; |
---|
865 | |
---|
866 | // Hide the right panel. |
---|
867 | hideRightPanel(); |
---|
868 | |
---|
869 | // Show title. |
---|
870 | mProcessTitle->label("Visualize LodStrips"); |
---|
871 | |
---|
872 | // Show the Visulize LodStrips panel. |
---|
873 | showLodStripSlider(); |
---|
874 | |
---|
875 | // Repaint the window. |
---|
876 | mMainWindow->redraw(); |
---|
877 | } |
---|
878 | else |
---|
879 | { |
---|
880 | fltk::alert("The loaded mesh does not contain LOD information.\nNothing will be done."); |
---|
881 | } |
---|
882 | } |
---|
883 | } |
---|
884 | |
---|
885 | inline void GeoMeshViewUI::cb_menuLodTreesVisualize_i(fltk::Item*, void*) |
---|
886 | { |
---|
887 | // Sets menus application state to NONE. |
---|
888 | mApplicationState = NONE; |
---|
889 | |
---|
890 | // Deactive Lod strip visualization. |
---|
891 | geoMeshView->deactiveLodTree(); |
---|
892 | geoMeshView->deactiveLodStrip(); |
---|
893 | |
---|
894 | // Loads a mesh file. |
---|
895 | openMeshFile(); |
---|
896 | |
---|
897 | // If an object is loaded. |
---|
898 | if (mGeoMesh != NULL) |
---|
899 | { |
---|
900 | if (geoMeshLoader->GetTreeSimpSeq() && geoMeshLoader->GetLodStripsData()) |
---|
901 | { |
---|
902 | setLodTreesLibrary( geoMeshLoader->GetLodStripsData(), |
---|
903 | geoMeshLoader->GetTreeSimpSeq(), |
---|
904 | mGeoMesh); |
---|
905 | |
---|
906 | // Sets the aplication mode. |
---|
907 | mApplicationState = VISUALIZE_LODTREES; |
---|
908 | |
---|
909 | // Hide the right panel. |
---|
910 | hideRightPanel(); |
---|
911 | |
---|
912 | // Show title. |
---|
913 | mProcessTitle->label("Visualize LodTrees"); |
---|
914 | |
---|
915 | // Show the Visulize LodTree panel. |
---|
916 | showLodStripSlider(); |
---|
917 | showLodTreeSlider(); |
---|
918 | |
---|
919 | // Repaint the window. |
---|
920 | mMainWindow->redraw(); |
---|
921 | } |
---|
922 | else |
---|
923 | fltk::alert("The loaded mesh does not contain LOD information.\nNothing will be done."); |
---|
924 | } |
---|
925 | } |
---|
926 | |
---|
927 | void GeoMeshViewUI::cb_menuLodTreesVisualize(fltk::Item *o, void *v) |
---|
928 | { |
---|
929 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
930 | -> |
---|
931 | cb_menuLodTreesVisualize_i(o,v); |
---|
932 | } |
---|
933 | |
---|
934 | void GeoMeshViewUI::cb_menuLodStripsVisualize(fltk::Item* o, void* v) |
---|
935 | { |
---|
936 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
937 | -> |
---|
938 | cb_menuLodStripsVisualize_i(o,v); |
---|
939 | } |
---|
940 | |
---|
941 | //------------------------------------------------------------------------- |
---|
942 | // Open LodStrip trunk Callback |
---|
943 | //------------------------------------------------------------------------- |
---|
944 | inline void GeoMeshViewUI::cb_menuLodTreesOpenLodStripTrunk_i(fltk::Item*, void*) |
---|
945 | { |
---|
946 | } |
---|
947 | |
---|
948 | void GeoMeshViewUI::cb_menuLodTreesOpenLodStripTrunk(fltk::Item* o, void* v) |
---|
949 | { |
---|
950 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
951 | -> |
---|
952 | cb_menuLodTreesOpenLodStripTrunk_i(o,v); |
---|
953 | } |
---|
954 | |
---|
955 | //------------------------------------------------------------------------- |
---|
956 | // Open leaves simplification Callback |
---|
957 | //------------------------------------------------------------------------- |
---|
958 | inline void GeoMeshViewUI::cb_menuLodTreesOpenLeavesSimplification_i(fltk::Item*, void*) |
---|
959 | { |
---|
960 | // Hide the right panel. |
---|
961 | hideRightPanel(); |
---|
962 | |
---|
963 | // Show the LodTrees panel. |
---|
964 | showOpenLeavesSimplification(); |
---|
965 | |
---|
966 | // Sets menus application state to LODTREES. |
---|
967 | mApplicationState = LODTREES; |
---|
968 | |
---|
969 | // Repaint the window. |
---|
970 | mMainWindow->redraw(); |
---|
971 | } |
---|
972 | |
---|
973 | void GeoMeshViewUI::cb_menuLodTreesOpenLeavesSimplification(fltk::Item* o, void* v) |
---|
974 | { |
---|
975 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
976 | -> |
---|
977 | cb_menuLodTreesOpenLeavesSimplification_i(o,v); |
---|
978 | } |
---|
979 | |
---|
980 | |
---|
981 | |
---|
982 | //------------------------------------------------------------------------- |
---|
983 | // About Callback |
---|
984 | //------------------------------------------------------------------------- |
---|
985 | inline void GeoMeshViewUI::cb_menuHelpAbout_i(fltk::Item*, void*) |
---|
986 | { |
---|
987 | new GTAboutDialog(); |
---|
988 | } |
---|
989 | |
---|
990 | void GeoMeshViewUI::cb_menuHelpAbout(fltk::Item* o, void* v) |
---|
991 | { |
---|
992 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
993 | -> |
---|
994 | cb_menuHelpAbout_i(o,v); |
---|
995 | } |
---|
996 | |
---|
997 | VertexBuffer *origSubMeshVB = NULL; |
---|
998 | int orig_numindices = 0; |
---|
999 | Index *orig_indices = NULL; |
---|
1000 | |
---|
1001 | //------------------------------------------------------------------------- |
---|
1002 | // Button Process Callback |
---|
1003 | //------------------------------------------------------------------------- |
---|
1004 | inline void GeoMeshViewUI::cb_mButtonProcess_i(fltk::Button*, void*) |
---|
1005 | { |
---|
1006 | bool error; |
---|
1007 | Mesh *mesh_aux; |
---|
1008 | |
---|
1009 | // Sets the progress bar to process bar. |
---|
1010 | progressBarType = PROCESS; |
---|
1011 | mProcessBar->position(0); |
---|
1012 | |
---|
1013 | origSubMeshVB = NULL; |
---|
1014 | |
---|
1015 | // Initialize error flag. |
---|
1016 | error = false; |
---|
1017 | |
---|
1018 | // If there is a mesh object. |
---|
1019 | if (mGeoMesh != NULL) |
---|
1020 | { |
---|
1021 | // Choose between aplication state. |
---|
1022 | switch (mApplicationState) |
---|
1023 | { |
---|
1024 | // Stripify state. |
---|
1025 | case STRIPIFY: |
---|
1026 | |
---|
1027 | // Stripify the mesh object. |
---|
1028 | stripify(); |
---|
1029 | |
---|
1030 | break; |
---|
1031 | |
---|
1032 | // Simplify edge collapse state. |
---|
1033 | case EDGE_COLLAPSE: |
---|
1034 | |
---|
1035 | // Check submeshes for triangles strips. |
---|
1036 | for (int i = 0; i < mGeoMesh->mSubMeshCount; i++) |
---|
1037 | { |
---|
1038 | // If current submesh is in triangle strips. |
---|
1039 | if (mGeoMesh->mSubMesh[i].mType == GEO_TRIANGLE_STRIPS) |
---|
1040 | { |
---|
1041 | error = true; |
---|
1042 | } |
---|
1043 | } |
---|
1044 | |
---|
1045 | // if the mesh is stripified. |
---|
1046 | if (error) |
---|
1047 | { |
---|
1048 | fltk::alert("Can't simplify a mesh in triagle strips."); |
---|
1049 | } |
---|
1050 | else |
---|
1051 | { |
---|
1052 | // Transform NoSV Mesh to a SV Mesh. |
---|
1053 | mesh_aux = mGeoMesh->toSharedVertex(); |
---|
1054 | |
---|
1055 | // Deletes the mesh No Shared Vertex. |
---|
1056 | delete mGeoMesh; |
---|
1057 | |
---|
1058 | // Gets the mesh Shared Vertex. |
---|
1059 | mGeoMesh = mesh_aux; |
---|
1060 | |
---|
1061 | // Simplify the mesh object. |
---|
1062 | if(simplifyEdgeCollapse()) |
---|
1063 | { |
---|
1064 | geoMeshView->restoreContext(); |
---|
1065 | } |
---|
1066 | |
---|
1067 | // Visualize mesh. |
---|
1068 | geoMeshView->setMesh(mGeoMesh); |
---|
1069 | |
---|
1070 | } |
---|
1071 | break; |
---|
1072 | |
---|
1073 | // Simplify leaves |
---|
1074 | case LEAVES_COLLAPSE: |
---|
1075 | |
---|
1076 | // Simplify the mesh object. |
---|
1077 | simplifyLeavesCollapse(); |
---|
1078 | |
---|
1079 | // Create the leaves simplification sequence. |
---|
1080 | createLeavesSequence("leavesSimplification.txt"); |
---|
1081 | |
---|
1082 | break; |
---|
1083 | |
---|
1084 | // Simplify and generate simplification sequence. |
---|
1085 | case LODTREES_AUTO: |
---|
1086 | |
---|
1087 | if (idMeshLeaves == (unsigned short)-1) |
---|
1088 | { |
---|
1089 | fltk::alert("Leaves submesh not selected!"); |
---|
1090 | } |
---|
1091 | else |
---|
1092 | { |
---|
1093 | origSubMeshVB = mGeoMesh-> |
---|
1094 | mSubMesh[idMeshLeaves].mVertexBuffer->Clone(); |
---|
1095 | |
---|
1096 | orig_numindices = mGeoMesh->mSubMesh[idMeshLeaves].mIndexCount; |
---|
1097 | orig_indices = new Index[orig_numindices]; |
---|
1098 | |
---|
1099 | for (int i = 0; i < orig_numindices; i++) |
---|
1100 | { |
---|
1101 | orig_indices[i]=mGeoMesh->mSubMesh[idMeshLeaves].mIndex[i]; |
---|
1102 | } |
---|
1103 | |
---|
1104 | std::cout << "Simplificando hojas..."; |
---|
1105 | simplifyLeavesCollapse(); |
---|
1106 | std::cout << "OK!" << std::endl; |
---|
1107 | |
---|
1108 | // std::cout << "Creando secuencia de simplificacion de hojas..."; |
---|
1109 | // createLeavesSequence("leavesSimplification.txt"); |
---|
1110 | // std::cout << "OK!" << std::endl; |
---|
1111 | |
---|
1112 | undo(); |
---|
1113 | |
---|
1114 | |
---|
1115 | std::cout << "Simplificando tronco..."; |
---|
1116 | std::cout << "OK!" << std::endl; |
---|
1117 | |
---|
1118 | // Transform NoSV Mesh to a SV Mesh. |
---|
1119 | mesh_aux = mGeoMesh->toSharedVertex(); |
---|
1120 | |
---|
1121 | // Deletes the mesh No Shared Vertex. |
---|
1122 | delete mGeoMesh; |
---|
1123 | |
---|
1124 | // Gets the mesh Shared Vertex. |
---|
1125 | mGeoMesh = mesh_aux; |
---|
1126 | |
---|
1127 | // Simplify the mesh object. |
---|
1128 | if (simplifyEdgeCollapse()) |
---|
1129 | { |
---|
1130 | // Create the simplification sequence. |
---|
1131 | //createSimplificationSequence(); |
---|
1132 | |
---|
1133 | // Show build process. |
---|
1134 | activeBuildProcess(); |
---|
1135 | } |
---|
1136 | |
---|
1137 | geoMeshView->setMesh(mGeoMesh); |
---|
1138 | } |
---|
1139 | |
---|
1140 | break; |
---|
1141 | |
---|
1142 | case LODSTRIPS_AUTO: |
---|
1143 | |
---|
1144 | // Check submeshes for triangles strips. |
---|
1145 | for (int i = 0; i < mGeoMesh->mSubMeshCount; i++) |
---|
1146 | { |
---|
1147 | // If current submesh is in triangle strips. |
---|
1148 | if (mGeoMesh->mSubMesh[i].mType == GEO_TRIANGLE_STRIPS) |
---|
1149 | { |
---|
1150 | error = true; |
---|
1151 | } |
---|
1152 | } |
---|
1153 | |
---|
1154 | // if the mesh is stripified. |
---|
1155 | if (error) |
---|
1156 | { |
---|
1157 | fltk::alert("Can't simplify a mesh in triagle strips."); |
---|
1158 | } |
---|
1159 | else |
---|
1160 | { |
---|
1161 | // Transform NoSV Mesh to a SV Mesh. |
---|
1162 | mesh_aux = mGeoMesh->toSharedVertex(); |
---|
1163 | |
---|
1164 | // Deletes the mesh No Shared Vertex. |
---|
1165 | delete mGeoMesh; |
---|
1166 | |
---|
1167 | // Gets the mesh Shared Vertex. |
---|
1168 | mGeoMesh = mesh_aux; |
---|
1169 | |
---|
1170 | // Simplify the mesh object. |
---|
1171 | if (simplifyEdgeCollapse()) |
---|
1172 | { |
---|
1173 | //delete mMeshSimplifier; |
---|
1174 | geoMeshView->restoreContext(); |
---|
1175 | |
---|
1176 | // Show build process. |
---|
1177 | activeBuildProcess(); |
---|
1178 | } |
---|
1179 | |
---|
1180 | // Visualize mesh. |
---|
1181 | geoMeshView->setMesh(mGeoMesh); |
---|
1182 | } |
---|
1183 | |
---|
1184 | break; |
---|
1185 | |
---|
1186 | // Añadido 23-12-2005 |
---|
1187 | case SELECT_LEAVES: |
---|
1188 | |
---|
1189 | idMeshLeaves = paintMesh(); |
---|
1190 | |
---|
1191 | // Set the leaves submesh. |
---|
1192 | geoMeshView->setLeavesSubMesh(idMeshLeaves); |
---|
1193 | |
---|
1194 | // Refresh mesh info. |
---|
1195 | showMeshInfo(); |
---|
1196 | |
---|
1197 | break; |
---|
1198 | } |
---|
1199 | |
---|
1200 | // Refresh geometry attributes. |
---|
1201 | refreshApplicationBar(); |
---|
1202 | } |
---|
1203 | |
---|
1204 | // Repaint the GL Window. |
---|
1205 | mMainWindow->redraw(); |
---|
1206 | } |
---|
1207 | |
---|
1208 | void GeoMeshViewUI::cb_mButtonProcess(fltk::Button* o, void* v) |
---|
1209 | { |
---|
1210 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
1211 | -> |
---|
1212 | cb_mButtonProcess_i(o,v); |
---|
1213 | } |
---|
1214 | |
---|
1215 | //--------------------------------------------------------------------------- |
---|
1216 | // Button Sort Callback |
---|
1217 | //--------------------------------------------------------------------------- |
---|
1218 | inline void GeoMeshViewUI::cb_mButtonSort_i(fltk::Button*, void*) |
---|
1219 | { |
---|
1220 | } |
---|
1221 | |
---|
1222 | void GeoMeshViewUI::cb_mButtonSort(fltk::Button* o, void* v) |
---|
1223 | { |
---|
1224 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
1225 | -> |
---|
1226 | cb_mButtonSort_i(o,v); |
---|
1227 | } |
---|
1228 | |
---|
1229 | //--------------------------------------------------------------------------- |
---|
1230 | // Button Build Callback |
---|
1231 | //--------------------------------------------------------------------------- |
---|
1232 | inline void GeoMeshViewUI::cb_mButtonBuild_i(fltk::Button*, void*) |
---|
1233 | { |
---|
1234 | char *file_name = NULL; |
---|
1235 | GeoMeshSaver *mesh_saver; |
---|
1236 | Serializer *oSerializer; |
---|
1237 | |
---|
1238 | // Sets the progress bar to process bar. |
---|
1239 | progressBarType = BUILD; |
---|
1240 | |
---|
1241 | // Reset the build bar. |
---|
1242 | mBuildBar->position(0); |
---|
1243 | |
---|
1244 | // If there is a mesh object. |
---|
1245 | if (mGeoMesh != NULL) |
---|
1246 | { |
---|
1247 | // Choose between aplication state. |
---|
1248 | if (mApplicationState == LODSTRIPS_AUTO |
---|
1249 | || |
---|
1250 | mApplicationState == LODTREES_AUTO) |
---|
1251 | { |
---|
1252 | file_name = fltk::file_chooser("Build LOD","*.mesh",""); |
---|
1253 | |
---|
1254 | // If a file was selected. |
---|
1255 | if (file_name) |
---|
1256 | { |
---|
1257 | // Undo the simplification changes. |
---|
1258 | undo(); |
---|
1259 | |
---|
1260 | // Stripify the mesh object. |
---|
1261 | stripify(); |
---|
1262 | |
---|
1263 | // Reset the build bar. |
---|
1264 | mBuildBar->position(0); |
---|
1265 | |
---|
1266 | // Simplification sequence. |
---|
1267 | oMeshSimpSequence = mMeshSimplifier->GetSimplificationSequence(); |
---|
1268 | |
---|
1269 | // If the simplification sequence and the mesh exist. |
---|
1270 | if (oMeshSimpSequence && mGeoMesh) |
---|
1271 | { |
---|
1272 | oLodStrip = new LodStripsConstructor( mGeoMesh, |
---|
1273 | oMeshSimpSequence, |
---|
1274 | idMeshLeaves, |
---|
1275 | progress_function); |
---|
1276 | |
---|
1277 | oLodStrip->UpdateMesh(); |
---|
1278 | |
---|
1279 | // Deletes the previous mesh. |
---|
1280 | delete mUndoMesh; |
---|
1281 | |
---|
1282 | |
---|
1283 | mUndoMesh = new Mesh(); |
---|
1284 | |
---|
1285 | // Sets the undo mesh. |
---|
1286 | *mUndoMesh = *mGeoMesh; |
---|
1287 | |
---|
1288 | delete mGeoMesh; |
---|
1289 | |
---|
1290 | mGeoMesh = oLodStrip->GetMesh(); |
---|
1291 | |
---|
1292 | geoMeshView->setMesh(mGeoMesh); |
---|
1293 | |
---|
1294 | mesh_saver = new GeoMeshSaver(); |
---|
1295 | |
---|
1296 | mesh_saver->leavesSubMesh = idMeshLeaves; |
---|
1297 | mesh_saver->leavesVB = origSubMeshVB; |
---|
1298 | mesh_saver->numindices = orig_numindices; |
---|
1299 | mesh_saver->indices = orig_indices; |
---|
1300 | |
---|
1301 | mesh_saver->save(mGeoMesh,file_name); |
---|
1302 | |
---|
1303 | delete mesh_saver; |
---|
1304 | |
---|
1305 | oLodStrip->Save(file_name); |
---|
1306 | |
---|
1307 | // Delete simplified mesh. |
---|
1308 | delete mMeshSimplifier; |
---|
1309 | } |
---|
1310 | else |
---|
1311 | { |
---|
1312 | // Error message. |
---|
1313 | fltk::alert("There is no simplification sequence."); |
---|
1314 | } |
---|
1315 | |
---|
1316 | if (mApplicationState == LODTREES_AUTO) |
---|
1317 | { |
---|
1318 | createLeavesSequence(file_name); |
---|
1319 | } |
---|
1320 | } |
---|
1321 | } |
---|
1322 | |
---|
1323 | // Refresh data aplication. |
---|
1324 | refreshApplicationBar(); |
---|
1325 | } |
---|
1326 | } |
---|
1327 | |
---|
1328 | void GeoMeshViewUI::cb_mButtonBuild(fltk::Button *o, void *v) |
---|
1329 | { |
---|
1330 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
1331 | -> |
---|
1332 | cb_mButtonBuild_i(o,v); |
---|
1333 | } |
---|
1334 | |
---|
1335 | //--------------------------------------------------------------------------- |
---|
1336 | // Lod Slider Callback |
---|
1337 | //--------------------------------------------------------------------------- |
---|
1338 | inline void GeoMeshViewUI::cb_mLodStripSlider_i(fltk::Slider *o, void *) |
---|
1339 | { |
---|
1340 | // Change the lod. |
---|
1341 | geoMeshView->GoToLod_LodStrip((float)o->value()); |
---|
1342 | |
---|
1343 | // Refresh data aplication. |
---|
1344 | refreshApplicationBar(); |
---|
1345 | |
---|
1346 | mMainWindow->flush(); |
---|
1347 | } |
---|
1348 | |
---|
1349 | void GeoMeshViewUI::cb_mLodStripSlider(fltk::Slider *o, void *v) |
---|
1350 | { |
---|
1351 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
1352 | -> |
---|
1353 | cb_mLodStripSlider_i(o,v); |
---|
1354 | } |
---|
1355 | |
---|
1356 | //--------------------------------------------------------------------------- |
---|
1357 | // Lod Slider Callback for the foliage |
---|
1358 | //--------------------------------------------------------------------------- |
---|
1359 | inline void GeoMeshViewUI::cb_mLodTreeSlider_i(fltk::Slider *o, void *) |
---|
1360 | { |
---|
1361 | // Change the lod. |
---|
1362 | geoMeshView->GoToLod_LodTree((float)o->value()); |
---|
1363 | |
---|
1364 | // Refresh data aplication. |
---|
1365 | refreshApplicationBar(); |
---|
1366 | |
---|
1367 | mMainWindow->flush(); |
---|
1368 | } |
---|
1369 | |
---|
1370 | void GeoMeshViewUI::cb_mLodTreeSlider(fltk::Slider *o, void *v) |
---|
1371 | { |
---|
1372 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
1373 | -> |
---|
1374 | cb_mLodTreeSlider_i(o,v); |
---|
1375 | } |
---|
1376 | |
---|
1377 | //--------------------------------------------------------------------------- |
---|
1378 | // Mesh Info Callback |
---|
1379 | //--------------------------------------------------------------------------- |
---|
1380 | inline void GeoMeshViewUI::cb_mMeshInfo_i(fltk::Browser *, void *) |
---|
1381 | { |
---|
1382 | paintMesh(); |
---|
1383 | } |
---|
1384 | |
---|
1385 | void GeoMeshViewUI::cb_mMeshInfo(fltk::Browser* o, void* v) |
---|
1386 | { |
---|
1387 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
1388 | -> |
---|
1389 | cb_mMeshInfo_i(o,v); |
---|
1390 | } |
---|
1391 | |
---|
1392 | //--------------------------------------------------------------------------- |
---|
1393 | // Logo Callback. |
---|
1394 | //--------------------------------------------------------------------------- |
---|
1395 | inline void GeoMeshViewUI::cb_mLogo_i(fltk::InvisibleBox*, void*) |
---|
1396 | { |
---|
1397 | } |
---|
1398 | |
---|
1399 | void GeoMeshViewUI::cb_mLogo(fltk::InvisibleBox* o, void* v) |
---|
1400 | { |
---|
1401 | ((GeoMeshViewUI*) (o->parent()->parent()->user_data())) |
---|
1402 | -> |
---|
1403 | cb_mLogo_i(o,v); |
---|
1404 | } |
---|
1405 | |
---|
1406 | //--------------------------------------------------------------------------- |
---|
1407 | // Active Build process. |
---|
1408 | //--------------------------------------------------------------------------- |
---|
1409 | void GeoMeshViewUI::activeBuildProcess() |
---|
1410 | { |
---|
1411 | //mButtonBuild->set_visible(); |
---|
1412 | mButtonBuild->activate(); |
---|
1413 | |
---|
1414 | //mBuildBar->set_visible(); |
---|
1415 | mBuildBar->activate(); |
---|
1416 | } |
---|
1417 | |
---|
1418 | //--------------------------------------------------------------------------- |
---|
1419 | // Show the stripify panel. |
---|
1420 | //--------------------------------------------------------------------------- |
---|
1421 | void GeoMeshViewUI::showStripify() |
---|
1422 | { |
---|
1423 | /* |
---|
1424 | mTypeLabel->set_visible(); |
---|
1425 | mTypeLabel->activate(); |
---|
1426 | |
---|
1427 | mOneCacheStrip->set_visible(); |
---|
1428 | mOneCacheStrip->activate(); |
---|
1429 | |
---|
1430 | mQualityStrips->set_visible(); |
---|
1431 | mQualityStrips->activate(); |
---|
1432 | */ |
---|
1433 | |
---|
1434 | mButtonProcess->set_visible(); |
---|
1435 | mButtonProcess->activate(); |
---|
1436 | |
---|
1437 | mProcessBar->set_visible(); |
---|
1438 | mProcessBar->activate(); |
---|
1439 | } |
---|
1440 | |
---|
1441 | //--------------------------------------------------------------------------- |
---|
1442 | // Hide the stripify panel. |
---|
1443 | //--------------------------------------------------------------------------- |
---|
1444 | void GeoMeshViewUI::hideStripify() |
---|
1445 | { |
---|
1446 | /* |
---|
1447 | mTypeLabel->hide(); |
---|
1448 | mTypeLabel->deactivate(); |
---|
1449 | */ |
---|
1450 | |
---|
1451 | mOneCacheStrip->hide(); |
---|
1452 | mOneCacheStrip->deactivate(); |
---|
1453 | |
---|
1454 | mQualityStrips->hide(); |
---|
1455 | mQualityStrips->deactivate(); |
---|
1456 | |
---|
1457 | mButtonProcess->hide(); |
---|
1458 | mButtonProcess->deactivate(); |
---|
1459 | |
---|
1460 | mProcessBar->hide(); |
---|
1461 | mProcessBar->deactivate(); |
---|
1462 | } |
---|
1463 | |
---|
1464 | //--------------------------------------------------------------------------- |
---|
1465 | // Show the Simplify Edge Collapse panel. |
---|
1466 | //--------------------------------------------------------------------------- |
---|
1467 | void GeoMeshViewUI::showEdgeCollapse() |
---|
1468 | { |
---|
1469 | mMetricLabel->set_visible(); |
---|
1470 | mMetricLabel->activate(); |
---|
1471 | |
---|
1472 | mGeometryBased->set_visible(); |
---|
1473 | mGeometryBased->activate(); |
---|
1474 | mGeometryBased->set(); |
---|
1475 | |
---|
1476 | mViewPointDriven->set_visible(); |
---|
1477 | mViewPointDriven->activate(); |
---|
1478 | mViewPointDriven->clear(); |
---|
1479 | |
---|
1480 | /* |
---|
1481 | mTypeLabel->set_visible(); |
---|
1482 | mTypeLabel->activate(); |
---|
1483 | |
---|
1484 | mChangeVertices->set_visible(); |
---|
1485 | mChangeVertices->activate(); |
---|
1486 | */ |
---|
1487 | |
---|
1488 | mMeshReductionLabel->set_visible(); |
---|
1489 | mMeshReductionLabel->activate(); |
---|
1490 | |
---|
1491 | mPercent->set_visible(); |
---|
1492 | mPercent->activate(); |
---|
1493 | mPercent->set(); |
---|
1494 | |
---|
1495 | mVerticesNumber->set_visible(); |
---|
1496 | mVerticesNumber->activate(); |
---|
1497 | mVerticesNumber->clear(); |
---|
1498 | |
---|
1499 | mMeshReduction->set_visible(); |
---|
1500 | mMeshReduction->value(100); |
---|
1501 | |
---|
1502 | // Allows floating point. |
---|
1503 | mMeshReduction->type(fltk::FloatInput::FLOAT); |
---|
1504 | |
---|
1505 | mMeshReduction->activate(); |
---|
1506 | |
---|
1507 | mButtonProcess->set_visible(); |
---|
1508 | mButtonProcess->activate(); |
---|
1509 | |
---|
1510 | mProcessBar->set_visible(); |
---|
1511 | mProcessBar->activate(); |
---|
1512 | } |
---|
1513 | |
---|
1514 | //--------------------------------------------------------------------------- |
---|
1515 | // Hide the Simplify Edge Collapse |
---|
1516 | //--------------------------------------------------------------------------- |
---|
1517 | void GeoMeshViewUI::hideEdgeCollapse() |
---|
1518 | { |
---|
1519 | mMetricLabel->hide(); |
---|
1520 | mMetricLabel->deactivate(); |
---|
1521 | |
---|
1522 | mGeometryBased->hide(); |
---|
1523 | mGeometryBased->deactivate(); |
---|
1524 | |
---|
1525 | mViewPointDriven->hide(); |
---|
1526 | mViewPointDriven->deactivate(); |
---|
1527 | |
---|
1528 | /* |
---|
1529 | mTypeLabel->hide(); |
---|
1530 | mTypeLabel->deactivate(); |
---|
1531 | |
---|
1532 | mChangeVertices->hide(); |
---|
1533 | mChangeVertices->deactivate(); |
---|
1534 | */ |
---|
1535 | |
---|
1536 | mMeshReductionLabel->hide(); |
---|
1537 | mMeshReductionLabel->deactivate(); |
---|
1538 | |
---|
1539 | mPercent->hide(); |
---|
1540 | mPercent->deactivate(); |
---|
1541 | |
---|
1542 | mVerticesNumber->hide(); |
---|
1543 | mVerticesNumber->deactivate(); |
---|
1544 | |
---|
1545 | mMeshReduction->hide(); |
---|
1546 | mMeshReduction->deactivate(); |
---|
1547 | |
---|
1548 | mButtonProcess->hide(); |
---|
1549 | mButtonProcess->deactivate(); |
---|
1550 | |
---|
1551 | mProcessBar->hide(); |
---|
1552 | mProcessBar->deactivate(); |
---|
1553 | } |
---|
1554 | |
---|
1555 | //--------------------------------------------------------------------------- |
---|
1556 | // Show the Simlify Leaves Collapse. |
---|
1557 | //--------------------------------------------------------------------------- |
---|
1558 | void GeoMeshViewUI::showLeavesCollapse() |
---|
1559 | { |
---|
1560 | mMetricLabel->set_visible(); |
---|
1561 | mMetricLabel->activate(); |
---|
1562 | |
---|
1563 | mGeometryBased->set_visible(); |
---|
1564 | mGeometryBased->activate(); |
---|
1565 | mGeometryBased->set(); |
---|
1566 | |
---|
1567 | mViewPointDriven->set_visible(); |
---|
1568 | mViewPointDriven->activate(); |
---|
1569 | |
---|
1570 | /* |
---|
1571 | mTypeLabel->set_visible(); |
---|
1572 | mTypeLabel->activate(); |
---|
1573 | |
---|
1574 | mChangeTexture->set_visible(); |
---|
1575 | mChangeTexture->activate(); |
---|
1576 | */ |
---|
1577 | |
---|
1578 | mMeshReductionLabel->set_visible(); |
---|
1579 | mMeshReductionLabel->activate(); |
---|
1580 | |
---|
1581 | mPercent->set_visible(); |
---|
1582 | mPercent->activate(); |
---|
1583 | mPercent->set(); |
---|
1584 | |
---|
1585 | mVerticesNumber->set_visible(); |
---|
1586 | mVerticesNumber->activate(); |
---|
1587 | |
---|
1588 | mMeshReduction->set_visible(); |
---|
1589 | mMeshReduction->type(fltk::FloatInput::FLOAT); |
---|
1590 | mMeshReduction->activate(); |
---|
1591 | |
---|
1592 | mButtonProcess->set_visible(); |
---|
1593 | mButtonProcess->activate(); |
---|
1594 | |
---|
1595 | mProcessBar->set_visible(); |
---|
1596 | mProcessBar->activate(); |
---|
1597 | } |
---|
1598 | |
---|
1599 | //--------------------------------------------------------------------------- |
---|
1600 | // Hide the Simplify Leaves Collapse. |
---|
1601 | //--------------------------------------------------------------------------- |
---|
1602 | void GeoMeshViewUI::hideLeavesCollapse() |
---|
1603 | { |
---|
1604 | mMetricLabel->hide(); |
---|
1605 | mMetricLabel->deactivate(); |
---|
1606 | |
---|
1607 | mGeometryBased->hide(); |
---|
1608 | mGeometryBased->deactivate(); |
---|
1609 | |
---|
1610 | mViewPointDriven->hide(); |
---|
1611 | mViewPointDriven->deactivate(); |
---|
1612 | |
---|
1613 | /* |
---|
1614 | mTypeLabel->hide(); |
---|
1615 | mTypeLabel->deactivate(); |
---|
1616 | |
---|
1617 | mChangeTexture->hide(); |
---|
1618 | mChangeTexture->deactivate(); |
---|
1619 | */ |
---|
1620 | |
---|
1621 | mMeshReductionLabel->hide(); |
---|
1622 | mMeshReductionLabel->deactivate(); |
---|
1623 | |
---|
1624 | mPercent->hide(); |
---|
1625 | mPercent->deactivate(); |
---|
1626 | |
---|
1627 | mVerticesNumber->hide(); |
---|
1628 | mVerticesNumber->deactivate(); |
---|
1629 | |
---|
1630 | mMeshReduction->hide(); |
---|
1631 | mMeshReduction->deactivate(); |
---|
1632 | |
---|
1633 | mButtonProcess->hide(); |
---|
1634 | mButtonProcess->deactivate(); |
---|
1635 | |
---|
1636 | mProcessBar->hide(); |
---|
1637 | mProcessBar->deactivate(); |
---|
1638 | } |
---|
1639 | |
---|
1640 | //--------------------------------------------------------------------------- |
---|
1641 | // Show the LodStrips Panel. |
---|
1642 | //--------------------------------------------------------------------------- |
---|
1643 | void GeoMeshViewUI::showOpenMeshSimplification() |
---|
1644 | { |
---|
1645 | mButtonProcess->set_visible(); |
---|
1646 | mButtonProcess->activate(); |
---|
1647 | |
---|
1648 | mProcessBar->set_visible(); |
---|
1649 | mProcessBar->activate(); |
---|
1650 | |
---|
1651 | mButtonBuild->set_visible(); |
---|
1652 | mButtonBuild->activate(); |
---|
1653 | |
---|
1654 | mBuildBar->set_visible(); |
---|
1655 | mBuildBar->activate(); |
---|
1656 | } |
---|
1657 | |
---|
1658 | //--------------------------------------------------------------------------- |
---|
1659 | // Hide the LodStrips Panel. |
---|
1660 | //--------------------------------------------------------------------------- |
---|
1661 | void GeoMeshViewUI::hideOpenMeshSimplification() |
---|
1662 | { |
---|
1663 | mButtonProcess->hide(); |
---|
1664 | mButtonProcess->deactivate(); |
---|
1665 | |
---|
1666 | mProcessBar->hide(); |
---|
1667 | mProcessBar->deactivate(); |
---|
1668 | |
---|
1669 | mButtonBuild->hide(); |
---|
1670 | mButtonBuild->deactivate(); |
---|
1671 | |
---|
1672 | mBuildBar->hide(); |
---|
1673 | mBuildBar->deactivate(); |
---|
1674 | } |
---|
1675 | |
---|
1676 | //--------------------------------------------------------------------------- |
---|
1677 | // Shows the auto generate LodStrips panel. |
---|
1678 | //--------------------------------------------------------------------------- |
---|
1679 | void GeoMeshViewUI::showAutoGenerateLodStrips() |
---|
1680 | { |
---|
1681 | // Shows the simplify panel. |
---|
1682 | showEdgeCollapse(); |
---|
1683 | |
---|
1684 | // Deactive VMI option. |
---|
1685 | //mViewPointDriven->deactivate(); |
---|
1686 | |
---|
1687 | mButtonBuild->set_visible(); |
---|
1688 | //mButtonBuild->activate(); |
---|
1689 | |
---|
1690 | mBuildBar->set_visible(); |
---|
1691 | //mBuildBar->activate(); |
---|
1692 | } |
---|
1693 | |
---|
1694 | //--------------------------------------------------------------------------- |
---|
1695 | // Shows the auto generate LodStrips panel. |
---|
1696 | //--------------------------------------------------------------------------- |
---|
1697 | void GeoMeshViewUI::showAutoGenerateLodTrees() |
---|
1698 | { |
---|
1699 | // Shows the simplify panel. |
---|
1700 | showEdgeCollapse(); |
---|
1701 | |
---|
1702 | // Deactive VMI option. |
---|
1703 | mViewPointDriven->deactivate(); |
---|
1704 | |
---|
1705 | mButtonBuild->set_visible(); |
---|
1706 | //mButtonBuild->activate(); |
---|
1707 | |
---|
1708 | mBuildBar->set_visible(); |
---|
1709 | //mBuildBar->activate(); |
---|
1710 | } |
---|
1711 | |
---|
1712 | //--------------------------------------------------------------------------- |
---|
1713 | // Show the LodStrips visulization panel. |
---|
1714 | //--------------------------------------------------------------------------- |
---|
1715 | void GeoMeshViewUI::showLodStripSlider() |
---|
1716 | { |
---|
1717 | mLodStripSlider->set_visible(); |
---|
1718 | mLodStripSlider->activate(); |
---|
1719 | } |
---|
1720 | |
---|
1721 | //--------------------------------------------------------------------------- |
---|
1722 | // Hide the LodStrips visualization panel. |
---|
1723 | //--------------------------------------------------------------------------- |
---|
1724 | void GeoMeshViewUI::hideLodStripSlider() |
---|
1725 | { |
---|
1726 | mLodStripSlider->hide(); |
---|
1727 | mLodStripSlider->deactivate(); |
---|
1728 | } |
---|
1729 | |
---|
1730 | //--------------------------------------------------------------------------- |
---|
1731 | // Show the LodTree visulization panel. |
---|
1732 | //--------------------------------------------------------------------------- |
---|
1733 | void GeoMeshViewUI::showLodTreeSlider() |
---|
1734 | { |
---|
1735 | mLodTreeSlider->set_visible(); |
---|
1736 | mLodTreeSlider->activate(); |
---|
1737 | } |
---|
1738 | |
---|
1739 | //--------------------------------------------------------------------------- |
---|
1740 | // Hide the LodTree visualization panel. |
---|
1741 | //--------------------------------------------------------------------------- |
---|
1742 | void GeoMeshViewUI::hideLodTreeSlider() |
---|
1743 | { |
---|
1744 | mLodTreeSlider->hide(); |
---|
1745 | mLodTreeSlider->deactivate(); |
---|
1746 | } |
---|
1747 | |
---|
1748 | //--------------------------------------------------------------------------- |
---|
1749 | // Show the LodTrees Panel. |
---|
1750 | //--------------------------------------------------------------------------- |
---|
1751 | void GeoMeshViewUI::showOpenLeavesSimplification() |
---|
1752 | { |
---|
1753 | mButtonBuild->set_visible(); |
---|
1754 | mButtonBuild->activate(); |
---|
1755 | |
---|
1756 | mBuildBar->set_visible(); |
---|
1757 | mBuildBar->activate(); |
---|
1758 | } |
---|
1759 | |
---|
1760 | //--------------------------------------------------------------------------- |
---|
1761 | // Hide the LodTrees Panel. |
---|
1762 | //--------------------------------------------------------------------------- |
---|
1763 | void GeoMeshViewUI::hideOpenLeavesSimplification() |
---|
1764 | { |
---|
1765 | mButtonBuild->hide(); |
---|
1766 | mButtonBuild->deactivate(); |
---|
1767 | |
---|
1768 | mBuildBar->hide(); |
---|
1769 | mBuildBar->deactivate(); |
---|
1770 | } |
---|
1771 | |
---|
1772 | //-------------------------------------------------------------------------- |
---|
1773 | // Show the mesh info browser. |
---|
1774 | //-------------------------------------------------------------------------- |
---|
1775 | void GeoMeshViewUI::showMeshInfo() |
---|
1776 | { |
---|
1777 | char type[10]; |
---|
1778 | unsigned int group_index; |
---|
1779 | unsigned int group_count; |
---|
1780 | unsigned int bone_count; |
---|
1781 | fltk::ItemGroup **info_group; |
---|
1782 | |
---|
1783 | group_index = 0; |
---|
1784 | |
---|
1785 | if (mGeoMesh) |
---|
1786 | { |
---|
1787 | // Remove previous mesh information |
---|
1788 | this->mMeshInfo->remove_all(); |
---|
1789 | ogeometry = new fltk::ItemGroup("Geometry"); |
---|
1790 | ogeometry->begin(); |
---|
1791 | |
---|
1792 | group_count = mGeoMesh->mSubMeshCount; |
---|
1793 | |
---|
1794 | // Add one group for skeleton info. |
---|
1795 | if (mGeoMesh->hasSkeleton) |
---|
1796 | { |
---|
1797 | group_count++; |
---|
1798 | } |
---|
1799 | |
---|
1800 | info_group = new fltk::ItemGroup*[group_count]; |
---|
1801 | |
---|
1802 | // Write skeleton info. |
---|
1803 | if (mGeoMesh->hasSkeleton) |
---|
1804 | { |
---|
1805 | char *group_name = new char[256]; |
---|
1806 | char *skel_name = new char[256]; |
---|
1807 | char *bone_assig = new char[256]; |
---|
1808 | sprintf(group_name,"Skeleton"); |
---|
1809 | info_group[group_index] = new fltk::ItemGroup(group_name); |
---|
1810 | |
---|
1811 | info_group[group_index]->begin(); |
---|
1812 | sprintf(skel_name,"Name: %s",mGeoMesh->mSkeletonName); |
---|
1813 | new fltk::Item(skel_name); |
---|
1814 | bone_count = mGeoMesh->mBones.size(); |
---|
1815 | |
---|
1816 | for (int i = 0; i < mGeoMesh->mSubMeshCount; i++) |
---|
1817 | { |
---|
1818 | bone_count += mGeoMesh->mSubMesh[i].mBones.size(); |
---|
1819 | } |
---|
1820 | sprintf(bone_assig,"Bone assignamets: %d",bone_count); |
---|
1821 | new fltk::Item(bone_assig); |
---|
1822 | info_group[group_index]->end(); |
---|
1823 | |
---|
1824 | group_index++; |
---|
1825 | } |
---|
1826 | |
---|
1827 | for(int i=0; i<mGeoMesh->mSubMeshCount;i++) |
---|
1828 | { |
---|
1829 | char *group_name = new char[256]; |
---|
1830 | |
---|
1831 | if (geoMeshView->getLeavesSubMesh() >= 0) |
---|
1832 | { |
---|
1833 | if (geoMeshView->getLeavesSubMesh() == i) |
---|
1834 | { |
---|
1835 | strcpy(type,"(Leaves)"); |
---|
1836 | } |
---|
1837 | else |
---|
1838 | { |
---|
1839 | strcpy(type,"(Trunc)"); |
---|
1840 | } |
---|
1841 | } |
---|
1842 | else |
---|
1843 | { |
---|
1844 | strcpy(type,""); |
---|
1845 | } |
---|
1846 | |
---|
1847 | // Submesh identifier. |
---|
1848 | sprintf(group_name,"SubMesh %d %s",i,type); |
---|
1849 | |
---|
1850 | info_group[group_index] = new fltk::ItemGroup(group_name); |
---|
1851 | info_group[group_index]->begin(); |
---|
1852 | fltk::Item *sharedGeometry; |
---|
1853 | if (mGeoMesh->mSubMesh[i].mSharedVertexBuffer) |
---|
1854 | { |
---|
1855 | sharedGeometry = new fltk::Item("Shared Geometry: Yes"); |
---|
1856 | } |
---|
1857 | else |
---|
1858 | { |
---|
1859 | sharedGeometry = new fltk::Item("Shared Geometry: No"); |
---|
1860 | } |
---|
1861 | |
---|
1862 | // Adds material name. |
---|
1863 | char *cadena2=new char[100]; |
---|
1864 | sprintf(cadena2, "Material: %s",mGeoMesh->mSubMesh[i].mMaterialName); |
---|
1865 | |
---|
1866 | fltk::Item *geomaterial = new fltk::Item(cadena2); |
---|
1867 | |
---|
1868 | char *cadena3=new char[100]; |
---|
1869 | |
---|
1870 | sprintf(cadena3, "Number of indexes: %d",mGeoMesh->mSubMesh[i].mIndexCount); |
---|
1871 | fltk::Item *numberIndex = new fltk::Item(cadena3); |
---|
1872 | if (mGeoMesh->mSubMesh[i].mType==Geometry::GEO_TRIANGLE_LIST) |
---|
1873 | { |
---|
1874 | fltk::Item *type = new fltk::Item("Triangle List"); |
---|
1875 | } |
---|
1876 | else |
---|
1877 | { |
---|
1878 | fltk::Item *type = new fltk::Item("Triangle Strips"); |
---|
1879 | } |
---|
1880 | |
---|
1881 | char *cadenavertex=new char[30]; |
---|
1882 | sprintf(cadenavertex, "Number of vertices: %d",mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount); |
---|
1883 | fltk::Item *numberVertex = new fltk::Item(cadenavertex); |
---|
1884 | |
---|
1885 | if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) |
---|
1886 | { |
---|
1887 | fltk::Item *normals = new fltk::Item("Normals: Yes"); |
---|
1888 | } |
---|
1889 | else |
---|
1890 | { |
---|
1891 | fltk::Item *normals = new fltk::Item("Normals: No"); |
---|
1892 | } |
---|
1893 | |
---|
1894 | if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) |
---|
1895 | { |
---|
1896 | fltk::Item *textures = new fltk::Item("Textures: Yes"); |
---|
1897 | } |
---|
1898 | else |
---|
1899 | { |
---|
1900 | fltk::Item *textures = new fltk::Item("Textures: No"); |
---|
1901 | } |
---|
1902 | |
---|
1903 | |
---|
1904 | info_group[group_index]->end(); |
---|
1905 | } |
---|
1906 | ogeometry->end(); |
---|
1907 | this->mMeshInfo->add(ogeometry); |
---|
1908 | } |
---|
1909 | |
---|
1910 | // Hide the right panel. |
---|
1911 | hideRightPanel(); |
---|
1912 | |
---|
1913 | mMeshInfo->set_visible(); |
---|
1914 | mMeshInfo->activate(); |
---|
1915 | } |
---|
1916 | |
---|
1917 | //-------------------------------------------------------------------------- |
---|
1918 | // Hide the mesh info browser. |
---|
1919 | //-------------------------------------------------------------------------- |
---|
1920 | void GeoMeshViewUI::hideMeshInfo() |
---|
1921 | { |
---|
1922 | mMeshInfo->hide(); |
---|
1923 | mMeshInfo->deactivate(); |
---|
1924 | } |
---|
1925 | |
---|
1926 | //-------------------------------------------------------------------------- |
---|
1927 | // Hide the right panel. |
---|
1928 | //-------------------------------------------------------------------------- |
---|
1929 | void GeoMeshViewUI::hideRightPanel() |
---|
1930 | { |
---|
1931 | hideStripify(); |
---|
1932 | hideEdgeCollapse(); |
---|
1933 | hideLeavesCollapse(); |
---|
1934 | hideOpenMeshSimplification(); |
---|
1935 | hideOpenLeavesSimplification(); |
---|
1936 | hideLodStripSlider(); |
---|
1937 | hideLodTreeSlider(); |
---|
1938 | hideMeshInfo(); |
---|
1939 | } |
---|
1940 | |
---|
1941 | //-------------------------------------------------------------------------- |
---|
1942 | // Get the number of vertices. |
---|
1943 | //-------------------------------------------------------------------------- |
---|
1944 | size_t GeoMeshViewUI::getVertexCount(Mesh *geoMesh) |
---|
1945 | { |
---|
1946 | size_t vertex_count; |
---|
1947 | SubMesh *geoSubMesh; |
---|
1948 | |
---|
1949 | vertex_count = geoMesh->mVertexBuffer->mVertexCount; |
---|
1950 | |
---|
1951 | // For each submesh. |
---|
1952 | for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) |
---|
1953 | { |
---|
1954 | // Gets the actual submesh. |
---|
1955 | geoSubMesh = &geoMesh->mSubMesh[submesh]; |
---|
1956 | |
---|
1957 | // If the mesh does not have shared vertex. |
---|
1958 | if (!geoSubMesh->mSharedVertexBuffer) |
---|
1959 | { |
---|
1960 | // Adds the vertex of the submesh to the total count. |
---|
1961 | vertex_count += geoSubMesh->mVertexBuffer->mVertexCount; |
---|
1962 | } |
---|
1963 | } |
---|
1964 | |
---|
1965 | return vertex_count; |
---|
1966 | } |
---|
1967 | |
---|
1968 | //--------------------------------------------------------------------------- |
---|
1969 | // Get the number of triangles. |
---|
1970 | //--------------------------------------------------------------------------- |
---|
1971 | size_t GeoMeshViewUI::getTriangleCount(Geometry::Mesh *geoMesh) |
---|
1972 | { |
---|
1973 | size_t triangle_count; |
---|
1974 | SubMesh *geoSubMesh; |
---|
1975 | |
---|
1976 | // Initialize the triangle count. |
---|
1977 | triangle_count = 0; |
---|
1978 | |
---|
1979 | // If the application is in visualize lodstrips mode. |
---|
1980 | if (mApplicationState == VISUALIZE_LODSTRIPS) |
---|
1981 | { |
---|
1982 | triangle_count = geoMeshView->getLodStripsTriangleCount(); |
---|
1983 | } |
---|
1984 | else |
---|
1985 | { |
---|
1986 | // For each submesh. |
---|
1987 | for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) |
---|
1988 | { |
---|
1989 | // Gets the actual submesh. |
---|
1990 | geoSubMesh = &geoMesh->mSubMesh[submesh]; |
---|
1991 | |
---|
1992 | switch (geoSubMesh->mType) |
---|
1993 | { |
---|
1994 | case GEO_TRIANGLE_LIST: |
---|
1995 | triangle_count += geoSubMesh->mIndexCount / 3; |
---|
1996 | break; |
---|
1997 | case GEO_TRIANGLE_STRIPS: |
---|
1998 | triangle_count += geoSubMesh->mIndexCount - 2; |
---|
1999 | break; |
---|
2000 | } |
---|
2001 | } |
---|
2002 | } |
---|
2003 | |
---|
2004 | return triangle_count; |
---|
2005 | } |
---|
2006 | |
---|
2007 | //--------------------------------------------------------------------------- |
---|
2008 | // Get the number of strips. |
---|
2009 | //--------------------------------------------------------------------------- |
---|
2010 | size_t GeoMeshViewUI::getStripCount(Geometry::Mesh *geoMesh) |
---|
2011 | { |
---|
2012 | size_t strip_count; |
---|
2013 | SubMesh *geoSubMesh; |
---|
2014 | |
---|
2015 | // Initialize the triangle count. |
---|
2016 | strip_count = 0; |
---|
2017 | |
---|
2018 | // For each submesh. |
---|
2019 | for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) |
---|
2020 | { |
---|
2021 | // Gets the actual submesh. |
---|
2022 | geoSubMesh = &geoMesh->mSubMesh[submesh]; |
---|
2023 | |
---|
2024 | if (geoSubMesh->mType == GEO_TRIANGLE_STRIPS) |
---|
2025 | { |
---|
2026 | strip_count += geoSubMesh->mStripCount; |
---|
2027 | } |
---|
2028 | } |
---|
2029 | |
---|
2030 | return strip_count; |
---|
2031 | } |
---|
2032 | |
---|
2033 | //--------------------------------------------------------------------------- |
---|
2034 | // It paints the submesh selected by the mMeshInfo tree. |
---|
2035 | // Trate the mMeshInfo event. |
---|
2036 | //--------------------------------------------------------------------------- |
---|
2037 | int GeoMeshViewUI::paintMesh(void) |
---|
2038 | { |
---|
2039 | char selectedTag[100]; |
---|
2040 | char *pch; |
---|
2041 | char *p; |
---|
2042 | int meshNumber; |
---|
2043 | |
---|
2044 | // Initializa mesh to not selected. |
---|
2045 | meshNumber = -1; |
---|
2046 | |
---|
2047 | // Shows the selected object label. |
---|
2048 | strcpy(selectedTag,mMeshInfo->goto_focus()->label()); |
---|
2049 | |
---|
2050 | p=strstr(selectedTag,"SubMesh "); |
---|
2051 | |
---|
2052 | // If the item begins with string "SubMesh". |
---|
2053 | if (p!=NULL) |
---|
2054 | { |
---|
2055 | pch = strtok (selectedTag," "); |
---|
2056 | pch = strtok (NULL, " "); |
---|
2057 | sscanf(pch,"%d",&meshNumber); |
---|
2058 | } |
---|
2059 | |
---|
2060 | geoMeshView->setSubMeshSelected(meshNumber); |
---|
2061 | geoMeshView->redraw(); |
---|
2062 | |
---|
2063 | return meshNumber; |
---|
2064 | } |
---|
2065 | |
---|
2066 | //--------------------------------------------------------------------------- |
---|
2067 | // Simplify the mesh object. |
---|
2068 | //--------------------------------------------------------------------------- |
---|
2069 | bool GeoMeshViewUI::simplifyEdgeCollapse() |
---|
2070 | { |
---|
2071 | Real percent; |
---|
2072 | |
---|
2073 | // If input field empty. |
---|
2074 | if (mMeshReduction->fvalue() <= 0.0) |
---|
2075 | { |
---|
2076 | return false; |
---|
2077 | } |
---|
2078 | |
---|
2079 | // Saves OpenGL contex. |
---|
2080 | geoMeshView->saveContext(); |
---|
2081 | |
---|
2082 | // Debug. |
---|
2083 | cout << "Mesh Reduction: " |
---|
2084 | << mMeshReduction->fvalue() |
---|
2085 | << endl; |
---|
2086 | |
---|
2087 | // Gets simplify option. |
---|
2088 | if (mGeometryBased->value()) |
---|
2089 | { |
---|
2090 | simplificationState = MESHSIMP; |
---|
2091 | mMeshSimplifier = new GeometryBasedSimplifier(mGeoMesh, |
---|
2092 | progress_function); |
---|
2093 | } |
---|
2094 | else |
---|
2095 | { |
---|
2096 | simplificationState = VIEWPOINTDRIVEN; |
---|
2097 | mMeshSimplifier = new ViewPointDrivenSimplifier(mGeoMesh, |
---|
2098 | progress_function); |
---|
2099 | } |
---|
2100 | |
---|
2101 | mMeshSimplifier->setMeshLeaves(idMeshLeaves); |
---|
2102 | |
---|
2103 | if (mPercent->value()) |
---|
2104 | { |
---|
2105 | // Simplificación por porcentaje |
---|
2106 | if (mMeshReduction->fvalue() <= 100.0 && |
---|
2107 | mMeshReduction->fvalue() > 0.0) |
---|
2108 | { |
---|
2109 | percent = mMeshReduction->fvalue(); |
---|
2110 | percent = percent / 100.0; |
---|
2111 | |
---|
2112 | // Simplifica el geomesh -> Parámetro es un factor LOD [0,1]. |
---|
2113 | |
---|
2114 | mMeshSimplifier->Simplify(percent); |
---|
2115 | |
---|
2116 | // Deletes the previous mesh. |
---|
2117 | delete mUndoMesh; |
---|
2118 | |
---|
2119 | mUndoMesh = new Mesh(); |
---|
2120 | |
---|
2121 | // Sets the undo mesh. |
---|
2122 | *mUndoMesh = *mGeoMesh; |
---|
2123 | |
---|
2124 | delete mGeoMesh; |
---|
2125 | |
---|
2126 | mGeoMesh = mMeshSimplifier->GetMesh(); |
---|
2127 | } |
---|
2128 | else |
---|
2129 | { |
---|
2130 | fltk::alert("Wrong value for simplification.\n" |
---|
2131 | "Valid values [0..100]"); |
---|
2132 | |
---|
2133 | return false; |
---|
2134 | } |
---|
2135 | } |
---|
2136 | else |
---|
2137 | { |
---|
2138 | // Simplificar hasta un número de vértices. |
---|
2139 | uint32 v = (uint32)mMeshReduction->fvalue(); |
---|
2140 | |
---|
2141 | // Simplifica el geomesh -> Parámetro es un factor LOD [0,1]. |
---|
2142 | mMeshSimplifier->Simplify(v); |
---|
2143 | |
---|
2144 | // Deletes the previous mesh. |
---|
2145 | delete mUndoMesh; |
---|
2146 | |
---|
2147 | mUndoMesh = new Mesh(); |
---|
2148 | |
---|
2149 | // Sets the undo mesh. |
---|
2150 | *mUndoMesh = *mGeoMesh; |
---|
2151 | |
---|
2152 | delete mGeoMesh; |
---|
2153 | |
---|
2154 | mGeoMesh = mMeshSimplifier->GetMesh(); |
---|
2155 | } |
---|
2156 | |
---|
2157 | return true; |
---|
2158 | } |
---|
2159 | |
---|
2160 | //--------------------------------------------------------------------------- |
---|
2161 | // Simplify the mesh object. |
---|
2162 | //--------------------------------------------------------------------------- |
---|
2163 | void GeoMeshViewUI::simplifyLeavesCollapse() |
---|
2164 | { |
---|
2165 | bool error; |
---|
2166 | uint32 vi; |
---|
2167 | |
---|
2168 | // Initialize error flag. |
---|
2169 | error = false; |
---|
2170 | |
---|
2171 | // Check submeshes for triangles strips. |
---|
2172 | for (int i = 0; i < mGeoMesh->mSubMeshCount; i++) |
---|
2173 | { |
---|
2174 | // If current submesh is in triangle strips. |
---|
2175 | if (mGeoMesh->mSubMesh[i].mType == GEO_TRIANGLE_STRIPS) |
---|
2176 | { |
---|
2177 | error = true; |
---|
2178 | } |
---|
2179 | } |
---|
2180 | |
---|
2181 | // if the mesh is stripified. |
---|
2182 | if (error) |
---|
2183 | { |
---|
2184 | fltk::alert("Can't simplify a tree in triagle strips."); |
---|
2185 | } |
---|
2186 | // if the mesh is in triangle list. |
---|
2187 | else |
---|
2188 | { |
---|
2189 | simplificationState = HOJAS; |
---|
2190 | |
---|
2191 | mTreeSimplifier = new TreeSimplifier(mGeoMesh, progress_function); |
---|
2192 | vi = (uint32)mMeshReduction->fvalue(); |
---|
2193 | |
---|
2194 | // Simplify |
---|
2195 | if(idMeshLeaves != (unsigned short)-1) |
---|
2196 | { |
---|
2197 | // Simplify |
---|
2198 | mTreeSimplifier->Simplify(vi, idMeshLeaves); |
---|
2199 | |
---|
2200 | // Deletes the previous mesh. |
---|
2201 | delete mUndoMesh; |
---|
2202 | |
---|
2203 | mUndoMesh = new Mesh(); |
---|
2204 | |
---|
2205 | // Sets the undo mesh. |
---|
2206 | *mUndoMesh = *mGeoMesh; |
---|
2207 | |
---|
2208 | delete mGeoMesh; |
---|
2209 | |
---|
2210 | mGeoMesh = mTreeSimplifier->GetMesh(); |
---|
2211 | |
---|
2212 | geoMeshView->setMesh(mGeoMesh); |
---|
2213 | } |
---|
2214 | else |
---|
2215 | { |
---|
2216 | fltk::alert("You must select the mesh that contains the leaves."); |
---|
2217 | } |
---|
2218 | } |
---|
2219 | } |
---|
2220 | |
---|
2221 | //--------------------------------------------------------------------------- |
---|
2222 | // Create a simplification sequence of the simplification method. |
---|
2223 | //--------------------------------------------------------------------------- |
---|
2224 | void GeoMeshViewUI::createSimplificationSequence() |
---|
2225 | { |
---|
2226 | MeshSimplificationSequence *secsimpl; |
---|
2227 | |
---|
2228 | secsimpl = mMeshSimplifier->GetSimplificationSequence(); |
---|
2229 | |
---|
2230 | // Nombre del mesh para guardar la secuencia de simplificación. |
---|
2231 | secsimpl->putMeshName(nombremesh); |
---|
2232 | secsimpl->Save(Geometry::Serializer("SimplifSequence.txt",Serializer::WRITE)); |
---|
2233 | } |
---|
2234 | |
---|
2235 | //--------------------------------------------------------------------------- |
---|
2236 | // Create a simplification sequence of the leaves. |
---|
2237 | //--------------------------------------------------------------------------- |
---|
2238 | void GeoMeshViewUI::createLeavesSequence(const std::string &filename) |
---|
2239 | { |
---|
2240 | TreeSimplificationSequence *tree_sequencer; |
---|
2241 | |
---|
2242 | tree_sequencer = mTreeSimplifier->GetSimplificationSequence(); |
---|
2243 | |
---|
2244 | tree_sequencer->putMeshName(nombremesh); |
---|
2245 | tree_sequencer->Save(Serializer(filename,Serializer::APPEND)); |
---|
2246 | |
---|
2247 | delete tree_sequencer; |
---|
2248 | } |
---|
2249 | |
---|
2250 | //--------------------------------------------------------------------------- |
---|
2251 | // Stripify the mesh object. |
---|
2252 | //--------------------------------------------------------------------------- |
---|
2253 | void GeoMeshViewUI::stripify() |
---|
2254 | { |
---|
2255 | bool error; |
---|
2256 | char char_value[10]; |
---|
2257 | CustomStripifier *geoStripifier; |
---|
2258 | |
---|
2259 | // Initialize error flag. |
---|
2260 | error = false; |
---|
2261 | |
---|
2262 | // Check submeshes for triangles strips. |
---|
2263 | for (int i = 0; i < mGeoMesh->mSubMeshCount; i++) |
---|
2264 | { |
---|
2265 | // If current submesh is in triangle strips. |
---|
2266 | if (mGeoMesh->mSubMesh[i].mType == GEO_TRIANGLE_STRIPS) |
---|
2267 | { |
---|
2268 | error = true; |
---|
2269 | } |
---|
2270 | } |
---|
2271 | |
---|
2272 | // if the mesh is stripified. |
---|
2273 | if (error) |
---|
2274 | { |
---|
2275 | fltk::alert("The mesh is already in strips."); |
---|
2276 | } |
---|
2277 | // if the mesh is in triangle list. |
---|
2278 | else |
---|
2279 | { |
---|
2280 | //Stripify. |
---|
2281 | geoStripifier = new CustomStripifier(mGeoMesh); |
---|
2282 | |
---|
2283 | // Set the progress bar function. |
---|
2284 | geoStripifier->SetProgressFunc(progress_function); |
---|
2285 | |
---|
2286 | // Sets the leaves submesh if exists. |
---|
2287 | geoStripifier->SetSubMeshLeaves(idMeshLeaves); |
---|
2288 | |
---|
2289 | if (geoStripifier->Stripify()) |
---|
2290 | { |
---|
2291 | // Deletes the mesh object. |
---|
2292 | delete mUndoMesh; |
---|
2293 | |
---|
2294 | mUndoMesh = new Mesh(); |
---|
2295 | |
---|
2296 | *mUndoMesh = *mGeoMesh; |
---|
2297 | |
---|
2298 | delete mGeoMesh; |
---|
2299 | |
---|
2300 | // Gets the mesh stripified. |
---|
2301 | mGeoMesh = geoStripifier->GetMesh(); |
---|
2302 | |
---|
2303 | // Visualize the mesh stripified. |
---|
2304 | geoMeshView->setMesh(mGeoMesh); |
---|
2305 | |
---|
2306 | // Store the color of the strips. |
---|
2307 | geoMeshView->setStripColors(); |
---|
2308 | } |
---|
2309 | else |
---|
2310 | { |
---|
2311 | // Error message. |
---|
2312 | fltk::alert("Impossible to stripify. The mesh is not manifold"); |
---|
2313 | } |
---|
2314 | |
---|
2315 | // Deletes the stripifier object. |
---|
2316 | delete geoStripifier; |
---|
2317 | } |
---|
2318 | } |
---|
2319 | |
---|
2320 | //--------------------------------------------------------------------------- |
---|
2321 | // Method that undo then mesh changes. |
---|
2322 | //--------------------------------------------------------------------------- |
---|
2323 | void GeoMeshViewUI::undo() |
---|
2324 | { |
---|
2325 | Mesh *aux_mesh; |
---|
2326 | |
---|
2327 | // if the undo mesh is not initialized. |
---|
2328 | if (mUndoMesh != NULL) |
---|
2329 | { |
---|
2330 | aux_mesh = mGeoMesh; |
---|
2331 | mGeoMesh = mUndoMesh; |
---|
2332 | |
---|
2333 | // Visualize the mesh. |
---|
2334 | geoMeshView->setMesh(mGeoMesh); |
---|
2335 | |
---|
2336 | // Refresh geometry attributes. |
---|
2337 | refreshApplicationBar(); |
---|
2338 | |
---|
2339 | // Repaint the window. |
---|
2340 | mMainWindow->redraw(); |
---|
2341 | |
---|
2342 | // Deletes the actual mesh. |
---|
2343 | delete aux_mesh; |
---|
2344 | |
---|
2345 | mUndoMesh = NULL; |
---|
2346 | } |
---|
2347 | } |
---|
2348 | |
---|
2349 | //--------------------------------------------------------------------------- |
---|
2350 | // Refresh number of vertices, triangles, strips, ... |
---|
2351 | //--------------------------------------------------------------------------- |
---|
2352 | void GeoMeshViewUI::refreshApplicationBar() |
---|
2353 | { |
---|
2354 | static char vertices_value[50]; |
---|
2355 | static char triangles_value[50]; |
---|
2356 | static char strips_value[50]; |
---|
2357 | |
---|
2358 | // Translate the vertex count to a char value. |
---|
2359 | sprintf(vertices_value,"Vertices %d",getVertexCount(mGeoMesh)); |
---|
2360 | |
---|
2361 | mVertices->label(vertices_value); |
---|
2362 | |
---|
2363 | // Translate the triangle count to a char value. |
---|
2364 | sprintf(triangles_value,"Triangles %d",getTriangleCount(mGeoMesh)); |
---|
2365 | |
---|
2366 | mTriangles->label(triangles_value); |
---|
2367 | |
---|
2368 | // Translate the triangle count to a char value. |
---|
2369 | sprintf(strips_value,"Strips %d",getStripCount(mGeoMesh)); |
---|
2370 | |
---|
2371 | mStrips->label(strips_value); |
---|
2372 | |
---|
2373 | mMainWindow->redraw(); |
---|
2374 | } |
---|
2375 | |
---|
2376 | // Method that updates the porgress bar. |
---|
2377 | float GeoMeshViewUI::updateProgressBar(float v) |
---|
2378 | { |
---|
2379 | fltk::ProgressBar *progressBar; |
---|
2380 | |
---|
2381 | // Choose progress bar to update. |
---|
2382 | switch(progressBarType) |
---|
2383 | { |
---|
2384 | case PROCESS: |
---|
2385 | progressBar = mProcessBar; |
---|
2386 | break; |
---|
2387 | case BUILD: |
---|
2388 | progressBar = mBuildBar; |
---|
2389 | break; |
---|
2390 | } |
---|
2391 | |
---|
2392 | // Update progress bar. |
---|
2393 | progressBar->step(v); |
---|
2394 | progressBar->step(); |
---|
2395 | mMainWindow->flush(); |
---|
2396 | //mMainWindow->redraw(); |
---|
2397 | |
---|
2398 | return 0; |
---|
2399 | } |
---|
2400 | |
---|
2401 | //--------------------------------------------------------------------------- |
---|
2402 | // Initialize the lodstripslibrary for visualization. |
---|
2403 | //--------------------------------------------------------------------------- |
---|
2404 | void GeoMeshViewUI::setLodStripsLibrary(const Geometry::LodStripsLibraryData *loddata, Mesh *geomesh) |
---|
2405 | { |
---|
2406 | // If there is no lod strips object. |
---|
2407 | if (lodStripsLib) |
---|
2408 | { |
---|
2409 | delete lodStripsLib; |
---|
2410 | delete lod_index_data; |
---|
2411 | } |
---|
2412 | |
---|
2413 | // New lod strips object. |
---|
2414 | lod_index_data = new GeoToolIndexData(geomesh->mSubMeshCount); |
---|
2415 | lodStripsLib = new LodStripsLibrary(loddata, geomesh, lod_index_data); |
---|
2416 | |
---|
2417 | // Sets the slider range. |
---|
2418 | // mLodStripSlider->range(lodStripsLib->MinLod(),lodStripsLib->MaxLod()); |
---|
2419 | mLodStripSlider->range(0.0f,1.0f); |
---|
2420 | |
---|
2421 | // Pass to geomeshview the lod strips object. |
---|
2422 | geoMeshView->setLodStripsLibrary(lodStripsLib); |
---|
2423 | |
---|
2424 | // Puts the slider in the max position. |
---|
2425 | mLodStripSlider->value(1.0f); |
---|
2426 | } |
---|
2427 | |
---|
2428 | //--------------------------------------------------------------------------- |
---|
2429 | // Initialize the lodTreelibrary for visualization. |
---|
2430 | //--------------------------------------------------------------------------- |
---|
2431 | void GeoMeshViewUI::setLodTreesLibrary(const LodStripsLibraryData *lodstripsdata, const TreeSimplificationSequence *treesimpseq, Mesh *geomesh/*, uint32 ileafSubMesh*/) |
---|
2432 | { |
---|
2433 | // If there is no lod strips object. |
---|
2434 | if (lodTreeLib) |
---|
2435 | { |
---|
2436 | delete lodTreeLib; |
---|
2437 | delete lod_index_data; |
---|
2438 | } |
---|
2439 | |
---|
2440 | // New lod strips object. |
---|
2441 | |
---|
2442 | lod_index_data = new GeoToolIndexData(geomesh->mSubMeshCount); |
---|
2443 | lodTreeLib = new Geometry::LodTreeLibrary(lodstripsdata,treesimpseq,geomesh,lod_index_data); |
---|
2444 | |
---|
2445 | // Sets the slider range. |
---|
2446 | mLodStripSlider->range(0.0f,1.0f); |
---|
2447 | mLodTreeSlider->range(0.0f,1.0f); |
---|
2448 | |
---|
2449 | // Pass to geomeshview the lod strips object. |
---|
2450 | geoMeshView->setLodTreesLibrary(lodTreeLib); |
---|
2451 | |
---|
2452 | // Puts the slider in the max position. |
---|
2453 | mLodStripSlider->value(1.0f); |
---|
2454 | mLodTreeSlider->value(1.0f); |
---|
2455 | } |
---|
2456 | |
---|
2457 | //--------------------------------------------------------------------------- |
---|
2458 | // Open a mesh file. |
---|
2459 | //--------------------------------------------------------------------------- |
---|
2460 | void GeoMeshViewUI::openMeshFile(void) |
---|
2461 | { |
---|
2462 | Mesh *mesh_loaded; |
---|
2463 | fltk::FileChooser *fcho; |
---|
2464 | static char char_value[10]; |
---|
2465 | static char title[256]; |
---|
2466 | |
---|
2467 | fcho = new fltk::FileChooser("", "*.{mesh,obj}", fltk::FileChooser::CREATE, "Open a mesh"); |
---|
2468 | |
---|
2469 | fcho->exec(); |
---|
2470 | |
---|
2471 | // File name. |
---|
2472 | mFileName = (char *)fcho->value(); |
---|
2473 | |
---|
2474 | if (mFileName) |
---|
2475 | { |
---|
2476 | // Loads a new mesh. |
---|
2477 | mesh_loaded = geoMeshLoader->load(mFileName); |
---|
2478 | |
---|
2479 | // If no error happens. |
---|
2480 | if (mesh_loaded) |
---|
2481 | { |
---|
2482 | // Identify the mesh that stores the leaves |
---|
2483 | idMeshLeaves = -1; |
---|
2484 | |
---|
2485 | // Delete the current mesh. |
---|
2486 | delete mGeoMesh; |
---|
2487 | delete mUndoMesh; |
---|
2488 | |
---|
2489 | // Assigns mesh loaded. |
---|
2490 | mGeoMesh = mesh_loaded; |
---|
2491 | |
---|
2492 | // Set Window Title. |
---|
2493 | strcpy(title,filename_name(mFileName)); |
---|
2494 | mMainWindow->label(strcat(title," - GeoTool")); |
---|
2495 | |
---|
2496 | // Stores the name of the mesh. |
---|
2497 | nombremesh = new char[255]; |
---|
2498 | strcpy(nombremesh,mFileName); |
---|
2499 | |
---|
2500 | // Reset the undo mesh. |
---|
2501 | mUndoMesh = new Mesh(); |
---|
2502 | *mUndoMesh = *mGeoMesh; |
---|
2503 | |
---|
2504 | // Translate the MB count to a char value. |
---|
2505 | sprintf(char_value, |
---|
2506 | "MB %.3f", |
---|
2507 | (float)geoMeshLoader->getFileSize()/1024/1024); |
---|
2508 | |
---|
2509 | mMB->label(char_value); |
---|
2510 | |
---|
2511 | // Set textures. |
---|
2512 | geoMeshView->resetTextures(); |
---|
2513 | setTextures(); |
---|
2514 | |
---|
2515 | // Visualize mesh. |
---|
2516 | geoMeshView->setMesh(mGeoMesh); |
---|
2517 | |
---|
2518 | // Hide right panel. |
---|
2519 | hideRightPanel(); |
---|
2520 | |
---|
2521 | // Quit culling. |
---|
2522 | menuRenderCW->clear_value(); |
---|
2523 | menuRenderCCW->clear_value(); |
---|
2524 | geoMeshView->deactiveCW(); |
---|
2525 | geoMeshView->deactiveCCW(); |
---|
2526 | |
---|
2527 | // Deactive solid mode and wire. |
---|
2528 | menuRenderSolid->clear_value(); |
---|
2529 | menuRenderWire->clear_value(); |
---|
2530 | menuRenderLighting->set_value(); |
---|
2531 | geoMeshView->deactiveSolid(); |
---|
2532 | geoMeshView->deactiveWire(); |
---|
2533 | geoMeshView->activeLighting(); |
---|
2534 | |
---|
2535 | // Fit model in midle. |
---|
2536 | geoMeshView->fit(); |
---|
2537 | |
---|
2538 | // Lighting smooth. |
---|
2539 | menuRenderFlat->clear_value(); |
---|
2540 | menuRenderSmooth->set_value(); |
---|
2541 | geoMeshView->smooth(); |
---|
2542 | |
---|
2543 | // Show title. |
---|
2544 | mProcessTitle->label("Mesh Info"); |
---|
2545 | |
---|
2546 | // Shows the mesh info. |
---|
2547 | showMeshInfo(); |
---|
2548 | |
---|
2549 | // if the mesh is stripified. |
---|
2550 | geoMeshView->setStripColors(); |
---|
2551 | |
---|
2552 | // Refresh geometry attributes. |
---|
2553 | refreshApplicationBar(); |
---|
2554 | |
---|
2555 | // Restore simplification state. |
---|
2556 | simplificationState = NO_SIMPLIFICATION; |
---|
2557 | } |
---|
2558 | } |
---|
2559 | // Free memory. |
---|
2560 | delete fcho; |
---|
2561 | } |
---|
2562 | |
---|
2563 | // Set textures to mesh model. |
---|
2564 | void GeoMeshViewUI::setTextures() |
---|
2565 | { |
---|
2566 | GeoMaterialLoader *loader; |
---|
2567 | string filename; |
---|
2568 | string material; |
---|
2569 | |
---|
2570 | loader = new GeoMaterialLoader(); |
---|
2571 | |
---|
2572 | // For each submesh. |
---|
2573 | for (int submesh = 0; submesh < mGeoMesh->mSubMeshCount; submesh++) |
---|
2574 | { |
---|
2575 | material = string(mGeoMesh->mSubMesh[submesh].mMaterialName); |
---|
2576 | |
---|
2577 | // If exists material. |
---|
2578 | if (loader->existsMaterial(material)) |
---|
2579 | { |
---|
2580 | // Gets file name. |
---|
2581 | filename = loader->getTextureFileName(material); |
---|
2582 | |
---|
2583 | geoMeshView->addTexFile(filename.c_str()); |
---|
2584 | } |
---|
2585 | // If not exists material. |
---|
2586 | else |
---|
2587 | { |
---|
2588 | // File name empty. |
---|
2589 | filename = string(); |
---|
2590 | |
---|
2591 | geoMeshView->addTexFile(filename.c_str()); |
---|
2592 | } |
---|
2593 | } |
---|
2594 | } |
---|
2595 | |
---|
2596 | //--------------------------------------------------------------------------- |
---|
2597 | // If file exists. |
---|
2598 | //--------------------------------------------------------------------------- |
---|
2599 | bool GeoMeshViewUI::fileExists(const char *fileNameMesh) |
---|
2600 | { |
---|
2601 | FILE *pFile; |
---|
2602 | |
---|
2603 | // Open the mesh file. |
---|
2604 | pFile = fopen(fileNameMesh, "r"); |
---|
2605 | |
---|
2606 | if (pFile) |
---|
2607 | { |
---|
2608 | return true; |
---|
2609 | } |
---|
2610 | else |
---|
2611 | { |
---|
2612 | return false; |
---|
2613 | } |
---|
2614 | } |
---|
2615 | |
---|
2616 | /******************/ |
---|
2617 | /* Constructor */ |
---|
2618 | /******************/ |
---|
2619 | GeoMeshViewUI::GeoMeshViewUI(TIPOFUNC fun) |
---|
2620 | { |
---|
2621 | progress_function = fun; |
---|
2622 | fltk::gifImage *logo; |
---|
2623 | |
---|
2624 | // Initialize the file name. |
---|
2625 | mFileName = NULL; |
---|
2626 | |
---|
2627 | // Initialize the 3D object. |
---|
2628 | mGeoMesh = NULL; |
---|
2629 | mUndoMesh = NULL; |
---|
2630 | |
---|
2631 | // Initialize the lod strip object. |
---|
2632 | lodStripsLib = NULL; |
---|
2633 | lodTreeLib = NULL; |
---|
2634 | |
---|
2635 | // Identify the mesh that stores the leaves |
---|
2636 | idMeshLeaves = -1; |
---|
2637 | |
---|
2638 | // Initialize the loader of meshes. |
---|
2639 | geoMeshLoader = new GeoMeshLoader(); |
---|
2640 | |
---|
2641 | // Initialize the menus application state. |
---|
2642 | mApplicationState = NONE; |
---|
2643 | |
---|
2644 | SubMeshNames=NULL; |
---|
2645 | |
---|
2646 | { |
---|
2647 | fltk::Window* o = new fltk::Window(800, 600,"GeoTool"); |
---|
2648 | |
---|
2649 | mMainWindow = o; |
---|
2650 | |
---|
2651 | // Program Icon for Win32. |
---|
2652 | mMainWindow->icon((char *)LoadIcon( GetModuleHandle(0), |
---|
2653 | MAKEINTRESOURCE(GEOICON))); |
---|
2654 | |
---|
2655 | // Double buffer. |
---|
2656 | mMainWindow->set_double_buffer(); |
---|
2657 | |
---|
2658 | o->user_data((void*)(this)); |
---|
2659 | o->begin(); |
---|
2660 | |
---|
2661 | { |
---|
2662 | fltk::Group* o = new fltk::Group(0, 27, 806, 559); |
---|
2663 | o->begin(); |
---|
2664 | |
---|
2665 | { |
---|
2666 | fltk::Group* o; |
---|
2667 | o = MainView = new fltk::Group(0, 0, 570, 530); |
---|
2668 | o->begin(); |
---|
2669 | |
---|
2670 | { |
---|
2671 | fltk::InvisibleBox* o; |
---|
2672 | o = cframe = new fltk::InvisibleBox(0, 0, 570, 530); |
---|
2673 | o->box(fltk::FLAT_BOX); |
---|
2674 | o->color((fltk::Color)0xffffff00); |
---|
2675 | } |
---|
2676 | |
---|
2677 | { |
---|
2678 | GeoMeshView* o; |
---|
2679 | o = geoMeshView = new GeoMeshView( 0,0,570,530,0,this); |
---|
2680 | } |
---|
2681 | |
---|
2682 | o->end(); |
---|
2683 | |
---|
2684 | fltk::Group::current()->resizable(o); |
---|
2685 | |
---|
2686 | } |
---|
2687 | |
---|
2688 | { |
---|
2689 | fltk::Group* o; |
---|
2690 | o = MainView = new fltk::Group(570, 0, 230, 530); |
---|
2691 | o->begin(); |
---|
2692 | |
---|
2693 | { |
---|
2694 | fltk::Button* o; |
---|
2695 | o = mButtonProcess = new fltk::Button(75, 410, 73, 25, "Process"); |
---|
2696 | o->callback((fltk::Callback*)cb_mButtonProcess); |
---|
2697 | o->hide(); |
---|
2698 | o->deactivate(); |
---|
2699 | } |
---|
2700 | |
---|
2701 | { |
---|
2702 | fltk::ProgressBar* o; |
---|
2703 | o = mProcessBar = new fltk::ProgressBar(16, 435, 195, 18); |
---|
2704 | o->hide(); |
---|
2705 | o->deactivate(); |
---|
2706 | } |
---|
2707 | |
---|
2708 | { |
---|
2709 | fltk::Button* o; |
---|
2710 | o = mButtonSort = new fltk::Button(75, 375, 73, 25, "Sort"); |
---|
2711 | o->callback((fltk::Callback*)cb_mButtonSort); |
---|
2712 | o->hide(); |
---|
2713 | o->deactivate(); |
---|
2714 | } |
---|
2715 | |
---|
2716 | { |
---|
2717 | fltk::ProgressBar* o; |
---|
2718 | o = mSortBar = new fltk::ProgressBar(16, 390, 195, 18); |
---|
2719 | o->hide(); |
---|
2720 | o->deactivate(); |
---|
2721 | } |
---|
2722 | |
---|
2723 | { |
---|
2724 | fltk::Button* o; |
---|
2725 | o = mButtonBuild = new fltk::Button(75, 455, 73, 25, "Build"); |
---|
2726 | o->callback((fltk::Callback*)cb_mButtonBuild); |
---|
2727 | o->hide(); |
---|
2728 | o->deactivate(); |
---|
2729 | } |
---|
2730 | |
---|
2731 | { |
---|
2732 | fltk::ProgressBar* o; |
---|
2733 | o = mBuildBar = new fltk::ProgressBar(16, 480, 195, 18); |
---|
2734 | o->hide(); |
---|
2735 | o->deactivate(); |
---|
2736 | } |
---|
2737 | |
---|
2738 | { |
---|
2739 | fltk::Slider* o; |
---|
2740 | o = mLodStripSlider = new fltk::Slider(16, 50, 30, 450); |
---|
2741 | o->linesize(0.01f); |
---|
2742 | o->type(fltk::Slider::TICK_BELOW); |
---|
2743 | o->set_vertical(); |
---|
2744 | o->callback((fltk::Callback*)cb_mLodStripSlider); |
---|
2745 | o->hide(); |
---|
2746 | o->deactivate(); |
---|
2747 | } |
---|
2748 | { |
---|
2749 | fltk::Slider* o; |
---|
2750 | o = mLodTreeSlider = new fltk::Slider(46, 50, 30, 450); |
---|
2751 | o->linesize(0.01f); |
---|
2752 | o->type(fltk::Slider::TICK_BELOW); |
---|
2753 | o->set_vertical(); |
---|
2754 | o->callback((fltk::Callback*)cb_mLodTreeSlider); |
---|
2755 | o->hide(); |
---|
2756 | o->deactivate(); |
---|
2757 | } |
---|
2758 | |
---|
2759 | { |
---|
2760 | mMetricLabel = new fltk::Output(26, 28, 0, 25, "Metric"); |
---|
2761 | fltk::Output* o = mMetricLabel; |
---|
2762 | o->set_vertical(); |
---|
2763 | o->box(fltk::NO_BOX); |
---|
2764 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
2765 | o->color((fltk::Color)0xe0dfe300); |
---|
2766 | o->align(fltk::ALIGN_RIGHT); |
---|
2767 | } |
---|
2768 | |
---|
2769 | { |
---|
2770 | fltk::Group* o; |
---|
2771 | o = MainView = new fltk::Group(30, 40, 30, 60); |
---|
2772 | o->begin(); |
---|
2773 | { |
---|
2774 | mGeometryBased = new fltk::RadioButton(0, 8, 25, 25, "Geometry based"); |
---|
2775 | mViewPointDriven = new fltk::RadioButton(0, 23, 25, 25, "Viewpoint driven"); |
---|
2776 | } |
---|
2777 | o->end(); |
---|
2778 | } |
---|
2779 | |
---|
2780 | { |
---|
2781 | mProcessTitle = new fltk::Widget(0, 0, 230, 25, ""); |
---|
2782 | fltk::Widget* o = mProcessTitle; |
---|
2783 | o->set_vertical(); |
---|
2784 | o->box(fltk::NO_BOX); |
---|
2785 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
2786 | o->labelsize(15.0); |
---|
2787 | o->color((fltk::Color)0xe0dfe300); |
---|
2788 | o->align(fltk::ALIGN_CENTER); |
---|
2789 | } |
---|
2790 | |
---|
2791 | { |
---|
2792 | mMeshReductionLabel = new fltk::Output(26, 124, 0, 25, "Mesh Reduction"); |
---|
2793 | fltk::Output* o = mMeshReductionLabel; |
---|
2794 | o->set_vertical(); |
---|
2795 | o->box(fltk::NO_BOX); |
---|
2796 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
2797 | o->color((fltk::Color)0xe0dfe300); |
---|
2798 | o->align(fltk::ALIGN_RIGHT); |
---|
2799 | } |
---|
2800 | |
---|
2801 | { |
---|
2802 | fltk::Group* o; |
---|
2803 | o = MainView = new fltk::Group(30, 140, 30, 60); |
---|
2804 | o->begin(); |
---|
2805 | |
---|
2806 | { |
---|
2807 | mPercent = new fltk::RadioButton(0, 5, 25, 25, "%"); |
---|
2808 | mVerticesNumber = new fltk::RadioButton(0, 20, 25, 25, "Vertices number"); |
---|
2809 | } |
---|
2810 | o->end(); |
---|
2811 | } |
---|
2812 | |
---|
2813 | { |
---|
2814 | mMeshReduction = new fltk::FloatInput(75, 181, 75, 21, "Value:"); |
---|
2815 | fltk::FloatInput* o = mMeshReduction; |
---|
2816 | o->type(1); |
---|
2817 | } |
---|
2818 | |
---|
2819 | { |
---|
2820 | fltk::Group* o; |
---|
2821 | o = MainView = new fltk::Group(30, 100, 30, 60); |
---|
2822 | o->begin(); |
---|
2823 | |
---|
2824 | { |
---|
2825 | mOneCacheStrip = new fltk::RadioButton(0, 4, 25, 25, "One cache strip"); |
---|
2826 | mQualityStrips = new fltk::RadioButton(0, 23, 25, 25, "Quality strips"); |
---|
2827 | } |
---|
2828 | o->end(); |
---|
2829 | } |
---|
2830 | |
---|
2831 | { |
---|
2832 | fltk::Browser* o = mMeshInfo = new fltk::Browser(0, 20, 230, 380); |
---|
2833 | o->set_vertical(); |
---|
2834 | o->callback((fltk::Callback*)cb_mMeshInfo); |
---|
2835 | } |
---|
2836 | o->end(); |
---|
2837 | } |
---|
2838 | |
---|
2839 | o->end(); |
---|
2840 | |
---|
2841 | fltk::Group::current()->resizable(o); |
---|
2842 | } |
---|
2843 | |
---|
2844 | { |
---|
2845 | fltk::MenuBar* o = menuBar = new fltk::MenuBar(1, 2, 801, 21); |
---|
2846 | o->begin(); |
---|
2847 | |
---|
2848 | // Menu File. |
---|
2849 | { |
---|
2850 | fltk::ItemGroup* o = menuFile = new fltk::ItemGroup("File"); |
---|
2851 | o->begin(); |
---|
2852 | |
---|
2853 | { |
---|
2854 | fltk::Item* o = menuFileOpen = new fltk::Item("Open"); |
---|
2855 | o->callback((fltk::Callback*)cb_menuFileOpen); |
---|
2856 | } |
---|
2857 | |
---|
2858 | { |
---|
2859 | fltk::Item* o = menuFileSave = new fltk::Item("Save"); |
---|
2860 | o->callback((fltk::Callback*)cb_menuFileSave); |
---|
2861 | } |
---|
2862 | |
---|
2863 | { |
---|
2864 | fltk::Item* o = menuFileSaveAs = new fltk::Item("Save As"); |
---|
2865 | o->callback((fltk::Callback*)cb_menuFileSaveAs); |
---|
2866 | } |
---|
2867 | |
---|
2868 | { |
---|
2869 | fltk::Item* o = menuMeshExportOBJ = new fltk::Item("Export to OBJ"); |
---|
2870 | o->callback((fltk::Callback*)cb_menuMeshExportOBJ); |
---|
2871 | } |
---|
2872 | |
---|
2873 | { |
---|
2874 | fltk::Item* o = new fltk::Item("Transform to SV"); |
---|
2875 | o->callback((fltk::Callback*)cb_menuFileTransformSharedVertex); |
---|
2876 | } |
---|
2877 | |
---|
2878 | { |
---|
2879 | menuLoadTextures = new fltk::ItemGroup("Load Textures"); |
---|
2880 | o->add(menuLoadTextures); |
---|
2881 | } |
---|
2882 | |
---|
2883 | { |
---|
2884 | fltk::Item* o = menuFileQuit = new fltk::Item("Quit"); |
---|
2885 | o->callback((fltk::Callback*)cb_menuFileQuit); |
---|
2886 | } |
---|
2887 | |
---|
2888 | o->end(); |
---|
2889 | } |
---|
2890 | |
---|
2891 | // Menu Edit. |
---|
2892 | { |
---|
2893 | fltk::ItemGroup* o = menuEdit = new fltk::ItemGroup("Edit"); |
---|
2894 | o->begin(); |
---|
2895 | |
---|
2896 | { |
---|
2897 | fltk::Item* o = menuEditUndo = new fltk::Item("Undo"); |
---|
2898 | o->callback((fltk::Callback*)cb_menuEditUndo); |
---|
2899 | } |
---|
2900 | |
---|
2901 | { |
---|
2902 | fltk::Item* o = menuEditFit = new fltk::Item("Fit"); |
---|
2903 | o->callback((fltk::Callback*)cb_menuEditFit); |
---|
2904 | } |
---|
2905 | |
---|
2906 | { |
---|
2907 | fltk::Item* o = menuEditRotate = new fltk::Item("Rotate"); |
---|
2908 | o->type(fltk::Item::RADIO); |
---|
2909 | o->set_value(); |
---|
2910 | o->callback((fltk::Callback*)cb_menuEditRotate); |
---|
2911 | } |
---|
2912 | |
---|
2913 | { |
---|
2914 | fltk::Item* o = menuEditPan = new fltk::Item("Pan"); |
---|
2915 | o->type(fltk::Item::RADIO); |
---|
2916 | o->callback((fltk::Callback*)cb_menuEditPan); |
---|
2917 | } |
---|
2918 | |
---|
2919 | new fltk::Divider(); |
---|
2920 | |
---|
2921 | { |
---|
2922 | fltk::Item* o = menuMeshInfo = new fltk::Item("Mesh info"); |
---|
2923 | o->callback((fltk::Callback*)cb_menuMeshInfo); |
---|
2924 | } |
---|
2925 | |
---|
2926 | { |
---|
2927 | fltk::Item* o; |
---|
2928 | o = menuSelectLeaves = new fltk::Item("Select leaves"); |
---|
2929 | o->callback((fltk::Callback*)cb_menuSelectLeaves); |
---|
2930 | } |
---|
2931 | o->end(); |
---|
2932 | } |
---|
2933 | |
---|
2934 | // Menu Render. |
---|
2935 | { |
---|
2936 | fltk::ItemGroup* o = menuRender = new fltk::ItemGroup("Render"); |
---|
2937 | o->begin(); |
---|
2938 | |
---|
2939 | { |
---|
2940 | fltk::Item* o = menuRenderWire = new fltk::Item("Wire"); |
---|
2941 | o->type(fltk::Item::RADIO); |
---|
2942 | o->callback((fltk::Callback*)cb_menuRenderWire); |
---|
2943 | } |
---|
2944 | |
---|
2945 | { |
---|
2946 | fltk::Item* o = menuRenderSolid = new fltk::Item("Solid"); |
---|
2947 | o->type(fltk::Item::RADIO); |
---|
2948 | o->callback((fltk::Callback*)cb_menuRenderSolid); |
---|
2949 | } |
---|
2950 | |
---|
2951 | { |
---|
2952 | fltk::Item* o = menuRenderLighting = new fltk::Item("Lighting"); |
---|
2953 | o->type(fltk::Item::RADIO); |
---|
2954 | o->callback((fltk::Callback*)cb_menuRenderLighting); |
---|
2955 | } |
---|
2956 | |
---|
2957 | { |
---|
2958 | fltk::Item* o = menuRenderCW = new fltk::Item("CW"); |
---|
2959 | o->type(fltk::Item::RADIO); |
---|
2960 | o->callback((fltk::Callback*)cb_menuRenderCW); |
---|
2961 | } |
---|
2962 | |
---|
2963 | { |
---|
2964 | fltk::Item* o = menuRenderCCW = new fltk::Item("CCW"); |
---|
2965 | o->type(fltk::Item::RADIO); |
---|
2966 | o->set_value(); |
---|
2967 | o->callback((fltk::Callback*)cb_menuRenderCCW); |
---|
2968 | } |
---|
2969 | |
---|
2970 | new fltk::Divider(); |
---|
2971 | |
---|
2972 | { |
---|
2973 | fltk::Item* o = menuRenderFlat = new fltk::Item("Flat"); |
---|
2974 | o->type(fltk::Item::RADIO); |
---|
2975 | o->clear_value(); |
---|
2976 | o->callback((fltk::Callback*)cb_menuRenderFlat); |
---|
2977 | } |
---|
2978 | |
---|
2979 | { |
---|
2980 | fltk::Item* o = menuRenderSmooth = new fltk::Item("Smooth"); |
---|
2981 | o->type(fltk::Item::RADIO); |
---|
2982 | o->set_value(); |
---|
2983 | o->callback((fltk::Callback*)cb_menuRenderSmooth); |
---|
2984 | } |
---|
2985 | |
---|
2986 | new fltk::Divider(); |
---|
2987 | |
---|
2988 | { |
---|
2989 | fltk::Item* o = menuRenderTextures = new fltk::Item("Texture mapping"); |
---|
2990 | o->type(fltk::Item::RADIO); |
---|
2991 | o->set_value(); |
---|
2992 | o->callback((fltk::Callback*)cb_menuRenderTextures); |
---|
2993 | } |
---|
2994 | |
---|
2995 | o->end(); |
---|
2996 | } |
---|
2997 | |
---|
2998 | // Menu Stripify. |
---|
2999 | { |
---|
3000 | fltk::Item* o = menuStripify = new fltk::Item("Stripify"); |
---|
3001 | o->callback((fltk::Callback*)cb_menuStripify); |
---|
3002 | } |
---|
3003 | |
---|
3004 | // Menu Simplify. |
---|
3005 | { |
---|
3006 | fltk::ItemGroup* o = menuSimplify = new fltk::ItemGroup("Simplify"); |
---|
3007 | o->callback((fltk::Callback*)cb_menuSimplify); |
---|
3008 | o->begin(); |
---|
3009 | |
---|
3010 | { |
---|
3011 | fltk::Item* o; |
---|
3012 | o = menuSimplifyEdgeCollapse = new fltk::Item("Mesh Simplification"); |
---|
3013 | o->callback((fltk::Callback*)cb_menuSimplifyEdgeCollapse); |
---|
3014 | } |
---|
3015 | |
---|
3016 | { |
---|
3017 | fltk::Item* o; |
---|
3018 | o = menuSimplifyLeavesCollapse = new fltk::Item("Leaves Simplification"); |
---|
3019 | o->callback((fltk::Callback*)cb_menuSimplifyLeavesCollapse); |
---|
3020 | } |
---|
3021 | |
---|
3022 | o->end(); |
---|
3023 | } |
---|
3024 | |
---|
3025 | // Menu LodStrips. |
---|
3026 | { |
---|
3027 | fltk::ItemGroup* o; |
---|
3028 | o = menuLodStrips = new fltk::ItemGroup("LodStrips"); |
---|
3029 | o->begin(); |
---|
3030 | |
---|
3031 | { |
---|
3032 | fltk::Item* o; |
---|
3033 | o = menuLodStripsGenerate = new fltk::Item("Generate"); |
---|
3034 | o->callback((fltk::Callback*)cb_menuLodStripsGenerate); |
---|
3035 | } |
---|
3036 | |
---|
3037 | { |
---|
3038 | fltk::Item* o; |
---|
3039 | o = menuLodStripsVisualize = new fltk::Item("Visualize"); |
---|
3040 | o->callback((fltk::Callback*)cb_menuLodStripsVisualize); |
---|
3041 | } |
---|
3042 | |
---|
3043 | o->end(); |
---|
3044 | } |
---|
3045 | |
---|
3046 | // Menu LodTrees. |
---|
3047 | { |
---|
3048 | fltk::ItemGroup* o; |
---|
3049 | o = menuLodTrees = new fltk::ItemGroup("LodTrees"); |
---|
3050 | o->begin(); |
---|
3051 | |
---|
3052 | { |
---|
3053 | fltk::Item* o; |
---|
3054 | o = menuLodTreesGenerate = new fltk::Item("Generate"); |
---|
3055 | o->callback((fltk::Callback*)cb_menuLodTreesGenerate); |
---|
3056 | } |
---|
3057 | { |
---|
3058 | fltk::Item* o; |
---|
3059 | o = menuLodTreesVisualize = new fltk::Item("Visualize"); |
---|
3060 | o->callback((fltk::Callback*)cb_menuLodTreesVisualize); |
---|
3061 | } |
---|
3062 | |
---|
3063 | o->end(); |
---|
3064 | } |
---|
3065 | |
---|
3066 | |
---|
3067 | { |
---|
3068 | fltk::ItemGroup* o = new fltk::ItemGroup("?"); |
---|
3069 | o->begin(); |
---|
3070 | |
---|
3071 | { |
---|
3072 | fltk::Item* o = menuHelpAbout = new fltk::Item("About"); |
---|
3073 | o->callback((fltk::Callback*)cb_menuHelpAbout); |
---|
3074 | } |
---|
3075 | |
---|
3076 | o->end(); |
---|
3077 | } |
---|
3078 | |
---|
3079 | o->end(); |
---|
3080 | } |
---|
3081 | |
---|
3082 | { |
---|
3083 | fltk::Group* o; |
---|
3084 | o = ApplicationBar = new fltk::Group(0, 570, 807, 28); |
---|
3085 | o->box(fltk::BORDER_BOX); |
---|
3086 | o->begin(); |
---|
3087 | |
---|
3088 | { |
---|
3089 | fltk::Widget* o; |
---|
3090 | o = mVertices = new fltk::Widget(154, 4, 40, 15, "Vertices"); |
---|
3091 | o->box(fltk::NO_BOX); |
---|
3092 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
3093 | o->color((fltk::Color)0xe0dfe300); |
---|
3094 | } |
---|
3095 | |
---|
3096 | { |
---|
3097 | fltk::Widget* o; |
---|
3098 | o = mTriangles = new fltk::Widget(254, 3, 40, 15, "Triangles"); |
---|
3099 | o->box(fltk::NO_BOX); |
---|
3100 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
3101 | o->color((fltk::Color)0xe0dfe300); |
---|
3102 | } |
---|
3103 | |
---|
3104 | { |
---|
3105 | fltk::Widget* o; |
---|
3106 | o = mStrips = new fltk::Widget(354, 3, 30, 15, "Strips"); |
---|
3107 | o->box(fltk::NO_BOX); |
---|
3108 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
3109 | o->color((fltk::Color)0xe0dfe300); |
---|
3110 | } |
---|
3111 | |
---|
3112 | { |
---|
3113 | fltk::Widget* o; |
---|
3114 | o = mMB = new fltk::Widget(740, 3, 30, 15, "MB"); |
---|
3115 | o->box(fltk::NO_BOX); |
---|
3116 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
3117 | o->color((fltk::Color)0xe0dfe300); |
---|
3118 | } |
---|
3119 | o->end(); |
---|
3120 | } |
---|
3121 | o->end(); |
---|
3122 | } |
---|
3123 | |
---|
3124 | fltk::focus(geoMeshView); |
---|
3125 | |
---|
3126 | /*Hide Right Panel*/ |
---|
3127 | hideRightPanel(); |
---|
3128 | |
---|
3129 | mMainWindow->show(); |
---|
3130 | } |
---|
3131 | |
---|
3132 | /****************/ |
---|
3133 | /* Destroyer */ |
---|
3134 | /****************/ |
---|
3135 | GeoMeshViewUI::~GeoMeshViewUI() |
---|
3136 | { |
---|
3137 | delete geoMeshLoader; |
---|
3138 | mMainWindow->destroy(); |
---|
3139 | } |
---|
3140 | |
---|
3141 | // Shows the main window. |
---|
3142 | void GeoMeshViewUI::show() |
---|
3143 | { |
---|
3144 | } |
---|
3145 | |
---|
3146 | // Build Textures menu. |
---|
3147 | void GeoMeshViewUI::BuildLoadTextureSubMeshMenu(void) |
---|
3148 | { |
---|
3149 | if (SubMeshNames) |
---|
3150 | { |
---|
3151 | menuLoadTextures->clear(); |
---|
3152 | |
---|
3153 | for (int i = 0; i < numSubMeshNames; i++) |
---|
3154 | { |
---|
3155 | delete[] SubMeshNames[i]; |
---|
3156 | } |
---|
3157 | delete[] SubMeshNames; |
---|
3158 | } |
---|
3159 | |
---|
3160 | menuFileLoadTexture = new fltk::Item("Entire model"); |
---|
3161 | |
---|
3162 | menuFileLoadTexture->callback((fltk::Callback*)cb_menuFileLoadTexture); |
---|
3163 | menuLoadTextures->add(menuFileLoadTexture); |
---|
3164 | |
---|
3165 | numSubMeshNames = geoMeshView->getSubMeshCount(); |
---|
3166 | SubMeshNames = new char*[numSubMeshNames]; |
---|
3167 | |
---|
3168 | for (int i = 0; i < numSubMeshNames; i++) |
---|
3169 | { |
---|
3170 | SubMeshNames[i] = new char[10]; |
---|
3171 | |
---|
3172 | sprintf(SubMeshNames[i],"submesh %d",i); |
---|
3173 | |
---|
3174 | fltk::Item *item = new fltk::Item(SubMeshNames[i]); |
---|
3175 | |
---|
3176 | item->callback((fltk::Callback*)cb_menuFileLoadTextureSubMesh); |
---|
3177 | menuLoadTextures->add(item); |
---|
3178 | } |
---|
3179 | } |
---|
3180 | |
---|