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

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