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