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 | for (int i=0; i<treeGeoMesh->mSubMeshCount; i++) |
---|
21 | { |
---|
22 | if (treeGeoMesh->mSubMesh[i].mType==GEO_TRIANGLE_LIST) |
---|
23 | { |
---|
24 | mLeavesSubMesh=i; |
---|
25 | break; |
---|
26 | } |
---|
27 | }
|
---|
28 |
|
---|
29 | // Cargar la copa del árbol
|
---|
30 | Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[mLeavesSubMesh]);
|
---|
31 | foliage = new Foliage(leafsSubMesh,simpseq);
|
---|
32 | GoToFoliageLod(1.0f);
|
---|
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 (foliage) delete foliage;
|
---|
57 | /* if (trunk_all_indices) delete trunk_all_indices;
|
---|
58 | if (indices_offsets) delete[] indices_offsets;
|
---|
59 | // if (current_foliage_indices) delete[] current_foliage_indices;*/
|
---|
60 | }
|
---|
61 | /*
|
---|
62 | uint32 LodTreeLibrary::CurrentLOD_Trunk_StripCount(void) const
|
---|
63 | {
|
---|
64 | assert(trunk);
|
---|
65 | return trunk->TOTAL;
|
---|
66 | // return trunk->dataRetrievalInterface->GetNumPrims();
|
---|
67 | }*/
|
---|
68 |
|
---|
69 |
|
---|
70 | /*uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCountByStrip(uint32 istrip) const
|
---|
71 | {
|
---|
72 | assert(trunk);
|
---|
73 | // return trunk->lStripsV[istrip].size();
|
---|
74 | // return trunk->GetIndexCountByStrip(istrip);
|
---|
75 | return trunk->dataRetrievalInterface->GetNumValidIndices(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 | void LodTreeLibrary::GoToTrunkLod(float newlod)
|
---|
86 | {
|
---|
87 | trunk->GoToLod(newlod);
|
---|
88 | }
|
---|
89 | /*
|
---|
90 | uint32 LodTreeLibrary::MinTrunkLod(void) const
|
---|
91 | {
|
---|
92 | return trunk->MinLod();
|
---|
93 | }
|
---|
94 | uint32 LodTreeLibrary::MaxTrunkLod(void) const
|
---|
95 | {
|
---|
96 | return trunk->MaxLod();
|
---|
97 | }
|
---|
98 | */
|
---|
99 |
|
---|
100 | void LodTreeLibrary::GoToFoliageLod(float newlod)
|
---|
101 | {
|
---|
102 | uint32 targetLeaves = (uint32)
|
---|
103 | (
|
---|
104 | (1.0f - newlod)
|
---|
105 | *
|
---|
106 | foliage->minLeaves
|
---|
107 | +
|
---|
108 | newlod
|
---|
109 | *
|
---|
110 | foliage->leafCount
|
---|
111 | );
|
---|
112 |
|
---|
113 | foliage->CalculateLOD(targetLeaves);
|
---|
114 |
|
---|
115 | foliage->indexdata->Begin();
|
---|
116 | foliage->vertexdata->Begin();
|
---|
117 | int i = foliage->begin;
|
---|
118 | int auxnumleaves = 0;
|
---|
119 | while(i!=-1)
|
---|
120 | {
|
---|
121 | auxnumleaves++;
|
---|
122 | i=foliage->Acth[i].next;
|
---|
123 | }
|
---|
124 |
|
---|
125 | assert(auxnumleaves*6<=int(foliage->indexdata->GetNumMaxIndices()));
|
---|
126 | foliage->indexdata->SetNumValidIndices(auxnumleaves*6);
|
---|
127 | i = foliage->begin;
|
---|
128 | int index=0;
|
---|
129 | while(i!=-1)
|
---|
130 | {
|
---|
131 | unsigned int v0,v1,v2,v3;
|
---|
132 | v0 = foliage->Leaves[i].vertsLeaf[0];
|
---|
133 | v1 = foliage->Leaves[i].vertsLeaf[1];
|
---|
134 | v2 = foliage->Leaves[i].vertsLeaf[2];
|
---|
135 | v3 = foliage->Leaves[i].vertsLeaf[3];
|
---|
136 |
|
---|
137 | foliage->indexdata->SetIndex(index+0,v0);
|
---|
138 | foliage->indexdata->SetIndex(index+1,v1);
|
---|
139 | foliage->indexdata->SetIndex(index+2,v2);
|
---|
140 | foliage->indexdata->SetIndex(index+3,v2);
|
---|
141 | foliage->indexdata->SetIndex(index+4,v1);
|
---|
142 | foliage->indexdata->SetIndex(index+5,v3);
|
---|
143 |
|
---|
144 | foliage->vertexdata->SetVertexTexCoord(v0,0,0);
|
---|
145 | foliage->vertexdata->SetVertexTexCoord(v1,0,1);
|
---|
146 | foliage->vertexdata->SetVertexTexCoord(v2,1,0);
|
---|
147 | foliage->vertexdata->SetVertexTexCoord(v3,1,1);
|
---|
148 |
|
---|
149 | index+=6;
|
---|
150 | i=foliage->Acth[i].next;
|
---|
151 | }
|
---|
152 | foliage->indexdata->End();
|
---|
153 | foliage->vertexdata->End();
|
---|
154 | }
|
---|
155 | /*
|
---|
156 | uint32 LodTreeLibrary::MinFoliageLod(void) const
|
---|
157 | {
|
---|
158 | return foliage->nHojas;
|
---|
159 | }
|
---|
160 | uint32 LodTreeLibrary::MaxFoliageLod(void) const
|
---|
161 | {
|
---|
162 | return foliage->minHojas;
|
---|
163 | }*/
|
---|
164 |
|
---|
165 | /*const VertexData* LodTreeLibrary::Get_Trunk_VertexData(void) const
|
---|
166 | {
|
---|
167 | return trunk->vertices;
|
---|
168 | }*/
|
---|
169 | const IndexData* LodTreeLibrary::CurrentLOD_Trunk_Indices(void) const
|
---|
170 | {
|
---|
171 | return trunk->dataRetrievalInterface;
|
---|
172 | }
|
---|
173 |
|
---|
174 |
|
---|
175 | const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const
|
---|
176 | {
|
---|
177 | return foliage->vertexdata;
|
---|
178 | }
|
---|
179 |
|
---|
180 | const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const
|
---|
181 | {
|
---|
182 | return foliage->indexdata;
|
---|
183 | }
|
---|
184 |
|
---|
185 |
|
---|
186 | /*void ThrowFileNotFoundError(const char *text)
|
---|
187 | {
|
---|
188 | throw Geometry::FileNotFound(text);
|
---|
189 | }*/
|
---|
190 |
|
---|
191 | uint32 LodTreeLibrary::CurrentLOD_Foliage_IndexCount(void) const
|
---|
192 | {
|
---|
193 | // return current_foliage_indexcount;
|
---|
194 | return foliage->indexdata->GetNumValidIndices();
|
---|
195 | }
|
---|
196 | /*
|
---|
197 | uint32 LodTreeLibrary::Get_Trunk_VertexCount(void) const
|
---|
198 | {
|
---|
199 | return trunk->TOTALVERTS;
|
---|
200 | }
|
---|
201 |
|
---|
202 | uint32 LodTreeLibrary::Get_Trunk_MaxIndexCount(uint32 istrip) const
|
---|
203 | {
|
---|
204 | // return trunk->indices_x_tira[istrip]->GetNumMaxIndices();
|
---|
205 | return trunk->indices->GetNumMaxIndices(istrip);
|
---|
206 | }
|
---|
207 |
|
---|
208 | uint32 LodTreeLibrary::Get_Foliage_VertexCount(void) const
|
---|
209 | {
|
---|
210 | return arbol->vertexdata->GetNumVertices();
|
---|
211 | }*/
|
---|
212 | uint32 LodTreeLibrary::Get_Foliage_MaxIndexCount(void) const
|
---|
213 | {
|
---|
214 | return foliage->indexdata->GetNumMaxIndices();
|
---|
215 | }
|
---|
216 |
|
---|
217 |
|
---|
218 | // changes the lod of the entire object (trunk and leaves)
|
---|
219 | void LodTreeLibrary::GoToLod(Real lod)
|
---|
220 | {
|
---|
221 | assert(lod<=1.0f && lod>=0.0f);
|
---|
222 | GoToTrunkLod(lod);
|
---|
223 | GoToFoliageLod(lod);
|
---|
224 | }
|
---|