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

Revision 1526, 5.3 KB checked in by gumbau, 18 years ago (diff)

Updated modules to the new interface and the new simplification algorithm improvements.

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                                                                                 Geometry::IndexData *userindexdata)
11{
12        // Cargar el tronco
13        trunk = new LodStripsLibrary(lodstripsdata,treeGeoMesh,userindexdata);
14
15        // select the first triangle-list submesh as leaves submesh
16        mLeavesSubMesh  =       -1;
17
18        for (size_t     i       =       0;      i < treeGeoMesh->mSubMeshCount; i++)
19        {
20                if (treeGeoMesh->mSubMesh[i].mType==GEO_TRIANGLE_LIST)
21                {
22                        mLeavesSubMesh  =       (uint32)i;
23                        break;
24                }
25        }
26
27        delete_indexdata=false;
28        dataRetrievalInterface=userindexdata;
29
30        // Cargar la copa del árbol
31        Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[mLeavesSubMesh]);
32        foliage = new Foliage(mLeavesSubMesh,leafsSubMesh,simpseq);
33        GoToFoliageLod(1.0f);
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;
57        if (foliage) delete foliage;
58        if (delete_indexdata) delete dataRetrievalInterface;
59}
60/*
61uint32 LodTreeLibrary::CurrentLOD_Trunk_StripCount(void) const
62{
63        assert(trunk);
64        return trunk->TOTAL;
65//      return trunk->dataRetrievalInterface->GetNumPrims();
66}*/
67
68
69/*uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCountByStrip(uint32 istrip) const
70{
71        assert(trunk);
72//      return trunk->lStripsV[istrip].size();
73//      return trunk->GetIndexCountByStrip(istrip);
74        return trunk->dataRetrievalInterface->GetNumValidIndices(istrip);
75}
76
77uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCount(void) const
78{
79        assert(trunk);
80        return trunk->num_indices_current_lod;
81}
82*/
83
84void LodTreeLibrary::GoToTrunkLod(float newlod)
85{
86        trunk->GoToLod(newlod);
87}
88/*
89uint32 LodTreeLibrary::MinTrunkLod(void) const
90{
91        return trunk->MinLod();
92}
93uint32 LodTreeLibrary::MaxTrunkLod(void) const
94{
95        return trunk->MaxLod();
96}
97*/
98
99void LodTreeLibrary::GoToFoliageLod(float newlod)
100{
101        uint32 targetLeaves = (uint32)  (       (1.0f - newlod) * foliage->minLeaves
102                                                                                                        +
103                                                                                newlod * foliage->leafCount     );
104
105        foliage->CalculateLOD(targetLeaves);
106
107        int i = foliage->begin;
108        int auxnumleaves = 0;
109        while(i!=-1)
110        {
111                auxnumleaves++;
112                i=foliage->Acth[i].next;
113        }
114
115//      foliage->indexdata->Begin(GetLeavesSubMesh(),auxnumleaves*6);
116        dataRetrievalInterface->Begin(GetLeavesSubMesh(),auxnumleaves*6);
117//      foliage->vertexdata->Begin();
118
119        i = foliage->begin;
120        int index=0;
121        while(i!=-1)
122        {
123                unsigned int v0,v1,v2,v3;
124                v0 = foliage->Leaves[i].vertsLeaf[0];
125                v1 = foliage->Leaves[i].vertsLeaf[1];
126                v2 = foliage->Leaves[i].vertsLeaf[2];
127                v3 = foliage->Leaves[i].vertsLeaf[3];
128
129                dataRetrievalInterface->SetIndex(index+0,v0);
130                dataRetrievalInterface->SetIndex(index+1,v1);
131                dataRetrievalInterface->SetIndex(index+2,v2);
132                dataRetrievalInterface->SetIndex(index+3,v2);
133                dataRetrievalInterface->SetIndex(index+4,v1);
134                dataRetrievalInterface->SetIndex(index+5,v3);
135
136/*              foliage->vertexdata->SetVertexTexCoord(v0,0,0);
137                foliage->vertexdata->SetVertexTexCoord(v1,0,1);
138                foliage->vertexdata->SetVertexTexCoord(v2,1,0);
139                foliage->vertexdata->SetVertexTexCoord(v3,1,1); */
140
141                index+=6;
142                i=foliage->Acth[i].next;
143        }
144        dataRetrievalInterface->End();
145//      foliage->vertexdata->End();
146        currentFoliageLodFactor = newlod;
147}
148/*
149uint32 LodTreeLibrary::MinFoliageLod(void) const
150{
151        return foliage->nHojas;
152}
153uint32 LodTreeLibrary::MaxFoliageLod(void) const
154{
155        return foliage->minHojas;
156}*/
157
158/*const VertexData* LodTreeLibrary::Get_Trunk_VertexData(void) const
159{
160        return trunk->vertices;
161}*/
162const IndexData* LodTreeLibrary::CurrentLOD_Trunk_Indices(void) const
163{
164        return trunk->GetIndexDataInterface();
165}
166
167/*
168const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const
169{
170        return foliage->vertexdata;
171}
172
173const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const
174{
175        return currentLOD_foliageIndexCount;
176}
177
178
179void ThrowFileNotFoundError(const char *text)
180{
181        throw Geometry::FileNotFound(text);
182}*/
183
184uint32 LodTreeLibrary::CurrentLOD_Foliage_IndexCount(void) const
185{
186//      return current_foliage_indexcount;
187//      return foliage->indexdata->GetNumValidIndices();
188        return foliage->active_leaf_count*6;
189}
190/*
191uint32 LodTreeLibrary::Get_Trunk_VertexCount(void) const
192{
193        return trunk->TOTALVERTS;
194}
195
196uint32 LodTreeLibrary::Get_Trunk_MaxIndexCount(uint32 istrip) const
197{
198//      return trunk->indices_x_tira[istrip]->GetNumMaxIndices();
199        return trunk->indices->GetNumMaxIndices(istrip);
200}
201
202uint32 LodTreeLibrary::Get_Foliage_VertexCount(void) const
203{
204        return arbol->vertexdata->GetNumVertices();
205}*/
206uint32 LodTreeLibrary::Get_Foliage_MaxIndexCount(void) const
207{
208        return foliage->leafTotal*6;
209}
210
211
212// changes the lod of the entire object (trunk and leaves)
213void LodTreeLibrary::GoToLod(Real lod)
214{
215        assert(lod<=1.0f && lod>=0.0f);
216        GoToTrunkLod(lod);
217        GoToFoliageLod(lod);
218}
Note: See TracBrowser for help on using the repository browser.