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