Repository navigation
Expand file tree
/
Copy pathasciiread.cpp
More file actions
3342 lines (3194 loc) · 208 KB
/
Copy pathasciiread.cpp
File metadata and controls
3342 lines (3194 loc) · 208 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
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 "MDL.h"
#include "ascii_compat.h"
#include <algorithm>
#include <limits>
#include <utility>
// Functions:
// TruncateLongName3216()
// ASCII::Read()
void TruncateLongName3216(std::string & sID, const std::string & sContext, unsigned int nLine, bool bWarnAt16 = true){
if(sID.size() > 32){
Warning(sContext + " (" + sID + ") at line " + std::to_string(nLine) + " is larger than the limit, 32 characters! Will truncate and continue.");
sID.resize(32);
}
else if(sID.size() > 16 && bWarnAt16){
Warning(sContext + " (" + sID + ") at line " + std::to_string(nLine) + " is larger than 16 characters! This may or may not cause problems in the game.");
}
}
void SetAsciiListCount(MdlInteger<unsigned int> & nDataMax, int nCount, const std::string & sListName){
if(nCount < 0) throw mdlexception(sListName + " count cannot be negative.");
nDataMax = static_cast<unsigned int>(nCount);
}
void SetAsciiListCountSize(MdlInteger<unsigned int> & nDataMax, std::size_t nCount, const std::string & sListName){
if(nCount > std::numeric_limits<unsigned int>::max()){
throw mdlexception(sListName + " count is too large.");
}
nDataMax = static_cast<unsigned int>(nCount);
}
MdlInteger<unsigned short> AsciiUShortOrInvalid(int nValue, const std::string & sField){
if(nValue == -1) return MdlInteger<unsigned short>();
if(nValue < -1){
throw mdlexception(sField + " cannot be less than -1.");
}
const int nInvalid = static_cast<int>(std::numeric_limits<unsigned short>::max());
if(nValue >= nInvalid){
throw mdlexception(sField + " must be -1 or in the range 0.." + std::to_string(nInvalid - 1) + ".");
}
return MdlInteger<unsigned short>(static_cast<unsigned short>(nValue));
}
MdlInteger<unsigned int> AsciiUIntOrInvalid(int nValue, const std::string & sField){
if(nValue == -1) return MdlInteger<unsigned int>();
if(nValue < -1){
throw mdlexception(sField + " cannot be less than -1.");
}
return MdlInteger<unsigned int>(static_cast<unsigned int>(nValue));
}
MdlInteger<unsigned short> AsciiUShortIndex(unsigned int nValue, const std::string & sField){
const unsigned int nInvalid = static_cast<unsigned int>(std::numeric_limits<unsigned short>::max());
if(nValue >= nInvalid){
throw mdlexception(sField + " must be in the range 0.." + std::to_string(nInvalid - 1) + ".");
}
return MdlInteger<unsigned short>(static_cast<unsigned short>(nValue));
}
void EnsureUniqueAsciiVisibleName(const std::vector<Name> & names, const std::string & sName, unsigned int nLine){
for(const Name & existing : names){
if(StringEqual(existing.sName, sName)){
throw mdlexception("Duplicate ASCII name '" + sName + "' at line " + std::to_string(nLine) +
"; node/name tokens must be unique before __dpl suffix stripping so references resolve to the original binary name index.");
}
}
}
MdlInteger<unsigned short> LookupAsciiNameIndex(MDL & Mdl, const std::string & sName, const std::string & sContext){
int nNameIndex = Mdl.GetNameIndex(sName);
if(nNameIndex < 0){
throw mdlexception(sContext + ": node/name '" + sName + "' was not indexed in the ASCII name table.");
}
return AsciiUShortIndex(static_cast<unsigned int>(nNameIndex), sContext + " name index");
}
void ThrowTooManyListRows(const std::string & sListName, const std::string & sNodeName){
throw mdlexception("Too many " + sListName + " rows for node '" + sNodeName + "'; refusing to consume following ASCII tokens as list data.");
}
template <class T>
void ResizeAsciiVector(std::vector<T> & values, std::size_t nCount, const std::string & sListName){
if(nCount > values.max_size()){
throw mdlexception(sListName + " count is too large to allocate safely.");
}
values.resize(nCount);
}
template <class T>
void ResizeAsciiVector(std::vector<T> & values, std::size_t nCount, const T & value, const std::string & sListName){
if(nCount > values.max_size()){
throw mdlexception(sListName + " count is too large to allocate safely.");
}
values.resize(nCount, value);
}
template <class T>
void EnsureAsciiVectorSize(std::vector<T> & values, std::size_t nCount, const std::string & sListName){
if(nCount > values.max_size()){
throw mdlexception(sListName + " count is too large to allocate safely.");
}
if(values.size() < nCount) values.resize(nCount);
}
template <class T>
void EnsureAsciiVectorSize(std::vector<T> & values, std::size_t nCount, const T & value, const std::string & sListName){
if(nCount > values.max_size()){
throw mdlexception(sListName + " count is too large to allocate safely.");
}
if(values.size() < nCount) values.resize(nCount, value);
}
namespace {
template <class F>
class AsciiScopeExit{
F fn;
bool active = true;
public:
explicit AsciiScopeExit(F f) : fn(std::move(f)) {}
AsciiScopeExit(const AsciiScopeExit &) = delete;
AsciiScopeExit & operator=(const AsciiScopeExit &) = delete;
AsciiScopeExit(AsciiScopeExit && other) : fn(std::move(other.fn)), active(other.active){
other.active = false;
}
AsciiScopeExit & operator=(AsciiScopeExit &&) = delete;
void Dismiss(){ active = false; }
~AsciiScopeExit(){ if(active) fn(); }
};
template <class F>
AsciiScopeExit<F> MakeAsciiScopeExit(F f){
return AsciiScopeExit<F>(std::move(f));
}
}
bool ASCII::Read(MDL & Mdl){
//std::cout << "We made it into ASCII::Read.\n";
ReportObject ReportMdl(Mdl);
std::unique_ptr<FileHeader> pOldFileData = std::move(Mdl.FH);
std::unique_ptr<MDX> pOldMdx = std::move(Mdl.Mdx);
std::unique_ptr<WOK> pOldWok = std::move(Mdl.Wok);
const ModelSource oldSource = Mdl.src;
const bool oldK2 = Mdl.bK2;
const bool oldXbox = Mdl.bXbox;
const int oldSupermodel = Mdl.nSupermodel;
Mdl.FH.reset(new FileHeader);
auto restoreReadState = MakeAsciiScopeExit([&](){
Mdl.FH = std::move(pOldFileData);
Mdl.Mdx = std::move(pOldMdx);
Mdl.Wok = std::move(pOldWok);
Mdl.src = oldSource;
Mdl.bK2 = oldK2;
Mdl.bXbox = oldXbox;
Mdl.nSupermodel = oldSupermodel;
});
FileHeader & Data = *Mdl.FH;
std::string sID; /// Will be reading the ascii text into this string in parts.
Mdl.src = AsciiSource;
Mdl.Report("Reading ASCII...");
//Set stuff to zero
nPosition = 0; /// Our position when reading the ascii file
nLine = 1;
Data.MH.Animations.resize(0);
Data.MH.Names.resize(0);
/// Conversion variables
int nConvert;
unsigned int uConvert;
double fConvert;
//bool bFound = false;
bool bGeometry = false; /// Are we inside geometry?
int nNode = 0; /// The current node type
MdlInteger<unsigned int> nAnimation; /// The current animation
bool bAnimation = false; /// Are we inside an animation?
/// Data type variables
bool bEventlist = false;
bool bVerts = false;
bool bFaces = false;
bool bFaceExtra = false;
bool bTverts = false;
bool bTexIndices1 = false;
bool bTverts1 = false;
bool bTexIndices2 = false;
bool bTverts2 = false;
bool bTexIndices3 = false;
bool bTverts3 = false;
bool bNormalIndices = false;
bool bNormals = false;
bool bTangentBasis = false;
bool bWeights = false;
bool bCompactBoneMap = false;
bool bCompactBoneMapRaw = false;
bool bBoneConstantIndices = false;
bool bExtraData = false;
bool bAabb = false;
bool bSaberData = false;
bool bConstraints = false;
bool bKeys = false;
bool bTextureNames = false;
bool bControllerRaw = false;
bool bControllerDataRaw = false;
bool bFlarePositions = false;
bool bFlareSizes = false;
bool bFlareColorShifts = false;
bool bRoomLinks = false;
bool bColors = false;
bool bColorIndices = false;
/// Variables for reading data
MdlInteger<unsigned int> nDataMax;
unsigned int nDataCounter;
bool bMagnusll = false; /// Magnus11-style lightmap reading
unsigned int nNodeCount = 0;
MdlInteger<unsigned short> nCurrentIndex;
std::vector<std::string> sBumpmapped; /// This variable collects the bumpmappable texture names specified in the ascii.
///This first loop is for building the name array, which we need for the weights
/// Actually, it seems that the ascii is potentially ambiguous. In binary, two objects may have the same name,
/// and they will still be distinguished in all cases, because they are always referred to by their name index.
/// In ascii, the name replaces the name index. This means that weights, which do not rely on a bonemap, will be
/// ambiguous when it comes to two objects with the same name. Actually the same applies for the parent field,
/// it is potentially possible for either of the objects to be the real parent. This should be addressed in the
/// conversion to ascii, so that the names are disambiguated. The user then only needs to make sure that the ascii
/// models they provide for reading are well-formed in that respect.
/// In short, we will now assume that all names are unique.
try{
/// Go through the ascii file and stop recording names when you get to endmodelgeom.
/// Skip all lines except the ones that start with node or name.
/// Get the name from both node and name lines, and record the number of node lines (actual nodes).
/// By doing this we also define the name order. The order of the names is the order in which they appear in the ascii.
///
bool bGeometryEnd = false;
while(nPosition < sBuffer.size()){
ReadUntilText(sID);
if(sID == "endmodelgeom") // Don't break because we're also getting the total file size
bGeometryEnd = true;
if(bGeometryEnd || (sID != "node" && sID != "name"))
SkipLine();
else{
//Once we get here, we have found a node. The name is only a keyword's strlen away!
if(sID == "node"){
if(!ReadUntilText(sID)){
throw mdlexception("Malformed node declaration in ASCII name-index pass: node type is missing at line " + std::to_string(nLine) + ".");
}
nNodeCount++; //Also record the number of actual nodes
}
if(!ReadUntilText(sID, false)){
throw mdlexception("Malformed node/name declaration in ASCII name-index pass: name is missing at line " + std::to_string(nLine) + ".");
}
// v1.0.104b did not apply its 16-character warning to node
// identifiers. Keep accepting the full binary-safe width here.
TruncateLongName3216(sID, "ASCII node/name table entry", nLine, false);
//Got it! Now to save it the name array. Do the uniqueness check
// after enforcing the binary name width, otherwise two long
// ASCII names with the same first 32 bytes would both resolve
// to distinct in-memory names and then collide during binary
// write.
EnsureUniqueAsciiVisibleName(Data.MH.Names, sID, nLine);
Name name; //our new name
name.sName = sID;
Data.MH.Names.push_back(std::move(name));
}
}
if(Data.MH.Names.size() > static_cast<std::size_t>(std::numeric_limits<unsigned short>::max())){
throw mdlexception("ASCII name table has too many entries to preserve 16-bit MDL name indices.");
}
ReportMdl << "Done indexing names (" << Data.MH.Names.size() << ").\n";
/// Reset position and line because we need to start again from the beginning
nPosition = 0, nLine = 1;
///Loops for every row
auto CurrentAsciiNodeNameForError = [&]() -> std::string {
if(nAnimation.Valid() && !Data.MH.Animations.empty() && !Data.MH.Animations.back().ArrayOfNodes.empty()){
const Node & node = Data.MH.Animations.back().ArrayOfNodes.back();
if(node.Head.nNameIndex.Valid()){
const unsigned short nName = static_cast<unsigned short>(node.Head.nNameIndex);
if(nName < Data.MH.Names.size()) return Data.MH.Names.at(nName).sName;
}
}
if(nCurrentIndex.Valid()){
const unsigned short nName = static_cast<unsigned short>(nCurrentIndex);
if(nName < Data.MH.Names.size()) return Data.MH.Names.at(nName).sName;
}
return std::string("<unknown>");
};
bool * lpbList = nullptr;
while(nPosition < sBuffer.size()){
//First set our current list
if(bKeys) lpbList = &bKeys;
else if(bWeights) lpbList = &bWeights;
else if(bEventlist) lpbList = &bEventlist;
else if(bAabb) lpbList = &bAabb;
else if(bSaberData) lpbList = &bSaberData;
else if(bVerts) lpbList = &bVerts;
else if(bFaces) lpbList = &bFaces;
else if(bFaceExtra) lpbList = &bFaceExtra;
else if(bTverts) lpbList = &bTverts;
else if(bTexIndices1) lpbList = &bTexIndices1;
else if(bTverts1) lpbList = &bTverts1;
else if(bTexIndices2) lpbList = &bTexIndices2;
else if(bTverts2) lpbList = &bTverts2;
else if(bTexIndices3) lpbList = &bTexIndices3;
else if(bTverts3) lpbList = &bTverts3;
else if(bNormalIndices) lpbList = &bNormalIndices;
else if(bNormals) lpbList = &bNormals;
else if(bTangentBasis) lpbList = &bTangentBasis;
else if(bCompactBoneMap) lpbList = &bCompactBoneMap;
else if(bCompactBoneMapRaw) lpbList = &bCompactBoneMapRaw;
else if(bBoneConstantIndices) lpbList = &bBoneConstantIndices;
else if(bExtraData) lpbList = &bExtraData;
else if(bConstraints) lpbList = &bConstraints;
else if(bFlarePositions) lpbList = &bFlarePositions;
else if(bFlareSizes) lpbList = &bFlareSizes;
else if(bFlareColorShifts) lpbList = &bFlareColorShifts;
else if(bTextureNames) lpbList = &bTextureNames;
else if(bControllerRaw) lpbList = &bControllerRaw;
else if(bControllerDataRaw) lpbList = &bControllerDataRaw;
else if(bRoomLinks) lpbList = &bRoomLinks;
else if(bColors) lpbList = &bColors;
else if(bColorIndices) lpbList = &bColorIndices;
else lpbList = nullptr;
//First, check if we have a blank line, we'll just skip it here.
if(EmptyRow())
SkipLine();
//Second, check if we are in some list of data. We should not look for a keyword then.
else if(lpbList != nullptr){
if(nDataMax.Valid() && nDataMax == 0){
const unsigned int nSavePos = nPosition;
if(ReadUntilText(sID) && sID == "endlist"){
SkipLine();
}
else{
nPosition = nSavePos;
}
*lpbList = false;
continue;
}
//First, check if we're done. Save your position, cuz we'll need to revert if we're not done
int nSavePos = nPosition;
ReadUntilText(sID);
if(sID == "endlist" || sID == "endnode"){
*lpbList = false;
if(sID == "endnode") nNode = 0;
SkipLine();
}
else{
//Revert back to old position
nPosition = nSavePos;
/// Read the data
try{
if(bKeys){
//if(DEBUG_LEVEL > 3) ReportMdl << "Reading key data " << nDataCounter << ".\n";
//We've already read the timekeys, we're left with the values
Animation & anim = Data.MH.Animations.back();
Node & node = anim.ArrayOfNodes.back();
int nNodeIndex = Mdl.GetNodeIndexByNameIndex(node.Head.nNameIndex);
if(nNodeIndex == -1) throw mdlexception("ReadAscii() reading keys error: dealing with a name index that does not have a node in geometry.");
Node & geonode = Data.MH.ArrayOfNodes.at(nNodeIndex);
Location loc = geonode.GetLocation();
Controller & ctrl = node.Head.Controllers.back();
//First read the timekey, also check that we're valid
if(!ReadFloat(fConvert)) throw mdlexception("Error reading animation key data for node '" + Mdl.GetNodeName(node) + "'.");
if(ctrl.nControllerType == CONTROLLER_HEADER_ORIENTATION && ctrl.nColumnCount < 16){
double fX, fY, fZ, fA;
if(ReadFloat(fConvert)) fX = fConvert;
else throw mdlexception("Error reading animation key data for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) fY = fConvert;
else throw mdlexception("Error reading animation key data for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) fZ = fConvert;
else throw mdlexception("Error reading animation key data for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) fA = fConvert;
else throw mdlexception("Error reading animation key data for node '" + Mdl.GetNodeName(node) + "'.");
Orientation NewOrientKey;
NewOrientKey.SetAxisAngle(fX, fY, fZ, fA);
if(Data.MH.bCompressQuaternions){
Quaternion q = NewOrientKey.GetQuaternion();
if(q.fW < 0.0) q.vAxis *= -1.0;
unsigned nCompressed = CompressQuaternion(q);
node.Head.ControllerData.push_back(FloatFromBits(nCompressed));
}
else{
node.Head.ControllerData.push_back(NewOrientKey.GetQuaternion().vAxis.fX);
node.Head.ControllerData.push_back(NewOrientKey.GetQuaternion().vAxis.fY);
node.Head.ControllerData.push_back(NewOrientKey.GetQuaternion().vAxis.fZ);
node.Head.ControllerData.push_back(NewOrientKey.GetQuaternion().fW);
}
}
else if(ctrl.nControllerType == CONTROLLER_HEADER_POSITION){
if(ReadFloat(fConvert)) node.Head.ControllerData.push_back(fConvert - loc.vPosition.fX);
else throw mdlexception("Error reading animation key data for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) node.Head.ControllerData.push_back(fConvert - loc.vPosition.fY);
else throw mdlexception("Error reading animation key data for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) node.Head.ControllerData.push_back(fConvert - loc.vPosition.fZ);
else throw mdlexception("Error reading animation key data for node '" + Mdl.GetNodeName(node) + "'.");
if(ctrl.nColumnCount > 16){
if(ReadFloat(fConvert)) node.Head.ControllerData.push_back(fConvert);
else throw mdlexception("Error reading animation key data for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) node.Head.ControllerData.push_back(fConvert);
else throw mdlexception("Error reading animation key data for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) node.Head.ControllerData.push_back(fConvert);
else throw mdlexception("Error reading animation key data for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) node.Head.ControllerData.push_back(fConvert);
else throw mdlexception("Error reading animation key data for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) node.Head.ControllerData.push_back(fConvert);
else throw mdlexception("Error reading animation key data for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) node.Head.ControllerData.push_back(fConvert);
else throw mdlexception("Error reading animation key data for node '" + Mdl.GetNodeName(node) + "'.");
}
}
else{
while(true){
if(ReadFloat(fConvert)){
//ReportMdl << "Reading non-position keys...\n";
node.Head.ControllerData.push_back(fConvert);
}
else break;
}
}
}
else if(bEventlist){
Animation & anim = Data.MH.Animations.back();
Event sound; //New sound
if(ReadFloat(fConvert)) sound.fTime = fConvert;
else throw mdlexception("Error reading eventlist data for animation '" + anim.sName + "'. Event time missing.");
std::string sValue;
if(!ReadUntilText(sValue, false)){
ReportMdl << "ReadUntilText() Event name is missing!\n";
throw mdlexception("Error reading eventlist data for animation '" + std::string(anim.sName.c_str()) + "'. Event name missing");
}
TruncateLongName3216(sValue, "Event name in " + std::string(anim.sName.c_str()), nLine);
sound.sName = sValue;
anim.Events.push_back(sound);
}
else if(bAabb){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
Aabb aabb;
if(ReadFloat(fConvert)) aabb.vBBmin.fX = fConvert;
else throw mdlexception("Error reading aabb data (bbmin x) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) aabb.vBBmin.fY = fConvert;
else throw mdlexception("Error reading aabb data (bbmin y) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) aabb.vBBmin.fZ = fConvert;
else throw mdlexception("Error reading aabb data (bbmin z) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) aabb.vBBmax.fX = fConvert;
else throw mdlexception("Error reading aabb data (bbmax x) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) aabb.vBBmax.fY = fConvert;
else throw mdlexception("Error reading aabb data (bbmax y) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) aabb.vBBmax.fZ = fConvert;
else throw mdlexception("Error reading aabb data (bbmax z) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) aabb.nID = AsciiUShortOrInvalid(nConvert, "aabb face id");
else throw mdlexception("Error reading aabb data (face id) for node '" + Mdl.GetNodeName(node) + "'.");
int nOptionalStart = nPosition;
if(ReadInt(nConvert)){
if(nConvert < -1){
throw mdlexception("Error reading aabb data for node '" + Mdl.GetNodeName(node) + "': property must be -1 or non-negative.");
}
aabb.nProperty = static_cast<unsigned int>(nConvert);
int nChild1 = 0;
int nChild2 = 0;
if(ReadInt(nChild1) && ReadInt(nChild2)){
if((nChild1 != 0 && nChild1 != 1) || (nChild2 != 0 && nChild2 != 1)){
throw mdlexception("Error reading aabb data for node '" + Mdl.GetNodeName(node) + "': child flags must be 0 or 1.");
}
aabb.nChild1 = static_cast<unsigned int>(nChild1);
aabb.nChild2 = static_cast<unsigned int>(nChild2);
node.Walkmesh.bPreserveAabbTree = true;
}
else{
// Old ASCII aabb format only carried the first seven values.
// Keep accepting it, but let postprocess rebuild the tree.
nPosition = nOptionalStart;
node.Walkmesh.bPreserveAabbTree = false;
}
}
else{
nPosition = nOptionalStart;
node.Walkmesh.bPreserveAabbTree = false;
}
node.Walkmesh.TempAabbNodes.push_back(std::move(aabb));
}
else if(bVerts){
//if(DEBUG_LEVEL > 3) ReportMdl << "Reading verts data " << nDataCounter << ".\n";
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
Vector vert;
if(ReadFloat(fConvert)) vert.fX = fConvert;
else throw mdlexception("Error reading vert coord X data for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) vert.fY = fConvert;
else throw mdlexception("Error reading vert coord Y data for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) vert.fZ = fConvert;
else throw mdlexception("Error reading vert coord Z data for node '" + Mdl.GetNodeName(node) + "'.");
node.Mesh.TempVerts.push_back(std::move(vert));
}
else if(bFaces){
//if(DEBUG_LEVEL > 3) ReportMdl << "Reading faces data" << "" << ".\n";
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
Face face;
face.nNameIndex = nCurrentIndex;
//Currently we read the regular NWMax version with only a single set of tvert indices
if(ReadInt(nConvert)) face.nIndexVertex[0] = AsciiUShortOrInvalid(nConvert, "face vertex index 1");
else throw mdlexception("Error reading face data (vert index 1) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) face.nIndexVertex[1] = AsciiUShortOrInvalid(nConvert, "face vertex index 2");
else throw mdlexception("Error reading face data (vert index 2) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) face.nIndexVertex[2] = AsciiUShortOrInvalid(nConvert, "face vertex index 3");
else throw mdlexception("Error reading face data (vert index 3) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadUInt(uConvert)) face.nSmoothingGroup = uConvert;
else throw mdlexception("Error reading face data (smoothing group) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) face.nIndexTvert[0] = AsciiUShortOrInvalid(nConvert, "face tvert index 1");
else throw mdlexception("Error reading face data (tvert index 1) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) face.nIndexTvert[1] = AsciiUShortOrInvalid(nConvert, "face tvert index 2");
else throw mdlexception("Error reading face data (tvert index 2) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) face.nIndexTvert[2] = AsciiUShortOrInvalid(nConvert, "face tvert index 3");
else throw mdlexception("Error reading face data (tvert index 3) for node '" + Mdl.GetNodeName(node) + "'.");
face.nTextureCount++;
if(ReadInt(nConvert)) face.nMaterialID = AsciiUIntOrInvalid(nConvert, "face material id");
else throw mdlexception("Error reading face data (material ID) for node '" + Mdl.GetNodeName(node) + "'.");
if(bMagnusll){ //read tverts magnusll style
int ntv1ind1, ntv1ind2, ntv1ind3;
//bitmap2
bool bTry = true;
if(ReadInt(nConvert)) ntv1ind1 = nConvert;
else bTry = false;
if(ReadInt(nConvert)) ntv1ind2 = nConvert;
else bTry = false;
if(ReadInt(nConvert)) ntv1ind3 = nConvert;
else bTry = false;
if(bTry){
face.nIndexTvert1[0] = AsciiUShortOrInvalid(ntv1ind1, "bitmap2 tvert index 1");
face.nIndexTvert1[1] = AsciiUShortOrInvalid(ntv1ind2, "bitmap2 tvert index 2");
face.nIndexTvert1[2] = AsciiUShortOrInvalid(ntv1ind3, "bitmap2 tvert index 3");
face.nTextureCount++;
//texture0
if(ReadInt(nConvert)) ntv1ind1 = nConvert;
else bTry = false;
if(ReadInt(nConvert)) ntv1ind2 = nConvert;
else bTry = false;
if(ReadInt(nConvert)) ntv1ind3 = nConvert;
else bTry = false;
if(bTry){
face.nIndexTvert2[0] = AsciiUShortOrInvalid(ntv1ind1, "texture0 tvert index 1");
face.nIndexTvert2[1] = AsciiUShortOrInvalid(ntv1ind2, "texture0 tvert index 2");
face.nIndexTvert2[2] = AsciiUShortOrInvalid(ntv1ind3, "texture0 tvert index 3");
face.nTextureCount++;
//texture1
if(ReadInt(nConvert)) ntv1ind1 = nConvert;
else bTry = false;
if(ReadInt(nConvert)) ntv1ind2 = nConvert;
else bTry = false;
if(ReadInt(nConvert)) ntv1ind3 = nConvert;
else bTry = false;
if(bTry){
face.nIndexTvert3[0] = AsciiUShortOrInvalid(ntv1ind1, "texture1 tvert index 1");
face.nIndexTvert3[1] = AsciiUShortOrInvalid(ntv1ind2, "texture1 tvert index 2");
face.nIndexTvert3[2] = AsciiUShortOrInvalid(ntv1ind3, "texture1 tvert index 3");
face.nTextureCount++;
}
}
}
}
node.Mesh.Faces.push_back(face);
}
else if(bFaceExtra){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
if(nDataCounter < node.Mesh.Faces.size()){
Face & face = node.Mesh.Faces.at(nDataCounter);
Vector vPreservedNormal;
double fPreservedDistance = 0.0;
std::array<MdlInteger<unsigned short>, 3> nPreservedAdjacentFaces;
if(ReadFloat(fConvert)) vPreservedNormal.fX = fConvert;
else throw mdlexception("Error reading faceextra data (normal X) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) vPreservedNormal.fY = fConvert;
else throw mdlexception("Error reading faceextra data (normal Y) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) vPreservedNormal.fZ = fConvert;
else throw mdlexception("Error reading faceextra data (normal Z) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) fPreservedDistance = fConvert;
else throw mdlexception("Error reading faceextra data (distance) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) nPreservedAdjacentFaces[0] = AsciiUShortOrInvalid(nConvert, "faceextra adjacent index 1");
else throw mdlexception("Error reading faceextra data (adjacent 1) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) nPreservedAdjacentFaces[1] = AsciiUShortOrInvalid(nConvert, "faceextra adjacent index 2");
else throw mdlexception("Error reading faceextra data (adjacent 2) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) nPreservedAdjacentFaces[2] = AsciiUShortOrInvalid(nConvert, "faceextra adjacent index 3");
else throw mdlexception("Error reading faceextra data (adjacent 3) for node '" + Mdl.GetNodeName(node) + "'.");
face.bPreserveRuntimeFaceData = true;
face.vPreservedNormal = vPreservedNormal;
face.fPreservedDistance = fPreservedDistance;
face.nPreservedAdjacentFaces = nPreservedAdjacentFaces;
face.vNormal = face.vPreservedNormal;
face.fDistance = face.fPreservedDistance;
face.nAdjacentFaces = face.nPreservedAdjacentFaces;
}
else{
ThrowTooManyListRows("faceextra", Mdl.GetNodeName(node));
}
}
else if(bTverts){
//if(DEBUG_LEVEL > 3) ReportMdl << "Reading tverts data" << "" << ".\n";
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
Vector vUV;
if(ReadFloat(fConvert)) vUV.fX = fConvert;
else throw mdlexception("Error reading tvert data (coord X) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) vUV.fY = fConvert;
else throw mdlexception("Error reading tvert data (coord Y) for node '" + Mdl.GetNodeName(node) + "'.");
node.Mesh.TempTverts.push_back(vUV);
}
else if(bTexIndices1){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
if(nDataCounter < node.Mesh.Faces.size()){
Face & face = node.Mesh.Faces.at(nDataCounter);
std::array<MdlInteger<unsigned short>, 3> nIndexTvert1;
if(ReadInt(nConvert)) nIndexTvert1[0] = AsciiUShortOrInvalid(nConvert, "texindices1 index 1");
else throw mdlexception("Error reading texindices1 data (index 1) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) nIndexTvert1[1] = AsciiUShortOrInvalid(nConvert, "texindices1 index 2");
else throw mdlexception("Error reading texindices1 data (index 2) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) nIndexTvert1[2] = AsciiUShortOrInvalid(nConvert, "texindices1 index 3");
else throw mdlexception("Error reading texindices1 data (index 3) for node '" + Mdl.GetNodeName(node) + "'.");
face.nIndexTvert1 = nIndexTvert1;
face.nTextureCount++;
}
else{
ThrowTooManyListRows("texindices1", Mdl.GetNodeName(node));
}
}
else if(bTverts1){
//if(DEBUG_LEVEL > 3) ReportMdl << "Reading tverts data" << "" << ".\n";
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
Vector vUV;
if(ReadFloat(fConvert)) vUV.fX = fConvert;
else throw mdlexception("Error reading tverts1 data (coord X) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) vUV.fY = fConvert;
else throw mdlexception("Error reading tverts1 data (coord Y) for node '" + Mdl.GetNodeName(node) + "'.");
node.Mesh.TempTverts1.push_back(vUV);
}
else if(bTexIndices2){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
if(nDataCounter < node.Mesh.Faces.size()){
Face & face = node.Mesh.Faces.at(nDataCounter);
std::array<MdlInteger<unsigned short>, 3> nIndexTvert2;
if(ReadInt(nConvert)) nIndexTvert2[0] = AsciiUShortOrInvalid(nConvert, "texindices2 index 1");
else throw mdlexception("Error reading texindices2 data (index 1) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) nIndexTvert2[1] = AsciiUShortOrInvalid(nConvert, "texindices2 index 2");
else throw mdlexception("Error reading texindices2 data (index 2) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) nIndexTvert2[2] = AsciiUShortOrInvalid(nConvert, "texindices2 index 3");
else throw mdlexception("Error reading texindices2 data (index 3) for node '" + Mdl.GetNodeName(node) + "'.");
face.nIndexTvert2 = nIndexTvert2;
face.nTextureCount++;
}
else{
ThrowTooManyListRows("texindices2", Mdl.GetNodeName(node));
}
}
else if(bTverts2){
//if(DEBUG_LEVEL > 3) ReportMdl << "Reading tverts data" << "" << ".\n";
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
Vector vUV;
if(ReadFloat(fConvert)) vUV.fX = fConvert;
else throw mdlexception("Error reading tverts2 data (coord X) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) vUV.fY = fConvert;
else throw mdlexception("Error reading tverts2 data (coord Y) for node '" + Mdl.GetNodeName(node) + "'.");
node.Mesh.TempTverts2.push_back(vUV);
}
else if(bTexIndices3){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
if(nDataCounter < node.Mesh.Faces.size()){
Face & face = node.Mesh.Faces.at(nDataCounter);
std::array<MdlInteger<unsigned short>, 3> nIndexTvert3;
if(ReadInt(nConvert)) nIndexTvert3[0] = AsciiUShortOrInvalid(nConvert, "texindices3 index 1");
else throw mdlexception("Error reading texindices3 data (index 1) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) nIndexTvert3[1] = AsciiUShortOrInvalid(nConvert, "texindices3 index 2");
else throw mdlexception("Error reading texindices3 data (index 2) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) nIndexTvert3[2] = AsciiUShortOrInvalid(nConvert, "texindices3 index 3");
else throw mdlexception("Error reading texindices3 data (index 3) for node '" + Mdl.GetNodeName(node) + "'.");
face.nIndexTvert3 = nIndexTvert3;
face.nTextureCount++;
}
else{
ThrowTooManyListRows("texindices3", Mdl.GetNodeName(node));
}
}
else if(bTverts3){
//if(DEBUG_LEVEL > 3) ReportMdl << "Reading tverts data" << "" << ".\n";
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
Vector vUV;
if(ReadFloat(fConvert)) vUV.fX = fConvert;
else throw mdlexception("Error reading tvert3 data (coord X) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) vUV.fY = fConvert;
else throw mdlexception("Error reading tvert3 data (coord Y) for node '" + Mdl.GetNodeName(node) + "'.");
node.Mesh.TempTverts3.push_back(vUV);
}
else if(bNormalIndices){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
if(nDataCounter < node.Mesh.Faces.size()){
Face & face = node.Mesh.Faces.at(nDataCounter);
std::array<MdlInteger<unsigned short>, 3> nIndexNormal;
if(ReadInt(nConvert)) nIndexNormal[0] = AsciiUShortOrInvalid(nConvert, "normalindices index 1");
else throw mdlexception("Error reading normalindices data (index 1) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) nIndexNormal[1] = AsciiUShortOrInvalid(nConvert, "normalindices index 2");
else throw mdlexception("Error reading normalindices data (index 2) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) nIndexNormal[2] = AsciiUShortOrInvalid(nConvert, "normalindices index 3");
else throw mdlexception("Error reading normalindices data (index 3) for node '" + Mdl.GetNodeName(node) + "'.");
face.nIndexNormal = nIndexNormal;
}
else{
ThrowTooManyListRows("normalindices", Mdl.GetNodeName(node));
}
}
else if(bNormals){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
Vector vNormal;
if(ReadFloat(fConvert)) vNormal.fX = fConvert;
else throw mdlexception("Error reading normal data (coord X) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) vNormal.fY = fConvert;
else throw mdlexception("Error reading normal data (coord Y) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) vNormal.fZ = fConvert;
else throw mdlexception("Error reading normal data (coord Z) for node '" + Mdl.GetNodeName(node) + "'.");
node.Mesh.TempNormals.push_back(vNormal);
}
else if(bTangentBasis){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
std::array<Vector, 3> basis;
for(int nBasis = 0; nBasis < 3; nBasis++){
if(ReadFloat(fConvert)) basis.at(nBasis).fX = fConvert;
else throw mdlexception("Error reading tangentbasis data (coord X) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) basis.at(nBasis).fY = fConvert;
else throw mdlexception("Error reading tangentbasis data (coord Y) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) basis.at(nBasis).fZ = fConvert;
else throw mdlexception("Error reading tangentbasis data (coord Z) for node '" + Mdl.GetNodeName(node) + "'.");
}
node.Mesh.TempTangent1.push_back(basis);
}
else if(bSaberData){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
VertexData sd;
if(ReadFloat(fConvert)) sd.vVertex.fX = fConvert;
else throw mdlexception("Error reading saberdata vertex X for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) sd.vVertex.fY = fConvert;
else throw mdlexception("Error reading saberdata vertex Y for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) sd.vVertex.fZ = fConvert;
else throw mdlexception("Error reading saberdata vertex Z for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) sd.vUV1.fX = fConvert;
else throw mdlexception("Error reading saberdata UV U for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) sd.vUV1.fY = fConvert;
else throw mdlexception("Error reading saberdata UV V for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) sd.vNormal.fX = fConvert;
else throw mdlexception("Error reading saberdata normal X for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) sd.vNormal.fY = fConvert;
else throw mdlexception("Error reading saberdata normal Y for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) sd.vNormal.fZ = fConvert;
else throw mdlexception("Error reading saberdata normal Z for node '" + Mdl.GetNodeName(node) + "'.");
node.Saber.SaberData.push_back(std::move(sd));
node.Saber.bPreserveSaberData = true;
}
else if(bColorIndices){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
if(nDataCounter < node.Mesh.Faces.size()){
Face & face = node.Mesh.Faces.at(nDataCounter);
std::array<MdlInteger<unsigned short>, 3> nIndexColor;
if(ReadInt(nConvert)) nIndexColor[0] = AsciiUShortOrInvalid(nConvert, "colorindices index 1");
else throw mdlexception("Error reading color indices data (index 1) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) nIndexColor[1] = AsciiUShortOrInvalid(nConvert, "colorindices index 2");
else throw mdlexception("Error reading color indices data (index 2) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadInt(nConvert)) nIndexColor[2] = AsciiUShortOrInvalid(nConvert, "colorindices index 3");
else throw mdlexception("Error reading color indices data (index 3) for node '" + Mdl.GetNodeName(node) + "'.");
face.nIndexColor = nIndexColor;
face.nTextureCount++;
}
else{
ThrowTooManyListRows("colorindices", Mdl.GetNodeName(node));
}
}
else if(bColors){
//if(DEBUG_LEVEL > 3) ReportMdl << "Reading color data" << "" << ".\n";
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
Color cColor;
if(ReadFloat(fConvert)) cColor.fR = fConvert;
else throw mdlexception("Error reading color data (1) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) cColor.fG = fConvert;
else throw mdlexception("Error reading color data (2) for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadFloat(fConvert)) cColor.fB = fConvert;
else throw mdlexception("Error reading color data (3) for node '" + Mdl.GetNodeName(node) + "'.");
node.Mesh.TempColors.push_back(std::move(cColor));
}
else if(bConstraints){
//if(DEBUG_LEVEL > 3) ReportMdl << "Reading constraints data" << "" << ".\n";
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
if(ReadFloat(fConvert)) node.Dangly.TempConstraints.push_back(fConvert);
else throw mdlexception("Error reading constraint data for node '" + Mdl.GetNodeName(node) + "'.");
}
else if(bWeights){
//if(DEBUG_LEVEL > 3) ReportMdl << "Reading weights data" << "" << ".\n";
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
//node.Skin.Bones[nCurrentIndex].nNameIndex = nCurrentIndex;
int z = 0;
int nNameIndex = 0;
Weight weight;
//std::vector<int> & nWeightIndices = node.Skin.BoneNameIndices;
while(z < 4){
//Get first name
if(!ReadUntilText(sID, false)) break;
std::string sCheck (sID);
ToLowerInPlace(sCheck);
if(sCheck != "root" && sCheck != "null" && sCheck != "-1"){
TruncateLongName3216(sID, "weight bone name", nLine, false);
}
// Resolve every active weight through the ASCII name table.
// Older code special-cased the literal token "root" by
// reading its numeric value but never storing either the
// bone index or the weight, which silently converted an
// active influence into an inactive zero-weight slot.
for(nNameIndex = 0; nNameIndex < static_cast<int>(Data.MH.Names.size()); nNameIndex++){
if(StringEqual(Data.MH.Names[nNameIndex].sName, sID)) break;
}
if(nNameIndex == static_cast<int>(Data.MH.Names.size())){
ReportMdl << "Reading weights data: failed to find name in name array! Name: " << sID << ".\n";
throw mdlexception("Error reading weight data for node '" + Mdl.GetNodeName(node) + "'. Could not find bone '" + sID + "' by name.");
}
weight.nWeightIndex[z] = AsciiUShortIndex(static_cast<unsigned int>(nNameIndex), "weight bone name index");
if(ReadFloat(fConvert)) weight.fWeightValue[z] = fConvert;
else throw mdlexception("Error reading weight data for node '" + Mdl.GetNodeName(node) + "'. No weight value for bone '" + sID + "'.");
z++;
}
if(z < 1){
//This means we exited before writing a single piece of data
ReportMdl << "Didn't even find one name" << "" << ".\n";
ReportMdl << "DataCounter: " << nDataCounter << ". DataMax: " << nDataMax.Print() << ".\n";
throw mdlexception("Error reading weight data for node '" + Mdl.GetNodeName(node) + "'. No weights specified for a vertex.");
}
else{
/// Here we assume that everything went fine, so we add the weight to our list
node.Skin.TempWeights.push_back(std::move(weight));
}
}
else if(bCompactBoneMap){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
if(!ReadUntilText(sID, false)) throw mdlexception("Error reading compactbonemap data for node '" + Mdl.GetNodeName(node) + "'.");
std::string sCheck(sID);
ToLowerInPlace(sCheck);
if(sCheck != "root" && sCheck != "null" && sCheck != "-1"){
TruncateLongName3216(sID, "compactbonemap bone name", nLine, false);
sCheck = sID;
ToLowerInPlace(sCheck);
}
MdlInteger<unsigned short> nNameIndex;
if(sCheck != "root" && sCheck != "null" && sCheck != "-1"){
bool bFoundName = false;
for(unsigned int n = 0; n < Data.MH.Names.size(); n++){
if(StringEqual(Data.MH.Names.at(n).sName, sID)){
nNameIndex = AsciiUShortIndex(n, "compactbonemap bone name index");
bFoundName = true;
break;
}
}
if(!bFoundName) throw mdlexception("compactbonemap references unknown bone '" + sID + "' on node '" + Mdl.GetNodeName(node) + "'.");
}
EnsureAsciiVectorSize(node.Skin.TempCompactBoneNameIndices, static_cast<std::size_t>(nDataCounter) + 1u, "compactbonemap");
node.Skin.TempCompactBoneNameIndices.at(nDataCounter) = nNameIndex;
}
else if(bCompactBoneMapRaw){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
if(ReadInt(nConvert)){
if(nConvert < 0 || nConvert > 65535) throw mdlexception("compactbonemapraw value is outside uint16 range.");
EnsureAsciiVectorSize(node.Skin.TempCompactBoneRawIndices, static_cast<std::size_t>(nDataCounter) + 1u, "compactbonemapraw");
node.Skin.TempCompactBoneRawIndices.at(nDataCounter) = static_cast<unsigned short>(nConvert);
}
else throw mdlexception("Error reading compactbonemapraw data for node '" + Mdl.GetNodeName(node) + "'.");
}
else if(bBoneConstantIndices){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
if(ReadUInt(uConvert)){
if(nDataCounter >= node.Skin.Bones.size()){
throw mdlexception("boneconstantindices row exceeds the current skin bone table for node '" + Mdl.GetNodeName(node) + "'.");
}
node.Skin.Bones.at(nDataCounter).nPadding = uConvert;
}
else throw mdlexception("Error reading boneconstantindices data for node '" + Mdl.GetNodeName(node) + "'.");
}
else if(bExtraData){
Animation & anim = Data.MH.Animations.back();
Node & node = anim.ArrayOfNodes.back();
if(ReadFloat(fConvert)){
EnsureAsciiVectorSize(node.Head.ControllerData, static_cast<std::size_t>(nDataCounter) + 1u, 0.0, "extra_data");
node.Head.ControllerData.at(nDataCounter) = fConvert;
}
else throw mdlexception("Error reading extra_data payload for animation node '" + Data.MH.Names.at(node.Head.nNameIndex).sName + "'.");
}
else if(bControllerRaw){
Node & node = nAnimation.Valid() ? Data.MH.Animations.back().ArrayOfNodes.back() : Data.MH.ArrayOfNodes.at(nCurrentIndex);
Controller ctrl;
if(ReadUInt(uConvert)) ctrl.nControllerType = uConvert;
else throw mdlexception("Error reading controllerraw type for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadUInt(uConvert)){
if(uConvert > 65535) throw mdlexception("controllerraw unknown2 is outside uint16 range.");
ctrl.nUnknown2 = static_cast<unsigned short>(uConvert);
}
else throw mdlexception("Error reading controllerraw unknown2 for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadUInt(uConvert)){
if(uConvert > 65535) throw mdlexception("controllerraw value count is outside uint16 range.");
ctrl.nValueCount = static_cast<unsigned short>(uConvert);
}
else throw mdlexception("Error reading controllerraw value count for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadUInt(uConvert)){
if(uConvert > 65535) throw mdlexception("controllerraw timekey start is outside uint16 range.");
ctrl.nTimekeyStart = static_cast<unsigned short>(uConvert);
}
else throw mdlexception("Error reading controllerraw timekey start for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadUInt(uConvert)){
if(uConvert > 65535) throw mdlexception("controllerraw data start is outside uint16 range.");
ctrl.nDataStart = static_cast<unsigned short>(uConvert);
}
else throw mdlexception("Error reading controllerraw data start for node '" + Mdl.GetNodeName(node) + "'.");
if(ReadUInt(uConvert)){
if(uConvert > 255) throw mdlexception("controllerraw column count is outside uint8 range.");
ctrl.nColumnCount = static_cast<unsigned char>(uConvert);
}
else throw mdlexception("Error reading controllerraw column count for node '" + Mdl.GetNodeName(node) + "'.");
for(int nPad = 0; nPad < 3; nPad++){
if(ReadUInt(uConvert)){
if(uConvert > 255) throw mdlexception("controllerraw padding byte is outside uint8 range.");
ctrl.nPadding.at(nPad) = static_cast<char>(static_cast<unsigned char>(uConvert));
}
else throw mdlexception("Error reading controllerraw padding for node '" + Mdl.GetNodeName(node) + "'.");
}
ctrl.nNameIndex = node.Head.nNameIndex;
ctrl.nAnimation = nAnimation;
node.Head.Controllers.push_back(ctrl);
}
else if(bControllerDataRaw){
Node & node = nAnimation.Valid() ? Data.MH.Animations.back().ArrayOfNodes.back() : Data.MH.ArrayOfNodes.at(nCurrentIndex);
if(ReadUInt(uConvert)) node.Head.ControllerData.push_back(FloatFromBits(uConvert));
else throw mdlexception("Error reading controllerdataraw data for node '" + Mdl.GetNodeName(node) + "'.");
}
else if(bTextureNames){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
std::string sValue;
if(ReadUntilText(sValue, false)){
Name name;
name.sName = sValue;
node.Light.FlareTextureNames.push_back(name);
}
else throw mdlexception("Error reading flare texture name data for node '" + Mdl.GetNodeName(node) + "'.");
}
else if(bFlareSizes){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
if(ReadFloat(fConvert)) node.Light.FlareSizes.push_back(fConvert);
else throw mdlexception("Error reading flare size data for node '" + Mdl.GetNodeName(node) + "'.");
}
else if(bFlarePositions){
Node & node = Data.MH.ArrayOfNodes.at(nCurrentIndex);
if(ReadFloat(fConvert)) node.Light.FlarePositions.push_back(fConvert);
else throw mdlexception("Error reading flare position data for node '" + Mdl.GetNodeName(node) + "'.");
}
else if(bFlareColorShifts){