source: GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsLibrary.cpp @ 1552

Revision 1552, 19.2 KB checked in by gumbau, 18 years ago (diff)

Fixed degenerates in LodStripsFixed?

RevLine 
[1009]1/*==========================================================================
[774]2 *      (C) 2005 Universitat Jaume I
[1009]3 *==========================================================================
[774]4 *      PROYECT:        GAME TOOLS
[1009]5 *==========================================================================
6 *      CONTENT:
7 *
8 *
9 *      @file   GeoLodStripsLibrary.cpp
10 *===========================================================================*/
[774]11
12#include "GeoLodStripsLibrary.h"
13
14using namespace Geometry;
[1541]15using   namespace       std;
[774]16
17//-----------------------------------------------------------------------------
[1526]18//      Constructor.
[774]19//-----------------------------------------------------------------------------
[1526]20LodStripsLibrary::LodStripsLibrary(const LodStripsLibraryData *lodstripsdata, Mesh *geomesh, IndexData *userindexdata)
21//:dataRetrievalInterface(idfun?idfun:DefaultIndexDataCreator)
[774]22{
[1078]23//      const   char    *name_of_file;
[774]24
25        //      Sets the current lod.
26        mCurrentLod     =       0;
27
28        //      Converts a String to const char *.
[1078]29//      name_of_file    =       name.data();
[774]30
31        //      Sets the global mesh.
32        mGeoMesh = geomesh;
[1018]33
[1526]34        delete_indexdata=false;
35        dataRetrievalInterface=userindexdata;
36       
[1078]37        indices_x_submesh = NULL;
[1083]38        offsets_x_submesh = NULL;
[1090]39        mStripsSubmesh = NULL;
[1526]40        submesh_x_strip = NULL;
41        lodFactor=1.0f;
42        current_triangle_count=0;
[774]43       
44        //      Loads the Level Of Detail file.
[1078]45        LodStripsLibrary::LoadStripMesh(lodstripsdata,mGeoMesh);
[1058]46
47        GoToLod(0.0f); 
48        minFaces = 0;
49        for (unsigned int strip = 0; strip < mTotalStrips; strip++)
50                minFaces += int(mStrips[strip].size() - 2);
51
52        GoToLod(1.0f);
53        maxFaces = 0;
54        for (unsigned int strip = 0; strip < mTotalStrips; strip++)
55                maxFaces += int(mStrips[strip].size() - 2);
[774]56}
57
58//-----------------------------------------------------------------------------
[1526]59//      Destructor
[774]60//-----------------------------------------------------------------------------
61LodStripsLibrary::~LodStripsLibrary()
62{
[1014]63        delete  [] mStrips;
[1526]64        if (delete_indexdata)
[1018]65                delete dataRetrievalInterface;
[1078]66        if (indices_x_submesh)
67                delete[] indices_x_submesh;
[1083]68        if (offsets_x_submesh)
69                delete[] offsets_x_submesh;
[1090]70        if (mStripsSubmesh)
71                delete[] mStripsSubmesh;
[1526]72        if (submesh_x_strip)
73                delete[] submesh_x_strip;
[774]74}
75
76//-----------------------------------------------------------------------------
77//      Public.
78//-----------------------------------------------------------------------------
79
[1009]80//-----------------------------------------------------------------------------
81//      Go to the level of detail.
82//-----------------------------------------------------------------------------
[1058]83void LodStripsLibrary::GoToLod(float lodfactor)
[774]84{
[1541]85        register        int                     j;
86        register        int                     offset;
[1526]87        long                    int                     i;
88        long                    int                     k;
89        long                    int                     b_change_ok     =       1;
[1541]90        unsigned long   int     lod;
[1526]91        long                    int                     t;
92        long                    int                     r;
93        long                    int                     next;
94        long                    int                     el1;
95        long                    int                     el2;
96        long                    int                     total_changes;
97        long                    int                     totalR;
[1541]98        SmallIntVector                                          *strip;
[774]99        SmallIntVector::iterator        start;
100
[1526]101        if (lodfactor<0.0f) lodfactor=0.0f;
102        if (lodfactor>1.0f) lodfactor=1.0f;
103
[1070]104        uint32 newLOD = (uint32)((1.0f - lodfactor) * mLods);
[1526]105
106        lodFactor=lodfactor;
[1058]107   
[774]108        if (newLOD != mCurrentLod)
109        {
110                if (newLOD > mCurrentLod)
111                {
[1014]112                        //      Forwards.
[1530]113                        //      Increments LOD (decreases level of detail)
[1541]114                        for (   lod     =       mCurrentLod;
115                                                (lod < newLOD)
116                                                ||
117                                                ((mCurrentRegLOD->obligatory == 1) && (lod < (mLods - 1)));
118                                                lod++)
[774]119                        {
[1541]120                                next                                    =       mVertex[lod];
[774]121                                total_changes   =       mPChanges[lod];
122
123                                for (i = 0; i < total_changes; i++)
124                                {
[1014]125                                        //      Strip change.
[1541]126                                        t                       =       mCurrentRegLOD->strip;
[774]127                                        strip   =       &(mStrips[t]);
[1541]128                                        start   =       strip->begin();
129
[1526]130                                        int stripsize_ini = strip->size();
[774]131                               
132                                        //      Position.
133                                        totalR  =       mCurrentRegLOD->position;
134
135                                        for (j = totalR - 1; j >= 0; j--)
136                                        {
[1526]137                                                start[*mCurrentData]    =       next;                                           
[774]138                                                ++mCurrentData;
139                                        }
140                                       
141                                        //      L1.
142                                        totalR  =       mCurrentRegLOD->vertexRepetition;
143                                       
144                                        for (j = totalR - 1; j >= 0; j--)
145                                        {
146                                                offset  =       *mCurrentData + 1;
147
148                                                strip->erase(   start + offset,
149                                                                                                        start
150                                                                                                        +
151                                                                                                        offset
152                                                                                                        +
153                                                                                                        (*(mCurrentData + 1)));
154
155                                                ++mCurrentData;
156                                                ++mCurrentData;
157                                        }
158                                       
159                                        //      L2
160                                        totalR  =       mCurrentRegLOD->edgeRepetition;
161                                       
162                                        for (j = totalR - 1; j >= 0; j--)
163                                        {
164                                                offset  =       *mCurrentData + 2;
165                                                strip->erase(   start   +       offset,
166                                                                                                        start
167                                                                                                        +
168                                                                                                        offset
169                                                                                                        +
170                                                                                                        2*(*(mCurrentData + 1)));
171
[1014]172                                                mCurrentData++;
173                                                mCurrentData++;
[774]174                                        }
175
[1530]176//                                      lastLOD = mCurrentRegLOD;
[1014]177                                        mCurrentRegLOD++;
[774]178                                       
179                                        mStripsChanges[t]       =       1;
[1526]180
181                                        int stripsize_end = strip->size();
182                                        indices_x_submesh[submesh_x_strip[t]] -= (stripsize_ini - stripsize_end);
[774]183                               
184                                }
185                               
186                                mCurrentLod     =       lod + 1;
187                        }
188
189                }
[1014]190                //      If LOD is less than actual.
[774]191                else
192                {
[1014]193                        mCurrentRegLOD--;
194                        mCurrentData--;
[1541]195
196
[1014]197                        //      Decrements LOD.
[1541]198                        for (   lod     =       mCurrentLod;
199                                                (lod > newLOD)
200                                                ||
201                                                ((mCurrentRegLOD->obligatory == 1) && (lod > 0))
202                                                ||
203                                                ((mCurrentRegLOD[1].obligatory == 1) && (lod > 0));
204                                                lod--)
[774]205                        {
[1541]206
[774]207                                total_changes   =       mPChanges[lod - 1];
208                               
209                                for (i = 0; i < total_changes; i++)
210                                {
211                                        t                       =       mCurrentRegLOD->strip;
212                                        strip   =       &(mStrips[t]);
213                                        start   =       mStrips[t].begin();
[1526]214                                        int stripsize_ini = strip->size();
[774]215
216                                        //      L2.
217                                        totalR  =       mCurrentRegLOD->edgeRepetition;
218                                       
219                                        for (j = 0; j < totalR; j++)
220                                        {
221                                                el1     =       (*strip)[*(mCurrentData - 1)];
222                                                el2     =       (*strip)[*(mCurrentData - 1) + 1];
223                                                r               =       *(mCurrentData);
224                                               
225                                                for (k = 0; k < r; k++)
226                                                {
227                                                        (*strip).insert(start+*(mCurrentData - 1),el2);
228                                                        (*strip).insert(start+*(mCurrentData - 1),el1);
229                                                }
230                                               
[1014]231                                                mCurrentData--;
232                                                mCurrentData--;
[774]233                                        }
234
235                                        //      Vertex Repetition.
236                                        totalR  =       mCurrentRegLOD->vertexRepetition;
237                                       
238                                        for (j = 0; j < totalR; j++)
239                                        {
240                                                el1     =       (*strip)[*(mCurrentData-1)];
241                                                r               =       *(mCurrentData);
242                                               
243                                                for (k = 0; k < r; k++)
244                                                {
245                                                        (*strip).insert(start+*(mCurrentData-1),el1);
246                                                }
247
[1014]248                                                mCurrentData--;
249                                                mCurrentData--;
[774]250                                        }
251                                       
252                                        //      POS.
253                                        totalR  =       mCurrentRegLOD->position;
254                                       
255                                        for (j = 0; j < totalR; j++)
256                                        {
257                                                (*strip)[*mCurrentData] =       lod - 1;
[1014]258                                                mCurrentData--;
[774]259                                        }
260                                       
[1530]261        //                              lastLOD = mCurrentRegLOD;
[1014]262                                        mCurrentRegLOD--;
[774]263                                        mStripsChanges[t]       =       1;
[1526]264
265                                        int stripsize_end = strip->size();
266                                        indices_x_submesh[submesh_x_strip[t]] += (stripsize_end - stripsize_ini);
[774]267                                }                       
268                               
[1541]269                                //      Update LOD.
[774]270                                mCurrentLod     =       lod - 1;
[1541]271
272                                //      Debug.
273                                cout    <<      "Obligatory: "
274                                                        <<      (int)mCurrentRegLOD->obligatory
275                                                        <<      endl;
[774]276                        }
277                       
[1014]278                        mCurrentData++;
279                        mCurrentRegLOD++;
[774]280                }
281        }
282
[1552]283/*      // debug!
284        FILE *f = fopen("lodstrips_lodinfo.txt","wt");
285        fprintf(f,"mCurrentLOD: %d",mCurrentLod);
286        fprintf(f,"mLods: %d",mLods);
287        for (int i=0; i<mTotalStrips; i++)
288        {
289                fprintf(f,"\nstrip: %d - ",i);
290                for (int j=0; j<mStrips[i].size(); j++)
291                {
292                        int ind = mStrips[i][j];
293                        fprintf(f,"%d ",ind);
294                }
295        }
296        fclose(f);*/
297
[1018]298        UpdateDataRetrievalInterface();
[1058]299//      return  return_value;
[774]300}
301
[1009]302//-----------------------------------------------------------------------------
303//      Returns the number of vertices of the highest LOD.
304//-----------------------------------------------------------------------------
[774]305uint32  LodStripsLibrary::MaxVertices()
306{
[1007]307        return  mMaxVerticesLOD;
[774]308}
309
[1009]310//-----------------------------------------------------------------------------
311//      Returns the number of vertices of the lowest LOD.
312//-----------------------------------------------------------------------------
[774]313uint32  LodStripsLibrary::MinVertices()
314{
315        uint32  number_of_vertices;
316
[1014]317        //      Total vertices of minimum lod.
[1007]318        number_of_vertices      =       mMaxVerticesLOD - (mMinLod + 1);
[774]319
320        return  number_of_vertices;
321}
322
[1009]323//-----------------------------------------------------------------------------
324//      Returns the number of triangles of the highest LOD.
325//-----------------------------------------------------------------------------
[774]326uint32  LodStripsLibrary::MaxFaces()
327{
[1058]328/*      uint32  number_of_faces;
[774]329
330        uint32  current_lod;
331
332        current_lod     =       GoToLod(MaxLod());
333
334        //      Initialize number of faces count.
335        number_of_faces =       0;
336
337        //      For each strip.
[985]338        for (unsigned int strip =       0; strip < mTotalStrips; strip++)
[774]339        {
[985]340                number_of_faces +=      int(mStrips[strip].size() - 2);
[774]341        }
342
343        GoToLod(current_lod);
344
[1058]345        return  number_of_faces;*/
346
347        return maxFaces;
[774]348}
349
[1009]350//-----------------------------------------------------------------------------
351//      Returns the number of triangles of the lowest LOD.
352//-----------------------------------------------------------------------------
[774]353uint32  LodStripsLibrary::MinFaces()
354{
[1058]355/*      uint32  current_lod;
[774]356        uint32  number_of_faces;
357
358        current_lod     =       GoToLod(MinLod());
359
360        //      Initialize number of faces count.
361        number_of_faces =       0;
362
363        //      For each strip.
[985]364        for (unsigned int strip =       0; strip < mTotalStrips; strip++)
[774]365        {
[985]366                number_of_faces +=      int(mStrips[strip].size() - 2);
[774]367        }
368
369        GoToLod(current_lod);
370
[1058]371        return  number_of_faces;*/
372
373        return minFaces;
[774]374}
375
[1009]376//-----------------------------------------------------------------------------
377//      Establishes the new LOD range.
378//      Only the LODs in that range are stored and used.
379//-----------------------------------------------------------------------------
[774]380void            LodStripsLibrary::TrimByLod(uint32 minLod, uint32 maxLod)
381{
[1007]382        //      Refresh number of vercies of the max lod.
383        mMaxVerticesLOD +=      mMaxLod - maxLod;
384       
[774]385        mMinLod =       minLod;
386        mMaxLod =       maxLod;
387}
[1018]388/*
[1009]389//-----------------------------------------------------------------------------
390//      Get strip count.
391//-----------------------------------------------------------------------------
[829]392uint32  LodStripsLibrary::GetStripCount() const
[774]393{
394        return  (uint32)        mTotalStrips;
395}
396
[1009]397//-----------------------------------------------------------------------------
398//      Get Index by strip.
399//-----------------------------------------------------------------------------
[829]400uint32  LodStripsLibrary::GetIndexCountByStrip(uint32 istrip) const
401{
402        return (uint32) mStrips[istrip].size();
403}
[1018]404*/
[774]405//-----------------------------------------------------------------------------
406//      Private.
407//-----------------------------------------------------------------------------
408
[1009]409//-----------------------------------------------------------------------------
410//      Copy a STL vector to a C array.
411//-----------------------------------------------------------------------------
[1526]412void LodStripsLibrary::CopyVectors2Arrays(void)
[774]413{
414        SmallInt                                        max;
415        SmallInt                                        t;
416        SmallInt                                        *data_array;
417        SmallIntVector          tira;
418        LODRegisterType         *changes_array;
419        LODRegisterVector       list_changes;
420
[985]421        mTotalStrips            =       int(mFileStrips.size());
[774]422        mVertex                                 =       new SmallInt[mTotalVertices];
423        mStripsChanges  =       new SmallInt[mTotalChanges];
424        mStrips                                 =       new SmallIntVector[mTotalStrips];
425        data_array                      =       new SmallInt[mData.size()];
426       
427        max                                     =       0;
428        mTotalFaces     =       0;
[1018]429
[1069]430//      unsigned int * strip_sizes = new unsigned int[mFileStrips.size()];
431        unsigned int total_strip_size = 0;
[1070]432       
433        for (unsigned   int     i = 0; i < mFileStrips.size(); i++)
[774]434        {
[1069]435                total_strip_size += t = int(mFileStrips[i].size());
[774]436                if (t>max)
437                        max     =       t;
438                mTotalFaces     +=      t - 2;
439        }
440
441        changes_array   =       new LODRegisterType[mFileChangesLOD.size()];
442       
[1014]443        //      Fill up changes array.
[1070]444        for (unsigned   int     i = 0; i < mFileChangesLOD.size(); ++i)
[774]445        {
446                changes_array[i]        =       mFileChangesLOD[i];
447        }
448
449        mCurrentRegLOD  =       changes_array;
450       
[1014]451        //      Copy strips.
[1325]452//      unsigned int numDegenerated = 2*mTotalStrips - 2;
[1526]453//      dataRetrievalInterface=create_index_data_func(total_strip_size,indexdata_user_data); // temporal!
[1070]454
[1526]455//      dataRetrievalInterface->Init(total_strip_size);
456/*      dataRetrievalInterface->numinds=total_strip_size;
457        dataRetrievalInterface->numvalidinds=total_strip_size;*/
458//      dataRetrievalInterface->Begin();
459
[1070]460        unsigned        int     ii = 0;
461
462        for (unsigned   int     i = 0; i < mFileStrips.size(); i++)
[774]463        {
[1070]464                for (unsigned   int     j = 0; j < mFileStrips[i].size(); j++,ii++)
[774]465                {
466                        mStrips[i].push_back(mFileStrips[i][j]);
[1526]467//                      dataRetrievalInterface->SetIndex(ii,mFileStrips[i][j]);
[774]468                }
469               
[1014]470                //      Reset flags of strips changed.
[774]471                mStripsChanges[i]       =       0;
472        }
[1552]473
[1526]474//      dataRetrievalInterface->End();
[774]475
[1070]476        for (unsigned   int     i = 0; i < mData.size(); i++)
[774]477        {
478                data_array[i]   =       mData[i];
479        }
480       
481        mCurrentData    =       data_array;
482
[1014]483        //      Fill up mVertex.
[1070]484        for(unsigned    int     i = 0; i < mFileVertices.size(); i++)
[774]485        {
486                mVertex[i]      =       mFileVertices[i];
487        }
[1018]488
[1069]489//      delete[] strip_sizes;
[774]490}
491
492//-----------------------------------------------------------------------------
[1009]493//      LoadStripMesh
[774]494//-----------------------------------------------------------------------------
[1083]495void LodStripsLibrary::LoadStripMesh(const LodStripsLibraryData *lodstripsdata, Mesh *geomesh)
[774]496{
[1136]497        //FILE                                                                                                                  *fp;
[774]498        SmallIntVector                                                                          strip_aux;
[1136]499        //LODRegisterType                                                                               lod_register;
[774]500        std::vector                     <LODRegisterType>       list_pos;
501        std::vector                     <unsigned int>          p_changes;
[1136]502        //int                                                                                                                           value;
[1014]503        int                                                                                                                             v                       =       0;
504        int                                                                                                                             t                       =       -1;
505        int                                                                                                                             s                       =       0;
506        int                                                                                                                             next    =       0;
507        int                                                                                                                             c                       =       -1;
[1136]508        //char                                                                                                                  buff[80];
[774]509        Index                                                                                                                   *index;
510        Index                                                                                                                   *indexBegin;
511        Index                                                                                                                   *indexEnd;
512        SubMesh                                                                                                         *geoSubMesh;
513
514        //      For each one of the submeshes.
[1078]515        indices_x_submesh = new int[geomesh->mSubMeshCount];
[1083]516        offsets_x_submesh = new int[geomesh->mSubMeshCount];
[1526]517
518        int totaltiras = 0;
519        for (unsigned int submesh = 0; submesh < geomesh->mSubMeshCount; submesh++)
520                for (unsigned int strip = 0; strip < geomesh->mSubMesh[submesh].mStripCount; strip++)
521                        totaltiras++;
522
523        submesh_x_strip = new int[totaltiras];
524
525        int istrip = 0;
[985]526        for (unsigned int submesh       =       0; submesh < geomesh->mSubMeshCount; submesh++)
[774]527        {
528                geoSubMesh      =       &geomesh->mSubMesh[submesh];
[1526]529                indices_x_submesh[submesh] = 0;
[774]530
531                //      For each one of the strips.
[1526]532                for (unsigned int strip = 0; strip < geoSubMesh->mStripCount; strip++, istrip++)
[774]533                {
534                        // Insert an empty strip.
[1526]535                        submesh_x_strip[istrip] = submesh;
[774]536                        t++;
537                        strip_aux.clear();
538                        mFileStrips.push_back(strip_aux);
539
540                        //      First index of the strip.
541                        indexBegin      =       geoSubMesh->mStrip[strip];
542
[1552]543                        //      If the strips is not the first. (DEG!)
544                        if (strip != 0)
[774]545                                indexBegin++;
546
547                        //      If is the final strip
548                        if (strip       == (geoSubMesh->mStripCount - 1))
549                        {
550                                //      The end of the index array.
551                                indexEnd        = &geoSubMesh->mIndex[geoSubMesh->mIndexCount];
552                        }
553                        else
554                        {
555                                //      The beginning of the next strip.
556                                indexEnd        = geoSubMesh->mStrip[strip + 1];
557
[1552]558                                //      Remove degenerated (DEG!)
559                                indexEnd--;
[774]560                        }
561                       
562                        int i;
563                        i       = 0;
[1526]564                       
[1083]565                        if (submesh==0)
566                                offsets_x_submesh[submesh] = 0;
567                        else
568                                offsets_x_submesh[submesh] = indices_x_submesh[submesh-1];
569
[774]570                        //      For each index of the strip.
571                        for (index = indexBegin; index < indexEnd; index++)
572                        {
573                                mFileStrips[t].push_back(indexBegin[i]);
[1078]574                                indices_x_submesh[submesh]++;
[774]575                                i++;
[1083]576                        }                       
[774]577                }
578        }
579
[1070]580        //      TODO:   LOD file loaded in load file mesh process.
[774]581        //      Open the LOD file.
[1078]582/*      if ((fp = fopen (name, "r")) == NULL)
[774]583        {
584                //      Error in open.
585        }
586        else
587        {
588                mTotalChanges   =       0;
589               
590                while (!feof (fp))
591                {
592                        fgets (buff, 80, fp);
593                       
594                        if (*buff == 'v')
595                        {
596                                sscanf (buff+2,"%d",&value);
597                               
598                                mFileVertices.push_back(value);
599                                v++;
600                        }
601                        else if ( (*buff == 'c') || (*buff == 'd'))
602                        {
603                                if (*buff == 'c')
604                                {
605                                        c++;
606                                }
607                                else
608                                {
609                                        unsigned        int     a;
610                                        unsigned        int     b;
611                                        unsigned        int     c;
612                                        unsigned        int     d;
613                                       
614                                        sscanf (buff+2,"%u %u %u %u\n",&a,&b,&c,&d);
615                                        lod_register.strip                                              =       a;
616                                        lod_register.position                                   =       b;
617                                        lod_register.vertexRepetition   =       c;
618                                        lod_register.edgeRepetition             =       d;
619                                       
620                                        mFileChangesLOD.push_back(lod_register);
621                                }
622                        }
623                        else if (*buff=='b')
624                        {
625                                sscanf(buff+2,"%u",&value);
626                                mData.push_back(value);
627                        }
628                        else if (*buff=='p')
629                        {
630                                sscanf (buff+2,"%u",&value);
631                                p_changes.push_back(value);
[1014]632                        }
633                }
[774]634               
[1078]635                fclose(fp);*/
636
[1083]637        mFileVertices = lodstripsdata->mFileVertices;
638        mFileChangesLOD = lodstripsdata->mFileChangesLOD;
639        mData = lodstripsdata->mData;
640        p_changes = lodstripsdata->p_changes;
[774]641
[1090]642        mStripsSubmesh = new int [geomesh->mSubMeshCount];
[1136]643        for (size_t     submesh = 0; submesh < geomesh->mSubMeshCount; submesh++)
[1090]644        {       
645                mStripsSubmesh[submesh]=0;
646        }
[774]647
[1090]648                       
649        //      Max / Min values for LOD.
650        mLods                                                                                   =       int(p_changes.size());
651        mMaxLod                                                                         =       0;
652        mMinLod                                                                         =       mLods;
[774]653
[1090]654        mPChanges                       =       new SmallInt[mLods];
655       
656        for (unsigned int i = 0; i < mLods; i++)
657                mPChanges[i] = p_changes[i];
658
659        mTotalVertices          =       int(mFileVertices.size());
660        mMaxVerticesLOD         =       mTotalVertices;
661        mTotalStrips                    =       int(mFileStrips.size());
662        mTotalChanges                   =       int(mFileChangesLOD.size());
663
664        //Copy the data to the structure we will use
665        CopyVectors2Arrays();
[774]666}
667
[1018]668void LodStripsLibrary::UpdateDataRetrievalInterface(void)
669{
[1325]670        int     target_submesh  = 0;
671        size_t  strip_count     = 0;
[1552]672        unsigned int ii_submesh = 0;   
673        current_triangle_count = 0;
[1078]674
[1552]675        // indices_x_submesh is calculated without degenerates,
676        // we must add the degenerate indices added here
677        uint32 numdeg = mGeoMesh->mSubMesh[target_submesh].mStripCount*2 - 2;
[1325]678
[1552]679        dataRetrievalInterface->Begin(target_submesh, indices_x_submesh[target_submesh] + numdeg);
680        current_triangle_count += indices_x_submesh[target_submesh] + numdeg;
[1526]681
[1552]682        for (unsigned int i = 0; i < mTotalStrips; i++, strip_count++)
[1018]683        {
[1078]684                if (strip_count >= mGeoMesh->mSubMesh[target_submesh].mStripCount)
685                {
[1083]686                        if (target_submesh==0)
687                                offsets_x_submesh[target_submesh] = 0;
688                        else
689                                offsets_x_submesh[target_submesh] = indices_x_submesh[target_submesh-1] + offsets_x_submesh[target_submesh-1];
690
[1136]691                        mStripsSubmesh[target_submesh]  =       (int)strip_count;
[1325]692                        strip_count     =       0;
[1136]693
[1078]694                        target_submesh++;
[1526]695                        ii_submesh = 0;
696                        dataRetrievalInterface->End();
[1552]697                       
698                        numdeg = mGeoMesh->mSubMesh[target_submesh].mStripCount*2 - 2;
699                        dataRetrievalInterface->Begin(target_submesh, indices_x_submesh[target_submesh] + numdeg);
700                        current_triangle_count += indices_x_submesh[target_submesh] + numdeg;
[1078]701                }
[1087]702               
703                int lastindex = -1;
[1552]704                for (SmallIntVector::iterator it=mStrips[i].begin(); it!=mStrips[i].end(); it++, ii_submesh++)
[1078]705                {
[1552]706                        // repeat the first index of the strip: degenerate (DEG!)
707                        // except for the first strip in a mesh
708                        if (lastindex==-1 && strip_count>0)
[1087]709                        {
710                                lastindex=*it;
[1552]711                                dataRetrievalInterface->SetIndex(ii_submesh,*it);                               
712                                ii_submesh++;
713                        }
[1087]714                        lastindex=*it;
[1526]715                        dataRetrievalInterface->SetIndex(ii_submesh,*it);
[1078]716                }
[1087]717
[1552]718                // repeat last vertex of the strip: degenerate (DEG!)
719                // except for the last strip in a mesh
720                if (strip_count<mGeoMesh->mSubMesh[target_submesh].mStripCount-1)
721                {
722                        dataRetrievalInterface->SetIndex(ii_submesh,lastindex);
723                        ii_submesh++;
724                }
[1018]725        }
[1078]726
727        if (strip_count >= mGeoMesh->mSubMesh[target_submesh].mStripCount)
728        {
[1083]729                if (target_submesh==0)
730                        offsets_x_submesh[target_submesh] = 0;
731                else
732                        offsets_x_submesh[target_submesh] = indices_x_submesh[target_submesh-1] + offsets_x_submesh[target_submesh-1];
733
[1136]734                mStripsSubmesh[target_submesh] = (int)strip_count;
[1078]735                strip_count = 0;
736                target_submesh++;
737        }
738
[1018]739        dataRetrievalInterface->End();
[1070]740}
Note: See TracBrowser for help on using the repository browser.