text
stringlengths
0
2.2M
polys[npolys*MAX_VERTS_PER_POLY+1] = indices[t[1]];
polys[npolys*MAX_VERTS_PER_POLY+2] = indices[t[2]];
npolys++;
}
}
if (!npolys)
continue;
// Merge polygons.
int maxVertsPerPoly =MAX_VERTS_PER_POLY ;
if (maxVertsPerPoly > 3)
{
for(;;)
{
// Find best polygons to merge.
int bestMergeVal = 0;
int bestPa = 0, bestPb = 0, bestEa = 0, bestEb = 0;
for (int j = 0; j < npolys-1; ++j)
{
unsigned short* pj = &polys[j*MAX_VERTS_PER_POLY];
for (int k = j+1; k < npolys; ++k)
{
unsigned short* pk = &polys[k*MAX_VERTS_PER_POLY];
int ea, eb;
int v = getPolyMergeValue(pj, pk, mesh.verts, ea, eb);
if (v > bestMergeVal)
{
bestMergeVal = v;
bestPa = j;
bestPb = k;
bestEa = ea;
bestEb = eb;
}
}
}
if (bestMergeVal > 0)
{
// Found best, merge.
unsigned short* pa = &polys[bestPa*MAX_VERTS_PER_POLY];
unsigned short* pb = &polys[bestPb*MAX_VERTS_PER_POLY];
mergePolys(pa, pb, bestEa, bestEb);
memcpy(pb, &polys[(npolys-1)*MAX_VERTS_PER_POLY], sizeof(unsigned short)*MAX_VERTS_PER_POLY);
npolys--;
}
else
{
// Could not merge any polygons, stop.
break;
}
}
}
// Store polygons.
for (int j = 0; j < npolys; ++j)
{
unsigned short* p = &mesh.polys[mesh.npolys*MAX_VERTS_PER_POLY*2];
unsigned short* q = &polys[j*MAX_VERTS_PER_POLY];
for (int k = 0; k < MAX_VERTS_PER_POLY; ++k)
p[k] = q[k];
mesh.areas[mesh.npolys] = cont.area;
mesh.npolys++;
if (mesh.npolys > maxTris)
return DT_FAILURE | DT_BUFFER_TOO_SMALL;
}
}
// Remove edge vertices.
for (int i = 0; i < mesh.nverts; ++i)
{
if (vflags[i])
{
if (!canRemoveVertex(mesh, (unsigned short)i))
continue;
dtStatus status = removeVertex(mesh, (unsigned short)i, maxTris);
if (dtStatusFailed(status))
return status;
// Remove vertex
// Note: mesh.nverts is already decremented inside removeVertex()!
for (int j = i; j < mesh.nverts; ++j)
vflags[j] = vflags[j+1];
--i;
}
}
// Calculate adjacency.
if (!buildMeshAdjacency(alloc, mesh.polys, mesh.npolys, mesh.verts, mesh.nverts, lcset))
return DT_FAILURE | DT_OUT_OF_MEMORY;
return DT_SUCCESS;
}
dtStatus dtMarkCylinderArea(dtTileCacheLayer& layer, const float* orig, const float cs, const float ch,
const float* pos, const float radius, const float height, const unsigned char areaId)
{
float bmin[3], bmax[3];
bmin[0] = pos[0] - radius;
bmin[1] = pos[1];