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