summaryrefslogblamecommitdiffstats
path: root/tools/ArtChecker/artchecker.cpp
blob: e2a9f1c2573633ac12110b6d50cb2c8323f5b173 (plain) (tree)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349




































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                                                                           
// artchecker.cpp : Defines the entry point for the console application.
// options -strict -add -all 
#pragma warning(disable:4786)


#include <iostream>
#include <cstring>
#include <iomanip>
//#include <mysql++>
#include "artobject.h"
#include "artlimits.h"
#include "badlist.hpp"
#include "outputbuffer.hpp"
#include <toollib.hpp>
#include <tlCollisionObjectChunk.hpp>
#include <tlMeshChunk.hpp>
#include <tlImageChunk.hpp>
#include <tlAnimationChunk.hpp>
#include <tlStatepropChunk.hpp>    
#include "..\..\..\..\game\code\constants\srrchunks.h"

using namespace std;

void debugstring(char * message);

int texturelookup(const texture_data& texturedata, bool add, bool strict,bool showall,badlist& p_badtextures ,bool suppress); 
int shaderlookup(shader_data* lp_shaderdata, bool add, bool strict,bool showall,badlist& badshaders,bool suppress);
//int artobjectlookup(art_object* lp_artobject, Query& query,bool add, bool strict,bool showall,bool suppress);
//int bvobjectlookup(bv_data* lp_bvobject,Query& query,bool add,bool strict,bool showall,bool suppress);

