forked from Najelith/ddmod-tool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodeleditor.cpp
3092 lines (2619 loc) · 107 KB
/
modeleditor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "modeleditor.h"
ModelEditor::ModelEditor(QMainWindow *parent) : QMainWindow(parent)
{
if (this->objectName().isEmpty())
this->setObjectName(QStringLiteral("Model Editor"));
this->resize(700, 280);
//setup menu
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
QToolBar *fileToolBar = addToolBar(tr("File"));
const QIcon newIcon(":/resources/Resource/icon_lot.png");
QAction *newOpenMod = new QAction(newIcon, tr("&Open"), this);
newOpenMod->setShortcuts(QKeySequence::Open);
newOpenMod->setStatusTip(tr("Open a .mod File.."));
// connect(newLetterAct, &QAction::triggered, this, &MainWindow::newLetter);
connect(newOpenMod,SIGNAL(triggered(bool)),this,SLOT(on_Open_clicked()));
fileMenu->addAction(newOpenMod);
fileToolBar->addAction(newOpenMod);
const QIcon saveIcon = QIcon(":/resources/Resource/icon_stone.png");
QAction *saveAct = new QAction(saveIcon, tr("&Save..."), this);
saveAct->setShortcuts(QKeySequence::Save);
saveAct->setStatusTip(tr("Save the current Model"));
// connect(saveAct, &QAction::triggered, this, &MainWindow::save);
connect(saveAct,SIGNAL(triggered(bool)),this,SLOT(on_Save_clicked()));
fileMenu->addAction(saveAct);
fileToolBar->addAction(saveAct);
fileMenu->addSeparator();
QAction *quitAct = fileMenu->addAction(tr("&Quit"), this, SLOT(close()));
quitAct->setShortcuts(QKeySequence::Quit);
quitAct->setStatusTip(tr("Quit the Model Editor"));
/*
QMenu *editMenu = menuBar()->addMenu(tr("&Edit"));
QToolBar *editToolBar = addToolBar(tr("Edit"));
const QIcon undoIcon = QIcon::fromTheme("edit-undo", QIcon(":/images/undo.png"));
QAction *undoAct = new QAction(undoIcon, tr("&Undo"), this);
undoAct->setShortcuts(QKeySequence::Undo);
undoAct->setStatusTip(tr("Undo the last editing action"));
connect(undoAct, &QAction::triggered, this, &MainWindow::undo);
editMenu->addAction(undoAct);
editToolBar->addAction(undoAct);
*/
viewMenu = menuBar()->addMenu(tr("&View"));
QMenu *renderMenu = menuBar()->addMenu(tr("&Render"));
menuBar()->addSeparator();
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
QAction *aboutAct = helpMenu->addAction(tr("&About"), this, SLOT(about()));
aboutAct->setStatusTip(tr("what do you want? go away"));
//setup menu
outerLayout = new QVBoxLayout;
insideboxLayout = new QVBoxLayout;
groupBox = new QGroupBox(this);
groupBox->setLayout(insideboxLayout);
groupBox->setObjectName(QStringLiteral("groupBox"));
// groupBox->setGeometry(QRect(10, 20, 385, 201));
// layoutWidget = new QWidget(groupBox);
// layoutWidget->setObjectName(QStringLiteral("layoutWidget"));
// layoutWidget->setGeometry(QRect(10, 110, 397, 92));
verticalLayout = new QHBoxLayout;
// verticalLayout->setSpacing(6);
// verticalLayout->setContentsMargins(11, 11, 11, 11);
// verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
// verticalLayout->setContentsMargins(0, 0, 0, 0);
rdoSingle = new QRadioButton;
rdoSingle->setObjectName(QStringLiteral("rdoSingle"));
verticalLayout->addWidget(rdoSingle);
rdoPooled = new QRadioButton;
rdoPooled->setObjectName(QStringLiteral("rdoPooled"));
rdoPooled->setChecked(true);
verticalLayout->addWidget(rdoPooled);
rdoTheaded = new QRadioButton;
rdoTheaded->setObjectName(QStringLiteral("rdoTheaded"));
verticalLayout->addWidget(rdoTheaded);
spinBox = new QLineEdit(groupBox);
spinBox->setObjectName(QStringLiteral("spinBox"));
// spinBox->setGeometry(QRect(58, 78, 70, 23));
// spinBox->setMaximum(64000);
// spinBox->setValue(52100);
label = new QLabel(groupBox);
label->setObjectName(QStringLiteral("label"));
// label->setGeometry(QRect(20, 80, 29, 16));
label_3 = new QLabel(groupBox);
label_3->setObjectName(QStringLiteral("label_3"));
//label_3->setGeometry(QRect(20, 40, 59, 14));
cmbAddress = new QComboBox(groupBox);
cmbAddress->setObjectName(QStringLiteral("cmbAddress"));
// cmbAddress->setGeometry(QRect(80, 40, 281, 22));
horizontalLayout_0 = new QHBoxLayout;
horizontalLayout_0->addWidget(label_3);
horizontalLayout_0->addWidget(cmbAddress);
spinboxIdle = new QLineEdit(groupBox);
spinboxIdle->setObjectName(QStringLiteral("spinboxIdle"));
// spinboxIdle->setGeometry(QRect(270, 80, 70, 23));
// spinboxIdle->setMaximum(64000);
// spinboxIdle->setValue(30000);
label_4 = new QLabel(groupBox);
label_4->setObjectName(QStringLiteral("label_4"));
// label_4->setGeometry(QRect(240, 80, 31, 16));
// layoutWidget1 = new QWidget(this);
// layoutWidget1->setObjectName(QStringLiteral("layoutWidget1"));
// layoutWidget1->setGeometry(QRect(180, 240, 239, 38));
horizontalLayout_2 = new QHBoxLayout;
// horizontalLayout_2->setSpacing(6);
// horizontalLayout_2->setContentsMargins(11, 11, 11, 11);
horizontalLayout_2->setObjectName(QStringLiteral("horizontalLayout_2"));
// horizontalLayout_2->setContentsMargins(0, 0, 0, 0);
btnListen = new QPushButton;
btnListen->setObjectName(QStringLiteral("btnListen"));
horizontalLayout_2->addWidget(btnListen);
btnClose = new QPushButton;
btnClose->setObjectName(QStringLiteral("btnClose"));
horizontalLayout_2->addWidget(btnClose);
meshcount = new QLineEdit(groupBox);
label_meshcount = new QLabel(groupBox);
materialcount = new QLineEdit(groupBox);
label_materialcount = new QLabel(groupBox);
vertexcount = new QLineEdit(groupBox);
label_vertexcount = new QLabel(groupBox);
horizontalLayout_3 = new QHBoxLayout;
horizontalLayout_3->addWidget(label_materialcount);
horizontalLayout_3->addWidget(materialcount);
horizontalLayout_3->addWidget(label_vertexcount);
horizontalLayout_3->addWidget(vertexcount);
facecount = new QLineEdit(groupBox);
label_facecount = new QLabel(groupBox);
vertexids = new QLineEdit(groupBox);
label_vertexids = new QLabel(groupBox);
vertexbuffersize = new QLineEdit(groupBox);
label_vertexbuffersize = new QLabel(groupBox);
horizontalLayout_4 = new QHBoxLayout;
horizontalLayout_4->addWidget(label_facecount);
horizontalLayout_4->addWidget(facecount);
horizontalLayout_4->addWidget(label_vertexids);
horizontalLayout_4->addWidget(vertexids);
horizontalLayout_4->addWidget(label_vertexbuffersize);
horizontalLayout_4->addWidget(vertexbuffersize);
secondbuffersize = new QLineEdit(groupBox);
label_secondbuffersize = new QLabel(groupBox);
groupcount = new QLineEdit(groupBox);
label_groupcount = new QLabel(groupBox);
bonesoffset = new QLineEdit(groupBox);
label_bonesoffset = new QLabel(groupBox);
horizontalLayout_5 = new QHBoxLayout;
horizontalLayout_5->addWidget(label_secondbuffersize);
horizontalLayout_5->addWidget(secondbuffersize);
horizontalLayout_5->addWidget(label_groupcount);
horizontalLayout_5->addWidget(groupcount);
horizontalLayout_5->addWidget(label_bonesoffset);
horizontalLayout_5->addWidget(bonesoffset);
groupoffset = new QLineEdit(groupBox);
label_groupoffset = new QLabel(groupBox);
textureoffset = new QLineEdit(groupBox);
label_textureoffset = new QLabel(groupBox);
meshoffset = new QLineEdit(groupBox);
label_meshoffset = new QLabel(groupBox);
horizontalLayout_6 = new QHBoxLayout;
horizontalLayout_6->addWidget(label_groupoffset);
horizontalLayout_6->addWidget(groupoffset);
horizontalLayout_6->addWidget(label_textureoffset);
horizontalLayout_6->addWidget(textureoffset);
horizontalLayout_6->addWidget(label_meshoffset);
horizontalLayout_6->addWidget(meshoffset);
vertexoffset = new QLineEdit(groupBox);
label_vertexoffset = new QLabel(groupBox);
facesoffset = new QLineEdit(groupBox);
label_facesoffset = new QLabel(groupBox);
unkoffset = new QLineEdit(groupBox);
label_unkoffset = new QLabel(groupBox);
horizontalLayout_7 = new QHBoxLayout;
horizontalLayout_7->addWidget(label_vertexoffset);
horizontalLayout_7->addWidget(vertexoffset);
horizontalLayout_7->addWidget(label_facesoffset);
horizontalLayout_7->addWidget(facesoffset);
horizontalLayout_7->addWidget(label_unkoffset);
horizontalLayout_7->addWidget(unkoffset);
horizontalLayout_1 = new QHBoxLayout;
horizontalLayout_1->addWidget(label);
horizontalLayout_1->addWidget(spinBox);
spinBox->setToolTip("Mt Framework Version? ddon:210 dd;da:212");
horizontalLayout_1->addWidget(label_4);
horizontalLayout_1->addWidget(spinboxIdle);
horizontalLayout_1->addWidget(label_meshcount);
horizontalLayout_1->addWidget(meshcount);
// new lazy stuff
label_bounding_boxmin = new QLabel(groupBox);
bounding_boxminx = new QLineEdit(groupBox);
bounding_boxminx->setToolTip("Bounding Box Min X");
bounding_boxminy = new QLineEdit(groupBox);
bounding_boxminy->setToolTip("Bounding Box Min Y");
bounding_boxminz = new QLineEdit(groupBox);
bounding_boxminz->setToolTip("Bounding Box Min Z");
bounding_boxminw = new QLineEdit(groupBox);
boundingboxminhLayout = new QHBoxLayout;
boundingboxminhLayout->addWidget(label_bounding_boxmin);
boundingboxminhLayout->addWidget(bounding_boxminx);
boundingboxminhLayout->addWidget(bounding_boxminy);
boundingboxminhLayout->addWidget(bounding_boxminz);
boundingboxminhLayout->addWidget(bounding_boxminw);
label_bounding_boxmax = new QLabel(groupBox);
bounding_boxmaxx = new QLineEdit(groupBox);
bounding_boxmaxx->setToolTip("Bounding Box Max X");
bounding_boxmaxy = new QLineEdit(groupBox);
bounding_boxmaxy->setToolTip("Bounding Box Max Y");
bounding_boxmaxz = new QLineEdit(groupBox);
bounding_boxmaxz->setToolTip("Bounding Box Max Z");
bounding_boxmaxw = new QLineEdit(groupBox);
boundingboxmaxhLayout = new QHBoxLayout;
boundingboxmaxhLayout->addWidget(label_bounding_boxmax);
boundingboxmaxhLayout->addWidget(bounding_boxmaxx);
boundingboxmaxhLayout->addWidget(bounding_boxmaxy);
boundingboxmaxhLayout->addWidget(bounding_boxmaxz);
boundingboxmaxhLayout->addWidget(bounding_boxmaxw);
label_bounding_sphere = new QLabel(groupBox);
bounding_spherex = new QLineEdit(groupBox);
bounding_spherex->setToolTip("Center X");
bounding_spherey = new QLineEdit(groupBox);
bounding_spherey->setToolTip("Center Y");
bounding_spherez = new QLineEdit(groupBox);
bounding_spherez->setToolTip("Center Z");
bounding_spherew = new QLineEdit(groupBox);
bounding_spherew->setToolTip("Radius");
boundingspherehLayout = new QHBoxLayout;
boundingspherehLayout->addWidget(label_bounding_sphere);
boundingspherehLayout->addWidget(bounding_spherex);
boundingspherehLayout->addWidget(bounding_spherey);
boundingspherehLayout->addWidget(bounding_spherez);
boundingspherehLayout->addWidget(bounding_spherew);
QHBoxLayout* unkchunk1hLayout = new QHBoxLayout;
label_h_unkn02 = new QLabel(groupBox);
h_unkn02 = new QLineEdit(groupBox);
h_unkn02->setToolTip("1000, relates to an id system.");
label_h_unkn03 = new QLabel(groupBox);
h_unkn03 = new QLineEdit(groupBox);
h_unkn03->setToolTip("3000 unkown.");
label_h_unkn04 = new QLabel(groupBox);
h_unkn04 = new QLineEdit(groupBox);
h_unkn04->setToolTip("layering info, usually 1");
label_h_unkn05 = new QLabel(groupBox);
h_unkn05 = new QLineEdit(groupBox);
label_h_unkn06 = new QLabel(groupBox);
h_unkn06 = new QLineEdit(groupBox);
unkchunk1hLayout->addWidget(label_h_unkn02);
unkchunk1hLayout->addWidget(h_unkn02);
unkchunk1hLayout->addWidget(label_h_unkn03);
unkchunk1hLayout->addWidget(h_unkn03);
unkchunk1hLayout->addWidget(label_h_unkn04);
unkchunk1hLayout->addWidget(h_unkn04);
QHBoxLayout* unkchunk2hLayout = new QHBoxLayout;
unkchunk2hLayout->addWidget(label_h_unkn05);
unkchunk2hLayout->addWidget(h_unkn05);
unkchunk2hLayout->addWidget(label_h_unkn06);
unkchunk2hLayout->addWidget(h_unkn06);
//new lazy stuff
insideboxLayout->addLayout(horizontalLayout_0);
insideboxLayout->addLayout(horizontalLayout_1);
insideboxLayout->addLayout(horizontalLayout_3);
insideboxLayout->addLayout(horizontalLayout_4);
insideboxLayout->addLayout(horizontalLayout_5);
insideboxLayout->addLayout(horizontalLayout_6);
insideboxLayout->addLayout(horizontalLayout_7);
insideboxLayout->addLayout(boundingspherehLayout);
insideboxLayout->addLayout(boundingboxminhLayout);
insideboxLayout->addLayout(boundingboxmaxhLayout);
insideboxLayout->addLayout(unkchunk1hLayout);
insideboxLayout->addLayout(unkchunk2hLayout);
insideboxLayout->addLayout(verticalLayout);
outerLayout->addWidget(groupBox);
outerLayout->addLayout(horizontalLayout_2);
// QVBoxLayout *textures = new QVBoxLayout(groupBox);
difflabel = new QLabel;
speclabel = new QLabel;
normlabel = new QLabel;
litelabel = new QLabel;
diffscroll = new QScrollArea;
specscroll = new QScrollArea;
normscroll = new QScrollArea;
litescroll = new QScrollArea;
diffscroll->setWidgetResizable(true);
specscroll->setWidgetResizable(true);
normscroll->setWidgetResizable(true);
litescroll->setWidgetResizable(true);
diffscroll->setWidget(difflabel);
specscroll->setWidget(speclabel);
normscroll->setWidget(normlabel);
litescroll->setWidget(litelabel);
// textures->addWidget(difflabel);
// textures->addWidget(speclabel);
// textures->addWidget(normlabel);
// textures->addWidget(litelabel);
// outerLayout->addLayout(textures);
this->setWindowTitle(QApplication::translate("ModelEditor", "Model Editor", 0));
// groupBox->setTitle(QApplication::translate("ModelEditor", "Headers", 0));
rdoSingle->setText(QApplication::translate("ModelEditor", "DDON", 0));
rdoPooled->setText(QApplication::translate("ModelEditor", "DD;DA", 0));
rdoTheaded->setText(QApplication::translate("ModelEditor", "DD;DA (PS3)", 0));
label->setText(QApplication::translate("ModelEditor", "Version:", 0));
label_3->setText(QApplication::translate("ModelEditor", "File:", 0));
label_4->setText(QApplication::translate("ModelEditor", "Bone Count:", 0));
btnListen->setText(QApplication::translate("ModelEditor", "Open", 0));
btnClose->setText(QApplication::translate("ModelEditor", "Save", 0));
label_meshcount->setText(QApplication::translate("ModelEditor", "Mesh Count: ", 0));
label_materialcount->setText(QApplication::translate("ModelEditor", "Material Count: ", 0));
label_vertexcount->setText(QApplication::translate("ModelEditor", "Vertex Count: ", 0));
label_facecount->setText(QApplication::translate("ModelEditor", "Face Count: ", 0));
label_vertexids->setText(QApplication::translate("ModelEditor", "Vertex Ids: ", 0));
label_vertexbuffersize->setText(QApplication::translate("ModelEditor", "Vertex Buffer Size: ", 0));
label_secondbuffersize->setText(QApplication::translate("ModelEditor", "Second Buffer Size: ", 0));
label_groupcount->setText(QApplication::translate("ModelEditor", "Group Count: ", 0));
label_bonesoffset->setText(QApplication::translate("ModelEditor", "Bones Offset: ", 0));
label_groupoffset->setText(QApplication::translate("ModelEditor", "Group Offset: ", 0));
label_textureoffset->setText(QApplication::translate("ModelEditor", "Texture Offset: ", 0));
label_meshoffset->setText(QApplication::translate("ModelEditor", "Mesh Offset: ", 0));
label_vertexoffset->setText(QApplication::translate("ModelEditor", "Vertex Offset: ", 0));
label_facesoffset->setText(QApplication::translate("ModelEditor", "Faces Offset: ", 0));
label_unkoffset->setText(QApplication::translate("ModelEditor", "Unknown Offset: ", 0));
label_bounding_sphere->setText(QApplication::translate("ModelEditor", "Bounding Sphere: ", 0));
label_bounding_boxmin->setText(QApplication::translate("ModelEditor", "Bounding Box Min: ", 0));
label_bounding_boxmax->setText(QApplication::translate("ModelEditor", "Bounding Box Max: ", 0));
label_h_unkn02->setText(QApplication::translate("ModelEditor", "Mid Dist: ", 0));
label_h_unkn03->setText(QApplication::translate("ModelEditor", "Low Dist: ", 0));
label_h_unkn04->setText(QApplication::translate("ModelEditor", "Light Group: ", 0));
label_h_unkn05->setText(QApplication::translate("ModelEditor", "Memory: ", 0));
label_h_unkn06->setText(QApplication::translate("ModelEditor", "Boundy Count: ", 0));
// renderer
MainWidget *r = new MainWidget;
r->addMainMenu(renderMenu);
r->setWindowTitle(QApplication::translate("Renderer", "Model Viewer", 0));
// r->show();
/* buttons
connect(btnListen,SIGNAL(clicked(bool)),this,SLOT(on_btnListen_clicked()));
connect(btnClose,SIGNAL(clicked(bool)),this,SLOT(on_btnClose_clicked()));
connect(cmbAddress,SIGNAL(activated(QString)),this,SLOT(on_addr_changed(QString)));
*/
// this->setLayout(outerLayout);
QDockWidget *dock = new QDockWidget(tr("Headers"),this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
QScrollArea *scroll = new QScrollArea;
scroll->setWidgetResizable(true);
scroll->setWidget(groupBox);
dock->setWidget(scroll);
// dock->setFloating(true);
addDockWidget(Qt::LeftDockWidgetArea,dock);
viewMenu->addAction(dock->toggleViewAction());
// r->showNormal();
/*
dock = new QDockWidget(tr("Model Viewer"),this);
dock->setWidget(r);
//dock->setFloating(true);
addDockWidget(Qt::RightDockWidgetArea,dock);
*/
// outerLayout->addWidget(r);
// this->setLayout(outerLayout);
this->setCentralWidget(r);
// bones
dock = new QDockWidget(tr("Bones"),this);
QGroupBox * bonesbox = new QGroupBox(dock);
bonesbox->setObjectName(QStringLiteral("Bones"));
bonetabs = new QTabWidget(bonesbox);
QVBoxLayout * boneboxlayout = new QVBoxLayout;
bonesbox->setLayout(boneboxlayout);
boneboxlayout->addWidget(bonetabs);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
dock->setWidget(bonesbox);
addDockWidget(Qt::LeftDockWidgetArea,dock);
viewMenu->addAction(dock->toggleViewAction());
// bone remaptable
dock = new QDockWidget(tr("Bone Remap Table"),this);
QGroupBox * bonesmbox = new QGroupBox(dock);
bonesmbox->setObjectName(QStringLiteral("Bone Remap Table"));
bonemaptv = new QTableView;
bonemapmodel = new QStandardItemModel;
bonemaptv->setModel(bonemapmodel);
bonemaptv->setWindowTitle(QString("Bone Remap Table"));
QVBoxLayout * bonemboxlayout = new QVBoxLayout;
bonesmbox->setLayout(bonemboxlayout);
bonemboxlayout->addWidget(bonemaptv);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
dock->setWidget(bonesmbox);
addDockWidget(Qt::LeftDockWidgetArea,dock);
viewMenu->addAction(dock->toggleViewAction());
// groups
dock = new QDockWidget(tr("Groups"),this);
QGroupBox * Groupsbox = new QGroupBox(dock);
Groupsbox->setObjectName(QStringLiteral("Groups"));
Groupstabs = new QTabWidget(Groupsbox);
QVBoxLayout * Groupsboxlayout = new QVBoxLayout;
Groupsbox->setLayout(Groupsboxlayout);
Groupsboxlayout->addWidget(Groupstabs);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
dock->setWidget(Groupsbox);
addDockWidget(Qt::LeftDockWidgetArea,dock);
viewMenu->addAction(dock->toggleViewAction());
// Materials
dock = new QDockWidget(tr("Materials"),this);
QGroupBox * Materialsbox = new QGroupBox(dock);
Materialsbox->setObjectName(QStringLiteral("Materials"));
Materialstabs = new QTabWidget(Materialsbox);
QVBoxLayout * Materialsboxlayout = new QVBoxLayout;
Materialsbox->setLayout(Materialsboxlayout);
Materialsboxlayout->addWidget(Materialstabs);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
dock->setWidget(Materialsbox);
addDockWidget(Qt::LeftDockWidgetArea,dock);
viewMenu->addAction(dock->toggleViewAction());
// Mesh Parts
dock = new QDockWidget(tr("Mesh Parts"),this);
QGroupBox * MeshPartsbox = new QGroupBox(dock);
MeshPartsbox->setObjectName(QStringLiteral("Mesh Parts"));
MeshPartstabs = new QTabWidget(MeshPartsbox);
QVBoxLayout * MeshPartsboxlayout = new QVBoxLayout;
MeshPartsbox->setLayout(MeshPartsboxlayout);
MeshPartsboxlayout->addWidget(MeshPartstabs);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
dock->setWidget(MeshPartsbox);
addDockWidget(Qt::RightDockWidgetArea,dock);
viewMenu->addAction(dock->toggleViewAction());
// Weights
dock = new QDockWidget(tr("Weights"),this);
QGroupBox * Weightsbox = new QGroupBox(dock);
Weightsbox->setObjectName(QStringLiteral("Weights"));
Weightstabs = new QTabWidget(Weightsbox);
QVBoxLayout * Weightsboxlayout = new QVBoxLayout;
Weightsbox->setLayout(Weightsboxlayout);
Weightsboxlayout->addWidget(Weightstabs);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
dock->setWidget(Weightsbox);
addDockWidget(Qt::RightDockWidgetArea,dock);
viewMenu->addAction(dock->toggleViewAction());
// Textures
dock = new QDockWidget(tr("Textures"),this);
QGroupBox * Texturesbox = new QGroupBox(dock);
Texturesbox->setObjectName(QStringLiteral("Textures"));
Texturestabs = new QTabWidget(Texturesbox);
QVBoxLayout * Texturesboxlayout = new QVBoxLayout;
Texturesbox->setLayout(Texturesboxlayout);
Texturesboxlayout->addWidget(Texturestabs);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
dock->setWidget(Texturesbox);
addDockWidget(Qt::RightDockWidgetArea,dock);
viewMenu->addAction(dock->toggleViewAction());
// VBOs
dock = new QDockWidget(tr("Mesh Data"),this);
QGroupBox * MeshDatabox = new QGroupBox(dock);
MeshDatabox->setObjectName(QStringLiteral("Mesh Data"));
MeshDatatabs = new QTabWidget(MeshDatabox);
QVBoxLayout * MeshDataboxlayout = new QVBoxLayout;
MeshDatabox->setLayout(MeshDataboxlayout);
MeshDataboxlayout->addWidget(MeshDatatabs);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
dock->setWidget(MeshDatabox);
addDockWidget(Qt::BottomDockWidgetArea,dock);
viewMenu->addAction(dock->toggleViewAction());
// progress bar (for loading or saving)
mProgressbar = new QProgressBar(this);
mProgressbar->setMaximum(100);
mProgressbar->setMinimum(0);
mProgressbar->setTextVisible(true);
mProgressbar->setValue(0);
mProgressbar->setVisible(false);
// status bar
mStatusbar = new QStatusBar(this);
mStatusbar->addPermanentWidget(mProgressbar);
mStatusbar->showMessage(tr("Ready."));
this->setStatusBar(mStatusbar);
// renderer connections
connect(this,SIGNAL(newTextures(const QImage&,const QImage&,const QImage&,const QImage&)),r,SLOT(onNewTextures(const QImage&,const QImage&,const QImage&,const QImage&)));
connect(this,SIGNAL(NewMeshData(std::vector<int>&,std::vector<std::vector<VertexData> >&,std::vector<std::vector<uint> >&)),r,SLOT(onNewMesh(std::vector<int>&,std::vector<std::vector<VertexData> >&,std::vector<std::vector<uint> >&)));
connect(this,SIGNAL(newMeshPartSelection(std::vector<int>&)),r,SLOT(onNewMeshselect(std::vector<int>&)));
// file change shit connections
connect(cmbAddress,SIGNAL(activated(QString)),this,SLOT(on_File_changed(QString)));
QIcon icon(":/resources/Resource/icon.png");
this->setWindowIcon(icon);
// QStringList lst = server.getAddresses();
// ui->
// cmbAddress->insertItems(0,lst);
// ui->
// cmbAddress->insertItem(0,"Any");
// ui->
// cmbAddress->setCurrentIndex(0);
// establish known blocktypes
blocktype[0x0CB68015]="4s4c4c4c";
blocktype[0x14D40020]="3s1s4c4c4c2h2h";
blocktype[0x5E7F202C]="3f4c4c2h2h";
blocktype[0x926FD02E]="3f4c4c2h2h4c";
blocktype[0xA320C016]="4s8c8c4c";
blocktype[0xA7D7D036]="3f4c2h";
blocktype[0xA8FAB018]="3s1s4c4c2h";
blocktype[0xB0983013]="3s1s4c";
blocktype[0xBB424024]="3s1s4c4c8c2h2h4c";
blocktype[0xC31F201C]="3s1s4c4c2h2h";
blocktype[0xD8297028]="3f4c4c2h";
blocktype[0xDB7DA014]="3s1s4c2s";
unktypesfound = 0; //initalize me
}
ModelEditor::~ModelEditor()
{
// cleanup
}
void ModelEditor::open_file(QString fileName)
{
Texturestabs->clear();
// try to open textures as well
int txcheck = fileName.lastIndexOf(QChar('.'));
QString tx = txcheck > 0 ? fileName.left(txcheck) : fileName;
// qDebug() <<tx;
QPixmap pixmap(tx + "_BM.dds");
if (pixmap.isNull())
pixmap.load(tx + "_NUKI.dds");
difflabel->setPixmap(pixmap);
// difflabel->show();
Texturestabs->addTab(diffscroll,"Diffuse");
QPixmap pixmap2(tx + "_CMM.dds");
if (pixmap2.isNull())
pixmap2.load(tx + "_MM.dds");
speclabel->setPixmap(pixmap2);
// speclabel->show();
Texturestabs->addTab(specscroll,"Specular");
QPixmap pixmap3(tx + "_NM.dds");
if (pixmap3.isNull())
pixmap3.load(tx + "_NM_HQ.dds");
normlabel->setPixmap(pixmap3);
// normlabel->show();
Texturestabs->addTab(normscroll,"Normal");
QPixmap pixmap4(tx + "_TM.dds");
litelabel->setPixmap(pixmap4);
// litelabel->show();
Texturestabs->addTab(litescroll,"Light");
// clear old selection
sel.clear();
selection.assign(selection.size(), 0);
emit this->newMeshPartSelection(selection);
FILE *Filep;
Filep = fopen(fileName.toLocal8Bit().constData(), "rb");
if (Filep == NULL) {
QMessageBox msgBox;
msgBox.setText(QString("Error Reading File: \n").append(fileName.toLocal8Bit().constData()));
msgBox.exec();
return;
}
size_t Fsize;
char *buffer;
size_t result;
// get file size
fseek(Filep, 0, SEEK_END);
Fsize = ftell(Filep);
rewind(Filep);
// allocate memory to contain the whole file:
buffer = (char *)malloc(sizeof(char)*Fsize);
if (buffer == NULL) {
//fputs("Memory error", stderr);
QMessageBox msgBox;
msgBox.setText("Memory Error: buffer is NULL. did you select a file? \n" +fileName);
msgBox.exec();
return;
// exit(2);
}
// copy the file into the buffer:
result = fread(buffer, 1, Fsize, Filep);
if (result != Fsize) {
// fputs("Reading error", stderr);
QMessageBox msgBox;
msgBox.setText("Read Error: unable to read file: \n" +fileName);
msgBox.exec();
return;
// exit(3);
}
// file should have been opened emit file to renderer
emit this->newTextures(pixmap.toImage(), pixmap2.toImage(), pixmap3.toImage(), pixmap4.toImage());
mProgressbar->setVisible(true);
mProgressbar->setMaximum(Fsize);
mProgressbar->setMinimum(0);
mProgressbar->setValue(0);
// copy value into readable
//long test;
//memcpy(&test,&id.data()[0],4);
unknownblocktypes.clear();
unktypesfound =0;
////////////////////////// reading header
uint offset = 0;
quint32 id = read_u32le(buffer,offset);
if (id == 0x00444F4D) {
read_file_le(buffer); //pc
spinBox->setText(QString::number(Mheader.version)); // version
spinboxIdle->setText(QString::number(Mheader.bonecount)); //bone count
meshcount->setText(QString::number(Mheader.meshcount));
materialcount->setText(QString::number(Mheader.materialcount));
vertexcount->setText(QString::number(Mheader.vertexcount));
facecount->setText(QString::number(Mheader.facecount));
vertexids->setText(QString::number(Mheader.vertexids));
vertexbuffersize->setText(QString::number(Mheader.vertexbuffersize));
secondbuffersize->setText(QString::number(Mheader.secondbuffersize));
groupcount->setText(QString::number(Mheader.groupcount));
bonesoffset->setText(QString::number(Mheader.bonesoffset));
groupoffset->setText(QString::number(Mheader.groupoffset));
textureoffset->setText(QString::number(Mheader.textureoffset));
meshoffset->setText(QString::number(Mheader.meshoffset));
vertexoffset->setText(QString::number(Mheader.vertexoffset));
facesoffset->setText(QString::number(Mheader.facesoffset));
unkoffset->setText(QString::number(Mheader.unkoffset));
entervaluestogui();
switch (Mheader.version) {
case 212:
rdoPooled->click();
break;
case 210:
rdoSingle->click();
break;
}
if (unktypesfound>0) {
QString msg = "Unknown VBO Format(s): \n";
for (auto const& x : unknownblocktypes) {
msg.append(QString::number(x.first,16));
msg.append("\n");
}
msg.append("\n!!!DATA SKIPPED!!!! \n Please report this along with the file you used.");
QMessageBox msgBox;
msgBox.setText(msg);
msgBox.exec();
mProgressbar->setValue(Fsize);
mProgressbar->setVisible(false);
mStatusbar->showMessage("File NOT Loaded: Unknown VBO formats");
}
else {
mProgressbar->setValue(Fsize);
mProgressbar->setVisible(false);
mStatusbar->showMessage("File Loaded.");
}
}
else if (id == 0x4D4F4400) {
read_file_be(buffer); //ps3?
spinBox->setText(QString::number(Mheader.version)); // version
spinboxIdle->setText(QString::number(Mheader.bonecount)); //bone count
meshcount->setText(QString::number(Mheader.meshcount));
materialcount->setText(QString::number(Mheader.materialcount));
vertexcount->setText(QString::number(Mheader.vertexcount));
facecount->setText(QString::number(Mheader.facecount));
vertexids->setText(QString::number(Mheader.vertexids));
vertexbuffersize->setText(QString::number(Mheader.vertexbuffersize));
secondbuffersize->setText(QString::number(Mheader.secondbuffersize));
groupcount->setText(QString::number(Mheader.groupcount));
bonesoffset->setText(QString::number(Mheader.bonesoffset));
groupoffset->setText(QString::number(Mheader.groupoffset));
textureoffset->setText(QString::number(Mheader.textureoffset));
meshoffset->setText(QString::number(Mheader.meshoffset));
vertexoffset->setText(QString::number(Mheader.vertexoffset));
facesoffset->setText(QString::number(Mheader.facesoffset));
unkoffset->setText(QString::number(Mheader.unkoffset));
entervaluestogui();
switch (Mheader.version) {
case 212:
rdoTheaded->click();
break;
case 210:
rdoSingle->click();
break;
}
if (unktypesfound>0) {
QString msg = "Unknown VBO Format(s): \n";
for (auto const& x : unknownblocktypes) {
msg.append(QString::number(x.first,16));
msg.append("\n");
}
msg.append("\n!!!DATA SKIPPED!!!! \n Please report this along with the file you used.");
QMessageBox msgBox;
msgBox.setText(msg);
msgBox.exec();
mProgressbar->setValue(Fsize);
mProgressbar->setVisible(false);
mStatusbar->showMessage("File NOT Loaded: Unknown VBO formats");
}
else {
mProgressbar->setValue(Fsize);
mProgressbar->setVisible(false);
mStatusbar->showMessage("File Loaded.");
}
}
else {
QMessageBox msgBox;
msgBox.setText(QString("Unknown Mod File Header: %1").arg(Mheader.magic,8,16,QChar('0')));
msgBox.exec();
mProgressbar->setValue(0);
mProgressbar->setVisible(false);
mStatusbar->showMessage("File NOT Loaded.");
}
//file is done
fclose(Filep);
free(buffer);
}
void ModelEditor::read_file_le(char *buffer)
{
uint offset = 0;
////////////////////////// reading header
Mheader.magic = read_u32le(buffer,offset);
Mheader.version = read_u16le(buffer,offset);
Mheader.bonecount = read_u16le(buffer,offset);
Mheader.meshcount = read_u16le(buffer,offset);
Mheader.materialcount = read_u16le(buffer,offset);
Mheader.vertexcount = read_u32le(buffer,offset);
Mheader.facecount = read_u32le(buffer,offset);
Mheader.vertexids = read_u32le(buffer,offset);
Mheader.vertexbuffersize = read_u32le(buffer,offset);
Mheader.secondbuffersize = read_u32le(buffer,offset);
Mheader.groupcount = read_u32le(buffer,offset);
Mheader.bonesoffset = read_u32le(buffer,offset);
Mheader.groupoffset = read_u32le(buffer,offset);
Mheader.textureoffset = read_u32le(buffer,offset);
Mheader.meshoffset = read_u32le(buffer,offset);
Mheader.vertexoffset = read_u32le(buffer,offset);
Mheader.facesoffset = read_u32le(buffer,offset);
Mheader.unkoffset = read_u32le(buffer,offset);
read_sphere_le(buffer,offset,Mheader.bsphere);
read_aabb_le(buffer,offset,Mheader.bbox);
Mheader.info.middist = read_s32le(buffer,offset);
Mheader.info.lowdist = read_s32le(buffer,offset);
Mheader.info.lightgroup = read_u32le(buffer,offset);
Mheader.info.memory = read_u16le(buffer,offset);
Mheader.info.reserved = read_u16le(buffer,offset);
Mheader.boundarycount = read_u32le(buffer,offset);
////////////////////// reading bone data
offset = Mheader.bonesoffset;
Mbones.boneinfo.clear();
for (uint i=0;i<Mheader.bonecount;i++) {
MOD_Bone_Info binf;
//if version == 237 -> boneinfo2
if (Mheader.version == 237) {
binf.id = read_u16le(buffer,offset);
binf.parent = read_u8(buffer,offset);
binf.child = read_u8(buffer,offset);
binf.unk = 0;
}
else {
binf.id = read_u8(buffer,offset);
binf.parent = read_u8(buffer,offset);
binf.child = read_u8(buffer,offset);
binf.unk = read_u8(buffer,offset);
}
binf.radius = read_f32le(buffer,offset);
binf.length = read_f32le(buffer,offset);
read_vec3le(buffer,offset,binf.offset);
Mbones.boneinfo.push_back(binf);
}
Mbones.lmatrices.clear();
for (uint i=0;i<Mheader.bonecount;i++) {
Matrix mtx;
read_matrix_le(buffer,offset,mtx);
Mbones.lmatrices.push_back(mtx);
}
Mbones.amatrices.clear();
for (uint i=0;i<Mheader.bonecount;i++) {
Matrix mtx;
read_matrix_le(buffer,offset,mtx);
Mbones.amatrices.push_back(mtx);
}
uint remaptablesize = (Mheader.bonecount + 0xFF) & 0xFFFFFF00;
Mbones.remaptable.clear();
for (uint i=0;i<remaptablesize;i++) {
Mbones.remaptable.push_back(read_u8(buffer,offset));
}
////////////////////// reading group data
offset = Mheader.groupoffset;
Mgroups.groupinfo.clear();
for (uint i=0;i<Mheader.groupcount;i++) {
MOD_Group_Info ginf;
ginf.id = read_u32le(buffer,offset);
ginf.h1 = read_u32le(buffer,offset);
ginf.h2 = read_u32le(buffer,offset);
ginf.h3 = read_u32le(buffer,offset);
read_sphere_le(buffer,offset,ginf.bsphere);
Mgroups.groupinfo.push_back(ginf);
}
////////////////////// reading material data
offset = Mheader.textureoffset;
Mmats.name.clear();
for (uint i=0;i<Mheader.materialcount;i++) {
Mmats.name.push_back(read_material(buffer,offset));
}
///////////////////// reading mesh data
offset = Mheader.meshoffset;
Mparts.parts.clear();
for (uint i=0;i<Mheader.meshcount;i++) {
MOD_Mesh_Info mp;
mp.drawmode = read_u16le(buffer,offset);
mp.vertexcount = read_u16le(buffer,offset);
quint32 v = read_u32le(buffer,offset);
mp.id = v & 0xFFF; v >>= 12;
mp.material = v & 0xFFF; v >>= 12;
mp.lod = v;
v = read_u32le(buffer,offset);
mp.disp = v & 1; v >>= 1;
mp.shape = v & 1; v >>= 1;
mp.sort = v & 1; v >>= 1;
mp.weightcount = v & 0x1F; v >>= 5;
mp.alphapri = v & 0xFF; v >>= 8;
mp.blocksize = v & 0xFF; v >>= 8;
mp.topology = v & 0x3F; v >>= 6;
mp.binormalflip = v & 1; v >>= 1;
mp.bridge = v & 1;
mp.vertexsub = read_u32le(buffer,offset);
mp.vertexoffset = read_u32le(buffer,offset);
mp.blocktype = read_u32le(buffer,offset);
mp.faceoffset = read_u32le(buffer,offset);
mp.facecount = read_u32le(buffer,offset);
mp.facebase = read_u32le(buffer,offset);
mp.envelope = read_u8(buffer,offset);
mp.boneremapid = read_u8(buffer,offset);
mp.connectid = read_u16le(buffer,offset);
mp.minindex = read_u16le(buffer,offset);
mp.maxindex = read_u16le(buffer,offset);
mp.unklong = read_u32le(buffer,offset);
Mparts.parts.push_back(mp);
}
Mparts.chunks.clear();
for (uint i=0;i<Mheader.boundarycount;i++) {
MOD_Boundary_Info chunk;
chunk.bone = read_u32le(buffer,offset);
chunk.un2 = read_u32le(buffer,offset);
chunk.un3 = read_u32le(buffer,offset);
chunk.un4 = read_u32le(buffer,offset);
read_sphere_le(buffer,offset,chunk.sphere);
read_aabb_le(buffer,offset,chunk.aabb);
read_obb_le(buffer,offset,chunk.obb);
Mparts.chunks.push_back(chunk);
}
///////////////// reading vbo permesh part data
offset = Mheader.vertexoffset;
for (uint i=0;i<Mheader.meshcount;i++) {
MOD_Mesh_Info &mp = Mparts.parts[i];
auto it = blocktype.find(mp.blocktype);
if (it != blocktype.end())
{
const char *fmt = it->second;
for (uint j=0;j<mp.vertexcount;j++) {
std::vector<MOD_Value> vtx;
const char *s = fmt;
char c;
while ((c = *s) != 0)
{
s++;
uint n = c - '0';
if (n <= 9 && (c = *s) != 0)
{
s++;
for (uint k=0;k<n;k++)
{
MOD_Value val = {};
switch (c)