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

Revision 1083, 5.2 KB checked in by gumbau, 18 years ago (diff)
RevLine 
[829]1#include <assert.h>
[774]2#include "GeoLodTreeLibrary.h"
[831]3#include "libs/leaves/Foliage.h"
[829]4
5using namespace Geometry;
6
[1083]7Geometry::LodTreeLibrary::LodTreeLibrary(const LodStripsLibraryData *lodstripsdata,
8                                                                                 const TreeSimplificationSequence *simpseq,
[895]9                                                                                 Geometry::Mesh *treeGeoMesh,
10                                                                                 uint32 leafSubMeshID/*
[829]11                                                           CREATEVERTEXDATAFUNC vdfun,
12                                                           CREATEINDEXDATAFUNC idfun,
13                                                           CREATEMULTIINDEXDATAFUNC midfun*/)
14{
15        // Cargar el tronco
[1078]16        trunk = new LodStripsLibrary(lodstripsdata,treeGeoMesh);
[829]17
18        // Cargar la copa del árbol
[895]19        Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[leafSubMeshID]);
[1078]20        foliage = new Foliage(leafsSubMesh,simpseq);
[1058]21        GoToFoliageLod(1.0f);
[829]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;
[831]45        if (foliage) delete foliage;
[829]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}
[1069]50/*
[829]51uint32 LodTreeLibrary::CurrentLOD_Trunk_StripCount(void) const
52{
53        assert(trunk);
[1069]54        return trunk->TOTAL;
55//      return trunk->dataRetrievalInterface->GetNumPrims();
56}*/
[829]57
58
[1069]59/*uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCountByStrip(uint32 istrip) const
[829]60{
61        assert(trunk);
62//      return trunk->lStripsV[istrip].size();
[1018]63//      return trunk->GetIndexCountByStrip(istrip);
64        return trunk->dataRetrievalInterface->GetNumValidIndices(istrip);
[829]65}
[1069]66
[829]67uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCount(void) const
68{
69        assert(trunk);
70        return trunk->num_indices_current_lod;
71}
72*/
73
[1058]74void LodTreeLibrary::GoToTrunkLod(float newlod)
[829]75{
[1058]76        trunk->GoToLod(newlod);
[829]77}
[1058]78/*
[829]79uint32 LodTreeLibrary::MinTrunkLod(void) const
80{
81        return trunk->MinLod();
82}
83uint32 LodTreeLibrary::MaxTrunkLod(void) const
84{
85        return trunk->MaxLod();
86}
[1058]87*/
[829]88
[1058]89void LodTreeLibrary::GoToFoliageLod(float newlod)
[829]90{
[1070]91        uint32 targetLeaves = (uint32)
92                                                                                                (
93                                                                                                        (1.0f - newlod)
94                                                                                                        *
95                                                                                                        foliage->minLeaves
96                                                                                                        +
97                                                                                                        newlod
98                                                                                                        *
99                                                                                                        foliage->leafCount
100                                                                                                );
101
[1058]102        foliage->CalculateLOD(targetLeaves);
[829]103
[1019]104        foliage->indexdata->Begin();
105        foliage->vertexdata->Begin();
[1058]106        int i = foliage->begin;
107        int auxnumleaves = 0;
[829]108        while(i!=-1)
109        {
[1058]110                auxnumleaves++;
[829]111                i=foliage->Acth[i].next;
112        }
113
[1058]114        assert(auxnumleaves*6<=int(foliage->indexdata->GetNumMaxIndices()));
115        foliage->indexdata->SetNumValidIndices(auxnumleaves*6);
116        i = foliage->begin;
117        int index=0;
[829]118        while(i!=-1)
119        {
120                unsigned int v0,v1,v2,v3;
[1019]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];
[829]125
[1058]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);
[829]132
[1019]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);
[829]137
[1058]138                index+=6;
[829]139                i=foliage->Acth[i].next;
140        }
[1019]141        foliage->indexdata->End();
142        foliage->vertexdata->End();
[829]143}
[1058]144/*
[829]145uint32 LodTreeLibrary::MinFoliageLod(void) const
146{
[1019]147        return foliage->nHojas;
[829]148}
149uint32 LodTreeLibrary::MaxFoliageLod(void) const
150{
[1019]151        return foliage->minHojas;
[1058]152}*/
[831]153
[829]154/*const VertexData* LodTreeLibrary::Get_Trunk_VertexData(void) const
155{
156        return trunk->vertices;
[1018]157}*/
[1069]158const IndexData* LodTreeLibrary::CurrentLOD_Trunk_Indices(void) const
[829]159{
[1018]160        return trunk->dataRetrievalInterface;
161}
[829]162
[895]163
[829]164const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const
165{
[1019]166        return foliage->vertexdata;
[829]167}
[895]168
[829]169const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const
170{
[1019]171        return foliage->indexdata;
[831]172}
[829]173
174
175/*void ThrowFileNotFoundError(const char *text)
176{
177        throw Geometry::FileNotFound(text);
178}*/
[831]179
[829]180uint32 LodTreeLibrary::CurrentLOD_Foliage_IndexCount(void) const
181{
182//      return current_foliage_indexcount;
[1019]183        return foliage->indexdata->GetNumValidIndices();
[829]184}
[831]185/*
[829]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();
[831]200}*/
[829]201uint32 LodTreeLibrary::Get_Foliage_MaxIndexCount(void) const
202{
[1019]203        return foliage->indexdata->GetNumMaxIndices();
[829]204}
[1057]205
206
207// changes the lod of the entire object (trunk and leaves)
[1058]208void LodTreeLibrary::GoToLod(Real lod)
[1057]209{
[1058]210        assert(lod<=1.0f && lod>=0.0f);
211        GoToTrunkLod(lod);
212        GoToFoliageLod(lod);
[1057]213}
Note: See TracBrowser for help on using the repository browser.