-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMODExtractor.pas
3102 lines (2087 loc) · 79.3 KB
/
MMODExtractor.pas
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
program MMODExtractor;
{==============================================================================================}
{ }
{ ce programme ouvre tous les fichiers .mmod se trouvant dans son répertoire et retrouve tous }
{ les LODs dans chacun d'eux pour en faire un fichier OBJ - 1 fichier OBJ part LOD }
{ }
{==============================================================================================}
uses sysutils, dos,strutils, Bin_Util, math;
const
PrintSizeLI = false;
var
FMmod, { fichier Mmod source }
FVertex : file; { fichier des vertexs }
FRapport : Text; { Rapport du travail fait }
FOBJ : Text; { fichier destination }
FMatLib : Text;
FSDCObj : Text;
FSDCMatLib : Text;
FPath : Text;
KeyWordIterations, IndicesTrackerGlobal, ItemNamesTracker, ItemNamesTracker2, GlobalSubsetTracker, LocalSubsetTracker, NoTextureTracker : longint;
GlobalName, TexturesPath : string;
ItemNames : array of string;
LODsTable : array of longint;
SubsetsTable : array of longint;
LODsPassed, LODsAdded, GlobalIndicesInc, GlobalIndicesTracker, GlobalSubsetTracker2, GlobalSubsetSpecialTracker, GlobalMatrixTracker, NbSubset : longint;
IncIndicesYes, IsModelBSP, CanMatrix, DoExtractLOD4, FlipModel, IsPlane, IsGun, KeepSettings, AskedSettings, PassNextThrow : boolean;
MatrixMoveXList, MatrixMoveYList, MatrixMoveZList : array of single;
{*****************************************************************************************************}
{ lit le mot clef dans le fichier source }
{*****************************************************************************************************}
Function ReadKeyWord : string;
var
LI : longint;
S : string;
begin
KeyWordIterations:=0;
ReadKeyWord:=''; { valeur par défaut }
{$I-}
BlockRead(FMmod,LI,4); { lit la longueur du mot }
{$I+}
KeyWordIterations:=KeyWordIterations+4;
if IOResult<>0 then exit;
{$I-}
BlockRead(FMmod,S[1],LI); { lit le mot clef }
{$I+}
S[0]:=chr(LI);
KeyWordIterations:=KeyWordIterations+LI;
if IOResult=0 then ReadKeyWord:=S; { met à jour la valeur de la fonction }
end;
{*****************************************************************************************************}
{ retourne la même chaine de caractère que S mais tout en majuscules }
{*****************************************************************************************************}
Function StrMajuscule(s:string):string;
var
i :integer;
s2 : string;
begin
S2:='';
for i:= 1 to length(s) do begin
case s[i] of
'a'..'z' : S2:=S2+chr(ord(S[i])-32);
else
S2:=S2+S[i]
end;
end;
StrMajuscule:=S2;
end;
{ IMPORTED FUNCTIONS FROM OTHER MMOD CONVERTERS START }
Function StrR(R:single) : string;
var
S : string;
begin
str(R:13:6,S);
StrR:=S;
end;
Function ReadR : single;
var
R : single;
begin
ReadR:=0;
{$I-}
BlockRead(Fmmod,R,4);
{$I+}
if IOResult=0 then ReadR:=R;
end;
Function StrLI(LI:longint) : string;
var
S : string;
begin
str(LI:8,S);
StrLI:=S;
end;
Function KeywordFind(S1 : string) : boolean;
var
p : longint;
S2 : string;
begin
KeyWordIterations:=0;
KeywordFind:=false;
p:=filepos(Fmmod);
{$i-}
BlockRead(Fmmod,S2[1],length(S1));
{$i+}
KeyWordIterations:=KeyWordIterations+length(S1);
if IOResult<>0 then begin
seek(FMmod,p);
exit;
end;
S2[0]:=S1[0];
KeywordFind:=S1=S2;
Seek(Fmmod,p);
end;
Function StrSizeLI(LI : longint) : string;
var
S : string;
begin
if PrintSizeLI then begin
str(LI,S);
s:=s+' ';
end
else
S:='';
StrSizeLI:=S;
end;
Function ReadB : byte;
var
B : byte;
begin
ReadB:=0;
{$I-}
Blockread(Fmmod,B,1);
{$I+}
if IOResult=0 then Readb:=B;
end;
Function ReadLI(readNums:longint): longint;
var
LI : longint;
begin
ReadLI:=0;
{$I-}
Blockread(Fmmod,LI,readNums);
{$I+}
if IOResult=0 then ReadLI:=LI;
end;
Procedure WriteW(W:word);
var
s : string;
begin
str(W,S);
Writeln(S);
end;
{ IMPORTED FUNCTIONS FROM OTHER MMOD CONVERTERS END }
{*****************************************************************************************************}
{ Constriut le fichier OBJ pour le subset demandé }
{ PosBeginIndices est la position du début de la section 'Indices' dans le ficjier mmod source }
{ NFirstVertex est le N° du premier vertex pour un indice valant 0 (le premier a le N° 0) }
{ dans le cas ou il y a plusieurs vertexstream dans le même mesh - VertexStreamindex<>0 dans subset }
{*****************************************************************************************************}
Procedure BuildSubset(name:string; PosBeginIndices, NFirstVertex, IndicesType : longint; TexName : string; IsLOD4 : boolean; MSHD : string; LocalSubsetTracker : longint);
var
LI,
FirstVertex,
NbVertex,
FirstIndice,
NbIndice : longint;
TR3 : array[1..3] of single; { stockage temporaire d'une composante des vertexs }
TW3 : array[1..3] of word; { stockage temporaire d'un indice }
TW3_ext : array[1..6] of word; { stockage temporaire d'un indice }
inc1 : longint;
inc2 : longint;
inc3 : longint;
S, OtherFileName : string;
int1 : longint;
int2 : longint;
int3 : longint;
OBJFile : text;
OBJMtlFile : text;
{IsGlass, IsFoliage, IsDefault, IsSoldiers, }IsOther, CanProceed{, OtherMSHD} : boolean;
OtherMSHDs : array of string;
MatrixX, MatrixY, MatrixZ : single;
begin
{ Lire les valeur de position et de nombre de vertex et d'incices }
BlockRead(FMmod,LI,4);
BlockRead(FMmod,FirstVertex,4);
BlockRead(FMmod,NbVertex,4);
BlockRead(FMmod,FirstIndice,4); FirstIndice:=FirstIndice div 3;
BlockRead(FMmod,NbIndice,4);
if DoExtractLOD4 = false then begin
IsLOD4:=false;
end;
CanProceed:=true;
OBJFile:=FOBJ;
if NbIndice = 0 then begin
IsLOD4:=false;
CanProceed:=false;
Writeln('---- ERROR: NO INDICES FOUND FOR "'+name+' '+MSHD+'"! ----');
WriteLN(OBJFile);Flush(OBJFile);
WriteLN(OBJFile,'# ---- ERROR: NO INDICES FOUND FOR "'+name+' '+MSHD+'"! ----');Flush(OBJFile);
WriteLN(OBJFile);Flush(OBJFile);
end;
if CanProceed = true then begin
{ SUBSET INDICE DIFFERENTIATION START }
IsOther:=false;
//OtherMSHD:=false;
//if GlobalSubsetTracker2<>0 then begin
int2:=FilePos(FMmod);
//Writeln(TexName);
SetLength(OtherMSHDs, 50);
OtherMSHDs[0]:='shipalphatestindexed.mshd';
OtherMSHDs[1]:='shipvcindexed.mshd';
OtherMSHDs[2]:='shipwindowindexed.mshd';
OtherMSHDs[3]:='ropeindexed.mshd';
OtherMSHDs[4]:='shipnumberindexed.mshd';
OtherMSHDs[5]:='texturedindexed.mshd';
OtherMSHDs[6]:='soldiers.mshd';
OtherMSHDs[7]:='soldier.mshd';
OtherMSHDs[8]:='cockpitwin.mshd';
OtherMSHDs[9]:='foliage.mshd';
OtherMSHDs[10]:='default.mshd';
OtherMSHDs[11]:='planealpha.mshd';
if IndicesType=102 then begin
seek(FMmod, PosBeginIndices+(FirstIndice*2*6));
Blockread(FMmod,TW3_ext,12);
str(TW3_ext[1],S);
int1:=StrToInt(S);
str(TW3_ext[2],S);
inc1:=StrToInt(S);
str(TW3_ext[3],S);
int2:=StrToInt(S);
str(TW3_ext[4],S);
inc2:=StrToInt(S);
str(TW3_ext[5],S);
int3:=StrToInt(S);
str(TW3_ext[6],S);
inc3:=StrToInt(S);
if IsLOD4=true then begin
dec(int1,FirstVertex);
dec(int2,FirstVertex);
dec(int3,FirstVertex);
end;
inc(int1);
inc(int2);
inc(int3);
int1:=int1+(65535*inc1)+inc1;
int2:=int2+(65535*inc2)+inc2;
int3:=int3+(65535*inc3)+inc3;
{str(int1,S);
Writeln('First indice: '+S);
str(inc1,S);
Writeln('Second indice: '+S);}
end;
if IndicesType=101 then begin
seek(FMmod, PosBeginIndices+(FirstIndice*2*3));
Blockread(FMmod,TW3,6);
str(TW3[1],S);
int1:=StrToInt(S);
str(TW3[2],S);
int2:=StrToInt(S);
str(TW3[3],S);
int3:=StrToInt(S);
if IsLOD4=true then begin
dec(int1,FirstVertex);
dec(int2,FirstVertex);
dec(int3,FirstVertex);
end;
inc(int1);
inc(int2);
inc(int3);
//str(int1,S);
//Writeln('First indice: '+S);
end;
{IsGlass:=((CompareText('cockpitwin.mshd',MSHD)=0) and (int1=1));
IsFoliage:=((CompareText('foliage.mshd',MSHD)=0) and (int1=1));
IsDefault:=((CompareText('default.mshd',MSHD)=0) and (int1=1));
IsSoldiers:=((CompareText('soldiers.mshd',MSHD)=0) and (int1=1));}
if IsLOD4 = true then begin
LocalSubsetTracker:=LocalSubsetTracker - 1;
end;
if ((int1 = 1) or (int2 = 1) or (int3 = 1)) and (LocalSubsetTracker > 0) then begin
if PassNextThrow = false then begin
IsOther:=true;
end else begin
PassNextThrow:=false;
end;
end;
if IsOther = false then begin
for int3:=1 to Length(OtherMSHDs) do begin
if CompareText(OtherMSHDs[int3-1],MSHD) = 0 then begin
if IsLOD4 = false then begin
IsOther:=true;
if LocalSubsetTracker = 0 then begin
PassNextThrow:=true;
end;
break;
end;
end;
end;
end;
str(GlobalSubsetSpecialTracker,S);
if IsLOD4 = true then begin
name:=name+'_LOD4';
assign(OBJFile,name+'.OBJ');
Rewrite(OBJFile);
assign(OBJMtlFile,name+'.mtl');
Rewrite(OBJMtlFile);
Writeln('-- "'+name+'.OBJ" created --');
Writeln('-- "'+name+'.mtl" created --');
WriteLN(OBJFile,'# File created by MMOD Model Extractor v1.0 for Battlestations: Pacific');Flush(OBJFile);
WriteLN(OBJFile);Flush(OBJFile);
WriteLN(OBJFile,'mtllib '+name+'.mtl');Flush(OBJFile);
WriteLN(OBJFile);Flush(OBJFile);
WriteLN(OBJMtlFile,'newmtl '+name+' '+MSHD);Flush(OBJMtlFile);
WriteLN(OBJMtlFile,'Kd 0.502 0.502 0.502');Flush(OBJMtlFile);
WriteLN(OBJMtlFile,'Ks 0.25 0.25 0.25');Flush(OBJMtlFile);
WriteLN(OBJMtlFile,'Ns 30');Flush(OBJMtlFile);
WriteLN(OBJMtlFile,'map_Kd '+TexturesPath+'\'+TexName+'.dds');Flush(OBJMtlFile);
end else if IsOther=true then begin
OtherFileName:=MSHD;
Delete(OtherFileName,(Length(OtherFileName)-4),5);
assign(OBJFile,name+'_'+OtherFileName+'_'+S+'.OBJ');
Rewrite(OBJFile);
Writeln('-- "'+name+'_'+OtherFileName+'_'+S+'.OBJ" created --');
WriteLN(OBJFile,'# File created by MMOD Model Extractor v1.0 for Battlestations: Pacific');Flush(OBJFile);
WriteLN(OBJFile);Flush(OBJFile);
WriteLN(OBJFile,'mtllib '+name+'.mtl');Flush(OBJFile);
WriteLN(OBJFile);Flush(OBJFile);
GlobalSubsetSpecialTracker:=GlobalSubsetSpecialTracker+1;
end;
seek(FMmod, int2);
//end;
{ SUBSET INDICE DIFFERENTIATION END }
TexName:=TexName+' '+MSHD;
{Writeln('LI: '+IntToStr(LI));
Writeln('FirstVertex: '+IntToStr(FirstVertex));
Writeln('NbVertex: '+IntToStr(NbVertex));
Writeln('FirstIndice: '+IntToStr(FirstIndice));
Writeln('NbIndice: '+IntToStr(NbIndice));}
WriteLN(OBJFile,'# ---- OBJECT START ----');Flush(OBJFile);
WriteLN(OBJFile);Flush(OBJFile);
{ lire la composante 'V' des vertexs et les écrire dans le fichier destination }
for LI:=FirstVertex+NFirstVertex to pred(FirstVertex+NFirstVertex+NbVertex) do begin
seek(FVertex,LI*8*4); { se positionner dans le fichier de vertex }
BlockRead(FVertex,TR3,3*4); { Lire les 3 réels }
if IsNan(TR3[1]) or IsInfinite(TR3[1]) then begin
TR3[1]:=0;
end;
if IsNan(TR3[2]) or IsInfinite(TR3[2]) then begin
TR3[2]:=0;
end;
if IsNan(TR3[3]) or IsInfinite(TR3[3]) then begin
TR3[3]:=0;
end;
MatrixX:=0;
MatrixY:=0;
MatrixZ:=0;
if CanMatrix = true then begin
MatrixX:=MatrixMoveXList[GlobalMatrixTracker - 1];
MatrixY:=MatrixMoveYList[GlobalMatrixTracker - 1];
MatrixZ:=MatrixMoveZList[GlobalMatrixTracker - 1];
end;
if FlipModel = true then begin
TR3[3]:=-(TR3[3]);
MatrixZ:=-(MatrixZ);
{end else begin
TR3[1]:=-(TR3[1]);
MatrixX:=-(MatrixX);}
end;
TR3[1]:=TR3[1] + MatrixX;
TR3[2]:=TR3[2] + MatrixY;
TR3[3]:=TR3[3] + MatrixZ;
WriteLN(OBJFile,'v',' ',TR3[1]:1:6,' ',TR3[2]:1:6,' ',TR3[3]:1:6); { écrire dans le fichier destination }
Flush(OBJFile);
end;
{ lire la composante 'Vt' des vertexs et les écrire dans le fichier destination }
for LI:=FirstVertex+NFirstVertex to pred(FirstVertex+NFirstVertex+NbVertex) do begin
seek(FVertex,LI*8*4+6*4); { se positionner dans le fichier de vertex }
BlockRead(FVertex,TR3,2*4); { Lire les 2 réels }
if IsNan(TR3[1]) or IsInfinite(TR3[1]) then begin
TR3[1]:=0;
end;
if IsNan(TR3[2]) or IsInfinite(TR3[2]) then begin
TR3[2]:=0;
end;
if IsModelBSP = false then begin
TR3[1]:=TR3[1];
TR3[2]:=-TR3[2];
end else begin
TR3[1]:=-TR3[1];
TR3[2]:=-TR3[2];
end;
WriteLN(OBJFile,'vt',' ',TR3[1]:1:6,' ',TR3[2]:1:6); { écrire dans le fichier destination }
Flush(OBJFile);
end;
{ lire la composante 'Vn' des vertexs et les écrire dans le fichier destination }
for LI:=FirstVertex+NFirstVertex to pred(FirstVertex+NFirstVertex+NbVertex) do begin
seek(FVertex,LI*8*4+3*4); { se positionner dans le fichier de vertex }
BlockRead(FVertex,TR3,3*4); { Lire les 3 réels }
if IsNan(TR3[1]) or IsInfinite(TR3[1]) then begin
TR3[1]:=0;
end;
if IsNan(TR3[2]) or IsInfinite(TR3[2]) then begin
TR3[2]:=0;
end;
if IsNan(TR3[3]) or IsInfinite(TR3[3]) then begin
TR3[3]:=0;
end;
MatrixX:=0;
MatrixY:=0;
MatrixZ:=0;
if CanMatrix = true then begin
MatrixX:=MatrixMoveXList[GlobalMatrixTracker - 1];
MatrixY:=MatrixMoveYList[GlobalMatrixTracker - 1];
MatrixZ:=MatrixMoveZList[GlobalMatrixTracker - 1];
end;
if FlipModel = true then begin
TR3[3]:=-(TR3[3]);
MatrixZ:=-(MatrixZ);
{end else begin
TR3[1]:=-(TR3[1]);
MatrixX:=-(MatrixX);}
end;
TR3[1]:=TR3[1] + MatrixX;
TR3[2]:=TR3[2] + MatrixY;
TR3[3]:=TR3[3] + MatrixZ;
WriteLN(OBJFile,'vn',' ',TR3[1]:1:6,' ',TR3[2]:1:6,' ',TR3[3]:1:6); { écrire dans le fichier destination }
Flush(OBJFile);
end;
if IsLOD4=true then begin
WriteLN(OBJFile);Flush(OBJFile);
WriteLN(OBJFile,'g '+name+' '+MSHD);Flush(OBJFile);
WriteLN(OBJFile,'usemtl '+name+' '+MSHD);Flush(OBJFile);
end else begin
WriteLN(OBJFile);Flush(OBJFile);
WriteLN(OBJFile,'g '+TexName);Flush(OBJFile);
WriteLN(OBJFile,'usemtl '+TexName);Flush(OBJFile);
end;
{* Extended Indices format *}
if IndicesType=102 then begin
{ lire les indices et mettre à jour leur valeur avant d'écrire dans le fichier destination }
for LI:=FirstIndice to pred(Firstindice+NbIndice) do begin
seek(FMmod,PosBeginIndices+(LI*2*6)); { se positionner dans le fichier source }
Blockread(FMmod,TW3_ext,12); { lire 6 entiers }
str(TW3_ext[1],S);
int1:=StrToInt(S);
str(TW3_ext[3],S);
int2:=StrToInt(S);
str(TW3_ext[5],S);
int3:=StrToInt(S);
str(TW3_ext[2],S);
inc1:=StrToInt(S);
str(TW3_ext[4],S);
inc2:=StrToInt(S);
str(TW3_ext[6],S);
inc3:=StrToInt(S);
{ ajuster la valeur des indices }
if (IsLOD4 = true) or (IsOther = true) then begin
dec(int1,FirstVertex);
dec(int2,FirstVertex);
dec(int3,FirstVertex);
end;
inc(int1);
inc(int2);
inc(int3);
{if CompareText('foliage.mshd',MSHD)=0 then begin
Writeln('FOLIAGE!!!!!!!');
GlobalIndicesTracker:=int3+(65535*inc3)+inc3;
int1:=int1+GlobalIndicesInc;
int2:=int2+GlobalIndicesInc;
int3:=int3+GlobalIndicesInc;
end else begin
GlobalIndicesInc:=int3+(65535*inc3)+inc3;
int1:=int1+GlobalIndicesTracker;
int2:=int2+GlobalIndicesTracker;
int3:=int3+GlobalIndicesTracker;
end;}
{if TW3_ext[2]>0 then begin
inc1:=1;
end;
if TW3_ext[4]>0 then begin
inc2:=1;
end;
if TW3_ext[6]>0 then begin
inc3:=1;
end;}
{ écrire les indices dans le fichier destination }
if FlipModel = true then begin
Writeln(OBJFile,'f ',
int3+(65535*inc3)+inc3,'/',int3+(65535*inc3)+inc3,'/',int3+(65535*inc3)+inc3,' ',
int2+(65535*inc2)+inc2,'/',int2+(65535*inc2)+inc2,'/',int2+(65535*inc2)+inc2,' ',
int1+(65535*inc1)+inc1,'/',int1+(65535*inc1)+inc1,'/',int1+(65535*inc1)+inc1
);
Flush(OBJFile);
end else begin
Writeln(OBJFile,'f ',
int1+(65535*inc1)+inc1,'/',int1+(65535*inc1)+inc1,'/',int1+(65535*inc1)+inc1,' ',
int2+(65535*inc2)+inc2,'/',int2+(65535*inc2)+inc2,'/',int2+(65535*inc2)+inc2,' ',
int3+(65535*inc3)+inc3,'/',int3+(65535*inc3)+inc3,'/',int3+(65535*inc3)+inc3
);
Flush(OBJFile);
end;
{Writeln(OBJFile,'f ',
TW3_ext[1]+(65535*TW3_ext[2])+inc1,'/',TW3_ext[1]+(65535*TW3_ext[2])+inc1,'/',TW3_ext[1]+(65535*TW3_ext[2])+inc1,' ',
TW3_ext[3]+(65535*TW3_ext[4])+inc2,'/',TW3_ext[3]+(65535*TW3_ext[4])+inc2,'/',TW3_ext[3]+(65535*TW3_ext[4])+inc2,' ',
TW3_ext[5]+(65535*TW3_ext[6])+inc3,'/',TW3_ext[5]+(65535*TW3_ext[6])+inc3,'/',TW3_ext[5]+(65535*TW3_ext[6])+inc3
);}
{Writeln(OBJFile,'f ',
TW3_ext[1],'/',TW3_ext[1],'/',TW3_ext[1],' ',
TW3_ext[3],'/',TW3_ext[3],'/',TW3_ext[3],' ',
TW3_ext[5],'/',TW3_ext[5],'/',TW3_ext[5]
);}
{Writeln(OBJFile,'f ',
int1,'/',TW3_ext[2],'/',int2,'/',TW3_ext[4],'/',int3,'/',TW3_ext[6]
);}
//GlobalIndicesInc:=int3+(65535*inc3)+inc3;
//GlobalIndicesInc:=GlobalIndicesInc+3;
end;
end;
{* Extended Indices format *}
if IndicesType=101 then begin
{ lire les indices et mettre à jour leur valeur avant d'écrire dans le fichier destination }
for LI:=FirstIndice to pred(Firstindice+NbIndice) do begin
seek(FMmod,PosBeginIndices+(LI*2*3)); { se positionner dans le fichier source }
Blockread(FMmod,TW3,6); { lire 3 entiers }
{ lire 3 entiers }
{TW3[1]:=ReadLI(2);
TW3[2]:=ReadLI(2);
TW3[3]:=ReadLI(2);}
{ ajuster la valeur des indices }
if (IsLOD4 = true) or (IsOther = true) then begin
dec(TW3[1],FirstVertex);
dec(TW3[2],FirstVertex);
dec(TW3[3],FirstVertex);
end;
inc(TW3[1]);
inc(TW3[2]);
inc(TW3[3]);
{ écrire les indices dans le fichier destination }
if FlipModel = true then begin
Writeln(OBJFile,'f ',
TW3[3],'/',TW3[3],'/',TW3[3],' ',
TW3[2],'/',TW3[2],'/',TW3[2],' ',
TW3[1],'/',TW3[1],'/',TW3[1]
);
Flush(OBJFile);
end else begin
Writeln(OBJFile,'f ',
TW3[1],'/',TW3[1],'/',TW3[1],' ',
TW3[2],'/',TW3[2],'/',TW3[2],' ',
TW3[3],'/',TW3[3],'/',TW3[3]
);
Flush(OBJFile);
end;
//GlobalIndicesInc:=TW3[3];
//GlobalIndicesInc:=GlobalIndicesInc+3;
end;
end;
WriteLN(OBJFile);Flush(OBJFile);
WriteLN(OBJFile,'# ---- OBJECT END ----');Flush(OBJFile);
WriteLN(OBJFile);Flush(OBJFile);
if IsLOD4=true then begin
Close(OBJFile);
Close(OBJMtlFile);
end else if IsOther=true then begin
Close(OBJFile);
end;
end;
GlobalSubsetTracker2:=GlobalSubsetTracker2+1;
end;
{*********************************************************************************************}
{ lit la chaine S contenant les 3 indices, et le retournes dans W1, W2 et W3 }
{*********************************************************************************************}
Procedure ReadIndice(S : string; var W1,W2,W3 : word);
var
S2 : string;
i,
j :integer;
begin
{ejecter les 2 premiers caractères }
S2:='';
for i:=3 to length(S) do S2:=S2+S[i];
S:=S2;
{ trouver le premier '/' }
i:=1;
while S[i]<>'/' do inc(i);
{ lire le premier nombre }
val(LeftStr(S,pred(i)),W1,j);
{ trouver le ' ' suivant }
while S[i]<>' ' do inc(i);
{ejecter les i premiers caractères }
S2:='';
for j:=succ(i) to length(S) do S2:=S2+S[j];
S:=S2;
{ trouver le '/' suivant}
i:=1;
while S[i]<>'/' do inc(i);
{ lire le second nombre }
val(LeftStr(S,pred(i)),W2,j);
{ trouver le ' ' suivant }
while S[i]<>' ' do inc(i);
{ejecter les i premiers caractères }
S2:='';
for j:=succ(i) to length(S) do S2:=S2+S[j];
S:=S2;
{ trouver le '/' suivant}
i:=1;
while S[i]<>'/' do inc(i);
{ lire le troisieme nombre }
val(LeftStr(S,pred(i)),W3,j);
end;
{*********************************************************************************************}
{ construit le fichier OBJ pour les LODPhase utilisant les subset de FirstSubset à LastSubset }
{*********************************************************************************************}
Procedure BuildLODPhase(Name : string; NLOD,FirstSubset,LastSubset:integer);
var
W1, W2, W3 : word;
i,
Subset : integer;
NbVertexDebutSection, { mémorise le nombre de vertex avant de commencer un nouveau subset }
NbVertex : longint;
FV, FVt, FVn, { fichier provisoir des vertexs }
FIndices, { fichier provisoir des indices }
FSubset, { fichier source subset }
FOBJ : Text; { fichier OBJ destination }
S : string;
begin
{ initialiser les fichiers temporaires }
assign(FV,'FV.TXT'); Rewrite(FV);
assign(FVt,'FVt.TXT'); Rewrite(FVt);
assign(FVn,'FVn.TXT'); Rewrite(FVn);
assign(FIndices,'Indices.TXT'); Rewrite(FIndices);
NbVertexDebutSection:=0;
for Subset:=FirstSubset to LastSubset do begin
{ assigner et initialiser le fichier subset source }
str(Subset,S);
assign(FSubset,Name+'_Subset_'+S+'.OBJ');
Reset(FSubset);
Writeln('-- "'+Name+'_Subset_'+S+'.OBJ" created --');
NbVertex:=0;
{ lire le fichier source, et écrire dans les fichiers provisoirs }
while not EOF(FSubset) do begin
ReadLN(FSubset,S);
if (S[1]='v') and ((S[2]=chr(9)) or (S[2]=' ')) then begin { vertex 'v' }
inc(NbVertex);
WriteLN(FV,S);
end;
if (S[1]='v') and (S[2]='t') then WriteLN(FVt,S); { vertex 'vt'}
if (S[1]='v') and (S[2]='n') then WriteLN(FVn,S); { vertex 'vn'}
if S[1]='f' then begin
{ il s'agit d'un indice : le lire, ajuster ses valeurs et l'écrire dans le fichier provisoir }
ReadIndice(S,W1,W2,W3);
inc(W1,NbVertexDebutSection);
inc(W2,NbVertexDebutSection);
inc(W3,NbVertexDebutSection);
Writeln(FIndices,'f ',
W1,'/',W1,'/',W1,' ',
W2,'/',W2,'/',W2,' ',
W3,'/',W3,'/',W3
);
end;
end;
close(FSubset);
inc(NbVertexDebutSection,NbVertex);
end;
{ initialiser le fichier destination }
str(NLod:2,S);
assign(FOBJ,Name+'_LOD'+S+'.OBJ'); Rewrite(FOBJ);
Writeln('-- "'+Name+'_LOD'+S+'.OBJ" created --');
{ Copier les fichiers temporaires dans le fichier destinaion }
reset(FV);
reset(FVt);
reset(FVn);
reset(FIndices);
while not EOF(FV) do begin ReadLN(FV,S); WriteLN(FOBJ,S); end;
while not EOF(FVt) do begin ReadLN(FVt,S); WriteLN(FOBJ,S); end;
while not EOF(FVn) do begin ReadLN(FVn,S); WriteLN(FOBJ,S); end;
while not EOF(FIndices) do begin ReadLN(FIndices,S); WriteLN(FOBJ,S); end;
{ fermer les fichiers }
close(FOBJ);
close(FV); Erase(FV);
close(FVt); Erase(FVt);
close(FVn); Erase(FVn);
close(FIndices); Erase(FIndices);
end;
{***************************************************************************************}
{ Lit la section Mesh pour en extraire les 'Vertex', 'Indices', 'Subset' et 'LODs' }
{***************************************************************************************}
Procedure ReadMesh(Name:string);
type
T_pssn4nubn4ussn2 = record
v : array[1..4] of smallint;
vn : array[1..4] of shortint;
vt : array[1..2] of smallint;
end;
T_pssn4nf24ussn2ussn2ccif41 = record
v : array[1..4] of smallint;
vn : array[1..4] of Float_16; { short reel }
vt : array[1..2] of smallint;
end;
T_pf24nubn4ussn2ussn2 = record
v : array[1..4] of Float_16;
vn : array[1..4] of shortint;
vt : array[1..2] of smallint;
end;
T_pf43nubn4ussn2 = record
v : array[1..3] of single;
vn : array[1..4] of shortint;
vt : array[1..2] of smallint;
end;
T_pssn4ussn2 = record
v : array[1..4] of smallint;
vt : array[1..2] of smallint;
end;
var
SM : smallint;
pssn4ussn2 : T_pssn4ussn2;
pssn4nf24ussn2ussn2ccif41 : T_pssn4nf24ussn2ussn2ccif41;
pssn4nubn4ussn2 : T_pssn4nubn4ussn2;
pf24nubn4ussn2ussn2 : T_pf24nubn4ussn2ussn2;
pf43nubn4ussn2 : T_pf43nubn4ussn2;
RCompressed1,
RCompressed2,
RCompressed3 : single; { valeur des taux de compression de compressedvertexformatdata }
BSP : boolean; { vrai s'il s'agit d'un format BSP }
pssn4_ussn2,
pf43,
pf24, { est vrai quand le format BSP pf24 est rencontré }
nf24 : boolean; { est vrai quand un format BSP nf24 est rencontré }
Pos,
PosCompressedVertexFormatData,
PosBeginIndices,
IndicesReadNum,
IndicesType,
PosBeginMesh, PosEndMesh, { position du début et de la fin de la section 'Mesh' }
PosBeginVertexStream, { position du début du vertexstream }
NbVertex, { nombre de Vertex dans VertexStream }
LVertex, { Longueur d'un vertex }
LVertexStream, { longueur de la section 'vertexstream' }
NbLODPhases,
FirstSubset,
LastSubset,