int main(int argc, char* argv[])
{
	
	char* arguements [4];
	char* filename;
	bool strict  =false;
	bool add	=false;
    bool badart=false;
    bool showall =false;
    bool suppress =false;
    bool shin=false;
    char screenoutput [1000];
	int i;

    //lists to track bad textures and shaders.
    badlist bad_textures;
    badlist bad_shaders;

    //list to track meshes using bad shaders and meshes over 500 polys
    outputbuffer* p_mesh_ref=new outputbuffer;
    outputbuffer* p_polycount=new outputbuffer;
    
    
    tlDataChunk::RegisterDefaultChunks();
	
    //processes arguements
	
	//no options 
	if (argc ==1)
	{
		printf("usage:artchecker filename <strict> \n");
		exit (1);
	}

		
	filename= argv[1];
	debugstring(filename);

	
	for (i=2;i<argc;i++)
	{
		arguements[i]=argv[i];

		// user set strict
		if (strcmp(arguements[i],"strict")== 0)
		{
			strict =true;
			debugstring("strict option set");
			break;
		}
						
		//user set add
		
		else if (strcmp (arguements[i],"add")==0)
		{
			add=true;
			debugstring("add option set");
			break;
		}

         else if (strcmp (arguements[i],"sum")==0)
        {
            suppress =true;
            break;
        }

        else if (strcmp (arguements[i],"all")==0)
        {
            showall =true;
            break;
        }
         
        else if (strcmp (arguements[i],"shin")==0)
        {
            shin =true;
            break;
        }
		//illegal option
		else 
		{
			printf("%s is an illegal option \n",arguements[i]);
			exit (1);
		}

	
	} //end for

    //have the pure3d file name

    tlFile input(new tlFileByteStream(filename,omREAD), tlFile::FROMFILE);
    if(!input.IsOpen()) 
    {
        printf("Could not open %s\n", filename);
        exit(-6);
    }

    printf("Processing Filename: %s\n",filename);

	//desend into the file and look at each object until no more objects left
        
    // make a tlDataChunk from the file
    // this is the wrapper chunk for the input
    tlDataChunk* inchunk = new tlDataChunk(&input);
    // we don't need the tlFile anymore
    // this cleans up the tlFile object including the
    // tlFileByteStream
	//printf("Fucking CLose! \n");
    input.Close();
	
	//printf("Closing File proceeding.\n");
    
    //lists to track memory stats for various components.
    badlist texturestats(inchunk->SubChunkCount());
    badlist animationstats(inchunk->SubChunkCount());
    badlist meshstats(inchunk->SubChunkCount());

    // build an output chunk
    tlDataChunk* outchunk = new tlDataChunk;
    int ch;		

    static int counter =0;

	//connect to the DB
	
	
		//setup artrb variables
		bool dbconnect=false;
//		char querybuffer [1000];
//		Row row;
	
	
		

		//creat connection and query
		//Connection con (use_exceptions);
		//Query query=con.query( );
		//dbconnect=con.connect ("srr2test","radit","root","custom47");	
/*
		if (dbconnect == true)
		{
			printf("Connection to Artdb established proceeding.\n");
		}
		else
		{
			printf("Cant connection to art db \n");
			exit (1);
		}
*/
		//printf("Counting chunks !\n");

        // go through all the sub-chunks of the input and
        // process the ones you care about
        for(ch=0; ch < inchunk->SubChunkCount(); ch++)
        {
			//printf("Processing Chunks, #%d \n",ch);
            // create the next sub-chunk
            tlDataChunk* sub = inchunk->GetSubChunk(ch);
            
            // look at the id of the subchunk to decide if we 
            // want to do something with it or not
            switch(sub->ID())
            {                  


            case Pure3D::Texture::TEXTURE:
                {
                    //temp variables
                    tlTexture* p_texture = new tlTexture ();
                    tlImage* p_image2d ;
                    texture_data mytexture;
                    unsigned int texturememsize =0;
                   
					//printf("texuture name: %s \n",p_texture->GetName());

                    int chunkcount1,chunkcount2;

                    for (chunkcount1 =0;chunkcount1<sub->SubChunkCount();chunkcount1++)
                    {
                        tlDataChunk* sub1=sub->GetSubChunk(chunkcount1);

                        switch(sub1->ID())
                        {
                        case Pure3D::Texture::IMAGE:
                            {
                                for (chunkcount2=0;chunkcount2<sub1->SubChunkCount();chunkcount2++)
                                {
                                    tlDataChunk* sub2=sub1->GetSubChunk(chunkcount2);
                                    switch (sub2->ID())
                                    {
                                    case Pure3D::Texture::IMAGE_DATA:
                                        {
                                            tlImageDataChunk* p_imagedatachunk = (tlImageDataChunk*) sub2;
                                            texturememsize += p_imagedatachunk->GetImageDataSize();
                                            //printf("%u bytes \n", p_imagedatachunk->GetImageDataSize());                                                                  
                                        }
                                    }
                                }//end for

                            }//end case
                        }//end switch

                    }//end outer for loop.




                    p_texture->LoadFromChunk(sub);
                                      
                    //cout<<"Checking for "<<p_texture->GetName()<<" Texture ";
                    p_image2d = p_texture->GetImage(0);                                  
    		        
                    //fill in texture struct.
                    strcpy(mytexture.name,p_texture->GetName());
		            mytexture.height=p_texture->GetHeight();
		            mytexture.width=p_texture->GetWidth();
		            mytexture.bpp=p_image2d->GetBpp();
		            mytexture.alpha=p_texture->GetAlphaDepth();      
                    
                    texturestats.add(p_texture->GetName(),1,texturememsize);
     
                    //texture check
		            if (texturelookup (mytexture,add,strict,showall,bad_textures,suppress) ) //
		            {
			            badart= true;
		            }

                  /*     
                    cout<<"Height: "<<p_image2d->GetHeight();
                    cout<<"Width: "<<p_image2d->GetWidth();
                    cout<<"Bpp: "<<mytexture.bpp;
                    cout<<"Alpha: "<<mytexture.alpha;
                    cout<<endl;
                   */
	        
                    delete p_texture;
                    outchunk->AppendSubChunk(sub,FALSE);
                    break;
                }

            case Pure3D::Shader::SHADER:
                {

                    shader_data myshader;
                    tlShader* p_shader =new tlShader ();
                    p_shader->LoadFromChunk(sub);
                    
                    //get data for myshader

                    strcpy(myshader.name,p_shader->GetName());
                    myshader.lit=p_shader->GetIntParam("LIT");
                    myshader.twosid=p_shader->GetIntParam("2SID");
                    
                    //cout<<"Checking for "<<myshader.name<<" Shader ";                 
                                      

                    if (p_shader->GetFloatParam("SHIN")  > 0.0 )
                    {   
                        if (shin)
                        {
                            printf("Shader: %s has shinyness %f greater than 0.0!!!\n",p_shader->GetName(),p_shader->GetFloatParam("SHIN"));
                            //printf("Shader: %s has shinyness %f greater than 0.0!!!, Setting it to 0.0\n",p_shader->GetName(),p_shader->GetFloatParam("SHIN"));
                            //p_shader->SetFloatParam("SHIN",0.0);
                        }
                    }


                    if( strcmp ("lambert",p_shader->GetShaderType() )==0)
                    {
                        printf("     =====> ERROR: %s is of type Lambert, SOMEONE is GETTING the BEATS ! \n",myshader.name);
                        badart=true;
                    }

                    if (p_shader->GetIntParam("2SID") == 0)
                    {
                       //printf("%-30s Shader:   =====>Warning : Double Sided FLAG is 0!\n",p_shader->GetName());
                       //p_shader->SetIntParam("2SID",1);
                       //error=true;
                    }     
                                     
                    if(shaderlookup(&myshader,add,strict,showall,bad_shaders,suppress))
                    {
                        badart=true;
                    }
                  
                    tlDataChunk* p_chunk=p_shader->Chunk();
                    delete p_shader;
                    outchunk->AppendSubChunk(p_chunk);
                    break;
                }
            case SRR2::ChunkID::ENTITY_DSG:
                {
                    tlDataChunk* p_temp = sub->GetSubChunk(0);
                   
                   
                    tlMeshChunk* p_mesh = (tlMeshChunk* )  p_temp;
                    tlPrimGroup* p_primgroup = new tlPrimGroup ();
                    unsigned int vertexmemsize =0;
                    p_primgroup->LoadFromChunk(p_mesh->GetSubChunk(0));                   
                   
                    if( p_primgroup->GetTriangleCount() >MAX_POLYCOUNT)
                    {
                        if(p_primgroup->GetType() == PDDI_PRIM_TRIANGLES)
                        {
                            sprintf(screenoutput,"%-30s mesh => Polycount : %6d \n",p_mesh->GetName(),p_primgroup->GetTriangleCount());
                        }

                        if(p_primgroup->GetType() == PDDI_PRIM_TRISTRIP)
                        {
                            sprintf(screenoutput,"%-30s mesh => Polycount Tristriped: %6d \n",p_mesh->GetName(),p_primgroup->GetTriangleCount());
                        }

                        //cout<< p_primgroup->GetTriangleCount()<<endl;
                        //printf("%-30s mesh => Polycount: %6d \n",p_mesh->GetName(),p_primgroup->GetTriangleCount());
                        p_polycount->add(screenoutput);
                    }

                    if(p_primgroup->GetVertexType()==8209)
                    {
                        //printf("ERROR: %s mesh HAS NO CVB lighting INFO!\n",p_mesh->GetName());
                        sprintf(screenoutput,"%-30s =====>ERROR: Mesh has No CBV (Color by Vertex) Lighting INFO! ", p_mesh->GetName());
                        p_mesh_ref->add(screenoutput);
                        badart=true;
                    }

                    if (bad_shaders.inlist(p_primgroup->GetShader( ) ))
                    {
                        sprintf(screenoutput,"%-30s =====>ERROR: Referencing bad shader : %-30s", p_mesh->GetName(), p_primgroup->GetShader());
                        p_mesh_ref->add(screenoutput);
                        badart =true;
                    }

                    delete p_primgroup;



                    // memory checkfunctionality
                    int chunkcount1,chunkcount2;

                    for (chunkcount1 =0;chunkcount1<p_temp->SubChunkCount();chunkcount1++)
                    {
                        tlDataChunk* sub1=p_temp->GetSubChunk(chunkcount1);

                        switch(sub1->ID())
                        {
                        case Pure3D::Mesh::PRIMGROUP:
                            {
                                for (chunkcount2=0;chunkcount2<sub1->SubChunkCount();chunkcount2++)
                                {
                                    tlDataChunk* sub2=sub1->GetSubChunk(chunkcount2);
                                    switch (sub2->ID())
                                    {
                                    case Pure3D::Mesh::MEMORYIMAGEVERTEXLIST:
                                        {
                                            tlPrimGroupMemoryImageVertexChunk* p_vertexmemorychunk = (tlPrimGroupMemoryImageVertexChunk*) sub2;
                                            vertexmemsize = p_vertexmemorychunk->GetMemoryImageVertexSize();
                                            //printf("%u bytes \n", p_vertexmemorychunk->GetMemoryImageVertexSize());                                                                  
                                        }
                                    }
                                }//end for

                            }//end case
                        }//end switch

                    }//end outer for loop.


                    meshstats.add(p_mesh->GetName(),1,vertexmemsize);
                    outchunk->AppendSubChunk(sub,FALSE);
                    break;

                }



            case Pure3D::Mesh::MESH:               
                {
                    counter++;

                    tlDataChunk* p_sub =NULL;
                    
                    unsigned int i = 0;
                    p_sub = sub->GetSubChunk(i);

                    while (p_sub ->ID( ) == Pure3D::Mesh::PRIMGROUP )
                    {
                        tlMeshChunk* p_mesh = (tlMeshChunk* ) sub;
                        tlPrimGroup* p_primgroup = new tlPrimGroup ();
                        unsigned int vertexmemsize =0;
                        p_primgroup->LoadFromChunk(p_mesh->GetSubChunk(i));                   
                                      
                        if( p_primgroup->GetTriangleCount() >MAX_POLYCOUNT)
                        {
                                               
                            if(p_primgroup->GetType() == PDDI_PRIM_TRIANGLES)
                            {
                                sprintf(screenoutput,"%-30s mesh => Polycount : %6d \n",p_mesh->GetName(),p_primgroup->GetTriangleCount());
                                p_polycount->add(screenoutput);
                            }

                            if(p_primgroup->GetType() == PDDI_PRIM_TRISTRIP)
                            {
                                sprintf(screenoutput,"%-30s mesh => Polycount Tristriped: %6d \n",p_mesh->GetName(),p_primgroup->GetTriangleCount());
                                p_polycount->add(screenoutput);
                            }
                        }
                
                        if(p_primgroup->GetVertexType()==8209)
                        {                        
                            sprintf(screenoutput,"%-30s =====>ERROR: Mesh has No CBV (Color by Vertex) Lighting INFO! ", p_mesh->GetName());
                            p_mesh_ref->add(screenoutput);
                            badart=true;
                        }
                        
                        //hack to make every 3rd shader be char swatch.
                        if (counter == 3)
                        {
                            counter =0;
                            p_primgroup->SetShader("char_swatch_m");
                        }

                        if (bad_shaders.inlist(p_primgroup->GetShader( ) ))
                        {
                            sprintf(screenoutput,"%-30s =====>ERROR: Referencing bad shader : %-30s", p_mesh->GetName(), p_primgroup->GetShader());
                            p_mesh_ref->add(screenoutput);
                            badart=true;
                        }

                        delete p_primgroup;
                        i++;
                    


                        // memory checkfunctionality
                        int chunkcount1,chunkcount2;

                        for (chunkcount1 =0;chunkcount1<sub->SubChunkCount();chunkcount1++)
                        {
                            tlDataChunk* sub1=sub->GetSubChunk(chunkcount1);

                            switch(sub1->ID())
                            {
                            case Pure3D::Mesh::PRIMGROUP:
                                {
                                    for (chunkcount2=0;chunkcount2<sub1->SubChunkCount();chunkcount2++)
                                    {
                                        tlDataChunk* sub2=sub1->GetSubChunk(chunkcount2);
                                        switch (sub2->ID())
                                        {
                                        case Pure3D::Mesh::MEMORYIMAGEVERTEXLIST:
                                            {
                                                tlPrimGroupMemoryImageVertexChunk* p_vertexmemorychunk = (tlPrimGroupMemoryImageVertexChunk*) sub2;
                                                vertexmemsize = p_vertexmemorychunk->GetMemoryImageVertexSize();
                                                //printf("%u bytes \n", p_vertexmemorychunk->GetMemoryImageVertexSize());                                                                  
                                            }
                                        }
                                    }//end for

                                }//end case
                            }//end switch

                        }//end outer for loop.

                    
                        meshstats.add(p_mesh->GetName(),1,vertexmemsize);
                        outchunk->AppendSubChunk(sub,FALSE);
						p_sub = sub->GetSubChunk(i);
                    }//end while loop
                    break;              
                }
            case Pure3D::Animation::AnimationData::ANIMATION:
                {
                
                    unsigned int animationmemsize =0;
                    int chunkcount1;

                    for (chunkcount1 =0;chunkcount1<sub->SubChunkCount();chunkcount1++)
                    {
                        tlDataChunk* sub1=sub->GetSubChunk(chunkcount1);

                        switch(sub1->ID())
                        {
                        case Pure3D::Animation::AnimationData::SIZE:
                            {                                                      
                             
                                tlAnimationSizeChunk* p_animationsizechunk = (tlAnimationSizeChunk*) sub1;
                                animationmemsize = p_animationsizechunk->GetPS2();
                                //printf("%u bytes \n", p_animationsizechunk->GetPS2());                                                                  
                                
                            }//end case
                        }//end switch
                    }//end outer for loop.
                    
                    //printf("name: %s , %u bytes \n",sub->GetName(),animationmemsize);
                    animationstats.add(sub->GetName(),1,animationmemsize);
                    outchunk->AppendSubChunk(sub,FALSE);
                    break;                 
                
                }
            
 /*
            case Simulation::Collision::OBJECT:
                {
                    //temp local variables

                    tlCollisionObjectChunk* p_collisionobject= (tlCollisionObjectChunk*)sub;
                    bv_data bv_object;
                    char source_name[max_length];
                    char object_name1[max_length];
                    char object_name2[max_length];
                    

                    //cout<<"Checking "<<p_collisionobject->GetName()<<" Collision Object "<< endl;
                    
                    //get the name of collision object
                    strcpy(source_name,p_collisionobject->GetName());
                    //cout<<"Source name: "<<source_name<<endl;
                    
                    //smash up string to remove the number appended by Maya
                    strcpy(object_name1,strtok(source_name,"_"));
                    strcpy(object_name2,strtok(NULL,"_"));
                    
                    //reform string
                    strcat(object_name1,"_");
                    strcat(object_name1,object_name2);
                   
                    
                    //set default vaules 
                    strcpy(bv_object.name,object_name1);
                    bv_object.classtype=0;
                    bv_object.physpropid=0;

                    //cout<<"New concated string: " <<object_name1<<endl;
                 
                 
                    if(bvobjectlookup(&bv_object,query,add,strict,showall))
                    {
                        badart=true;
                    }
                    
                    //creating object attribute chunk

                    tlObjectAttributeChunk* p_otc =new tlObjectAttributeChunk ();
                    p_otc->SetClassType(bv_object.classtype);
                    p_otc->SetPhyPropID(bv_object.physpropid);

                    tlPhysWrapperChunk* p_physwrapper = new tlPhysWrapperChunk ();
                    p_physwrapper->SetName(p_collisionobject->GetName());
                   
                    //append the chunks
                    //p_physwrapper->AppendSubChunk(p_otc);
                    //p_physwrapper->AppendSubChunk(sub, FALSE);
                    outchunk->AppendSubChunk(sub,FALSE);
                    break;
                }


  */
            case StateProp::STATEPROP:
                {
                    printf("This File:%s contains a stateprop \n",filename);
                    break;
                }
            default:
                 {
                    // this is not a chunk that we care about
                    // so simply copy it to the output wrapper chunk
                    // the optional parameter to AppendSubChunk
                    // indicates that we have merely copied a pointer
                    // so the destructor of outchunk should not
                    // destroy this sub-chunk as that duty will be
                    // taken care of by the destructor of inchunk
                    outchunk->AppendSubChunk(sub,FALSE);
                    break;

                 }
            }//end switch
        }//end for
	
		//record objects stats faking art object
        art_object target_object;   
		strcpy(target_object.name,"devil car");

		target_object.art_properties.vertex_count= 453;
		target_object.art_properties.poly_count=2345;
		target_object.art_properties.animation_frames=25;
		target_object.art_properties.bone_count=35;
		target_object.art_properties.shader_count=14;

/*
		if( artobjectlookup(&target_object,query,add,strict) )
		{
			cout<<"Art object:" <<target_object.name<< " has failed art check\n ";
			//exit (1);			
		}
				
*/		
		//check for shaders and textures are

	
		//all is good add physic proporties
		
		shader_data hmm;

		strcpy(hmm.name,"trunk");
		hmm.lit=false;
/*
		if (shaderlookup(&hmm,query,add,strict))
		{
			cout<<hmm.name<<"not in art db \n";
			//exit (1);
		}
*/


//}
	 //end of try

//	catch (BadQuery er)
	{
	//	cout<<"Error: " <<er.error<< endl;
	//	return 1;
	}
	
    if (badart)
    {       
        printf("\n");
        printf("\n");

        printf("*****         SUMMARY         ******* \n");
        fprintf(stdout,"ERROR: %-15s contains BAD ART and has FAILED Artchecker! \n",filename);
        
        // cleanup the no-longer-needed wrapper chunks
              
        printf("Total Memory size of    Textures: %20u bytes in %9u textures \n",texturestats.getsize(),texturestats.getindexcount());
        printf("Total Memory size of  Animations: %20u bytes in %9u animations \n",animationstats.getsize(),animationstats.getindexcount());
        printf("Total Memory size of      Meshes: %20u bytes in %9u meshes \n",meshstats.getsize(),meshstats.getindexcount());
        
        printf("*****        END OF SUMMARY         ******* \n");
        printf("\n");
        
        
        if(!suppress)
        {
            printf("\n");
            printf("\n");        
            printf("*****       Bad Meshes      *******\n");
            p_mesh_ref->print();
            printf("\n");
            printf("*****       HIGH POLY Meshes      *******\n");
            p_polycount->print();
            printf("\n");
        }
        if(showall)
        {
            printf("\n");
            printf("*****       Texture Breakdown      *******\n");
            texturestats.printverbose();
            printf("\n");
            printf("*****       Animation Breakdown      *******\n");
            animationstats.printverbose();
            printf("\n");
            printf("*****       Meshes Breakdown      *******\n");
            meshstats.printverbose();
            printf("\n");

        }
        delete p_mesh_ref ;
        delete p_polycount;
        
   /*         
        // create the new output file
        tlFile output(new tlFileByteStream(filename, omWRITE), tlFile::CHUNK32);

        if(!output.IsOpen())  
        {
            printf("Could not open %s for writing,unable to Save\n", filename);
            exit(-1);
        }

        // get the output wrapper chunk to write its data out
        // to the file
        outchunk->Write(&output);
*/
        
        delete inchunk;
        delete outchunk;
        return 1;
    }
    else
    {
        
/*     
        // create the new output file
        tlFile output(new tlFileByteStream(filename, omWRITE), tlFile::CHUNK32);

        if(!output.IsOpen()) 
        {
            printf("Could not open %s for writing\n", filename);
            exit(-1);
        }
*/
        // get the output wrapper chunk to write its data out
        // to the file
       // outchunk->Write(&output);
     
        
        // cleanup the no-longer-needed wrapper chunks
        delete inchunk;
        delete outchunk;
        delete p_mesh_ref;
        delete p_polycount;
        printf("\n");  
        printf("\n");
        printf("\n");

        printf("*****         SUMMARY         ******* \n");
        printf("\n");
        fprintf(stdout,"Filename:%-15s PASSED Artchecker. \n",filename);
        printf("\n");
        
        // cleanup the no-longer-needed wrapper chunks
              
        printf("Total Memory size of    Textures: %20u bytes in %9u textures \n",texturestats.getsize(),texturestats.getindexcount());
        printf("Total Memory size of  Animations: %20u bytes in %9u animations \n",animationstats.getsize(),animationstats.getindexcount());
        printf("Total Memory size of      Meshes: %20u bytes in %9u meshes \n",meshstats.getsize(),meshstats.getindexcount());
        
        printf("*****        END OF SUMMARY         ******* \n");

        if(showall)
        {
            printf("\n");
            printf("*****       Texture Breakdown      *******\n");
            texturestats.printverbose();
            printf("\n");
            printf("*****       Animation Breakdown      *******\n");
            animationstats.printverbose();
            printf("\n");
            printf("*****       Meshes Breakdown      *******\n");
            meshstats.printverbose();
            printf("\n");

        }
        return 0;
    }
} //end of main


