senoutouya / recastnavigation

Automatically exported from code.google.com/p/recastnavigation
zlib License
0 stars 0 forks source link

Bug when a non-shared vertex is marked for remove #54

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

See following discussion on group

---

it should be fine to remove a border vertex from a triangle. The
vertex removing code actually removes all the polygons which share the
vertex and then retriangulates the hole.

There might be a case where this fails, though. If the mesh is such
that only a tip of a triangle touches the border and only that
triangle uses the vertex, then the code may fail. To remedy this, you
could try code which is something like this at the top of the
removeVertex()

int numRemainingEdges = 0;
for (int i = 0; i < mesh.npolys; ++i)
{
       unsigned short* p = &mesh.polys[i*nvp*2];
       const int nv = countPolyVerts(p, nvp);
       for (int j = 0; j < nv; ++j)
       {
               unsigned short ia = p[j];
               unsigned short ib = p[(j+1)%nv];
               if (ia != rem && ib != rem)
                       numRemainingEdges++;
       }
}
if (numRemainingEdges < 2)
       return NOT_REMOVED;

You will also need to adjust the loop which is removing the vertex to
something like this:

if (vflags[i])
{
       int ret = removeVertex(mesh, i, maxTris);
       if (ret == NOT_REMOVED)
               continue;
       if (ret == FAILED)
       {
               if (rcGetLog())
                       rcGetLog()->log(RC_LOG_ERROR, "rcBuildPolyMesh:
Failed to remove
edge vertex %d.", i);
               return false;
       }
       // Note: mesh.nverts is already decremented inside removeVertex()!
       for (int j = i; j < mesh.nverts; ++j)
               vflags[j] = vflags[j+1];
       --i;
}

Original issue reported on code.google.com by memono...@gmail.com on 8 Mar 2010 at 9:05

GoogleCodeExporter commented 9 years ago
Fixed in R143. I could trigger this with real data, tested with some synthetic
examples and made sure it does not break existing working cases.

Original comment by memono...@gmail.com on 18 Mar 2010 at 8:48