//#include "defs.h" #include #include "GeoLodTreeLibrary.h" #include "libs/leaves/Foliage.h" using namespace Geometry; uint32 uniqueIDgen = 0; Geometry::LodTreeLibrary::LodTreeLibrary(std::string trunkSimpSeqFile, std::string leafSimpSeqFile, Geometry::Mesh *treeGeoMesh, uint32 leafSubMeshID/* std::string foliage_verts, std::string foliage_leafs, std::string foliage_simpl, uint32 leafSubMeshID, CREATEVERTEXDATAFUNC vdfun, CREATEINDEXDATAFUNC idfun, CREATEMULTIINDEXDATAFUNC midfun*/) { uniqueID = uniqueIDgen++; // Cargar el tronco trunk = new LodStripsLibrary(trunkSimpSeqFile,treeGeoMesh); // Cargar la copa del árbol // arbol = new Arbol(foliage_verts.c_str(),foliage_leafs.c_str(),foliage_simpl.c_str(),NULL/*vdfun*/,NULL/*idfun*/); Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[leafSubMeshID]); foliage = new Foliage(leafsSubMesh,leafSimpSeqFile.c_str()); } /* 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->TOTALTIRAS; 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; } */ uint32 LodTreeLibrary::GoToTrunkLod(uint32 newlod) { return trunk->GoToLod(newlod); /* uint32 previouslod = trunk->LodActual; trunk->VerModeloVBO(newlod); return previouslod;*/ } uint32 LodTreeLibrary::MinTrunkLod(void) const { // return 3; // un polígono: preguntar a francisco // return (trunk->TOTALCAMBIOS*0.95f); return trunk->MinLod(); } uint32 LodTreeLibrary::MaxTrunkLod(void) const { // return (trunk->cVerts.size()*0.99); // return (trunk->TOTALCAMBIOS*0.95f); // return 0; return trunk->MaxLod(); } uint32 LodTreeLibrary::GoToFoliageLod(uint32 newlod) { foliage->AjusteHojas(newlod); foliage->indexdata->Begin(); foliage->vertexdata->Begin(); int i = foliage->ppio; int auxnumhojas = 0; while(i!=-1) { auxnumhojas++; i=foliage->Acth[i].next; } assert(auxnumhojas*6<=int(foliage->indexdata->GetNumMaxIndices())); foliage->indexdata->SetNumValidIndices(auxnumhojas*6); i = foliage->ppio; int kkkk=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(kkkk+0,v0); foliage->indexdata->SetIndex(kkkk+1,v1); foliage->indexdata->SetIndex(kkkk+2,v2); foliage->indexdata->SetIndex(kkkk+3,v2); foliage->indexdata->SetIndex(kkkk+4,v1); foliage->indexdata->SetIndex(kkkk+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); kkkk+=6; i=foliage->Acth[i].next; } foliage->indexdata->End(); foliage->vertexdata->End(); return 0; } uint32 LodTreeLibrary::MinFoliageLod(void) const { // return arbol->minHojas; return foliage->nHojas; } uint32 LodTreeLibrary::MaxFoliageLod(void) const { // return arbol->TotHojas; //return arbol->nHojas; return foliage->minHojas; } /*const VertexData* LodTreeLibrary::Get_Trunk_VertexData(void) const { return trunk->vertices; }*/ const MultiIndexData* LodTreeLibrary::CurrentLOD_Trunk_Indices(void) const { // return (uint32*)trunk->vStrips[istrip]; // return trunk->indices_x_tira[istrip]; return trunk->dataRetrievalInterface; } const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const { return foliage->vertexdata; } const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const { // return current_foliage_indices; 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(); }