[829] | 1 | //#include "defs.h"
|
---|
| 2 | #include <assert.h>
|
---|
[774] | 3 | #include "GeoLodTreeLibrary.h"
|
---|
[831] | 4 | #include "libs/leaves/Foliage.h"
|
---|
[829] | 5 |
|
---|
| 6 | using namespace Geometry;
|
---|
| 7 |
|
---|
| 8 | Geometry::LodTreeLibrary::LodTreeLibrary(std::string trunkSimpSeqFile,
|
---|
[895] | 9 | std::string leafSimpSeqFile,
|
---|
| 10 | Geometry::Mesh *treeGeoMesh,
|
---|
| 11 | uint32 leafSubMeshID/*
|
---|
| 12 | std::string foliage_verts,
|
---|
| 13 | std::string foliage_leafs,
|
---|
| 14 | std::string foliage_simpl,
|
---|
[829] | 15 | uint32 leafSubMeshID,
|
---|
| 16 | CREATEVERTEXDATAFUNC vdfun,
|
---|
| 17 | CREATEINDEXDATAFUNC idfun,
|
---|
| 18 | CREATEMULTIINDEXDATAFUNC midfun*/)
|
---|
| 19 | {
|
---|
| 20 | // Cargar el tronco
|
---|
| 21 | trunk = new LodStripsLibrary(trunkSimpSeqFile,treeGeoMesh);
|
---|
| 22 |
|
---|
| 23 | // Cargar la copa del árbol
|
---|
[895] | 24 | // arbol = new Arbol(foliage_verts.c_str(),foliage_leafs.c_str(),foliage_simpl.c_str(),NULL/*vdfun*/,NULL/*idfun*/);
|
---|
| 25 | Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[leafSubMeshID]);
|
---|
[1019] | 26 | foliage = new Foliage(leafsSubMesh,leafSimpSeqFile.c_str());
|
---|
[829] | 27 | }
|
---|
| 28 | /*
|
---|
| 29 | LodTreeLibrary::LodTreeLibrary(const LodTreeLibrary &t)
|
---|
| 30 | {
|
---|
| 31 | uniqueID = uniqueIDgen++;
|
---|
| 32 | assert(
|
---|
| 33 | // trunk=new LodStrip(t.trunk);
|
---|
| 34 | arbol=new Arbol(t.arbol);
|
---|
| 35 | foliage=new Foliage(arbol);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | LodTreeLibrary::LodTreeLibrary(LodTreeLibrary *t)
|
---|
| 39 | {
|
---|
| 40 | uniqueID = uniqueIDgen++;
|
---|
| 41 | trunk=new LodStrip(t->trunk);
|
---|
| 42 | arbol=new Arbol(t->arbol);
|
---|
| 43 | foliage=new Foliage(arbol);
|
---|
| 44 | }
|
---|
| 45 | */
|
---|
| 46 |
|
---|
| 47 | LodTreeLibrary::~LodTreeLibrary(void)
|
---|
| 48 | {
|
---|
| 49 | if (trunk) delete trunk;
|
---|
[831] | 50 | if (foliage) delete foliage;
|
---|
[829] | 51 | /* if (trunk_all_indices) delete trunk_all_indices;
|
---|
| 52 | if (indices_offsets) delete[] indices_offsets;
|
---|
| 53 | // if (current_foliage_indices) delete[] current_foliage_indices;*/
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | uint32 LodTreeLibrary::CurrentLOD_Trunk_StripCount(void) const
|
---|
| 57 | {
|
---|
| 58 | assert(trunk);
|
---|
| 59 | // return trunk->TOTALTIRAS;
|
---|
[1018] | 60 | return trunk->dataRetrievalInterface->GetNumPrims();
|
---|
[829] | 61 | }
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCountByStrip(uint32 istrip) const
|
---|
| 65 | {
|
---|
| 66 | assert(trunk);
|
---|
| 67 | // return trunk->lStripsV[istrip].size();
|
---|
[1018] | 68 | // return trunk->GetIndexCountByStrip(istrip);
|
---|
| 69 | return trunk->dataRetrievalInterface->GetNumValidIndices(istrip);
|
---|
[829] | 70 | }
|
---|
| 71 | /*
|
---|
| 72 | uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCount(void) const
|
---|
| 73 | {
|
---|
| 74 | assert(trunk);
|
---|
| 75 | return trunk->num_indices_current_lod;
|
---|
| 76 | }
|
---|
| 77 | */
|
---|
| 78 |
|
---|
| 79 | uint32 LodTreeLibrary::GoToTrunkLod(uint32 newlod)
|
---|
| 80 | {
|
---|
| 81 | return trunk->GoToLod(newlod);
|
---|
| 82 | /* uint32 previouslod = trunk->LodActual;
|
---|
| 83 | trunk->VerModeloVBO(newlod);
|
---|
| 84 | return previouslod;*/
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | uint32 LodTreeLibrary::MinTrunkLod(void) const
|
---|
| 88 | {
|
---|
| 89 | // return 3; // un polígono: preguntar a francisco
|
---|
| 90 | // return (trunk->TOTALCAMBIOS*0.95f);
|
---|
| 91 | return trunk->MinLod();
|
---|
| 92 | }
|
---|
| 93 | uint32 LodTreeLibrary::MaxTrunkLod(void) const
|
---|
| 94 | {
|
---|
| 95 | // return (trunk->cVerts.size()*0.99);
|
---|
| 96 | // return (trunk->TOTALCAMBIOS*0.95f);
|
---|
| 97 | // return 0;
|
---|
| 98 | return trunk->MaxLod();
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[831] | 101 |
|
---|
[829] | 102 | uint32 LodTreeLibrary::GoToFoliageLod(uint32 newlod)
|
---|
| 103 | {
|
---|
| 104 | foliage->AjusteHojas(newlod);
|
---|
| 105 |
|
---|
[1019] | 106 | foliage->indexdata->Begin();
|
---|
| 107 | foliage->vertexdata->Begin();
|
---|
[829] | 108 | int i = foliage->ppio;
|
---|
| 109 | int auxnumhojas = 0;
|
---|
| 110 | while(i!=-1)
|
---|
| 111 | {
|
---|
| 112 | auxnumhojas++;
|
---|
| 113 | i=foliage->Acth[i].next;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[1019] | 116 | assert(auxnumhojas*6<=int(foliage->indexdata->GetNumMaxIndices()));
|
---|
| 117 | foliage->indexdata->SetNumValidIndices(auxnumhojas*6);
|
---|
[829] | 118 | i = foliage->ppio;
|
---|
| 119 | int kkkk=0;
|
---|
| 120 | while(i!=-1)
|
---|
| 121 | {
|
---|
| 122 | unsigned int v0,v1,v2,v3;
|
---|
[1019] | 123 | v0 = foliage->Leaves[i].vertsLeaf[0];
|
---|
| 124 | v1 = foliage->Leaves[i].vertsLeaf[1];
|
---|
| 125 | v2 = foliage->Leaves[i].vertsLeaf[2];
|
---|
| 126 | v3 = foliage->Leaves[i].vertsLeaf[3];
|
---|
[829] | 127 |
|
---|
[1019] | 128 | foliage->indexdata->SetIndex(kkkk+0,v0);
|
---|
| 129 | foliage->indexdata->SetIndex(kkkk+1,v1);
|
---|
| 130 | foliage->indexdata->SetIndex(kkkk+2,v2);
|
---|
| 131 | foliage->indexdata->SetIndex(kkkk+3,v2);
|
---|
| 132 | foliage->indexdata->SetIndex(kkkk+4,v1);
|
---|
| 133 | foliage->indexdata->SetIndex(kkkk+5,v3);
|
---|
[829] | 134 |
|
---|
[1019] | 135 | foliage->vertexdata->SetVertexTexCoord(v0,0,0);
|
---|
| 136 | foliage->vertexdata->SetVertexTexCoord(v1,0,1);
|
---|
| 137 | foliage->vertexdata->SetVertexTexCoord(v2,1,0);
|
---|
| 138 | foliage->vertexdata->SetVertexTexCoord(v3,1,1);
|
---|
[829] | 139 |
|
---|
| 140 | kkkk+=6;
|
---|
| 141 | i=foliage->Acth[i].next;
|
---|
| 142 | }
|
---|
[1019] | 143 | foliage->indexdata->End();
|
---|
| 144 | foliage->vertexdata->End();
|
---|
[829] | 145 |
|
---|
| 146 | return 0;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | uint32 LodTreeLibrary::MinFoliageLod(void) const
|
---|
| 150 | {
|
---|
[895] | 151 | // return arbol->minHojas;
|
---|
[1019] | 152 | return foliage->nHojas;
|
---|
[829] | 153 | }
|
---|
| 154 | uint32 LodTreeLibrary::MaxFoliageLod(void) const
|
---|
| 155 | {
|
---|
[895] | 156 | // return arbol->TotHojas;
|
---|
| 157 | //return arbol->nHojas;
|
---|
[1019] | 158 | return foliage->minHojas;
|
---|
[829] | 159 | }
|
---|
[831] | 160 |
|
---|
[829] | 161 | /*const VertexData* LodTreeLibrary::Get_Trunk_VertexData(void) const
|
---|
| 162 | {
|
---|
| 163 | return trunk->vertices;
|
---|
[1018] | 164 | }*/
|
---|
[829] | 165 | const MultiIndexData* LodTreeLibrary::CurrentLOD_Trunk_Indices(void) const
|
---|
| 166 | {
|
---|
| 167 | // return (uint32*)trunk->vStrips[istrip];
|
---|
| 168 | // return trunk->indices_x_tira[istrip];
|
---|
[1018] | 169 | return trunk->dataRetrievalInterface;
|
---|
| 170 | }
|
---|
[829] | 171 |
|
---|
[895] | 172 |
|
---|
[829] | 173 | const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const
|
---|
| 174 | {
|
---|
[1019] | 175 | return foliage->vertexdata;
|
---|
[829] | 176 | }
|
---|
[895] | 177 |
|
---|
[829] | 178 | const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const
|
---|
| 179 | {
|
---|
| 180 | // return current_foliage_indices;
|
---|
[1019] | 181 | return foliage->indexdata;
|
---|
[831] | 182 | }
|
---|
[829] | 183 |
|
---|
| 184 |
|
---|
| 185 | /*void ThrowFileNotFoundError(const char *text)
|
---|
| 186 | {
|
---|
| 187 | throw Geometry::FileNotFound(text);
|
---|
| 188 | }*/
|
---|
[831] | 189 |
|
---|
[829] | 190 | uint32 LodTreeLibrary::CurrentLOD_Foliage_IndexCount(void) const
|
---|
| 191 | {
|
---|
| 192 | // return current_foliage_indexcount;
|
---|
[1019] | 193 | return foliage->indexdata->GetNumValidIndices();
|
---|
[829] | 194 | }
|
---|
[831] | 195 | /*
|
---|
[829] | 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();
|
---|
[831] | 210 | }*/
|
---|
[829] | 211 | uint32 LodTreeLibrary::Get_Foliage_MaxIndexCount(void) const
|
---|
| 212 | {
|
---|
[1019] | 213 | return foliage->indexdata->GetNumMaxIndices();
|
---|
[829] | 214 | }
|
---|