//#include "defs.h" #include #include "GeoLodTreeLibrary.h" #include "libs/leaves/arbol.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]); arbol = new Arbol(leafsSubMesh,leafSimpSeqFile.c_str()); foliage = new Foliage(arbol); } /* 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 (arbol) delete arbol; 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->GetStripCount(); } uint32 LodTreeLibrary::CurrentLOD_Trunk_IndexCountByStrip(uint32 istrip) const { assert(trunk); // return trunk->lStripsV[istrip].size(); return trunk->GetIndexCountByStrip(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); arbol->indexdata->Begin(); arbol->vertexdata->Begin(); int i = foliage->ppio; int auxnumhojas = 0; while(i!=-1) { auxnumhojas++; i=foliage->Acth[i].next; } assert(auxnumhojas*6<=arbol->indexdata->GetNumMaxIndices()); arbol->indexdata->SetNumValidIndices(auxnumhojas*6); i = foliage->ppio; int kkkk=0; while(i!=-1) { unsigned int v0,v1,v2,v3; v0 = arbol->Hojas[i].Vert_Hoja[0]; v1 = arbol->Hojas[i].Vert_Hoja[1]; v2 = arbol->Hojas[i].Vert_Hoja[2]; v3 = arbol->Hojas[i].Vert_Hoja[3]; arbol->indexdata->SetIndex(kkkk+0,v0); arbol->indexdata->SetIndex(kkkk+1,v1); arbol->indexdata->SetIndex(kkkk+2,v2); arbol->indexdata->SetIndex(kkkk+3,v2); arbol->indexdata->SetIndex(kkkk+4,v1); arbol->indexdata->SetIndex(kkkk+5,v3); arbol->vertexdata->SetVertexTexCoord(v0,0,0); arbol->vertexdata->SetVertexTexCoord(v1,0,1); arbol->vertexdata->SetVertexTexCoord(v2,1,0); arbol->vertexdata->SetVertexTexCoord(v3,1,1); kkkk+=6; i=foliage->Acth[i].next; } arbol->indexdata->End(); arbol->vertexdata->End(); return 0; } uint32 LodTreeLibrary::MinFoliageLod(void) const { // return arbol->minHojas; return arbol->nHojas; } uint32 LodTreeLibrary::MaxFoliageLod(void) const { // return arbol->TotHojas; //return arbol->nHojas; return arbol->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->indices; }*/ const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const { return arbol->vertexdata; } const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const { // return current_foliage_indices; return arbol->indexdata; } /*void ThrowFileNotFoundError(const char *text) { throw Geometry::FileNotFound(text); }*/ uint32 LodTreeLibrary::CurrentLOD_Foliage_IndexCount(void) const { // return current_foliage_indexcount; return arbol->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 arbol->indexdata->GetNumMaxIndices(); }