forked from reyhard/o2scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RDS_Check_All.bio2s
1175 lines (1068 loc) · 32 KB
/
RDS_Check_All.bio2s
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 "std\lodNames.inc"
#include "std\o2config.inc"
#include "std\paramFile.inc"
#include "CheckMat.inc.bio2s"
#include "std\flags.inc"
scopeName "CheckAll";
console=openStandardIO;
lastLodShow=-1;
inLodShow={
private "_res";
bugreported=true;
if (lastLodShow!=_this) then
{
_res=eoln+"In level "+(_this call lodNameGetName)+":"+eoln;
lastLodShow=_this;
}
else
{
_res="";
};
_res
};
valid_res_properties =
[
"shadowlod",
"lodnoshadow"
];
valid_geo_properties =
[
"aicovers",
"armor",
"autocenter",
"buoyancy",
"canbeoccluded",
"canocclude",
"class",
"damage",
"dammage",
"destroysound",
"drawimportance",
"explosionshielding",
"forcenotalpha",
"frequent",
"keyframe",
"loddensitycoef",
//"lodnoshadow",
"map",
"mass",
"placement",
"prefershadowvolume",
"sbsource",
"shadow",
"shadowlod",
"shadowvolumelod",
"shadowbufferlod",
"shadowbufferlodvis",
"shadowoffset",
"viewdensitycoef"
];
#define ERROR(x) {console<<(_resol call inLodShow)<<" "<<x<<eoln;}
#define ERROR_LOG(x) ERROR(x)
// define if you want autofix detected issues
#define FIX_P3D true
_getTexOrMatName =
{
private["_currentLOD","_faceIndex","_isMat"];
_currentLOD = _this @ 0;
_faceIndex = _this @ 1;
_isMat = _this @ 2;
if (_isMat) then
{
getMaterial (_currentLOD face _faceIndex)
}
else
{
getTexture (_currentLOD face _faceIndex)
};
};
_getProxyFaces =
{
private ["_currentLOD","_faces","_face","_proxySel"];
_currentLOD = _this;
_faces = [];
{
if (_x @ [0,6]=="proxy:") then
{
_proxySel = _currentLOD loadSelection _x;
_face = (getSelectedFaces _proxySel) @ 0;
_faces set [count _faces,_face];
};
} forEach (getSelections _currentLOD);
_faces
};
_faceIndicesByTexture =
{
private["_currentLOD","_texName","_faceIndices"];
_currentLOD = _this @ 0;
_texName = _this @ 1;
_texIsMat = _this @ 2;
_proxyFaces = _currentLOD call _getProxyFaces;
_faceIndices = [];
_currentLOD forEachFace [{[_currentLOD,_x,_texIsMat] call _getTexOrMatName == _texName},
{
if (!(_x in _proxyFaces)) then
{
_faceIndices set [count _faceIndices,_x];
};
}];
_faceIndices
};
_selectByFaceIndices =
{
private ["_currentLOD","_faceIndices","_sel"];
_currentLOD = _this @ 0;
_facesIndices = _this @ 1;
_sel = newSelection _currentLOD;
_sel selectFaces _facesIndices;
selectPointsFromFaces _sel
};
_selectionByTexture =
{
private["_currentLOD","_texName","_texIsMat","_faceIndices"];
_currentLOD = _this @ 0;
_texName = _this @ 1;
_texIsMat = _this @ 2;
_faceIndices = [_currentLOD,_texName,_texIsMat] call _faceIndicesByTexture;
[_currentLOD,_faceIndices] call _selectByFaceIndices
};
_removeFaces =
{
private["_currentLOD","_sel","_faceSel"];
_currentLOD = _this @ 0;
_sel = _this @ 1;
//create new selection with just faces
_faceSel = newSelection _currentLOD;
_faceSel selectFaces (getSelectedFaces _sel);
deleteSelected _faceSel;
};
_copySelection =
{
private["_currentLOD","_sel","_pointsIndices","_faceIndices","_pointsCopy","_pointFlagsCopy","_pi","_facesCopy","_face","_vertices","_uv","_flags","_tex","_mat","_faceData"];
_currentLOD = _this @ 0;
_sel = _this @ 1;
_pointsIndices = getSelectedPoints _sel;
_faceIndices = getSelectedFaces _sel;
_pointsCopy = [];
_pointFlagsCopy = [];
for "_i" from 0 to ((count _pointsIndices) - 1) do
{
_pi = _pointsIndices @ _i;
_pointsCopy set [count _pointsCopy,_currentLOD getPoint _pi];
_pointFlagsCopy set [count _pointFlagsCopy,_currentLOD getPointFlags [_pi,[0,31]]];
};
_facesCopy = [];
for "_i" from 0 to ((count _faceIndices) - 1) do
{
_face = _currentLOD face (_faceIndices @ _i);
_vertices = getVertices _face;
_uv = getUVSet _face;
_flags = _face getFaceFlags [0,31];
_tex = getTexture _face;
_mat = getMaterial _face;
_faceData = [_vertices,_tex,_mat,_uv,_flags];
_facesCopy set [count _facesCopy,_faceData];
};
[_pointsCopy,_pointFlagsCopy,_facesCopy]
};
_pasteACopy =
{
private["_currentLOD","_copyData","_points","_pointFlags","_pi","_faces","_face","_faceData","_faceIndex"];
_currentLOD = _this @ 0;
_copyData = _this @ 1;
_points = _copyData @ 0;
_pointFlags = _copyData @ 1;
_faces = _copyData @ 2;
for "_i" from 0 to ((count _points) - 1) do
{
_pi = obj addPoint (_points @ _i);
_currentLOD setPointFlags [_pi,[0,31],_pointFlags @ _i];
};
for "_i" from 0 to ((count _faces) - 1) do
{
_faceData = _faces @ _i;
_faceIndex = addFace _currentLOD;
_face = _currentLOD face _faceIndex;
_face setVertices (_faceData @ 0);
_face setTexture (_faceData @ 1);
_face setMaterial (_faceData @ 2);
_face setUVSet (_faceData @ 3);
_face setFaceFlags [[0,31],_faceData @ 4];
};
};
_optimizeByTex =
{
private["_currentLOD","_texName","_texIsMat","_sel","_copyData"];
_currentLOD = _this @ 0;
_texName = _this @ 1;
_texIsMat = _this @ 2;
_sel = [_currentLOD,_texName,_texIsMat] call _selectionByTexture;
_copyData = [_currentLOD,_sel] call _copySelection;
[_currentLOD,_sel] call _removeFaces;
[_currentLOD,_copyData] call _pasteACopy;
//_currentLOD call _removeIsolatedPoints;
};
_optimizeLOD =
{
private["_currentLOD","_texList","_matList"];
_currentLOD = _this;
_texList = (_currentLOD callRuntime "texlist");
// _matList = (_currentLOD callRuntime "matlist");
_textures =
[
"_ca.paa",
"#(argb,8,8,3)color(0,0,0,0)",
"#(argb,8,8,3)color(0,0,0,0,ca)",
"#(argb,8,8,3)color(0,0,0,0.0,ca)",
"#(argb,8,8,3)color(0,0,0,0.01,ca)",
"glass"
];
{
_tex = _x;
if (logging) then {console<<"_tex: "<<_tex<<eoln;};
{
_filter = _x;
// _found1 = _filter in [_tex];
_found2 = _tex findi _filter;
// if (logging) then {console<<"_in: "<<str _found1<<eoln;};
// if (logging) then {console<<"_found2: "<<typename _found2<<eoln;};
if (typename _found2=="SCALAR") then
{
if (logging) then {console<<"_findi: "<<str _found2<<eoln;};
[_currentLOD,_tex,false] call _optimizeByTex;
};
} forEach _textures;
} forEach _texList;
};
0 call
{
needSave=false;
bugreported=false;
if (this in ["options"]) then {messageBox ["No options are available in this script!",0];BreakTo "CheckAll";};
if (typename this=="STRING") then
{
p3d=newLODObject;
p3dname=this;
if (!(p3d loadP3d this)) then { console<<"Unable to open:"<<this<<eoln;BreakTo "CheckAll";};
runFromO2=false;
texpath="P:\"; // define path to your project, most people will use P:\
//texpath=((splitPath p3dname) @ 0);
console<<"----------------------------------------------------------------------"<<eoln;
console<<"Checking file: "<<p3dname<<eoln;
}
else
{
p3dname=nameof this;
p3dname=splitPath p3dname;
p3dname=p3dname @ 2 + p3dname @ 3;
runFromO2=true;
p3d=this;
o2GetConfig IDS_CFGPATHFORTEX;
console<<"--------- Checking "<<p3dname<<" ------"<<eoln;
};
objects=getObjects p3d;
resols=getResolutions p3d;
collectMats=+[];
_hasView = false;
_hasFire = false;
_hasSW1000 = false;
_hasPhysx = false;
if(LOD_GEOMETRY_PHYSX in resols)then{_hasPhysx=true};
for "_i" from 0 to (count p3d-1) do
{
private ["_obj","_resol","_isol","_numsect","_degen"];
_resol=resols @ _i;
_obj=objects @ _i;
// check isolated points
if (_resol<LOD_EDIT_MIN || _resol>=LOD_EDIT_MAX) then
{
// check characters skining (count not full keight (<100%) must be less that 3)
/*if (IS_LOD_RESOLUTION(_resol) || (_resol>=LOD_SHADOW_MIN && _resol<=LOD_SHADOW_MAX)) then
{
_obj forEachFace [{true},
{
_vx=getVertices (_obj face _x);
};
}; */
_excludePoints = [];
{
if (_x@[0,6]=="proxy:") then
{
_excludePoints = _excludePoints + (getSelectedPoints (_obj loadSelection _x));
};
}forEach getSelections _obj;
if (IS_LOD_RESOLUTION(_resol) || _resol==LOD_MEMORY || (_resol>=LOD_SHADOW_MIN && _resol<=LOD_SHADOW_MAX)) then
{
_obj callRuntime "isolatedpts";
_isol=getSelectedPoints (_obj loadSelection "_current");
if (count _isol>0) then
{
private ["_nsel","_pt"];
{
_pt=_x;
{
_nsel=_obj loadSelection _x;
if (_nsel isPointSelected _pt) exitWith {_isol=_isol-[_pt];};
}forEach GetSelections _obj
}forEach _isol;
};
_isol=count _isol;
if (_isol>0) then
ERROR("found isolated "<<str(_isol)<<" point(s)");
};
// check resolution levels for sections & blank lods
if (IS_LOD_RESOLUTION(_resol)) then
{
private "_mult";
_mult=[_resol,1] select (_resol>=1000);
_numsect=_obj callRuntime "countsections";
if (_numsect>1 && _numsect * _mult >50) then
{
if(true)then ERROR("probably too many sections ("<<str(_numsect)<<")");
if(FIX_P3D)then
{
//_obj call _optimizeLOD;
needSave = true;
};
};
if (_numsect == 0)then ERROR("blank lod detected");
};
//check 2. UV in not visible LODS
if (NOT IS_LOD_RESOLUTION(_resol)) then
{
_UV = getUVSetList _obj;
_count = count _UV;
if (_count>1) then{
if (true) then ERROR("2nd UV in special lod ");
if(FIX_P3D)then{
if (true) then ERROR("attempting to fix by deleting excese uv sets");
if (0 in _UV) then
{
_obj setActiveUVSet 0;
_UV = _UV- [0];
{
_obj deleteUVSet _x;
}foreach _UV;
needSave=true;
} else ERROR("no 0 and 1 UV SET");
};
};
};
//check 3. UV & named properties in visible LODS
if (IS_LOD_RESOLUTION(_resol)) then
{
//private["_UV","_count","_prop"];
_UV = getUVSetList _obj;
_count = count _UV;
if (_count>2) then{
if (true) then ERROR("3rd UV not supported");
if(FIX_P3D)then{
if (true) then ERROR("attempting to fix by deleting excese uv sets");
if ((0 in _UV)and (1 in _UV)) then
{
_obj setActiveUVSet 0;
_UV = _UV- [0,1];
{
_obj deleteUVSet _x;
}foreach _UV;
needSave=true;
} else ERROR("no 0 and 1 UV SET");
};
};
_prop = properties _obj;
_count = (count _prop)-1;
if(_count > 1)then{
if (true) then ERROR("multiple named properties detected");
if(FIX_P3D)then{
if (true) then ERROR("attempting to fix by deleting excese properties [except lodNoShadow]");
private ["_i"];
for [{_i=0},{_i<_count},{_i=_i+2}] do {
if(_prop select _i != "lodnoshadow")then{
_obj setProperty [_prop select _i,nil];
};
};
needSave=true;
};
};
};
// proxies
_names= [];
_namesReg= [];
_proxies = 0;
{
_lName = toLower _x;
if (_lName in _names) then
{
if(true) then ERROR("duplicate named selection ("<<_x<<")");
if(FIX_P3D)then
{
// find index
_index = 0;
{
if(_x == _lName)exitWith{};
_index = _index + 1;
} forEach _names;
_newName = _namesReg select _index;
_sel = _obj loadSelection _x;
_obj deleteSelection _x;
//_obj save _sel as _newName;
console<<" attempting to fix it by renaming it to "<< _newName <<eoln;
};
};
_names=_names+[_lName];
_namesReg=_namesReg+[_x];
private "_nsel";
if (_x @ [0,6]=="proxy:") then
{
_nsel=_obj loadSelection _x;
// check name selections in geometry
if (_resol in LOD_ARR_GEOMETRY) then
{
{
if (_x @ [0,9]=="Component") then
{
_nselB=_obj loadSelection _x;
_nselB &= _nsel; // intersection of named selections
if (countPoints _nselB > 0) then ERROR("strange convex component in named selection ("<<_x<<")");
};
}forEach getSelections _obj;
};
// delete proxies
if (IS_LOD_SHADOW(_resol)) then
{
if (true) then ERROR("proxies in shadow LOD detected - attempting to remove them");
deleteSelected _nsel;
needSave = true;
}else{
_proxies = _proxies + (countPoints _nsel);
};
};
}forEach getSelections _obj;
// check levels for degenerated faces
_obj callRuntime "degfaces";
_degen=getSelectedPoints (_obj loadSelection "_current");
if (count _degen>0) then
ERROR("found degenerated face(s)");
// check unselected points in geometry
if (_resol in LOD_ARR_GEOMETRY) then
{
private ["_sel"];
_sel=newSelection _obj;
selectAll _sel;
{
private "_nsel";
_nsel=_obj loadSelection _x;
_sel-=_nsel;
}forEach getSelections _obj;
_obj forEachPoint [{(_sel weight _x)<0.2},{_sel unselectPoint _x}];
_isol=countPoints _sel;
if (_isol>0) then ERROR("has incorrectly generated components."<<eoln
<<" "<<str(_isol)<<" point(s) aren't selected.");
_obj callRuntime "checkclosed";
if (countPoints (_obj loadSelection "_current")>_proxies) then ERROR("open topology detected! ");
_obj callRuntime "checkconvexity";
if (countPoints (_obj loadSelection "_current")>0) then ERROR("non-convex points detected!");
_prop = properties _obj;
for "_i" from 0 to count _prop step 2 do
{
_temp = _prop select _i;
if(!((toLower (_temp)) in valid_geo_properties))then
{
if (true) then ERROR("Invalid property dedetcted in geometry LOD. Property:" << _temp );
if(FIX_P3D)then{
if (true) then ERROR("deleting property");
_obj setProperty [_temp,nil];
needSave=true;
};
};
};
// Removes UVs
_obj forEachFace [{true},
{
(_obj face _x) setUVSet [];
}];
_edges=+[];
_quad=false;
_obj forEachFace [{true},
{
private ["_vx","_last"];
(_obj face _x) setUVSet [];
_vx=getVertices (_obj face _x);
_quad=[_quad,true] select (count _vx>3);
_last=_vx @ (count _vx-1);
{
_edges set [count _edges,_last];
_edges set [count _edges,_x];
_last=_x;
}forEach _vx;
}];
if (_obj testSharpEdges _edges<1) then ERROR("Smooth edges detected");
if (_obj testSharpEdges _edges<1 && FIX_P3D) then {
console<<" attempting to fix it by making all edges sharp."<<eoln;
_obj sharpEdges _edges;
needSave=true;
};
};
// check for zero mass
if (_resol==LOD_GEOMETRY) then
{
{
private ["_nsel","_nozero"];
_nozero=false;
_sel = (_obj loadSelection _x);
_nsel=getSelectedPoints _sel;
_fsel=getSelectedFaces _sel;
if ((_x @ [0,9]=="Component")and(count _fsel <4)) then ERROR("Selection "<<_x<<" none face selected");
if (count _nsel>0) then
{
{
if (_obj getPointMass _x>0 OR (_x in _excludePoints)) exitWith {_nozero=true;}
}forEach _nsel;
if (!_nozero) then ERROR("Selection "<<_x<<" has zero mass.");
if (!_nozero && FIX_P3D)then{
console<<" attempting to fix it by adding mass = 0.1."<<eoln;
{
_obj setPointMass [_x,0.1];
}forEach _nsel;
needSave=true;
};
};
}forEach getSelections _obj;
if(_hasPhysx)then
{
if(_obj getProperty "buoyancy" == "")then
{
if (true) then ERROR("object has geo physx but is missing buoyancy = 1 named property");
if(FIX_P3D)then{
if (true) then ERROR("attempting to fix by adding buoyancy = 1");
_obj setProperty ["buoyancy",1];
needSave=true;
};
};
if(_obj getProperty "autocenter" == "0")then
{
if (true) then ERROR("object has geo physx but has autocenter = 0 named property. Is it intended?");
};
};
if ((_obj getProperty "sbsource" != "") and (_hasSW1000)) then ERROR_LOG("Probably using flag sbsource=shadowvolume and shadow buffer LOD is already present. Generated shadow buffer LODs are not used.");
};
if (LOD_SHADOW_MIN+1000<=_resol and LOD_SHADOW_MAX>_resol) then
{
_hasSW1000 = true;
};
// check for less than 3 Points in selections within Geo
if (_resol==LOD_GEOMETRY) then
{
{
private "_nsel";
_nozero=false;
_nsel=getSelectedPoints (_obj loadSelection _x);
_testComponent= _x@[0,9] findi "Component";
if ( !(isnil "_testComponent") && (count _nsel < 3) ) then {
ERROR("Selection "<<_x<<" has less then 3 points.")
};
}forEach getSelections _obj;
};
// check shadow
//if (_resol>=LOD_SHADOW_MIN) then {halt;};
if (IS_LOD_SHADOW(_resol)) then
{
_numsect=_obj callRuntime "countsections";
if(_numsect == 0)exitWith{};
if ((_resol==LOD_SHADOW_MIN) || (_resol==LOD_SHADOW_MIN+10)|| (_resol==LOD_SHADOW_VIEW_GUNNER)|| (_resol==LOD_SHADOW_VIEW_PILOT)|| (_resol==LOD_SHADOW_VIEW_CARGO)) then
{
private ["_edges","_quad"];
_obj callRuntime "checkclosed";
if (countPoints (_obj loadSelection "_current")>0) then ERROR("opened topology detected!");
_edges=+[];
_quad=false;
_obj forEachFace [{true},
{
private ["_vx","_last"];
(_obj face _x) setUVSet [];
_vx=getVertices (_obj face _x);
_quad=[_quad,true] select (count _vx>3);
_last=_vx @ (count _vx-1);
{
_edges set [count _edges,_last];
_edges set [count _edges,_x];
_last=_x;
}forEach _vx;
}];
if (_obj testSharpEdges _edges<1) then ERROR("Smooth edges detected");
if (_obj testSharpEdges _edges<1 && FIX_P3D) then {
console<<" attempting to fix it by making all edges sharp."<<eoln;
_obj sharpEdges _edges;
needSave=true;
};
if (_quad) then{
if (true) then ERROR("Polygons detected (only triangles allowed)");
if(FIX_P3D)then{
//if (true) then ERROR("attempting to fix by triangulation selections");
//_sel= _obj loadSelection "open";
//_sel callRuntime "triangulatesel";
};
};
//if (_resol>LOD_SHADOW_MIN) then ERROR("Warrning: Shadow volume LOD number different than 0");
if (_resol==LOD_SHADOW_MIN) then
{
private ["_num","_faceT","_texture","_material","_x","_txLinkBugInShadow","_matLinkBugInShadow"];
_num = countFaces _obj;
for "_x" from 0 to _num do
{
_faceT =_obj face _X;
_texture = getTexture _FaceT;
_material = getMaterial _FaceT;
if (_texture!="") then
{
_txLinkBugInShadow=1;
if(FIX_P3D)then
{
_faceT setTexture "";
};
};
if (_material!="") then
{
_matLinkBugInShadow=1;
if(FIX_P3D)then
{
_faceT setMaterial "";
};
};
};
if (_txLinkBugInShadow==1) then ERROR("Warrning: There is a texture link");
if (_matLinkBugInShadow==1) then ERROR("Warrning: There is a material link");
};
_chckSHDProp=_obj getProperty "LODNoShadow";
if (_chckSHDProp=="1") then {
if(true) then ERROR("Warrning: ShadowVolume disabled by property");
if(FIX_P3D)then{
if (true) then ERROR("attempting to fix by deleting excese properties");
private ["_prop","_count"];
_prop= properties _obj;
_count = (count _prop)-1;
private ["_i"];
for [{_i=0},{_i<=_count},{_i=_i+2}] do {
_obj setProperty [_prop select _i,nil];
needSave=true;
};
};
};
}
else
{
if (_resol==LOD_SHADOW_MIN+1000) then
{
_chckSHDProp=_obj getProperty "LODNoShadow";
if (_chckSHDProp=="1") then {
if(true) then ERROR("Warrning: ShadowVolume disabled by property");
if(FIX_P3D)then{
if (true) then ERROR("attempting to fix by deleting excese properties");
private ["_prop","_count"];
_prop= properties _obj;
_count = (count _prop)-1;
private ["_i"];
for [{_i=0},{_i<=_count},{_i=_i+2}] do {
if(_prop select _i != "lodnoshadow")then{
_obj setProperty [_prop select _i,nil];
};
needSave=true;
};
};
};
} else ERROR("ShadowVolume "+str(_resol-LOD_SHADOW_MIN)+" is not supported");
};
};
// collect materials
// check wrong material or texture links
private ["_reportMissing"];
_reportMissing={
private ["_file"];
if ((_x!="")and (_x@0!="#")) then
{
_file=openFile [texpath+_x,0];
_slash = _x find "/";
if ((isnil "_file")or(!isnil "_slash")) then ERROR("reference to file "<<_x<<" is invalid")
else
{
if (_this==1) then
{
_x=tolower (texpath+_x);
if (!(_x in collectMats)) then
{
collectMats set [count collectMats,_x];
};
};
};
};
};
/*
{
0 call _reportMissing;
if ((_x!="")and (_x@0!="#")) then
{
_iscorect = _x findi "_co.tga";
_iscorect2 = _x findi "_ca.tga";
if (( isnil "_iscorect")and( isnil "_iscorect2")) then ERROR("texture "<<_x<<" is is not ""_co.tga"" || ""_ca.tga"" ending")
};
} forEach (_obj callRuntime "texlist");
*/
{1 call _reportMissing} forEach (_obj callRuntime "matlist");
private "_checkUVSource";
_checkUVSource={
private ["_matname","_paramFile"];
_matname=texpath+_x;
_paramFile=openFile [_matname,1];
if (!isnil{_paramFile}) then
{
_paramFile=_paramFile call ParamFileRead;
if (!isnil{_paramFile}) then
{
private "_findUvSource";
_findUvSource={
if (_x @ 1=="class") then
{
_findUvSource forEach (_x @ 2);
}else{
if (tolower(_x @ 0)=="uvsource") then
{
private "_tmp";
_tmp=_x @ 2;
if (_tmp=="tex") then
{
_tmp="tex0";
};
if (_tmp @ [0,3]=="tex") then
{
_tmp=val(_tmp@[3]);
if (!(_obj isuvset _tmp)) then
ERROR("Referenced unknown uv-set: "<<str(_tmp)<<" by material "<<_matname);
};
};
};
};
_findUvSource forEach _paramFile;
}
else
{
ERROR("Parse error: "<<_matname);
};
};
};
_checkUVSource forEach (_obj callRuntime "matlist");
// check ST coordinates
if (false and IS_LOD_RESOLUTION(_resol)) then
{
_deleteMaterial=
{
_material=getMaterial (_obj face _x);
if (_material=="") then
{
_actual=newSelection _obj;
_actual selectFace _x;
deleteSelected _actual;
};
};
_obj forEachFace [{true},_deleteMaterial];
{
if (_x@[0,5]=="proxy:") then
{
deleteSelected _x;
};
} forEach getSelections _obj ;
_obj callRuntime "chkstvects";
_STbugs=getSelectedPoints (_obj loadSelection "_current");
if (count _STbugs>0) then
ERROR("cannot generate ST coordinates");
// Check texels
_texelmin = 0;
_texelmax = 0;
_checkTexels =
{
halt;
f_CrossProduct =
{
_ox = (_this@0)@0;
_oy = (_this@0)@1;
_oz = (_this@0)@2;
_lx = (_this@1)@0;
_ly = (_this@1)@1;
_lz = (_this@1)@2;
__x=_ly*_oz-_lz*_oy;
__y=_lz*_ox-_lx*_oz;
__z=_lx*_oy-_ly*_ox;
[__x,__y,__z]
};
_face =_obj face _X;
_uvset = getUVSet _face;
texwidth = 1;
texheight = 1;
halt;
_texture = getTexture _Face;
if (_texture!="") then
{
for "_k" from 0 to 3 step 3 do
{
_ps1_0=_uvset@(_k*2)*texwidth;
_ps1_1=_uvset@(_k*2+1)*texheight;
_ps2_0=_uvset@(1*2)*texwidth;
_ps2_1=_uvset@(1*2+1)*texheight;
_ps3_0=_uvset@(2*2)*texwidth;
_ps3_1=_uvset@(2*2+1)*texheight;
_da=[(_ps2_0-_ps1_0),(_ps2_1-_ps1_1),0];
_db=[(_ps3_0-_ps1_0),(_ps3_1-_ps1_1),0];
_cross=[_db,_da]call f_CrossProduct;
_texvolume=(sqrt (_cross@0^2 + _cross@1^2+ _cross@2^2))*0.5;
};
};
_texelmin=(_texelmin min _nfo_texelmin);
_texelmax=(_texelman max _nfo_texelmax);
};
_obj forEachFace [{true},_checkTexels];
};
// check link to temp directories
if (IS_LOD_RESOLUTION(_resol)||(_resol==LOD_SHADOW_MIN+1000)) then
{
private ["_num","_faceT","_texture","_material","_TellMe","_X"];
_num = countFaces _obj;
for "_x" from 0 to _num do
{
_faceT =_obj face _X;
_texture = getTexture _FaceT;
_material = getMaterial _FaceT;
_TellMe = str(_material) findi "\temp\";
if (isnil{str(_TellMe)}) then
{}else
{
_X = _num;
console<<" There is link to temp directory"<<eoln;
};
_TellMe = str(_texture) findi "\temp\";
if (isnil{str(_TellMe)}) then
{}else
{
_X = _num;
console<<" There is link to temp directory"<<eoln;
};
};
};
// check flags in all
#define CHECK_FLAGS true
if (CHECK_FLAGS) then
{
_landERR = false;
_lightERR = false;
_fogERR = false;
_decalERR = false;
_userERR = false;
_specialERR = false;
_unknERR = false;
_hiddenERR = false;
for "_x" from 0 to (countPoints _obj)-1 do
{
_landERR = _landERR or ((_obj getPointFlags [_x,POINT_LAND_MASK])!=0);
_lightERR = _lightERR or ((_obj getPointFlags [_x,POINT_LIGHT_MASK])!=0);
_fogERR = _fogERR or ((_obj getPointFlags [_x,POINT_FOG_MASK])!=0);
_decalERR = _decalERR or ((_obj getPointFlags [_x,POINT_DECAL_MASK])!=0);
_userERR = _userERR or ((_obj getPointFlags [_x,POINT_USER_MASK])!=0);
_spc = (_obj getPointFlags [_x,POINT_SPECIAL_MASK]);
_specialERR = _specialERR or (_spc>1);
if(!(_x in _excludePoints))then{ hiddenERR = _hiddenERR or (_spc==1);};
_unknERR = _unknERR or ((_obj getPointFlags [_x,[10,11]]!=0) or (_obj getPointFlags [_x,[14,15]]!=0) or (_obj getPointFlags [_x,[28,31]]!=0));
};
_FuserERR = false;
_FunknERR = false;
for "_x" from 0 to (countFaces _obj)-1 do
{
_face = _obj face _x;
_FuserERR = _FuserERR or ((_face getFaceFlags FACE_USER_MASK)!=0);
_FunknERR = _FunknERR or ((_face getFaceFlags [10,11]!=0) or (_face getFaceFlags [16,19]!=0) or (_face getFaceFlags [22,23]!=0));
};
if (_lightERR or _decalERR or _unknERR or _hiddenERR) then
{
if (_hiddenERR)then ERROR_LOG("vertex hidden flag");
if (_decalERR)then ERROR_LOG("vertex decal flag");
if (_lightERR)then ERROR_LOG("vertex lighting flag");
if (_unknERR) then ERROR_LOG("vertex unknow flag");
if (_userERR) then ERROR_LOG("vertex user flag");
if (FIX_P3D) then
{
console<<" attempting to fix vert flags."<<eoln;
needSave=true;
for "_x" from 0 to (countPoints _obj)-1 do
{
_obj setPointFlags [_x,POINT_LIGHT_MASK,0];
_obj setPointFlags [_x,POINT_DECAL_MASK,0];
_obj setPointFlags [_x,POINT_USER_MASK,0];
//_obj setPointFlags [_x,POINT_SPECIAL_MASK,0];
_obj setPointFlags [_x,[10,11],0];
_obj setPointFlags [_x,[14,15],0];
_obj setPointFlags [_x,[28,31],0];
};
};
};
if ( _FunknERR or _FuserERR) then