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