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

Revision 831, 5.2 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/arbol.h"
5#include "libs/leaves/Foliage.h"
6
7using namespace Geometry;
8
9uint32 uniqueIDgen = 0;
10
11Geometry::LodTreeLibrary::LodTreeLibrary(std::string trunkSimpSeqFile,
12                                                           Geometry::Mesh *treeGeoMesh,
13                                                           std::string foliage_verts,
14                                                           std::string foliage_leafs,
15                                                           std::string foliage_simpl/*,
16                                                           uint32 leafSubMeshID,
17                                                           CREATEVERTEXDATAFUNC vdfun,
18                                                           CREATEINDEXDATAFUNC idfun,
19                                                           CREATEMULTIINDEXDATAFUNC midfun*/)
20{
21        uniqueID = uniqueIDgen++;
22
23        // Cargar el tronco
24        trunk = new LodStripsLibrary(trunkSimpSeqFile,treeGeoMesh);
25
26        // Cargar la copa del árbol
27        arbol = new Arbol(foliage_verts.c_str(),foliage_leafs.c_str(),foliage_simpl.c_str(),NULL/*vdfun*/,NULL/*idfun*/);
28        foliage = new Foliage(arbol);
29}
30/*
31LodTreeLibrary::LodTreeLibrary(const LodTreeLibrary &t)
32{
33        uniqueID = uniqueIDgen++;
34        assert(
35//      trunk=new LodStrip(t.trunk);
36        arbol=new Arbol(t.arbol);
37        foliage=new Foliage(arbol);
38}
39
40LodTreeLibrary::LodTreeLibrary(LodTreeLibrary *t)
41{
42        uniqueID = uniqueIDgen++;
43        trunk=new LodStrip(t->trunk);
44        arbol=new Arbol(t->arbol);
45        foliage=new Foliage(arbol);
46}
47*/
48
49LodTreeLibrary::~LodTreeLibrary(void)
50{
51        if (trunk) delete trunk;
52        if (arbol) delete arbol;
53        if (foliage) delete foliage;
54/*      if (trunk_all_indices) delete trunk_all_indices;
55        if (indices_offsets) delete[] indices_offsets;
56//      if (current_foliage_indices) delete[] current_foliage_indices;*/
57}
58
59uint32 LodTreeLibrary::CurrentLOD_Trunk_StripCount(void) const
60{
61        assert(trunk);
62//      return trunk->TOTALTIRAS;
63        return trunk->GetStripCount();
64}
65
66
67uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCountByStrip(uint32 istrip) const
68{
69        assert(trunk);
70//      return trunk->lStripsV[istrip].size();
71        return trunk->GetIndexCountByStrip(istrip);
72}
73/*
74uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCount(void) const
75{
76        assert(trunk);
77        return trunk->num_indices_current_lod;
78}
79*/
80
81uint32 LodTreeLibrary::GoToTrunkLod(uint32 newlod)
82{
83        return trunk->GoToLod(newlod);
84/*      uint32 previouslod = trunk->LodActual;
85        trunk->VerModeloVBO(newlod);
86        return previouslod;*/
87}
88
89uint32 LodTreeLibrary::MinTrunkLod(void) const
90{
91//      return 3; // un polígono: preguntar a francisco
92//      return (trunk->TOTALCAMBIOS*0.95f);
93        return trunk->MinLod();
94}
95uint32 LodTreeLibrary::MaxTrunkLod(void) const
96{
97//      return (trunk->cVerts.size()*0.99);
98//      return (trunk->TOTALCAMBIOS*0.95f);
99//      return 0;
100        return trunk->MaxLod();
101}
102
103
104uint32 LodTreeLibrary::GoToFoliageLod(uint32 newlod)
105{
106        foliage->AjusteHojas(newlod);
107
108        arbol->indexdata->Begin();
109        arbol->vertexdata->Begin();
110        int i = foliage->ppio;
111        int auxnumhojas = 0;
112        while(i!=-1)
113        {
114                auxnumhojas++;
115                i=foliage->Acth[i].next;
116        }
117
118        assert(auxnumhojas*6<=arbol->indexdata->GetNumMaxIndices());
119        arbol->indexdata->SetNumValidIndices(auxnumhojas*6);
120        i = foliage->ppio;
121        int kkkk=0;
122        while(i!=-1)
123        {
124                unsigned int v0,v1,v2,v3;
125                v0 = arbol->Hojas[i].Vert_Hoja[0];
126                v1 = arbol->Hojas[i].Vert_Hoja[1];
127                v2 = arbol->Hojas[i].Vert_Hoja[2];
128                v3 = arbol->Hojas[i].Vert_Hoja[3];
129
130                arbol->indexdata->SetIndex(kkkk+0,v0);
131                arbol->indexdata->SetIndex(kkkk+1,v1);
132                arbol->indexdata->SetIndex(kkkk+2,v2);
133                arbol->indexdata->SetIndex(kkkk+3,v2);
134                arbol->indexdata->SetIndex(kkkk+4,v1);
135                arbol->indexdata->SetIndex(kkkk+5,v3);
136
137                arbol->vertexdata->SetVertexTexCoord(v0,0,0);
138                arbol->vertexdata->SetVertexTexCoord(v1,0,1);
139                arbol->vertexdata->SetVertexTexCoord(v2,1,0);
140                arbol->vertexdata->SetVertexTexCoord(v3,1,1);
141
142                kkkk+=6;
143                i=foliage->Acth[i].next;
144        }
145        arbol->indexdata->End();
146        arbol->vertexdata->End();
147
148        return 0;
149}
150
151uint32 LodTreeLibrary::MinFoliageLod(void) const
152{
153        return arbol->minHojas; // una hoja: preguntar a francisco
154}
155uint32 LodTreeLibrary::MaxFoliageLod(void) const
156{
157//      return arbol->TotHojas;
158        return arbol->nHojas;
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->indices;
170}*/
171
172/*
173const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const
174{
175        return arbol->vertexdata;
176}
177*/
178const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const
179{
180//      return current_foliage_indices;
181        return arbol->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 arbol->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 arbol->indexdata->GetNumMaxIndices();
214}
Note: See TracBrowser for help on using the repository browser.