[829] | 1 | #include <assert.h>
|
---|
[774] | 2 | #include "GeoLodTreeLibrary.h"
|
---|
[831] | 3 | #include "libs/leaves/Foliage.h"
|
---|
[829] | 4 |
|
---|
| 5 | using namespace Geometry;
|
---|
| 6 |
|
---|
| 7 | Geometry::LodTreeLibrary::LodTreeLibrary(std::string trunkSimpSeqFile,
|
---|
[895] | 8 | std::string leafSimpSeqFile,
|
---|
| 9 | Geometry::Mesh *treeGeoMesh,
|
---|
| 10 | uint32 leafSubMeshID/*
|
---|
[829] | 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
|
---|
[895] | 19 | Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[leafSubMeshID]);
|
---|
[1019] | 20 | foliage = new Foliage(leafsSubMesh,leafSimpSeqFile.c_str());
|
---|
[1058] | 21 | GoToFoliageLod(1.0f);
|
---|
[829] | 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;
|
---|
[831] | 45 | if (foliage) delete foliage;
|
---|
[829] | 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;
|
---|
[1018] | 55 | return trunk->dataRetrievalInterface->GetNumPrims();
|
---|
[829] | 56 | }
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCountByStrip(uint32 istrip) const
|
---|
| 60 | {
|
---|
| 61 | assert(trunk);
|
---|
| 62 | // return trunk->lStripsV[istrip].size();
|
---|
[1018] | 63 | // return trunk->GetIndexCountByStrip(istrip);
|
---|
| 64 | return trunk->dataRetrievalInterface->GetNumValidIndices(istrip);
|
---|
[829] | 65 | }
|
---|
| 66 | /*
|
---|
| 67 | uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCount(void) const
|
---|
| 68 | {
|
---|
| 69 | assert(trunk);
|
---|
| 70 | return trunk->num_indices_current_lod;
|
---|
| 71 | }
|
---|
| 72 | */
|
---|
| 73 |
|
---|
[1058] | 74 | void LodTreeLibrary::GoToTrunkLod(float newlod)
|
---|
[829] | 75 | {
|
---|
[1058] | 76 | trunk->GoToLod(newlod);
|
---|
[829] | 77 | }
|
---|
[1058] | 78 | /*
|
---|
[829] | 79 | uint32 LodTreeLibrary::MinTrunkLod(void) const
|
---|
| 80 | {
|
---|
| 81 | return trunk->MinLod();
|
---|
| 82 | }
|
---|
| 83 | uint32 LodTreeLibrary::MaxTrunkLod(void) const
|
---|
| 84 | {
|
---|
| 85 | return trunk->MaxLod();
|
---|
| 86 | }
|
---|
[1058] | 87 | */
|
---|
[829] | 88 |
|
---|
[1058] | 89 | void LodTreeLibrary::GoToFoliageLod(float newlod)
|
---|
[829] | 90 | {
|
---|
[1058] | 91 | uint32 targetLeaves = (1.0f-newlod)*foliage->minLeaves + newlod*foliage->leafCount;
|
---|
| 92 | foliage->CalculateLOD(targetLeaves);
|
---|
[829] | 93 |
|
---|
[1019] | 94 | foliage->indexdata->Begin();
|
---|
| 95 | foliage->vertexdata->Begin();
|
---|
[1058] | 96 | int i = foliage->begin;
|
---|
| 97 | int auxnumleaves = 0;
|
---|
[829] | 98 | while(i!=-1)
|
---|
| 99 | {
|
---|
[1058] | 100 | auxnumleaves++;
|
---|
[829] | 101 | i=foliage->Acth[i].next;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[1058] | 104 | assert(auxnumleaves*6<=int(foliage->indexdata->GetNumMaxIndices()));
|
---|
| 105 | foliage->indexdata->SetNumValidIndices(auxnumleaves*6);
|
---|
| 106 | i = foliage->begin;
|
---|
| 107 | int index=0;
|
---|
[829] | 108 | while(i!=-1)
|
---|
| 109 | {
|
---|
| 110 | unsigned int v0,v1,v2,v3;
|
---|
[1019] | 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];
|
---|
[829] | 115 |
|
---|
[1058] | 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);
|
---|
[829] | 122 |
|
---|
[1019] | 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);
|
---|
[829] | 127 |
|
---|
[1058] | 128 | index+=6;
|
---|
[829] | 129 | i=foliage->Acth[i].next;
|
---|
| 130 | }
|
---|
[1019] | 131 | foliage->indexdata->End();
|
---|
| 132 | foliage->vertexdata->End();
|
---|
[829] | 133 | }
|
---|
[1058] | 134 | /*
|
---|
[829] | 135 | uint32 LodTreeLibrary::MinFoliageLod(void) const
|
---|
| 136 | {
|
---|
[1019] | 137 | return foliage->nHojas;
|
---|
[829] | 138 | }
|
---|
| 139 | uint32 LodTreeLibrary::MaxFoliageLod(void) const
|
---|
| 140 | {
|
---|
[1019] | 141 | return foliage->minHojas;
|
---|
[1058] | 142 | }*/
|
---|
[831] | 143 |
|
---|
[829] | 144 | /*const VertexData* LodTreeLibrary::Get_Trunk_VertexData(void) const
|
---|
| 145 | {
|
---|
| 146 | return trunk->vertices;
|
---|
[1018] | 147 | }*/
|
---|
[829] | 148 | const MultiIndexData* LodTreeLibrary::CurrentLOD_Trunk_Indices(void) const
|
---|
| 149 | {
|
---|
[1018] | 150 | return trunk->dataRetrievalInterface;
|
---|
| 151 | }
|
---|
[829] | 152 |
|
---|
[895] | 153 |
|
---|
[829] | 154 | const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const
|
---|
| 155 | {
|
---|
[1019] | 156 | return foliage->vertexdata;
|
---|
[829] | 157 | }
|
---|
[895] | 158 |
|
---|
[829] | 159 | const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const
|
---|
| 160 | {
|
---|
[1019] | 161 | return foliage->indexdata;
|
---|
[831] | 162 | }
|
---|
[829] | 163 |
|
---|
| 164 |
|
---|
| 165 | /*void ThrowFileNotFoundError(const char *text)
|
---|
| 166 | {
|
---|
| 167 | throw Geometry::FileNotFound(text);
|
---|
| 168 | }*/
|
---|
[831] | 169 |
|
---|
[829] | 170 | uint32 LodTreeLibrary::CurrentLOD_Foliage_IndexCount(void) const
|
---|
| 171 | {
|
---|
| 172 | // return current_foliage_indexcount;
|
---|
[1019] | 173 | return foliage->indexdata->GetNumValidIndices();
|
---|
[829] | 174 | }
|
---|
[831] | 175 | /*
|
---|
[829] | 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();
|
---|
[831] | 190 | }*/
|
---|
[829] | 191 | uint32 LodTreeLibrary::Get_Foliage_MaxIndexCount(void) const
|
---|
| 192 | {
|
---|
[1019] | 193 | return foliage->indexdata->GetNumMaxIndices();
|
---|
[829] | 194 | }
|
---|
[1057] | 195 |
|
---|
| 196 |
|
---|
| 197 | // changes the lod of the entire object (trunk and leaves)
|
---|
[1058] | 198 | void LodTreeLibrary::GoToLod(Real lod)
|
---|
[1057] | 199 | {
|
---|
[1058] | 200 | assert(lod<=1.0f && lod>=0.0f);
|
---|
| 201 | GoToTrunkLod(lod);
|
---|
| 202 | GoToFoliageLod(lod);
|
---|
[1057] | 203 | }
|
---|