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