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

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