text
stringlengths 0
2.2M
|
---|
dtSwap(a,b);
|
// Check if the edge exists
|
bool exists = false;
|
for (int m = 0; m < nedges; ++m)
|
{
|
unsigned short* e = &edges[m*3];
|
if (e[1] == b)
|
{
|
// Exists, increment vertex share count.
|
e[2]++;
|
exists = true;
|
}
|
}
|
// Add new edge.
|
if (!exists)
|
{
|
unsigned short* e = &edges[nedges*3];
|
e[0] = (unsigned short)a;
|
e[1] = (unsigned short)b;
|
e[2] = 1;
|
nedges++;
|
}
|
}
|
}
|
}
|
// There should be no more than 2 open edges.
|
// This catches the case that two non-adjacent polygons
|
// share the removed vertex. In that case, do not remove the vertex.
|
int numOpenEdges = 0;
|
for (int i = 0; i < nedges; ++i)
|
{
|
if (edges[i*3+2] < 2)
|
numOpenEdges++;
|
}
|
if (numOpenEdges > 2)
|
return false;
|
return true;
|
}
|
static dtStatus removeVertex(dtTileCachePolyMesh& mesh, const unsigned short rem, const int maxTris)
|
{
|
// Count number of polygons to remove.
|
int numRemovedVerts = 0;
|
for (int i = 0; i < mesh.npolys; ++i)
|
{
|
unsigned short* p = &mesh.polys[i*MAX_VERTS_PER_POLY*2];
|
const int nv = countPolyVerts(p);
|
for (int j = 0; j < nv; ++j)
|
{
|
if (p[j] == rem)
|
numRemovedVerts++;
|
}
|
}
|
int nedges = 0;
|
unsigned short edges[MAX_REM_EDGES*3];
|
int nhole = 0;
|
unsigned short hole[MAX_REM_EDGES];
|
int nharea = 0;
|
unsigned short harea[MAX_REM_EDGES];
|
for (int i = 0; i < mesh.npolys; ++i)
|
{
|
unsigned short* p = &mesh.polys[i*MAX_VERTS_PER_POLY*2];
|
const int nv = countPolyVerts(p);
|
bool hasRem = false;
|
for (int j = 0; j < nv; ++j)
|
if (p[j] == rem) hasRem = true;
|
if (hasRem)
|
{
|
// Collect edges which does not touch the removed vertex.
|
for (int j = 0, k = nv-1; j < nv; k = j++)
|
{
|
if (p[j] != rem && p[k] != rem)
|
{
|
if (nedges >= MAX_REM_EDGES)
|
return DT_FAILURE | DT_BUFFER_TOO_SMALL;
|
unsigned short* e = &edges[nedges*3];
|
e[0] = p[k];
|
e[1] = p[j];
|
e[2] = mesh.areas[i];
|
nedges++;
|
}
|
}
|
// Remove the polygon.
|
unsigned short* p2 = &mesh.polys[(mesh.npolys-1)*MAX_VERTS_PER_POLY*2];
|
memcpy(p,p2,sizeof(unsigned short)*MAX_VERTS_PER_POLY);
|
memset(p+MAX_VERTS_PER_POLY,0xff,sizeof(unsigned short)*MAX_VERTS_PER_POLY);
|
mesh.areas[i] = mesh.areas[mesh.npolys-1];
|
mesh.npolys--;
|
--i;
|
}
|
}
|
// Remove vertex.
|
for (int i = (int)rem; i < mesh.nverts; ++i)
|
{
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.