summaryrefslogblamecommitdiffstats
path: root/tools/DSGmaker/dsgmaker.cpp
blob: 9624e041438706858d0bbe8d50d5577692c5147f (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






































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                                                            
//DSGmaker a tool to traverse the the inventory of a Pure3d file and creates 
//DSGchucks and bundles mesh,phys,BV,instance chunk together. Supports multiple objects in a file.

#pragma warning(disable:4786)

#include <iostream>
#include <cstring>
#include <iomanip>
#include <mysql++>
#include <..\..\..\tools\artchecker\artobject.h>
#include <..\..\..\tools\artchecker\artlimits.h>
#include <..\..\..\tools\artchecker\badlist.hpp>
#include <..\..\..\tools\artchecker\outputbuffer.hpp>


#include <toollib.hpp>
#include <tlCollisionObjectChunk.hpp>
#include <tlPhysicsObjectChunk.hpp>
#include <tlMeshChunk.hpp>
#include <..\constants\srrchunks.h>
#include <..\..\..\tools\dsgmaker\DSGList.hpp>
using namespace std;

//function that strips all the extra crap(prefixes and appended junk)
//and returns actual object name  in output pointer.

unsigned int rootname(const char* input,char* output);


int main(int argc, char* argv[])
{
    
    //char* arguements [4];
    char* filename;
    char querybuffer [1000];
    bool badart = false;
    bool showall= false;
    Result::iterator sql_iterator;
    DSGList* p_dsglist =new DSGList();
    bool mbIgnoreMissingInstanceChunk = false;

    tlDataChunk::RegisterDefaultChunks();

    //processes arguements
    
    //no options 
    if (argc ==1)
    {
        cout<<"Usage:Dsgmaker filename \n";
        exit (1);
    }
        
    filename= argv[1];

    if ( argc ==3)
    {
        if (strcmp( argv[2],"-nI") == 0)
        {
            mbIgnoreMissingInstanceChunk = true;
            //printf("Ignoring Missing Chunks!\n");
        }
        else
        {
            printf("Error: unknown arguement %s \n",argv[2]);
        }
    }

/*  
    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],"all")==0)
        {
            showall =true;
            break;
        }
        //illegal option
        else 
        {
            cout <<arguements[i] <<" is an illegal option \n";
            exit (1);
        }
            
#ifdef DEBUG
        cout<< i ;
        cout<< arguements [i] << "\n";
#endif
    
    } //end for

   */

     //read in the pure3d file name

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

    cout<<"Processing Filename:"<<filename<<endl;

    //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
    input.Close();


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

    //connect to the Art DB
    try
    {
        //setup artrb variables
        bool dbconnect=false;
        Row row;    
        
        //creat connection and query objects
        Connection con (use_exceptions);
        Query query=con.query( );
        dbconnect=con.connect ("srr2test","radit","root","custom47");   
       

        if (dbconnect == true)
        {
            cout<<"Connection to Artdb established proceeding.\n";
        }
        else
        {
            cout<<"Cant connection to ArtDB Aborting! \n";
            exit (1);
        }


        // go through all the sub-chunks of the input and
        // process the ones you care about
        for(ch=0; ch < inchunk->SubChunkCount(); 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::Mesh::MESH:               
                {
                    
                    //printf("\n");
                    tlMeshChunk* p_mesh = (tlMeshChunk* )  sub;                                     
                    char mesh_name[max_length];
                    
                    //get object name and remove extra appended crap
                    ::rootname(p_mesh->GetName(),mesh_name);                    
                                                    
                   
                    //query ArtDB for info on this mesh 
                    sprintf(querybuffer, "SELECT * FROM objects WHERE name = '%s' ",mesh_name);
                    query<< querybuffer;
                    Result  myresult = query.store ( );
    
                    //check results, 
                    //if not found in ArtDB make it a  into a StaticEntityDSG as a default.
                    if (myresult.size ( ) ==0 )
                    {
                        //create StaticEntityDSG chunk and append mesh
                        printf("%s : Mesh not found in ArtDB creating EntityDSGChunk !\n",mesh_name);
                        tlEntityDSGChunk* p_entitydsg =new tlEntityDSGChunk();
                        p_entitydsg->SetName(p_mesh->GetName());
                        p_entitydsg->AppendSubChunk(sub,FALSE);
                        outchunk->AppendSubChunk(p_entitydsg,FALSE);

                    }
                    // its found in the ArtDB, need to determine what kind of DSG to make.          
                    else
                    {
        
                        for (sql_iterator=myresult.begin ( ); sql_iterator!= myresult.end ( ); sql_iterator++)
                        {
                            row =*sql_iterator;
                            char classtypeID [max_length];
                            strcpy(classtypeID, row["ClassType"]);
                            printf("Found %s meshchunk \n",p_mesh->GetName());
                            //printf("Classtype ID: %s \n",classtypeID);

                           //make the correct DSG chunktype
                            if (
                                    (strcmp(classtypeID,"PROP_MOVEABLE")==0)                    ||
                                    (strcmp(classtypeID,"PROP_BREAKABLE")==0)                   ||
                                    (strcmp(classtypeID,"PROP_ONETIME_MOVEABLE")==0)
                                )
                            {
                                printf("    %s is of type %s creating DynaPhysDSGChunk \n",mesh_name,classtypeID);
                                tlDynaPhysDSGChunk* p_dynaphysdsg =new tlDynaPhysDSGChunk ();
                                p_dynaphysdsg->SetName(p_mesh->GetName());
                                p_dynaphysdsg->AppendSubChunk(sub,FALSE);
                                outchunk->AppendSubChunk(p_dynaphysdsg,FALSE);
                                p_dsglist->AddDSG(p_dynaphysdsg);
                                //printf("    Finished making chunk\n");
                            }
                           
                            else if (strcmp(classtypeID,"PROP_STATIC")==0)
                            {
                                printf("    %s is of type %s creating InstaStaticPhysDSGChunk \n",mesh_name,classtypeID);
                                tlInstaStaticPhysDSGChunk* p_instaphysdsg =new tlInstaStaticPhysDSGChunk ();
                                p_instaphysdsg->SetName(p_mesh->GetName());
                                p_instaphysdsg->AppendSubChunk(sub,FALSE);
                                outchunk->AppendSubChunk(p_instaphysdsg,FALSE);
                                p_dsglist->AddDSG(p_instaphysdsg);
                            }

                            else if (strcmp(classtypeID,"PROP_DRAWABLE")==0)
                            {
                                printf("    %s is of type %s creating InstaEntityDSGChunk \n",mesh_name,classtypeID);
                                tlInstaEntityDSGChunk* p_instaentitydsg =new tlInstaEntityDSGChunk();
                                p_instaentitydsg->SetName(p_mesh->GetName());
                                p_instaentitydsg->AppendSubChunk(sub,FALSE);
                                outchunk->AppendSubChunk(p_instaentitydsg,FALSE);
                                p_dsglist->AddDSG(p_instaentitydsg);
                            }

                            else if (strcmp(classtypeID,"STATIC")==0)
                            {
                                printf("    %s is of type %s creating EntityDSGChunk \n",mesh_name,classtypeID);
                                tlEntityDSGChunk* p_entitydsg =new tlEntityDSGChunk();
                                p_entitydsg->SetName(p_mesh->GetName());
                                p_entitydsg->AppendSubChunk(sub,FALSE);
                                outchunk->AppendSubChunk(p_entitydsg,FALSE);
                            }
                            
                            else if (strcmp(classtypeID,"DRAWABLE")==0)
                            {
                                printf("    %s is of type %s creating EntityDSGChunk \n",mesh_name,classtypeID);
                                tlEntityDSGChunk* p_entitydsg =new tlEntityDSGChunk();
                                p_entitydsg->SetName(p_mesh->GetName());
                                p_entitydsg->AppendSubChunk(sub,FALSE);
                                outchunk->AppendSubChunk(p_entitydsg,FALSE);
                            }
                            
                            else if (strcmp(classtypeID,"ANIMATED_BV")==0)
                            {
                                printf("    %s is of type %s creating AnimatedBvDSGChunk \n",mesh_name,classtypeID);

                                //Need to finalize class specs with Greg, Devin and Trav TBD still

                                //tlDynaPhysDSGChunk* p_dynaphysdsg =new tlDynaPhysDSGChunk ();
                                //p_dynaphysdsg->SetName(p_mesh->GetName());
                                //p_dynaphysdsg->AppendSubChunk(sub,FALSE);
                                outchunk->AppendSubChunk(sub,FALSE);
                            }
                            else 
                            {
                                printf("\n===================================================\n");
                                printf("\n=\tError unknown %s ClasstypeID \n",classtypeID);
                                printf("\n===================================================\n");
                            }
                                

                        }//end for loop

                    }//end else
                    //printf("exiting Mesh case\n");
                    break;
                }
            case Simulation::Physics::OBJECT:
                {
                    tlPhysicsObjectChunk *p_physobject = (tlPhysicsObjectChunk*) sub;
                    tlDataChunk* p_dsg=NULL;
                    char name[max_length];
                    
                    ::rootname(p_physobject->GetName(),name);
                    printf("\n");
                    printf("Phys Chunk: %s \n",p_physobject->GetName());

                    p_dsg =p_dsglist->GetDSG(p_physobject->GetName());

                    if( p_dsg ==NULL)
                    {
                        badart=true;
                        printf("\n===================================================\n");
                        printf("\n=\tERROR: Cant find Parent DSG for %s, This Physics Volume is MISSING its mesh!!\n",p_physobject->GetName());
                        printf("\n===================================================\n");
                    }
                    else
                    {
                        printf("    Found the parent for %s\n",p_physobject->GetName());
                        p_dsg->AppendSubChunk(sub,FALSE);
                    }
                    break;
                }


            case Simulation::Collision::OBJECT:
                {
                    //printf("entering Collision object \n");
                    //temp local variables

                    tlCollisionObjectChunk* p_collisionobject= (tlCollisionObjectChunk*)sub;
                    bv_data bv_object;
                    tlDataChunk* p_dsg=NULL;
					char sound [64] ="nosound"; //default vaule

                    bool errors =false;
                    char querybuffer [1000];
                                     
                    
                    ::rootname(p_collisionobject->GetName(),bv_object.name);
                    
                    printf("\n");
                    printf("BV name: %s \t ",p_collisionobject->GetName());
                    
                    //seting default vaules, 7 is the default for staticphysDSG's,
                    //and physprop 0 is bogus vaule and should get filled in if BV object is know in the artdb. 
                    bv_object.classtype=7;
                    bv_object.physpropid=0;                    
                    
                    sprintf(querybuffer, "SELECT * FROM objects WHERE name = '%s' ",bv_object.name);
                    query<< querybuffer;
                    Result myresult= query.store ( );       

                    //  cout << "Records Found: " << myresult.size() << endl ;
    
                    for (sql_iterator=myresult.begin ( ); sql_iterator!= myresult.end ( ); sql_iterator++)
                    {
            
                        row =*sql_iterator;
                        char classtypeID [max_length];
                        strcpy(classtypeID, row["ClassType"]);
                        bv_object.physpropid=row["physpropid"];
						strcpy(sound,row["Sound"]);

                        //make the correct DSG chunktype
                        if (strcmp(classtypeID,"PROP_MOVEABLE")==0)
                        {
                            printf("    %s is of type %s Setting Classtype to 3\n",bv_object.name,classtypeID);
                            bv_object.classtype=3;                            
                        }
                            
                        else if (strcmp(classtypeID,"PROP_BREAKABLE")==0)
                        {
                            printf("    %s is of type %s Setting Classtype to 4\n",bv_object.name,classtypeID);
                            bv_object.classtype=4;                            
                        }

                        else if (strcmp(classtypeID,"PROP_STATIC")==0)
                        {
                            printf("    %s is of type %s Setting Classtype to 2\n",bv_object.name,classtypeID);
                            bv_object.classtype=2;
                        }
                            
                        else if (strcmp(classtypeID,"DRAWABLE")==0)
                        {
                            printf("    %s is of type %s ERROR Drawable Objects DO NOT HAVE BV'S!!!\n",bv_object.name,classtypeID);
                            badart=true;
                        }
                        else if (strcmp(classtypeID,"PROP_DRAWABLE")==0)
                        {
                            printf("    %s is of type %s ERROR PROP_DRAWABLE Objects DO NOT HAVE BV'S!!!\n",bv_object.name,classtypeID);
                            badart=true;
                        }
                            
                        else if (strcmp(classtypeID,"ANIMATED_BV")==0)
                        {
                            printf("    %s is of type %s Setting Classtype to 5\n",bv_object.name,classtypeID);
                            bv_object.classtype=5;
                        }
                        else if (strcmp(classtypeID,"STATIC")==0)
                        {
                            printf("    %s is of type %s Setting Classtype to 2\n",bv_object.name,classtypeID);
                            bv_object.classtype=7;
                        }
                        else if (strcmp (classtypeID,"PROP_ONETIME_MOVEABLE")==0)
                        {
                            printf("    %s is of type %s Setting Classtype to 10\n",bv_object.name,classtypeID);
                            bv_object.classtype=10;
                        }



                    }//end for iterator loop


                    
                    //creating object attribute chunk
                    tlObjectAttributeChunk* p_otc =new tlObjectAttributeChunk ();
                    p_otc->SetClassType(bv_object.classtype);
                    p_otc->SetPhyPropID(bv_object.physpropid);
					p_otc->SetSound(sound);

                    //if object is a static then create a StaticPhysDSGChunk
                    if(bv_object.classtype == 7)
                    {
                        tlStaticPhysDSGChunk* p_statdsg =new tlStaticPhysDSGChunk ();
                        p_statdsg->AppendSubChunk(sub,FALSE);
                        p_statdsg->AppendSubChunk(p_otc);
                        p_statdsg->SetName(p_collisionobject->GetName());
                        outchunk->AppendSubChunk(p_statdsg,FALSE);
                    }

                    //otherwise find the Parent DSG and add OTC and 
                    else
                    {
                        //printf("    Need to find Parent DSG \n");
                        // find the parent DynaDSG object
                        p_dsg=p_dsglist->GetDSG(p_collisionobject->GetName());
                        if(p_dsg ==NULL)
                        {
                            printf("\n===================================================\n");
                            printf("\n=\tERROR: Cant Find Parent DSG for %s, This Bounding Volume is MISSING its Mesh!! \n",p_collisionobject->GetName());
                            printf("\n===================================================\n");
                            badart=true;
                        }
                        else
                        {
                            printf("    Found the parent for %s\n",p_collisionobject->GetName());
                            p_dsg->AppendSubChunk(p_otc,FALSE);
                            p_dsg->AppendSubChunk(sub,FALSE);
                        }              
                    }                   
                    //printf("exiting collision\n");
                    break;
                  }
                 
		
			case SRR2::ChunkID::ANIM_DSG_WRAPPER:
					  {
						  bv_data bv_object;
						  char sound[64] = "nosound"; //setting default vaule
						  char chunkname [64];							
						  

						  //tlAnimDSGWrapperChunk* p_animwrapper = dynamic_cast<tlAnimDSGWrapperChunk*>(sub);

						  printf("Found %s AnimWrapperChunk \n",sub->GetName());
						  ::rootname(sub->GetName(),chunkname);
						  
						  //query ArtDB for info on this instanced Animated object
						  sprintf(querybuffer, "SELECT * FROM objects WHERE name = '%s' ",chunkname);
						  query<< querybuffer;
						  Result  myresult = query.store ( );
						  

						  //check if animwrapper found in artDB
						  if (myresult.size ( ) ==0 )
						
						  {
							  //object not found in the art db
							  printf("	ERROR: Object not found in the artDB,Skipping InstAnimDSGChuck Creation!\n");
							  break;
						  }
						  
						 
						  //getting the phys properties						
						  for (sql_iterator=myresult.begin ( ); sql_iterator!= myresult.end ( ); sql_iterator++)
						{            
							row =*sql_iterator;
							
							//set classtype to prop_breakable
							bv_object.classtype =4;
							bv_object.physpropid=row["physpropid"];
							strcpy(sound,row["Sound"]);

						 }

						  printf("    %s is of type InstaAnimDynaPhysDSG creating InstaEntityDSGChunk \n",sub->GetName());

						   //create InstaAnimDSGChunk and OTC 						
						  tlInstAnimDynaPhysDSGChunk* p_instanimdsg = new tlInstAnimDynaPhysDSGChunk ();
						  tlObjectAttributeChunk* p_otc = new tlObjectAttributeChunk ();

						  //fill in data for the newly created chunks
						  p_instanimdsg->SetName(sub->GetName());
						  p_otc->SetClassType(bv_object.classtype);
						  p_otc->SetPhyPropID(bv_object.physpropid);
						  p_otc->SetSound(sound);

						  //append chunks into the InstaAnimDynaPhysDSGChunk
						  p_instanimdsg->AppendSubChunk(sub,FALSE);
						  p_instanimdsg->AppendSubChunk(p_otc,FALSE);						
						
						  //append InstaAnimDynaPhysDSGChunk to the outchunk
						  outchunk->AppendSubChunk(p_instanimdsg,FALSE);
						  p_dsglist->AddDSG(p_instanimdsg);

						  break;
					  }

            case SRR2::ChunkID::ANIM_OBJ_DSG_WRAPPER:
					  {
						  bv_data bv_object;
						  char sound[64] = "nosound"; //setting default vaule
						  char chunkname [64];							
						  

						  //tlAnimDSGWrapperChunk* p_animwrapper = dynamic_cast<tlAnimDSGWrapperChunk*>(sub);

						  printf("Found %s AnimObjWrapperChunk \n",sub->GetName());
						  ::rootname(sub->GetName(),chunkname);
						  
						  //query ArtDB for info on this instanced Animated object
						  sprintf(querybuffer, "SELECT * FROM objects WHERE name = '%s' ",chunkname);
						  query<< querybuffer;
						  Result  myresult = query.store ( );
						  

						  //check if animobjwrapper found in artDB
						  if (myresult.size ( ) ==0 )
						
						  {
							  //object not found in the art db
							  printf("	ERROR: Object not found in the artDB,Skipping InstAnimDSGChuck Creation!\n");
							  break;
						  }
						  
						 
						  //getting the phys properties						
						  for (sql_iterator=myresult.begin ( ); sql_iterator!= myresult.end ( ); sql_iterator++)
						  { 
                              
							    row =*sql_iterator;

                                char classtypeID [max_length];
                                strcpy(classtypeID, row["ClassType"]);
                                bv_object.physpropid=row["physpropid"];
						        strcpy(sound,row["Sound"]);
                                strcpy(bv_object.name,sub->GetName());

                                //set the correct classtypeID
                                if (strcmp(classtypeID,"PROP_MOVEABLE")==0)
                                {
                                    printf("    %s is of type %s Setting Classtype to 3\n",bv_object.name,classtypeID);
                                    bv_object.classtype=3;                            
                                }
                            
                                else if (strcmp(classtypeID,"PROP_BREAKABLE")==0)
                                {
                                    printf("    %s is of type %s Setting Classtype to 4\n",bv_object.name,classtypeID);
                                    bv_object.classtype=4;                            
                                }

                                else if (strcmp(classtypeID,"PROP_STATIC")==0)
                                {
                                    printf("    %s is of type %s Setting Classtype to 2\n",bv_object.name,classtypeID);
                                    bv_object.classtype=2;
                                }
                            
                                else if (strcmp(classtypeID,"DRAWABLE")==0)
                                {
                                    printf("    %s is of type %s ERROR Drawable Objects DO NOT HAVE BV'S!!!\n",bv_object.name,classtypeID);
                                    badart=true;
                                }
                                else if (strcmp(classtypeID,"PROP_DRAWABLE")==0)
                                {
                                    printf("    %s is of type %s ERROR PROP_DRAWABLE Objects DO NOT HAVE BV'S!!!\n",bv_object.name,classtypeID);
                                    badart=true;
                                }
                            
                                else if (strcmp(classtypeID,"ANIMATED_BV")==0)
                                {
                                    printf("    %s is of type %s Setting Classtype to 5\n",bv_object.name,classtypeID);
                                    bv_object.classtype=5;
                                }
                                else if (strcmp(classtypeID,"STATIC")==0)
                                {
                                    printf("    %s is of type %s Setting Classtype to 2\n",bv_object.name,classtypeID);
                                    bv_object.classtype=7;
                                }

                                else if (strcmp(classtypeID,"PROP_ANIM_BREAKABLE")==0)
                                {
                                    printf("    %s is of type %s Setting Classtype to 9 \n",bv_object.name,classtypeID);
                                    bv_object.classtype=9;
                                }
                                
                                else if (strcmp(classtypeID,"PROP_ONETIME_MOVEABLE")==0)
                                {
                                    printf("    %s is of type %s Setting Classtype to 10\n",bv_object.name,classtypeID);
                                    bv_object.classtype=10;
                                }
							    
							    
							   
                          }//end for loop

						  printf("    %s is of type InstaAnimDynaPhysDSG creating InstaAnimDynaPhysDSGChunk \n",sub->GetName());

						   //create InstaAnimDSGChunk and OTC 						
						  tlInstAnimDynaPhysDSGChunk* p_instanimdsg = new tlInstAnimDynaPhysDSGChunk ();
						  tlObjectAttributeChunk* p_otc = new tlObjectAttributeChunk ();

						  //fill in data for the newly created chunks
						  p_instanimdsg->SetName(sub->GetName());
						  p_otc->SetClassType(bv_object.classtype);
						  p_otc->SetPhyPropID(bv_object.physpropid);
						  p_otc->SetSound(sound);

						  //append chunks into the InstaAnimDynaPhysDSGChunk
						  p_instanimdsg->AppendSubChunk(sub,FALSE);
						  p_instanimdsg->AppendSubChunk(p_otc,FALSE);						
						
						  //append InstaAnimDynaPhysDSGChunk to the outchunk
						  outchunk->AppendSubChunk(p_instanimdsg,FALSE);
						  p_dsglist->AddDSG(p_instanimdsg);

						  break;
					  }


            case SRR2::ChunkID::INSTANCES:
                      {
                          tlDataChunk* p_dsg=NULL;
                          tlDataChunk* subchunk= sub->GetSubChunk(0);
                          tlScenegraphChunk* p_scenegraphchunk= dynamic_cast<tlScenegraphChunk *>(subchunk);

                          printf("\n");
                          printf("Found %s instance chunk,looking for Parent DSG.\n",p_scenegraphchunk->GetName());
                          p_dsg=p_dsglist->GetDSG(p_scenegraphchunk->GetName());
                          if(p_dsg ==NULL)
                          {      
                                printf("\n===================================================\n");
                                printf("\n=\tERROR: Cant Find Parent DSG Chunk for %s, SceneGraph is MISSING its Mesh!! \n",p_scenegraphchunk->GetName());
                                printf("\n===================================================\n");
                                badart=true;
                           }
                          else
                          {
                                printf("    Found the parent for %s\n",p_scenegraphchunk->GetName());
                                p_dsg->AppendSubChunk(sub,FALSE);
                          }
                          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
        
        p_dsglist->ReSortDSGChunks();

        if ( mbIgnoreMissingInstanceChunk == true)
        {
            p_dsglist->mbNoInstanceChunks = true;
            //printf("Ignore chunk is set!\n");
        }
        
        if(p_dsglist->VerifyChunks() == 1)
        {
            badart=true;
        }



    } //end of try

   

    catch (BadQuery er)
    {
        cout<<"Error: " <<er.error<< endl;
        return 1;
    }
    
    if (badart)
    {     
      
        printf("\n=======================================================\n");
        printf("\n=\tERROR: %s is missing Chunks for DSG objects Aborting DSG Prop Creation !!! \n",filename);
        printf("\n=======================================================\n");

/*        
        // 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;
        delete p_dsglist;
        return 1;
    }
    else
    {
        
        printf("\n=======================================================\n");
        printf("\n=\tDSGmaker: Completed without ERRORS \n");
        printf("\n=======================================================\n");

        // 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  chunks
        delete inchunk;
        delete outchunk;
        delete p_dsglist;


        return 0;
    }
} //end of main



/********************************************************************/                                                                                                      
/* Helper Function to strip extra crap from the string                                         */
/********************************************************************/


unsigned int  rootname(const char * input,char* output)
{
     char source_name[max_length];
     char object_name1[max_length];
     char object_name2[max_length];
     char* token =NULL;

     //printf("Phase 1 get name \n");
                                    
     //get the name of collision object
     strcpy(source_name,input);
     //cout<<"Source name: "<<source_name<<endl;
                   
     //printf("smashing %s\n",source_name);
     //smash up string to remove the number appended by Maya
     //printf("strtok1\n");
     token=strtok(source_name,"_");
     strcpy(object_name1,token);
     //printf("After stringtok :%s \n",object_name1);

     //printf("strcat1\n");
     //reform string
     strcat(object_name1,"_");
     
     
     //printf("strtok2\n");
     token=strtok(NULL,"_");
     
     if(token != NULL)
     {
        strcpy(object_name2,token);
        //printf("After stringtok :%s \n",object_name2);            
       // printf("strcat2\n");
        strcat(object_name1,object_name2);
     }
       
     //printf("strcpy\n");
     //set default vaules 

     strcpy(output,object_name1);
     //printf("processed name : %s\n",output);
     return 0;
}