source: GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodTreeLibrary.cpp @ 1136

Revision 1136, 5.4 KB checked in by gumbau, 18 years ago (diff)
RevLine 
[829]1#include <assert.h>
[774]2#include "GeoLodTreeLibrary.h"
[831]3#include "libs/leaves/Foliage.h"
[829]4
5using namespace Geometry;
6
[1083]7Geometry::LodTreeLibrary::LodTreeLibrary(const LodStripsLibraryData *lodstripsdata,
8                                                                                 const TreeSimplificationSequence *simpseq,
[1090]9                                                                                 Geometry::Mesh *treeGeoMesh/*,
10                                                                                 uint32 leafSubMeshID,
[829]11                                                           CREATEVERTEXDATAFUNC vdfun,
12                                                           CREATEINDEXDATAFUNC idfun,
13                                                           CREATEMULTIINDEXDATAFUNC midfun*/)
14{
15        // Cargar el tronco
[1078]16        trunk = new LodStripsLibrary(lodstripsdata,treeGeoMesh);
[829]17
[1090]18        // select the first triangle-list submesh as leaves submesh
[1136]19        mLeavesSubMesh  =       -1;
20
21        for (size_t     i       =       0;      i < treeGeoMesh->mSubMeshCount; i++)
[1090]22        {
23                if (treeGeoMesh->mSubMesh[i].mType==GEO_TRIANGLE_LIST)
24                {
[1136]25                        mLeavesSubMesh  =       (uint32)i;
[1090]26                        break;
27                }
[1136]28        }
[1090]29
[829]30        // Cargar la copa del árbol
[1090]31        Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[mLeavesSubMesh]);
[1078]32        foliage = new Foliage(leafsSubMesh,simpseq);
[1058]33        GoToFoliageLod(1.0f);
[829]34}
35/*
36LodTreeLibrary::LodTreeLibrary(const LodTreeLibrary &t)
37{
38        uniqueID = uniqueIDgen++;
39        assert(
40//      trunk=new LodStrip(t.trunk);
41        arbol=new Arbol(t.arbol);
42        foliage=new Foliage(arbol);
43}
44
45LodTreeLibrary::LodTreeLibrary(LodTreeLibrary *t)
46{
47        uniqueID = uniqueIDgen++;
48        trunk=new LodStrip(t->trunk);
49        arbol=new Arbol(t->arbol);
50        foliage=new Foliage(arbol);
51}
52*/
53
54LodTreeLibrary::~LodTreeLibrary(void)
55{
56        if (trunk) delete trunk;
[831]57        if (foliage) delete foliage;
[829]58/*      if (trunk_all_indices) delete trunk_all_indices;
59        if (indices_offsets) delete[] indices_offsets;
60//      if (current_foliage_indices) delete[] current_foliage_indices;*/
61}
[1069]62/*
[829]63uint32 LodTreeLibrary::CurrentLOD_Trunk_StripCount(void) const
64{
65        assert(trunk);
[1069]66        return trunk->TOTAL;
67//      return trunk->dataRetrievalInterface->GetNumPrims();
68}*/
[829]69
70
[1069]71/*uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCountByStrip(uint32 istrip) const
[829]72{
73        assert(trunk);
74//      return trunk->lStripsV[istrip].size();
[1018]75//      return trunk->GetIndexCountByStrip(istrip);
76        return trunk->dataRetrievalInterface->GetNumValidIndices(istrip);
[829]77}
[1069]78
[829]79uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCount(void) const
80{
81        assert(trunk);
82        return trunk->num_indices_current_lod;
83}
84*/
85
[1058]86void LodTreeLibrary::GoToTrunkLod(float newlod)
[829]87{
[1058]88        trunk->GoToLod(newlod);
[829]89}
[1058]90/*
[829]91uint32 LodTreeLibrary::MinTrunkLod(void) const
92{
93        return trunk->MinLod();
94}
95uint32 LodTreeLibrary::MaxTrunkLod(void) const
96{
97        return trunk->MaxLod();
98}
[1058]99*/
[829]100
[1058]101void LodTreeLibrary::GoToFoliageLod(float newlod)
[829]102{
[1070]103        uint32 targetLeaves = (uint32)
104                                                                                                (
105                                                                                                        (1.0f - newlod)
106                                                                                                        *
107                                                                                                        foliage->minLeaves
108                                                                                                        +
109                                                                                                        newlod
110                                                                                                        *
111                                                                                                        foliage->leafCount
112                                                                                                );
113
[1058]114        foliage->CalculateLOD(targetLeaves);
[829]115
[1019]116        foliage->indexdata->Begin();
117        foliage->vertexdata->Begin();
[1058]118        int i = foliage->begin;
119        int auxnumleaves = 0;
[829]120        while(i!=-1)
121        {
[1058]122                auxnumleaves++;
[829]123                i=foliage->Acth[i].next;
124        }
125
[1058]126        assert(auxnumleaves*6<=int(foliage->indexdata->GetNumMaxIndices()));
127        foliage->indexdata->SetNumValidIndices(auxnumleaves*6);
128        i = foliage->begin;
129        int index=0;
[829]130        while(i!=-1)
131        {
132                unsigned int v0,v1,v2,v3;
[1019]133                v0 = foliage->Leaves[i].vertsLeaf[0];
134                v1 = foliage->Leaves[i].vertsLeaf[1];
135                v2 = foliage->Leaves[i].vertsLeaf[2];
136                v3 = foliage->Leaves[i].vertsLeaf[3];
[829]137
[1058]138                foliage->indexdata->SetIndex(index+0,v0);
139                foliage->indexdata->SetIndex(index+1,v1);
140                foliage->indexdata->SetIndex(index+2,v2);
141                foliage->indexdata->SetIndex(index+3,v2);
142                foliage->indexdata->SetIndex(index+4,v1);
143                foliage->indexdata->SetIndex(index+5,v3);
[829]144
[1019]145                foliage->vertexdata->SetVertexTexCoord(v0,0,0);
146                foliage->vertexdata->SetVertexTexCoord(v1,0,1);
147                foliage->vertexdata->SetVertexTexCoord(v2,1,0);
148                foliage->vertexdata->SetVertexTexCoord(v3,1,1);
[829]149
[1058]150                index+=6;
[829]151                i=foliage->Acth[i].next;
152        }
[1019]153        foliage->indexdata->End();
154        foliage->vertexdata->End();
[829]155}
[1058]156/*
[829]157uint32 LodTreeLibrary::MinFoliageLod(void) const
158{
[1019]159        return foliage->nHojas;
[829]160}
161uint32 LodTreeLibrary::MaxFoliageLod(void) const
162{
[1019]163        return foliage->minHojas;
[1058]164}*/
[831]165
[829]166/*const VertexData* LodTreeLibrary::Get_Trunk_VertexData(void) const
167{
168        return trunk->vertices;
[1018]169}*/
[1069]170const IndexData* LodTreeLibrary::CurrentLOD_Trunk_Indices(void) const
[829]171{
[1018]172        return trunk->dataRetrievalInterface;
173}
[829]174
[895]175
[829]176const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const
177{
[1019]178        return foliage->vertexdata;
[829]179}
[895]180
[829]181const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const
182{
[1019]183        return foliage->indexdata;
[831]184}
[829]185
186
187/*void ThrowFileNotFoundError(const char *text)
188{
189        throw Geometry::FileNotFound(text);
190}*/
[831]191
[829]192uint32 LodTreeLibrary::CurrentLOD_Foliage_IndexCount(void) const
193{
194//      return current_foliage_indexcount;
[1019]195        return foliage->indexdata->GetNumValidIndices();
[829]196}
[831]197/*
[829]198uint32 LodTreeLibrary::Get_Trunk_VertexCount(void) const
199{
200        return trunk->TOTALVERTS;
201}
202
203uint32 LodTreeLibrary::Get_Trunk_MaxIndexCount(uint32 istrip) const
204{
205//      return trunk->indices_x_tira[istrip]->GetNumMaxIndices();
206        return trunk->indices->GetNumMaxIndices(istrip);
207}
208
209uint32 LodTreeLibrary::Get_Foliage_VertexCount(void) const
210{
211        return arbol->vertexdata->GetNumVertices();
[831]212}*/
[829]213uint32 LodTreeLibrary::Get_Foliage_MaxIndexCount(void) const
214{
[1019]215        return foliage->indexdata->GetNumMaxIndices();
[829]216}
[1057]217
218
219// changes the lod of the entire object (trunk and leaves)
[1058]220void LodTreeLibrary::GoToLod(Real lod)
[1057]221{
[1058]222        assert(lod<=1.0f && lod>=0.0f);
223        GoToTrunkLod(lod);
224        GoToFoliageLod(lod);
[1057]225}
Note: See TracBrowser for help on using the repository browser.