-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodel.cpp
5631 lines (4646 loc) · 154 KB
/
model.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
// Filename:- model.cpp
//
// non-format specific model routines entry point, calls format-specific code from within here
//
// ( This is the nice clean gateway module into all the evil crap I have to call from other codebases )
//
#include "stdafx.h"
#include "includes.h"
#include "ModViewTreeView.h"
#include "glm_code.h"
#include "R_Model.h"
#include "R_Surface.h"
#include "textures.h"
#include "TEXT.H"
#include "sequence.h"
#include "script.h"
#include "shader.h"
#include "skins.h"
//
#include "model.h"
static int Model_MultiSeq_GetSeqHint(ModelContainer_t *pContainer, bool bPrimary);
static void Model_MultiSeq_SetSeqHint(ModelContainer_t *pContainer, bool bPrimary, int iHint);
static bool Model_MultiSeq_EnsureSeqHintLegal(ModelContainer_t *pContainer, int iFrame, bool bPrimary);
#define sERROR_MODEL_NOT_LOADED "Error: Model not loaded, you shouldn't get here! -Ste"
#define sERROR_CONTAINER_NOT_FOUND "Error: Could not resolve model handle to container ptr, you shouldn't get here! -Ste"
#define sSECONDARY_ANIM_STATS_STRING "(Secondary anim)" // try and keep this fairly short, since it occupies roughly the same space as "bolt: <boltname>"
#define POINT_SCALE 64.0f
#define POINT_ST_SCALE 16384.0f
ModViewAppVars_t AppVars;
bool gbRenderInhibit = false; // MUST stay in this state except when loading a model
// some protos...
//
static void ModelDraw_InfoText_Totals(void);
static void ModelDraw_InfoText_Header(void);
static void R_ModelContainer_CallBack_InfoText(ModelContainer_t *pContainer, void *pvData);
typedef struct // simple struct for passing text data to callback functions during info printing (ZEROMEM'd)
{
int iTextY;
int iTextX;
int iPrevX;
int iTextXForVertStats;
char sString[1024];
int iTot_RenderedVerts;
int iTot_RenderedTris;
int iTot_RenderedSurfs;
int iTot_XformedG2Bones;
int iTot_RenderedBoneWeights;
int iTot_OmittedBoneWeights;
// auto-measure stuff, finding longest string for neater padding...
//
int iFrameDigitsNeeded;
int iAttachedViaCharsNeeded;
int iSequenceNameCharsNeeded;
int iModelNameCharsNeeded;
int iModelVertInfoCharsNeeded;
//
int iMostMultiLockedSequences;
bool bAnyMultiLockedSecondarySequences;
int iMultiLockedTextX;
} TextData_t;
TextData_t TextData;
double getDoubleTime (void)
{
return (double)clock() / (double)CLOCKS_PER_SEC;
}
// returns NULL if not attached to anything, else name of tag-surface or boltpoint
//
static LPCSTR Stats_GetParentAttachmentPointString(ModelContainer_t *pContainer)
{
LPCSTR psAttachedVia = (!pContainer->pBoneBolt_ParentContainer)?
((!pContainer->pSurfaceBolt_ParentContainer)?
NULL:
pContainer->pSurfaceBolt_ParentContainer->tSurfaceBolt_BoltPoints[pContainer->iSurfaceBolt_ParentBoltIndex].sAttachName.c_str())
:
pContainer->pBoneBolt_ParentContainer->tBoneBolt_BoltPoints[pContainer->iBoneBolt_ParentBoltIndex].sAttachName.c_str();
return psAttachedVia;
}
// returned string will be valid for printing, even if only blank...
//
static LPCSTR Stats_GetAttachmentString(ModelContainer_t *pContainer)
{
LPCSTR psAttachedVia = Stats_GetParentAttachmentPointString(pContainer);
LPCSTR psAttachmentString = va("%s", psAttachedVia?va("(bolt: \"%s\")",psAttachedVia):"");
return psAttachmentString;
}
static void R_ModelContainer_Apply_Actual(ModelContainer_t* pContainer, void (*pFunction) ( ModelContainer_t* pContainer, void *pvData), void *pvData, bool bFromBottomUp )
{
int iBoltPoint = 0;
if (!bFromBottomUp )
{
// process this...
//
pFunction(pContainer, pvData);
}
// process this container's bone bolts...
//
for (iBoltPoint=0; iBoltPoint < pContainer->iBoneBolt_MaxBoltPoints; iBoltPoint++)
{
BoltPoint_t *pBoltPoint = &pContainer->tBoneBolt_BoltPoints[ iBoltPoint ];
for (int iBoltOn = 0; iBoltOn < pBoltPoint->vBoltedContainers.size(); iBoltOn++)
{
R_ModelContainer_Apply(&pBoltPoint->vBoltedContainers[ iBoltOn ], pFunction, pvData);
}
}
// process this container's surface bolts...
//
for (iBoltPoint=0; iBoltPoint<pContainer->iSurfaceBolt_MaxBoltPoints; iBoltPoint++)
{
BoltPoint_t *pBoltPoint = &pContainer->tSurfaceBolt_BoltPoints[ iBoltPoint ];
for (int iBoltOn = 0; iBoltOn < pBoltPoint->vBoltedContainers.size(); iBoltOn++)
{
R_ModelContainer_Apply(&pBoltPoint->vBoltedContainers[ iBoltOn ], pFunction, pvData);
}
}
if (bFromBottomUp )
{
// process this... (which has no children by now)
//
pFunction(pContainer, pvData);
}
}
void R_ModelContainer_Apply(ModelContainer_t* pContainer, void (*pFunction) ( ModelContainer_t* pContainer, void *pvData), void *pvData)
{
R_ModelContainer_Apply_Actual(pContainer, pFunction, pvData, false);
}
// same as above, but calls from bottom of recursion tree to top, so can destroy ptrs to lower elements during freeup...
//
static void R_ModelContainer_ApplyFromBottomUp(ModelContainer_t* pContainer, void (*pFunction) ( ModelContainer_t* pContainer, void *pvData), void *pvData = NULL);
static void R_ModelContainer_ApplyFromBottomUp(ModelContainer_t* pContainer, void (*pFunction) ( ModelContainer_t* pContainer, void *pvData), void *pvData )
{
R_ModelContainer_Apply_Actual(pContainer, pFunction, pvData, true);
}
// set the supplied container to be empty... (note that because of stl, 99% of this works for either init or dealloc)
//
static void ModelContainer_Clear(ModelContainer_t* pContainer, void *pvData = NULL);// last field provided for R_ModelContainer_Apply() only
static void ModelContainer_Clear(ModelContainer_t* pContainer, void *pvData)
{
pContainer->hModel = 0;
pContainer->eModType = MOD_BAD;
ZEROMEM(pContainer->sLocalPathName);
ZEROMEM(pContainer->slist);
ZEROMEM(pContainer->blist);
pContainer->iBoneNum_SecondaryStart = -1; // default, meaning "ignore", else bone num to stop primary animation on, and begin secondary
pContainer->iSurfaceNum_RootOverride = -1;
pContainer->iCurrentFrame_Primary = 0;
pContainer->iOldFrame_Primary = 0;
pContainer->iCurrentFrame_Secondary = 0;
pContainer->iOldFrame_Secondary = 0;
pContainer->iSequenceLockNumber_Primary = -1;
pContainer->iSequenceLockNumber_Secondary = -1;
pContainer->iNumFrames = 0;
pContainer->iNumLODs = 0;
pContainer->iNumBones = 0;
pContainer->iNumSurfaces = 0;
// stats only...
pContainer->iRenderedTris = 0;
pContainer->iRenderedVerts = 0;
pContainer->iRenderedSurfs = 0;
pContainer->iXformedG2Bones = 0;
pContainer->iRenderedBoneWeights = 0;
pContainer->iOmittedBoneWeights = 0;
pContainer->SequenceList.clear();
pContainer->bSeqMultiLock_Primary_Active = false;
pContainer->SeqMultiLock_Primary.clear();
pContainer->bSeqMultiLock_Secondary_Active = false;
pContainer->SeqMultiLock_Secondary.clear();
pContainer->iSeqMultiLock_Primary_SeqHint =0; // not really important what number is picked
pContainer->iSeqMultiLock_Secondary_SeqHint =0; // ""
pContainer->SkinSets.clear();
pContainer->SkinSetsSurfacePrefs.clear();
pContainer->OldSkinSets.clear();
pContainer->strCurrentSkinFile = "";
pContainer->strCurrentSkinEthnic= "";
pContainer->MaterialBinds.clear();
pContainer->MaterialShaders.clear();
pContainer->SurfaceEdgeInfoPerLOD.clear();
pContainer->iBoneHighlightNumber = iITEMHIGHLIGHT_NONE;
pContainer->iSurfaceHighlightNumber = iITEMHIGHLIGHT_NONE;
// pContainer->iRenderedBoneWeightsThisSurface = 0;
pContainer->Aliases.clear();
pContainer->pModelInfoFunction = NULL;
pContainer->pModelGetBoneNameFunction = NULL;
pContainer->pModelGetBoneBoltNameFunction = NULL;
pContainer->pModelGetSurfaceNameFunction = NULL;
pContainer->pModelGetSurfaceBoltNameFunction= NULL;
// some freaky stuff...
//
ZEROMEM(pContainer->XFormedG2Bones);
ZEROMEM(pContainer->XFormedG2BonesValid);
ZEROMEM(pContainer->XFormedG2TagSurfs);
ZEROMEM(pContainer->XFormedG2TagSurfsValid);
// special linkage stuff (this can all safely be cleared since during freeup we're called recursively backwards)...
//
if (pContainer->tBoneBolt_BoltPoints.size() || pContainer->tSurfaceBolt_BoltPoints.size())
{
AppVars.iTotalContainers--; // we're calling this to free stuff, not to init it
}
//
// now do specific bolt-free code...
//
{// bone bolts...
pContainer->pBoneBolt_ParentContainer = NULL;
pContainer->iBoneBolt_ParentBoltIndex = -1; // .. if we're the root model, seems a reasonable default (as is NULL on line above)
pContainer->iBoneBolt_MaxBoltPoints = -1; // similar to modtype_bad, should never exist when init code called after this
pContainer->tBoneBolt_BoltPoints.clear();
}
{// surface bolts...
pContainer->pSurfaceBolt_ParentContainer = NULL;
pContainer->iSurfaceBolt_ParentBoltIndex = -1; // .. if we're the root model, seems a reasonable default (as is NULL on line above)
pContainer->iSurfaceBolt_MaxBoltPoints = -1; // similar to modtype_bad, should never exist when init code called after this
pContainer->tSurfaceBolt_BoltPoints.clear();
}
pContainer->hTreeItem_ModelName = NULL;
pContainer->hTreeItem_BoltOns = NULL;
}
// this is stuff that gets cleared during both AppVars_OnceOnlyInit() and Model_Delete()...
//
static void AppVars_Delete(void)
{
// int iNumBolts = 0;
R_ModelContainer_ApplyFromBottomUp(&AppVars.Container, ModelContainer_Clear);//, &iNumBolts);
AppVars.iSurfaceNumToHighlight = iITEMHIGHLIGHT_NONE;
AppVars.hModelToHighLight = 0;
// do this stuff so new models don't load and immediately animate...
//
AppVars.bAnimate = false;
AppVars.bForceWrapWhenAnimating = false;
AppVars.iLOD = 0;
AppVars.iTotalContainers = 0;
AppVars.strLoadedModelPath = "";
AppVars.hModelLastLoaded = NULL;
}
void AppVars_ResetViewParams(void)
{
#if 0
// FOV 90 params...
//
AppVars.xPos = 0.0f;
AppVars.yPos = 0.0f;
AppVars.zPos = -2.0f;
AppVars.rotAngleX = 0.0f;
AppVars.rotAngleY = 0.0f;
AppVars.rotAngleZ = -90.0f;
AppVars.dFOV = 90.0f;
#else
// FOV 10 params... (and slightly rotated to pleasing angle)
//
AppVars.xPos = 0.0f;
AppVars.yPos = 0.0f;
AppVars.zPos = -30.0f;
AppVars.rotAngleX = 15.5f;
AppVars.rotAngleY = 44.0f;
AppVars.rotAngleZ = -90.0f;
AppVars.dFOV = 10.0f;
#endif
AppVars.xPos_SCROLL = 0.0f;
AppVars.yPos_SCROLL = 0.0f;
AppVars.zPos_SCROLL = 0.0f;
AppVars.rotAngleX_SCROLL = 0.0f;
AppVars.rotAngleY_SCROLL = 0.0f;
AppVars.rotAngleZ_SCROLL = 0.0f;
}
void AppVars_OnceOnlyInit(void)
{
AppVars.bFinished = false;
AppVars.bBilinear = true;
AppVars.bInterpolate = true;
AppVars.bUseAlpha = false;
AppVars.bUseAlphaMode2 = false;
AppVars.bWireFrame = false;
AppVars.bOriginLines = false;
AppVars.bBBox = false;
AppVars.bFloor = false;
AppVars.fFloorZ = -24;
AppVars.bRuler = false;
AppVars.bBoneHighlight = true;
AppVars.bBoneWeightThreshholdingActive = false;
AppVars.fBoneWeightThreshholdPercent = 5.0f; //
AppVars.bSurfaceHighlight = true;
AppVars.bSurfaceHighlightShowsBoneWeighting = false;
AppVars.bTriIndexes = false;
AppVars.bVertIndexes = false;
AppVars.bVertWeighting = false;
AppVars.bAtleast1VertWeightDisplayed = false;
AppVars.bVertexNormals = false;
AppVars.bShowOriginsAsRGB = true;
AppVars.bForceWhite = false;
AppVars.bCleanScreenShots = true;
AppVars.bFullPathsInSequenceTreeitems = false;
AppVars.bCrackHighlight = false;
AppVars.bShowUnshadowableSurfaces = false;
AppVars.bAllowGLAOverrides = false;
AppVars.bShowPolysAsDoubleSided = true;
// crap...
//
AppVars.iSurfaceNumToHighlight = iITEMHIGHLIGHT_NONE;
AppVars.hModelToHighLight = NULL;
AppVars.hModelLastLoaded = NULL;
AppVars.bAlwaysOnTop = false;
AppVars.bSortSequencesByAlpha = false;
AppVars.iLOD = 0;
AppVars_ResetViewParams();
AppVars._R = AppVars._G = AppVars._B = 256/5; // dark grey
AppVars.dAnimSpeed = 0.05; // so 1/this = 20 = 20FPS
AppVars.dTimeStamp1 = getDoubleTime();
AppVars.fFramefrac = 0.0f;
AppVars.bAnimate = false;
AppVars.bForceWrapWhenAnimating = false;
AppVars_Delete();
}
void AppVars_WriteIdeal(void)
{
if (!AppVars.strLoadedModelPath.IsEmpty())
{
CString strOut;
#define OUTBYTE(blah) strOut += va("%s:%d\n",#blah,AppVars.blah);
#define OUTDOUBLE(blah) strOut += va("%s:%f\n",#blah,AppVars.blah);
OUTBYTE(bBilinear);
OUTBYTE(bOriginLines);
OUTBYTE(bBBox);
OUTBYTE(bUseAlpha);
OUTBYTE(bUseAlphaMode2);
OUTBYTE(bWireFrame);
OUTBYTE(_R);
OUTBYTE(_G);
OUTBYTE(_B);
OUTDOUBLE(dFOV);
OUTDOUBLE(dAnimSpeed);
OUTDOUBLE(xPos);
OUTDOUBLE(yPos);
OUTDOUBLE(zPos);
OUTDOUBLE(rotAngleX);
OUTDOUBLE(rotAngleY);
OUTDOUBLE(rotAngleZ);
LPCSTR psIdealName = va("%s.ideal",Filename_WithoutExt(AppVars.strLoadedModelPath));
FILE *fHandle = fopen(psIdealName,"wt");
if (fHandle)
{
fprintf(fHandle,(LPCSTR)strOut);
fclose(fHandle);
}
else
{
ErrorBox(va("Unable to write \"%s\"!, write protected?",psIdealName));
}
}
else
{
ErrorBox("Cannot write out a .ideal file if no model loaded");
}
}
void AppVars_ReadIdeal(void)
{
if (!AppVars.strLoadedModelPath.IsEmpty())
{
LPCSTR psIdealName = va("%s.ideal",Filename_WithoutExt(AppVars.strLoadedModelPath));
FILE *fHandle = fopen(psIdealName,"rt");
if (fHandle)
{
CString str;
char sLine[1024];
while (fgets(sLine,sizeof(sLine),fHandle)!=NULL)
{
// deal with CR stuff manually, in case file was edited by hand and last line doesn't have one...
//
if (strchr(sLine,'\n'))
*strchr(sLine,'\n') = '\0';
str += sLine;
str += "\n";
}
fclose(fHandle);
extern bool Gallery_Active(void);
if (Gallery_Active())
{
// this won't actually put up a box if the gallery is active, but it will add it to the
// overall report file so they'll know about it...
//
// (I may offer the ability to use these, but can't be bothered hassling them with extra
// Yes/No queries at the moment)
//
WarningBox(va("Ignoring settings file \"%s\" during gallery snapshots",psIdealName));
return;
}
// now check for certain values...
//
while (1)
{
int iLoc = str.Find('\n');
if (iLoc == -1)
break;
CString strThis = str.Left(iLoc);
if (strThis.IsEmpty())
break;
str = str.Mid(iLoc+1);
iLoc = strThis.Find(':');
if (iLoc == -1)
break;
CString strValue = strThis.Mid(iLoc+1);
strThis = strThis.Left(iLoc);
// now look for one of the named/saved fields...
//
#define CHECKBOOL(blah) \
if (strThis.CompareNoCase(#blah) == 0) \
{ \
AppVars.blah = !!atoi(strValue); \
continue; \
}
#define CHECKBYTE(blah) \
if (strThis.CompareNoCase(#blah) == 0) \
{ \
AppVars.blah = atoi(strValue); \
continue; \
}
#define CHECKDOUBLE(blah) \
if (strThis.CompareNoCase(#blah) == 0) \
{ \
AppVars.blah = atof(strValue); \
continue; \
}
CHECKBOOL(bBilinear);
CHECKBOOL(bOriginLines);
CHECKBOOL(bBBox);
CHECKBOOL(bUseAlpha);
CHECKBOOL(bUseAlphaMode2);
CHECKBOOL(bWireFrame);
CHECKBYTE(_R);
CHECKBYTE(_G);
CHECKBYTE(_B);
CHECKDOUBLE(dFOV);
CHECKDOUBLE(dAnimSpeed);
CHECKDOUBLE(xPos);
CHECKDOUBLE(yPos);
CHECKDOUBLE(zPos);
CHECKDOUBLE(rotAngleX);
CHECKDOUBLE(rotAngleY);
CHECKDOUBLE(rotAngleZ);
}
TextureList_SetFilter(); // in case filtering was changed
ModelList_ForceRedraw();
}
// DT EDIT
/*
else
{
ErrorBox( va("Couldn't open file: %s\n", psIdealName));
return;
}
*/
}
}
// the global stuff for any loaded model, regardless of format...
//
// this deletes the primary model, all bolted models, and the low-level model cache
//
void Model_Delete(void)
{
// delete common stuff...
//
// SAFEFREE(pvLoadedModel);
ModelTree_DeleteAllItems();
// delete any format-specific stuff that this code doesn't know about...
//
GLMModel_DeleteExtra(); // delete anything specific to this format
RE_DeleteModels();
// delete other app vars...
//
AppVars_Delete();
extern bool g_bReportImageLoadErrors;
g_bReportImageLoadErrors = false; // uninhibit any inhibited errors
}
LPCSTR Model_GetSupportedTypesFilter(bool bScriptsEtcAlsoAllowed /* = false */)
{
static char sFilterString[1024];
strcpy(sFilterString,"Model files (*.glm)|*.glm|");
if (bScriptsEtcAlsoAllowed)
{
strcat(sFilterString, Script_GetFilter(false));
}
strcat(sFilterString,"All Files(*.*)|*.*||");
return sFilterString;
}
// findme: All code that uses cut/paste from other projects should go through here, since it allows the whole
// code-exit mechanism that they use to be trapped properly...
//
// call this before calling any cut/paste other-format model code
ModelHandle_t Model_Register( CString strLocalFilename )
{
ModelHandle_t hModel = NULL;
try
{
StatusMessage(va("Registering model: \"%s\"\n",(LPCSTR)strLocalFilename));
hModel = RE_RegisterModel( strLocalFilename );
}
catch(LPCSTR psMessage)
{
Model_Delete();
ErrorBox(psMessage);
hModel = NULL;
}
StatusMessage(NULL);
return hModel;
}
ModelContainer_t* pMatchingContainer;
static void ModelContainer_CallBack_HandleCheck(ModelContainer_t* pContainer, void *pvData )
{
if (pContainer->hModel == *((ModelHandle_t*) pvData))
{
pMatchingContainer = pContainer;
}
}
ModelContainer_t* ModelContainer_FindFromModelHandle(ModelHandle_t hModel)
{
pMatchingContainer = NULL;
R_ModelContainer_Apply(&AppVars.Container, ModelContainer_CallBack_HandleCheck, &hModel);
if (pMatchingContainer)
return pMatchingContainer;
return NULL;
}
// read in a model using main engine code, then parse any extra stuff that this modview apps wants to know about...
//
// note that this doesn't know or care whether it's the parent container or a bolt on, and neither should it.
// Any error will delete all loaded models (as per usual)...
//
static ModelHandle_t ModelContainer_RegisterModel(LPCSTR psLocalFilename, ModelContainer_t *pContainer, HTREEITEM hTreeItem_Parent = NULL);
static ModelHandle_t ModelContainer_RegisterModel(LPCSTR psLocalFilename, ModelContainer_t *pContainer, HTREEITEM hTreeItem_Parent)
{
CWaitCursor wait;
ModelContainer_Clear(pContainer); // ZEROMEM(*pContainer);
ModelHandle_t hModel = Model_Register( psLocalFilename );
strncpy(pContainer->sLocalPathName,psLocalFilename,sizeof(pContainer->sLocalPathName));
pContainer->sLocalPathName[sizeof(pContainer->sLocalPathName)-1] = '\0';
int iBoltPoint = 0;
if (hModel)
{
pContainer->hModel = hModel;
modtype_t modtype = MOD_BAD; // reasonable default
// do any game-type post-process code... (hence the try-catch block)
//
try
{
if ( (modtype = RE_GetModelType( hModel )) == MOD_MDXM)
{
trap_G2_SurfaceOffList(hModel, &pContainer->slist);
trap_G2_Init_Bone_List(&pContainer->blist);
//trap_G2_Set_Bone_Anim(ent->ghoulmodel, ent->s.blist, "model_root", 0, 9, BONE_ANIM_OVERRIDE_LOOP, 0.1f);
}
}
catch(LPCSTR psMessage)
{
Model_Delete();
ErrorBox(psMessage);
hModel = NULL;
}
// now do any of my post-process stuff... (which doesn't need try-catch because it's well written :-)
//
if (hModel)
{
pContainer->eModType = modtype;
bool bModelOk = true;
switch (modtype)
{
case MOD_MDXM:
bModelOk = GLMModel_Parse( pContainer, psLocalFilename, hTreeItem_Parent);
if (bModelOk)
{
// specific to this format...
//
assert(pContainer->pModelGetBoneNameFunction);
assert(pContainer->pModelGetBoneBoltNameFunction);
assert(pContainer->pModelGetSurfaceBoltNameFunction);
}
break;
default:
//assert(0);
bModelOk = false;
ErrorBox(va("The model \"%s\" is valid, but ModView doesn't fully support this type at present",psLocalFilename));
break;
}
if (bModelOk)
{
// the above switch-case should have filled in these per-format...
//
assert(pContainer->iBoneBolt_MaxBoltPoints != -1); // check that deliberate illegal default is overwritten
assert(pContainer->iSurfaceBolt_MaxBoltPoints != -1); // check that deliberate illegal default is overwritten
assert(pContainer->iNumLODs);
assert(pContainer->iNumFrames);
assert(pContainer->pModelInfoFunction);
assert(pContainer->pModelGetSurfaceNameFunction);
// if failed to read any sequence files then make a default one...
//
if (!pContainer->SequenceList.size())
{
pContainer->SequenceList.push_back( *Sequence_CreateDefault(pContainer->iNumFrames) );
}
// default bolton stuff (ensure that matrix mem initialised, and bolton array resized correctly...)
//
// bone bolts...
//
pContainer->tBoneBolt_BoltPoints.resize(pContainer->iBoneBolt_MaxBoltPoints);
for (iBoltPoint = 0; iBoltPoint < pContainer->iBoneBolt_MaxBoltPoints; iBoltPoint++)
{
BoltPoint_t *pBoltPoint = &pContainer->tBoneBolt_BoltPoints[ iBoltPoint ];
pBoltPoint->vMatricesPerFrame.resize( pContainer->iNumFrames );
pBoltPoint->sAttachName = pContainer->pModelGetBoneBoltNameFunction(pContainer->hModel, iBoltPoint);
pBoltPoint->vBoltedContainers.clear(); // probably not nec., but wtf?
}
//
// surface bolts...
//
pContainer->tSurfaceBolt_BoltPoints.resize(pContainer->iSurfaceBolt_MaxBoltPoints);
for (iBoltPoint=0; iBoltPoint<pContainer->iSurfaceBolt_MaxBoltPoints; iBoltPoint++)
{
BoltPoint_t *pBoltPoint = &pContainer->tSurfaceBolt_BoltPoints[iBoltPoint];
pBoltPoint->vMatricesPerFrame.resize( pContainer->iNumFrames );
pBoltPoint->sAttachName = pContainer->pModelGetSurfaceBoltNameFunction(pContainer->hModel, iBoltPoint);
pBoltPoint->vBoltedContainers.clear();
}
// finally, we can do stuff like skin file code that can popup GetYesNo boxes, which cause grief
// if they happen before the bolt stuff above has occured...
//
switch (modtype)
{
case MOD_MDXM:
// only one of these will be valid at once, so no need to check...
//
Skins_ApplyDefault(pContainer);
OldSkins_ApplyDefault(pContainer);
break;
default:
assert(0);
break;
}
}
if (!bModelOk)
{
Model_Delete();
hModel = NULL;
}
}
}
return hModel;
}
void ModelTree_DeleteAllItems(void)
{
if (gModViewTreeViewhandle) // will be valid unless this is called from app exit
{
gModViewTreeViewhandle->DeleteAllItems();
}
}
DWORD ModelTree_GetItemData(HTREEITEM hTreeItem)
{
if (gModViewTreeViewhandle) // will be valid unless this is called from app exit
{
return gModViewTreeViewhandle->GetTreeCtrl().GetItemData(hTreeItem);
}
assert(0);
return NULL;
}
bool ModelTree_SetItemText(HTREEITEM hTreeItem, LPCSTR psText)
{
if (gModViewTreeViewhandle) // will be valid unless this is called from app exit
{
return !!gModViewTreeViewhandle->GetTreeCtrl().SetItemText(hTreeItem, psText);
}
assert(0);
return NULL;
}
// param 'bPure' should be TRUE if you want to strip stuff like "////" from "///////// surfacename",
// and return the original un-decorated text by querying the model directly if possible...
//
// this function was written so Keith could remote-query from ConfuseEd...
//
LPCSTR ModelTree_GetItemText(HTREEITEM hTreeItem, bool bPure /* = false */)
{
if (gModViewTreeViewhandle) // will be valid unless this is called from app exit
{
if (bPure)
{
// let's see if this is a treeitem type that can return pure text...
//
TreeItemData_t TreeItemData;
TreeItemData.uiData = ModelTree_GetItemData(hTreeItem);
if (TreeItemData.iItemType == TREEITEMTYPE_GLM_SURFACE
||
TreeItemData.iItemType == TREEITEMTYPE_GLM_TAGSURFACE
)
{
return GLMModel_GetSurfaceName( TreeItemData.iModelHandle, TreeItemData.iItemNumber );
}
}
// whatever it is, just return its itemtext in full...
//
// do NOT use the CString(input) constructor here!!
//
static CString string;
string = gModViewTreeViewhandle->GetTreeCtrl().GetItemText(hTreeItem);
return (LPCSTR) string;
}
assert(0);
return NULL;
}
// search tree for an item whose userdata matches what's been passed...
//
// hTreeItem = tree item to start from, pass NULL to start from root
//
static HTREEITEM R_ModelTree_FindItemWithThisData(HTREEITEM hTreeItem, UINT32 uiData2Match, int *piItemsScanned = NULL);
static HTREEITEM R_ModelTree_FindItemWithThisData(HTREEITEM hTreeItem, UINT32 uiData2Match, int *piItemsScanned/*=NULL*/)
{
if (!hTreeItem)
hTreeItem = ModelTree_GetRootItem();
if (hTreeItem)
{
if (piItemsScanned)
{
*piItemsScanned +=1;
}
// LPCSTR psText = ModelTree_GetItemText(hTreeItem);
// OutputDebugString(va("Scanning item %X (%s)\n",hTreeItem,psText));
// check this tree item...
//
TreeItemData_t TreeItemData;
TreeItemData.uiData = ModelTree_GetItemData(hTreeItem);
// match?...
//
if (TreeItemData.uiData == uiData2Match)
return hTreeItem;
// check child...
//
HTREEITEM hTreeItem_Child = ModelTree_GetChildItem(hTreeItem);
if (hTreeItem_Child)
{
HTREEITEM hTreeItemFound = R_ModelTree_FindItemWithThisData(hTreeItem_Child, uiData2Match, piItemsScanned);
if (hTreeItemFound)
return hTreeItemFound;
}
// process siblings...
//
HTREEITEM hTreeItem_Sibling = ModelTree_GetNextSiblingItem(hTreeItem);
if (hTreeItem_Sibling)
{
HTREEITEM hTreeItemFound = R_ModelTree_FindItemWithThisData(hTreeItem_Sibling, uiData2Match, piItemsScanned);
if (hTreeItemFound)
return hTreeItemFound;
}
// this treeitem isnt a match, and neither are its siblings or children, so...
//
return NULL;
}
// we must have called this when the treeview was uninitialised... (duh!)
//
ASSERT(0);
return NULL;
}
int ModelTree_GetChildCount(HTREEITEM hTreeItem)
{
int iChildCount = 0;
if (gModViewTreeViewhandle) // will be valid unless this is called from app exit
{
if (gModViewTreeViewhandle->GetTreeCtrl().ItemHasChildren(hTreeItem))
{
hTreeItem = gModViewTreeViewhandle->GetTreeCtrl().GetChildItem(hTreeItem);
R_ModelTree_FindItemWithThisData(hTreeItem, 0xDEADDEAD, &iChildCount); // massive-function abuse here! :-)
}
}
return iChildCount;
}
bool ModelTree_ItemHasChildren(HTREEITEM hTreeItem)
{
if (gModViewTreeViewhandle) // will be valid unless this is called from app exit
{
return !!gModViewTreeViewhandle->GetTreeCtrl().ItemHasChildren(hTreeItem);
}
assert(0);
return NULL;
}
HTREEITEM ModelTree_GetChildItem(HTREEITEM hTreeItem)
{
if (gModViewTreeViewhandle) // will be valid unless this is called from app exit
{
return gModViewTreeViewhandle->GetTreeCtrl().GetChildItem(hTreeItem);
}
assert(0);
return NULL;
}
HTREEITEM ModelTree_GetNextSiblingItem(HTREEITEM hTreeItem)
{
if (gModViewTreeViewhandle) // will be valid unless this is called from app exit
{
return gModViewTreeViewhandle->GetTreeCtrl().GetNextSiblingItem(hTreeItem);
}
assert(0);
return NULL;
}
HTREEITEM ModelTree_GetRootItem(void)
{
if (gModViewTreeViewhandle) // will be valid unless this is called from app exit
{
return gModViewTreeViewhandle->GetRootItem();
}
ASSERT(0);
return NULL;
}
bool ModelTree_DeleteItem(HTREEITEM hTreeItem)
{
if (gModViewTreeViewhandle) // will be valid unless this is called from app exit
{
return !!gModViewTreeViewhandle->GetTreeCtrl().DeleteItem(hTreeItem);
}
ASSERT(0);
return NULL;
}
// this should only be called when you know it's a GLM model for the moment... (put in for Keith's remote access)
//
HTREEITEM ModelTree_GetRootSurface(ModelHandle_t hModel)
{