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

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