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