Work on mesh decimation.

This commit is contained in:
David Williams 2007-09-21 22:34:22 +00:00
parent 63c5886d1d
commit f569abe501
3 changed files with 40 additions and 22 deletions

View File

@ -35,8 +35,9 @@ namespace Ogre
void endDefinition(void);
void addTriangle(const SurfaceVertex& v0,const SurfaceVertex& v1,const SurfaceVertex& v2);
SurfaceVertexIterator findVertex(const SurfaceVertex& vertex);
SurfaceVertexIterator findOrAddVertex(const SurfaceVertex& vertex);
SurfaceEdgeIterator findEdge(const SurfaceVertexIterator& source, const SurfaceVertexIterator& target);
SurfaceEdgeIterator findOrAddEdge(const SurfaceVertexIterator& source, const SurfaceVertexIterator& target);
//SurfaceVertexIterator findTriangle(const SurfaceTriangle& triangle);
void getVertexAndIndexData(std::vector<SurfaceVertex>& vertexData, std::vector<uint>& indexData);

View File

@ -64,14 +64,14 @@ namespace Ogre
m_uTrianglesAdded++;
m_uVerticesAdded += 3;
SurfaceVertexIterator v0Iter = findVertex(v0);
SurfaceVertexIterator v1Iter = findVertex(v1);
SurfaceVertexIterator v2Iter = findVertex(v2);
SurfaceVertexIterator v0Iter = findOrAddVertex(v0);
SurfaceVertexIterator v1Iter = findOrAddVertex(v1);
SurfaceVertexIterator v2Iter = findOrAddVertex(v2);
SurfaceEdgeIterator v0v1Iter = findEdge(v0Iter,v1Iter);
SurfaceEdgeIterator v1v2Iter = findEdge(v1Iter,v2Iter);
SurfaceEdgeIterator v2v0Iter = findEdge(v2Iter,v0Iter);
SurfaceEdgeIterator v0v1Iter = findOrAddEdge(v0Iter,v1Iter);
SurfaceEdgeIterator v1v2Iter = findOrAddEdge(v1Iter,v2Iter);
SurfaceEdgeIterator v2v0Iter = findOrAddEdge(v2Iter,v0Iter);
v0Iter->edge = v0v1Iter;
v1Iter->edge = v1v2Iter;
@ -98,7 +98,7 @@ namespace Ogre
v2v0Iter->triangle = iterTriangle;
}
SurfaceVertexIterator SurfacePatch::findVertex(const SurfaceVertex& vertex)
SurfaceVertexIterator SurfacePatch::findOrAddVertex(const SurfaceVertex& vertex)
{
SurfaceVertexIterator vertexIter = find(m_listVertices.begin(), m_listVertices.end(), vertex);
if(vertexIter == m_listVertices.end())
@ -121,6 +121,20 @@ namespace Ogre
}
}
//Not found - return end.
return m_listEdges.end();
}
SurfaceEdgeIterator SurfacePatch::findOrAddEdge(const SurfaceVertexIterator& source, const SurfaceVertexIterator& target)
{
for(SurfaceEdgeIterator edgeIter = m_listEdges.begin(); edgeIter != m_listEdges.end(); ++edgeIter)
{
if((edgeIter->target == target) && (edgeIter->otherHalfEdge->target == source))
{
return edgeIter;
}
}
//Not found - add it.
SurfaceEdge edge;
edge.target = target;
@ -484,25 +498,28 @@ namespace Ogre
}
LogManager::getSingleton().logMessage("Vertex can be removed");
SurfaceEdgeIterator firstEdge = vertexIter->edge;
/*SurfaceEdgeIterator firstEdge = vertexIter->edge;
SurfaceEdgeIterator nextEdge = firstEdge;
nextEdge = firstEdge;
std::list<SurfaceEdgeIterator> edgesToRemove = removeTrianglesAndFindEdges(vertexIter);
/*do
{
LogManager::getSingleton().logMessage("Removing triangle");
m_listTriangles.erase(nextEdge->triangle);
std::list<SurfaceEdgeIterator> edgesToRemove = removeTrianglesAndFindEdges(vertexIter);
edgesToRemove.push_back(nextEdge);
nextEdge = nextEdge->previousHalfEdge;
edgesToRemove.push_back(nextEdge);
nextEdge = nextEdge->otherHalfEdge;
}while(nextEdge != firstEdge);*/
LogManager::getSingleton().logMessage("Removing edges " + vertexIter->toString());
for(std::list<SurfaceEdgeIterator>::iterator edgesToRemoveIter = edgesToRemove.begin(); edgesToRemoveIter != edgesToRemove.end(); ++edgesToRemoveIter)
{
m_listEdges.erase(*edgesToRemoveIter);
}*/
for(std::list<SurfaceVertexIterator>::iterator iter = listConnectedVertices.begin(); iter != listConnectedVertices.end(); ++iter)
{
SurfaceEdgeIterator edgeToDelete = findEdge(vertexIter, *iter);
SurfaceEdgeIterator otherEdgeToDelete = edgeToDelete->otherHalfEdge;
if(edgeToDelete->nextHalfEdge != edgeToDelete->otherHalfEdge)
{
m_listTriangles.erase(edgeToDelete->triangle);
}
m_listEdges.erase(edgeToDelete);
m_listEdges.erase(otherEdgeToDelete);
}
LogManager::getSingleton().logMessage("Removing vertex " + vertexIter->toString());

View File

@ -70,7 +70,7 @@ namespace Ogre
volIter.setVoxelAt(x,y,z,0);
}
}
//volIter.setVoxelAt(130,130,23,0);
volIter.setVoxelAt(130,130,23,0);
//Periodically see if we can tidy the memory to avoid excessive usage during loading.
if(z%OGRE_BLOCK_SIDE_LENGTH == OGRE_BLOCK_SIDE_LENGTH-1)