#include #include "GeoLodTreeLibrary.h" #include "libs/leaves/Foliage.h" using namespace Geometry; Geometry::LodTreeLibrary::LodTreeLibrary(const LodStripsLibraryData *lodstripsdata, const TreeSimplificationSequence *simpseq, Geometry::Mesh *treeGeoMesh/*, uint32 leafSubMeshID, CREATEVERTEXDATAFUNC vdfun, CREATEINDEXDATAFUNC idfun, CREATEMULTIINDEXDATAFUNC midfun*/) { // Cargar el tronco trunk = new LodStripsLibrary(lodstripsdata,treeGeoMesh); // select the first triangle-list submesh as leaves submesh mLeavesSubMesh = -1; for (size_t i = 0; i < treeGeoMesh->mSubMeshCount; i++) { if (treeGeoMesh->mSubMesh[i].mType==GEO_TRIANGLE_LIST) { mLeavesSubMesh = (uint32)i; break; } } // Cargar la copa del árbol Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[mLeavesSubMesh]); foliage = new Foliage(leafsSubMesh,simpseq); GoToFoliageLod(1.0f); } /* LodTreeLibrary::LodTreeLibrary(const LodTreeLibrary &t) { uniqueID = uniqueIDgen++; assert( // trunk=new LodStrip(t.trunk); arbol=new Arbol(t.arbol); foliage=new Foliage(arbol); } LodTreeLibrary::LodTreeLibrary(LodTreeLibrary *t) { uniqueID = uniqueIDgen++; trunk=new LodStrip(t->trunk); arbol=new Arbol(t->arbol); foliage=new Foliage(arbol); } */ LodTreeLibrary::~LodTreeLibrary(void) { if (trunk) delete trunk; if (foliage) delete foliage; /* if (trunk_all_indices) delete trunk_all_indices; if (indices_offsets) delete[] indices_offsets; // if (current_foliage_indices) delete[] current_foliage_indices;*/ } /* uint32 LodTreeLibrary::CurrentLOD_Trunk_StripCount(void) const { assert(trunk); return trunk->TOTAL; // return trunk->dataRetrievalInterface->GetNumPrims(); }*/ /*uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCountByStrip(uint32 istrip) const { assert(trunk); // return trunk->lStripsV[istrip].size(); // return trunk->GetIndexCountByStrip(istrip); return trunk->dataRetrievalInterface->GetNumValidIndices(istrip); } uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCount(void) const { assert(trunk); return trunk->num_indices_current_lod; } */ void LodTreeLibrary::GoToTrunkLod(float newlod) { trunk->GoToLod(newlod); } /* uint32 LodTreeLibrary::MinTrunkLod(void) const { return trunk->MinLod(); } uint32 LodTreeLibrary::MaxTrunkLod(void) const { return trunk->MaxLod(); } */ void LodTreeLibrary::GoToFoliageLod(float newlod) { uint32 targetLeaves = (uint32) ( (1.0f - newlod) * foliage->minLeaves + newlod * foliage->leafCount ); foliage->CalculateLOD(targetLeaves); foliage->indexdata->Begin(); foliage->vertexdata->Begin(); int i = foliage->begin; int auxnumleaves = 0; while(i!=-1) { auxnumleaves++; i=foliage->Acth[i].next; } assert(auxnumleaves*6<=int(foliage->indexdata->GetNumMaxIndices())); foliage->indexdata->SetNumValidIndices(auxnumleaves*6); i = foliage->begin; int index=0; while(i!=-1) { unsigned int v0,v1,v2,v3; v0 = foliage->Leaves[i].vertsLeaf[0]; v1 = foliage->Leaves[i].vertsLeaf[1]; v2 = foliage->Leaves[i].vertsLeaf[2]; v3 = foliage->Leaves[i].vertsLeaf[3]; foliage->indexdata->SetIndex(index+0,v0); foliage->indexdata->SetIndex(index+1,v1); foliage->indexdata->SetIndex(index+2,v2); foliage->indexdata->SetIndex(index+3,v2); foliage->indexdata->SetIndex(index+4,v1); foliage->indexdata->SetIndex(index+5,v3); foliage->vertexdata->SetVertexTexCoord(v0,0,0); foliage->vertexdata->SetVertexTexCoord(v1,0,1); foliage->vertexdata->SetVertexTexCoord(v2,1,0); foliage->vertexdata->SetVertexTexCoord(v3,1,1); index+=6; i=foliage->Acth[i].next; } foliage->indexdata->End(); foliage->vertexdata->End(); } /* uint32 LodTreeLibrary::MinFoliageLod(void) const { return foliage->nHojas; } uint32 LodTreeLibrary::MaxFoliageLod(void) const { return foliage->minHojas; }*/ /*const VertexData* LodTreeLibrary::Get_Trunk_VertexData(void) const { return trunk->vertices; }*/ const IndexData* LodTreeLibrary::CurrentLOD_Trunk_Indices(void) const { return trunk->dataRetrievalInterface; } const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const { return foliage->vertexdata; } const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const { return foliage->indexdata; } /*void ThrowFileNotFoundError(const char *text) { throw Geometry::FileNotFound(text); }*/ uint32 LodTreeLibrary::CurrentLOD_Foliage_IndexCount(void) const { // return current_foliage_indexcount; return foliage->indexdata->GetNumValidIndices(); } /* uint32 LodTreeLibrary::Get_Trunk_VertexCount(void) const { return trunk->TOTALVERTS; } uint32 LodTreeLibrary::Get_Trunk_MaxIndexCount(uint32 istrip) const { // return trunk->indices_x_tira[istrip]->GetNumMaxIndices(); return trunk->indices->GetNumMaxIndices(istrip); } uint32 LodTreeLibrary::Get_Foliage_VertexCount(void) const { return arbol->vertexdata->GetNumVertices(); }*/ uint32 LodTreeLibrary::Get_Foliage_MaxIndexCount(void) const { return foliage->indexdata->GetNumMaxIndices(); } // changes the lod of the entire object (trunk and leaves) void LodTreeLibrary::GoToLod(Real lod) { assert(lod<=1.0f && lod>=0.0f); GoToTrunkLod(lod); GoToFoliageLod(lod); }