//********************************************
//              Function Bodies
//********************************************

//helper function to print error messages
void debugstring (char * message)
{
#ifdef DEBUG
	cout<<message<<endl;
#endif
}


//helper funtion to check texutre return 0 if texture matches db ,1 if their is a mismatch or error
int texturelookup(const texture_data& texturedata, bool add, bool strict,bool showall,badlist& badtextures,bool suppress)  //badlist* p_badtextures
{
		bool error=false ;
		//char querybuffer [1000];
        char output [1000];
//		Result::iterator sql_iterator;
//		Row row;
        outputbuffer texture_errors;

		//sprintf(querybuffer, "SELECT * FROM textures WHERE name = '%s' ",texturedata.name);
		//query<< querybuffer;
		//Result myresult= query.store ( );
		
	
	
		//cant find texture in the database	
		//if (myresult.size ( ) ==0 )
		if (1)
		{
			
			if ( add == true)
			{
				//add object to the DB
				cout<< "Adding:" << texturedata.name << " texture to the ArtDB \n";

				//todo add stuff here
            }
			//texture not found in the the DB 
		
			if (strict)
			{
				//cout<<",Not Found !" <<endl;
                sprintf(output,"    ERROR :%s texture not found in the ArtDB",texturedata.name);
                texture_errors.add(output);
                //cout<<"ERROR :"<<texturedata.name<< " texture not found in the ArtDB \n";
				error = true;
			}

            //check texture attributes against the default limits
				              
            //check against art limits
            if(texturedata.height>MAX_TEXTURE_SIZE)
            {
                error=true;
                sprintf(output,"    ERROR : %u  Height exceeds Max Texture SIZE OF %u",texturedata.height,MAX_TEXTURE_SIZE);
                texture_errors.add(output);
             // cout<<"     =====>Warning "<<texturedata.name<<" : "<< texturedata.height << " Height exceeds Max Texture SIZE OF "<<MAX_TEXTURE_SIZE<<endl;            
            }

            if(texturedata.width>MAX_TEXTURE_SIZE)
            {
                error=true;
                sprintf(output,"    ERROR : %u  Width exceeds Max Texture SIZE OF %u",texturedata.width,MAX_TEXTURE_SIZE);
                texture_errors.add(output);
             // cout<<"     =====>Warning "<<texturedata.name<<": "<< texturedata.width << " Width exceeds Max Texture SIZE OF "<<MAX_TEXTURE_SIZE<<endl;            
            }

            if(texturedata.bpp>MAX_BPP)
            {         
                error=true;
                sprintf(output,"    ERROR : %u  BPP exceeds Max BPP SIZE OF %u",texturedata.bpp,MAX_BPP);
                texture_errors.add(output);
             //cout<<"     =====>Warning "<<texturedata.name<<": "<< texturedata.bpp << " BPP exceeds Max BPP SIZE OF "<<MAX_BPP<<endl;            
             }			
             //	  cout<<"     Warning :"<<texturedata.name<< " texture not found in the ArtDB \n";    
		
		}//end if  in artdb block

        //if(myresult.size()!=0)
		if(0)
        {
		    //cout <<",Found . " << endl;

          /*
			for (sql_iterator=myresult.begin ( ); sql_iterator!= myresult.end ( ); sql_iterator++)
		    {
		                
			    row =*sql_iterator;
                int height= row["height"];
                int width=row["width"];
                int bpp=row["bpp"];
                int alpha=row["alphabits"];
                              

                //check texture height
                if( texturedata.height > height)
                {
			        if (strict)
                    {
                        error=true;
                        sprintf(output,"    ERROR :Texture height %u exceeds expected %u",texturedata.height,height);
                        texture_errors.add(output);
                    }
                    else
                    {
                        sprintf(output,"    Warning :Texture height %u exceeds expected %u",texturedata.height,height);
                        texture_errors.add(output);
                    }
                }//end if

                //check width
                if( texturedata.width > width)
                {
			        if (strict)
                    {
                        error=true;
                        sprintf(output,"    ERROR :Texture width %u exceeds expected %u",texturedata.width,width);
                        texture_errors.add(output);
                    }
                    else
                    {
                        sprintf(output,"    Warning :Texture width %u exceeds expected %u",texturedata.width,width);
                        texture_errors.add(output);
                    }
                }//end if

                //check bpp
                if( texturedata.bpp > bpp)
                {
			        if (strict)
                    {
                        error=true;
                        sprintf(output,"    ERROR :Texture BPP %u exceeds expected %u",texturedata.bpp,bpp);
                        texture_errors.add(output);
                    }
                    else
                    {                        
                        sprintf(output,"    Warning :Texture BPP %u exceeds expected %u",texturedata.bpp,bpp);
                        texture_errors.add(output);
                    }
                }//end if

                          
                
                
            //just printing out the rows
			//for (int j=0;j<row.size ( ); j++)
			//{
			//	cout<< "[" << row[j] << "]" ;
			//}
			//cout<<endl;

		    }//end for iterator loop

  */
       
        }//end if found in the Artdb block

	
   

    if (error)
    {
        if(!suppress)
        {
            printf("\n");
            printf("%s Texture:\n",texturedata.name);                             
            texture_errors.print();
            printf("\n");
        }
            badtextures.add(texturedata.name,1,0);
        return 1;
    }
    else
    {
        return 0;
    }

}// end texture lookup


