// NeL - MMORPG Framework
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
#include "std3d.h"
#include "nel/3d/mrm_internal.h"
#include "nel/misc/common.h"
using namespace std;
using namespace NLMISC;
namespace NL3D
{
// ***************************************************************************
sint CMRMSewingMesh::mustCollapseEdge(uint lod, const CMRMEdge &edge, uint &vertToCollapse) const
{
nlassert(lod<_Lods.size());
for(uint i=0;i<_Lods[lod].EdgeToCollapse.size();i++)
{
if(edge==_Lods[lod].EdgeToCollapse[i])
{
// the vertex which must be collapsed is v0.
vertToCollapse= _Lods[lod].EdgeToCollapse[i].v0;
return i;
}
}
// not found
return -1;
}
// ***************************************************************************
sint CMRMSewingMesh::getNumCollapseEdge(uint lod) const
{
nlassert(lod<_Lods.size());
return (sint)_Lods[lod].EdgeToCollapse.size();
}
// ***************************************************************************
void CMRMSewingMesh::build(const CMesh::CInterface &meshInt, uint nWantedLods, uint divisor)
{
/* The polygon is MRM-egde-like reduced (pop an edge when needed)
At each lod we store what edge is collapsed.
*/
_Lods.clear();
_Lods.resize(nWantedLods);
// build edge list
std::vector edgeList;
uint nMaxEdges= (uint)meshInt.Vertices.size();
edgeList.resize(nMaxEdges);
for(uint i=0;i0;lod--)
{
// Linear.
sint nCurEdges= (sint)floor( 0.5f + nBaseEdges + (nMaxEdges-nBaseEdges) * (float)(lod-1)/(nWantedLods-1) );
nCurEdges=max(nCurEdges,3);
// the current edge list is reduced until same size as wanted
while(nCurEdges<(sint)edgeList.size())
{
// search the smallest edge
float bestDist= FLT_MAX;
uint bestEdgeId= 0;
for(uint j=0;j 01 12 23... becomes 02 23 (NB: 1 is collapsed to 2)
uint precEdgeId= (uint)((bestEdgeId+edgeList.size()-1)%edgeList.size());
edgeList[precEdgeId].v1= edgeList[bestEdgeId].v1;
// and erase the edge from the current list
edgeList.erase( edgeList.begin()+bestEdgeId );
}
}
}
} // NL3D