[829] | 1 | //#include "defs.h"
|
---|
| 2 | #include <assert.h>
|
---|
[774] | 3 | #include "GeoLodTreeLibrary.h"
|
---|
[831] | 4 | #include "libs/leaves/arbol.h"
|
---|
| 5 | #include "libs/leaves/Foliage.h"
|
---|
[829] | 6 |
|
---|
| 7 | using namespace Geometry;
|
---|
| 8 |
|
---|
| 9 | uint32 uniqueIDgen = 0;
|
---|
| 10 |
|
---|
| 11 | Geometry::LodTreeLibrary::LodTreeLibrary(std::string trunkSimpSeqFile,
|
---|
[895] | 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,
|
---|
[829] | 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
|
---|
[895] | 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());
|
---|
[831] | 32 | foliage = new Foliage(arbol);
|
---|
[829] | 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;
|
---|
[831] | 56 | if (arbol) delete arbol;
|
---|
| 57 | if (foliage) delete foliage;
|
---|
[829] | 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 |
|
---|
[831] | 107 |
|
---|
[829] | 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<=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 | {
|
---|
[895] | 157 | // return arbol->minHojas;
|
---|
| 158 | return arbol->nHojas;
|
---|
[829] | 159 | }
|
---|
| 160 | uint32 LodTreeLibrary::MaxFoliageLod(void) const
|
---|
| 161 | {
|
---|
[895] | 162 | // return arbol->TotHojas;
|
---|
| 163 | //return arbol->nHojas;
|
---|
| 164 | return arbol->minHojas;
|
---|
[829] | 165 | }
|
---|
[831] | 166 |
|
---|
[829] | 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 |
|
---|
[895] | 178 |
|
---|
[829] | 179 | const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const
|
---|
| 180 | {
|
---|
| 181 | return arbol->vertexdata;
|
---|
| 182 | }
|
---|
[895] | 183 |
|
---|
[829] | 184 | const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const
|
---|
| 185 | {
|
---|
| 186 | // return current_foliage_indices;
|
---|
| 187 | return arbol->indexdata;
|
---|
[831] | 188 | }
|
---|
[829] | 189 |
|
---|
| 190 |
|
---|
| 191 | /*void ThrowFileNotFoundError(const char *text)
|
---|
| 192 | {
|
---|
| 193 | throw Geometry::FileNotFound(text);
|
---|
| 194 | }*/
|
---|
[831] | 195 |
|
---|
[829] | 196 | uint32 LodTreeLibrary::CurrentLOD_Foliage_IndexCount(void) const
|
---|
| 197 | {
|
---|
| 198 | // return current_foliage_indexcount;
|
---|
| 199 | return arbol->indexdata->GetNumValidIndices();
|
---|
| 200 | }
|
---|
[831] | 201 | /*
|
---|
[829] | 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();
|
---|
[831] | 216 | }*/
|
---|
[829] | 217 | uint32 LodTreeLibrary::Get_Foliage_MaxIndexCount(void) const
|
---|
| 218 | {
|
---|
| 219 | return arbol->indexdata->GetNumMaxIndices();
|
---|
| 220 | }
|
---|