//helper funtion to check shader, returns 0 if shader matches db ,1 if their is a mismatch
int shaderlookup(shader_data* lp_shaderdata, bool add, bool strict,bool showall,badlist& badshaders,bool suppress)
{

    bool error=false;
	char querybuffer [1000];
    char output [1000];
	//Result::iterator sql_iterator;
	//Row row;
    outputbuffer shader_errors;
	sprintf(querybuffer, "SELECT * FROM shaders WHERE name = '%s' ",lp_shaderdata->name);
	//query<< querybuffer;
	//Result myresult= query.store ( );
	
			
//	if (myresult.size ( ) ==0 )
	if (1)
	{
	
	    if ( add == true)
		{
		//add object to the DB
		printf("Adding: %s  shader to the ArtDB \n",lp_shaderdata->name);
		//todo add stuff here
		}
		        
		if (strict)
		{         
            sprintf(output,"    ERROR: %s Shader not found in the ArtDB",lp_shaderdata->name);
            shader_errors.add(output);
         }					                 
                
         //check for lit
         if ( lp_shaderdata->lit)
         {                             
               shader_errors.add("    =====>ERROR   : LIT shader FOUND!");
               error = true;
              
               if(badshaders.inlist(lp_shaderdata->name) ==0)
               {
                   badshaders.add(lp_shaderdata->name,1,0);
                }  
         }         
/*
         if ((lp_shaderdata->twosid) == 0)
         {
             shader_errors.add("    =====>Warning : Double Sided FLAG is 0!");
             error=true;
          }                                    

 */

	}//end if shader in artdb check
		
	//cout << "Records Found: " << myresult.size() << endl ;
/*		

	for (sql_iterator=myresult.begin ( ); sql_iterator!= myresult.end ( ); sql_iterator++)
		{	
			row =*sql_iterator;
   			
			//just printing out the rows
			for (int j=0;j<row.size ( ); j++)
			{
				cout<< "[" << row[j] << "]" ;
			}
			cout<<endl;
  		}//end for iterator loop
*/

    if (error)
    {
        if(!suppress)
        {

            printf("\n");
            printf("%s shader : \n",lp_shaderdata->name);
            shader_errors.print();
        }
        if(strict)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
    else
    { 
        return 0;
    }

}// end shader lookup

/*


//helper funtion to check object, returns 0 if shader matches db ,1 if their is a mismatch
int artobjectlookup(art_object* lp_artobject, Query& query,bool add, bool strict,bool showall,bool suppress)
{
		
		char querybuffer [1000];
		Result::iterator sql_iterator;
		Row row;
		unsigned int artpropid,shaderid;
        bool error= false;

		//setup a query to artdb ask if object is in Artdb
		
		sprintf(querybuffer, "SELECT * FROM objects WHERE name = '%s' ",lp_artobject->name);	
		query<< querybuffer;
		Result myresult= query.store ( );
		//cout << "Records Found: " << myresult.size() << endl ;
		
        //if result size is zero, object not found
		//if ( myresult.size ( ) ==0 )
		if(1)
		{		
			if ( add == true)
			{
				//add object to the DB
				cout<< "Adding:" << lp_artobject->name << " to the ArtDB \n";
				//todo add stuff here

				return 0;
			}
			//object not found in the the DB halt
			else
			{
				if (strict)
				{
					printf("ERROR: %s object not found in the ArtDB, \n",lp_artobject->name);
					error =true;
				}
				else
				{
					printf("Warning:%s object not found in the ArtDB \n",lp_artobject->name);
				}
			}
		}//end if object in artdb check
						
	
		for (sql_iterator=myresult.begin ( ); sql_iterator!= myresult.end ( ); sql_iterator++)
		{
			row =*sql_iterator;
    		artpropid = row["artpropid"];
			shaderid = row["shaderid"];
			//just printing out the rows
			for (int j=0;j<row.size ( ); j++)
			{
				cout<< "[" << row[j] << "]" ;
			}
			cout<<endl;
		}//end for iterator loop
		
		
		//check check the art proporties  if less than max vertices,etc then we ok
		sprintf(querybuffer, "SELECT * FROM artprops WHERE id = '%i' ",artpropid);
		query<< querybuffer;
		myresult= query.store ( );

		cout << "Records Found: " << myresult.size() << endl ;
		//check if artprops in the ArtDB
		//if ( myresult.size ( ) ==0 )
		if(1)
		{
			if ( add == true)
			{
				//add object to the DB
				cout<< "Adding:" <<lp_artobject->name << " art props to the ArtDB \n";
				cout<< "Adding:  Artprops to artdb \n";
				return 0;

				//todo add stuff here
			}

			//object not found in the the DB halt
			else
			{
				if (strict)
				{
					cout<<"ERROR: "<<lp_artobject->name<< " Art properties not found in the ArtDB, Halting \n";
					error=true;
				}
				else
				{
					cout<<"Warning: "<<lp_artobject->name<< " Art properties not found in the ArtDB, using default physic properties\n";
				}//end else
			}//end else
		}//end if		
		
		for (sql_iterator=myresult.begin ( ); sql_iterator!= myresult.end ( ); sql_iterator++)
		{
			row =*sql_iterator;
			
			unsigned int vertexcount,polycount,shadercount,bonecount,animationframes;
			vertexcount=row["VertexCount"];
			polycount=row["PolyCount"];
			shadercount=row["ShaderCount"];
			bonecount=row["BoneCount"];
			animationframes=row["Animframes"];
		
			if (strict)
			{
				if(	lp_artobject->art_properties.vertex_count > vertexcount)
				{
					cout<<"ERROR:"<< lp_artobject->name<<" has exceeded " << row["VertexCount"]<<" Vertexcount, HALTING \n";
					error =true;
				}
				
				if(	lp_artobject->art_properties.poly_count > polycount)
				{
					cout<<"ERROR:"<< lp_artobject->name<<" has exceeded " << row["PolyCount"]<<" Polycount, HALTING \n";
					error =true;
				}
			
				if(	lp_artobject->art_properties.animation_frames > animationframes)
				{
					cout<<"ERROR:"<< lp_artobject->name<<" has exceeded " << row["AnimFrames"]<< " Animation frames, HALTING \n";
					error =true;
				}
				
				if(	lp_artobject->art_properties.bone_count > bonecount)
				{	
					cout<<"ERROR:"<< lp_artobject->name<<" has exceeded " << row["BoneCount"]<<" Bonecount, HALTING \n";
					error =true;
				}
				
				if(	lp_artobject->art_properties.shader_count > shadercount)
				{
					cout<<"ERROR:"<< lp_artobject->name<<" has exceeded " << row["ShaderCount"]<<" Shadercount, HALTING\n";
					error =true;
				}
			}//end if artprops check
		else
			{
				if(	lp_artobject->art_properties.vertex_count > vertexcount)
				{
					cout<<"Warning:"<< lp_artobject->name<<" has exceeded " << row["VertexCount"]<<" Vertexcount \n";
				}
				
				if(	lp_artobject->art_properties.poly_count > polycount)
				{
					cout<<"Warning:"<< lp_artobject->name<<" has exceeded " << row["PolyCount"]<<" Polycount \n";
				}
			
				if(	lp_artobject->art_properties.animation_frames > animationframes)
				{
					cout<<"Warning:"<< lp_artobject->name<<" has exceeded " << row["AnimFrames"]<< " Animation frames \n";
				}
				
				if(	lp_artobject->art_properties.bone_count > bonecount)
				{	
					cout<<"Warning:"<< lp_artobject->name<<" has exceeded " << row["BoneCount"]<<" Bonecount  \n";
				}
				
				if(	lp_artobject->art_properties.shader_count > shadercount)
				{
					cout<<"Warning:"<< lp_artobject->name<<" has exceeded " << row["ShaderCount"]<<" Shadercount \n";
				}
			}// end else artprops check


		
		}//for loop end artobjectlookup

        
		//printing art props
		
		for (int j=0;j<row.size ( ); j++)
		{
			cout<< "[" << row[j] << "]" ;
		}

  
		printf("\n");

    if (error)
    {
        return 1;
    }
    else
    {    
	    return 0;
    }

}//end artobject lookup


//*************************************************************************
// Check's if root of Bound Volume exists, if not then treats it as a strict object
		
int bvobjectlookup(bv_data* lp_bvobject,Query& query,bool add,bool strict,bool showall,bool suppress)
{
    bool errors =false;
    char querybuffer [1000];
    char output[1000];
    outputbuffer bv_errors;
	Result::iterator sql_iterator;
	Row row;


    sprintf(querybuffer, "SELECT * FROM objects WHERE name = '%s' ",lp_bvobject->name);
	query<< querybuffer;
	Result myresult= query.store ( );
	
			
	if (myresult.size ( ) ==0 )
	{	
        if ( add == true)
		{
				//add object to the DB
				//cout<< "Adding:" << lp_shaderdata->name << " shader to the ArtDB \n";

				//todo add stuff here
		}
			//object not found in the the DB halt
		else
		{
		    if (strict)
		    {
					sprintf(output,"ERROR: %s object not found in the ArtDB \n",lp_bvobject->name);
                    bv_errors.add(output);
                    //cout<<"     ERROR:"<<lp_bvobject->name<< " object not found in the ArtDB \n";
					//return 1;
                    errors =true;
			}
			else
			{
                    errors =true;
                    sprintf(output,"Warning: %s object not found in the ArtDB , using  defaults vaules for ObjectAttributeChunk \n",lp_bvobject->name);
                    bv_errors.add(output);
					//cout<<"     Warning:"<<lp_bvobject->name<< " bv object not found in the ArtDB, using  defaults vaules for ObjectAttributeChunk \n";
                    lp_bvobject->physpropid=0;
                    lp_bvobject->classtype=2; // set to dsg_static_phys
			}

		}

	}//end if object check in artdb check
		
	//	cout << "Records Found: " << myresult.size() << endl ;
	
	for (sql_iterator=myresult.begin ( ); sql_iterator!= myresult.end ( ); sql_iterator++)
		{
			
			row =*sql_iterator;
            lp_bvobject->classtype =2;
            lp_bvobject->physpropid=row["physpropid"];

			
			//just printing out the rows
			for (int j=0;j<row.size ( ); j++)
			{
				cout<< "[" << row[j] << "]" ;
			}

			cout<<endl;


	}//end for iterator loop

    if (errors)
    {
        if(strict)
        {
            bv_errors.print();
            return 1;
        }
        else
        {
            if(!suppress)
            {
                bv_errors.print ();
            }
            return 0;
        }
    }
    else
    {
        return 0;
    }
}// end of Bv object check


*/