text
stringlengths 0
2.2M
|
---|
maxVertsPerCont = dtMax(maxVertsPerCont, lcset.conts[i].nverts);
|
}
|
// TODO: warn about too many vertices?
|
mesh.nvp = MAX_VERTS_PER_POLY;
|
dtFixedArray<unsigned char> vflags(alloc, maxVertices);
|
if (!vflags)
|
return DT_FAILURE | DT_OUT_OF_MEMORY;
|
memset(vflags, 0, maxVertices);
|
mesh.verts = (unsigned short*)alloc->alloc(sizeof(unsigned short)*maxVertices*3);
|
if (!mesh.verts)
|
return DT_FAILURE | DT_OUT_OF_MEMORY;
|
mesh.polys = (unsigned short*)alloc->alloc(sizeof(unsigned short)*maxTris*MAX_VERTS_PER_POLY*2);
|
if (!mesh.polys)
|
return DT_FAILURE | DT_OUT_OF_MEMORY;
|
mesh.areas = (unsigned char*)alloc->alloc(sizeof(unsigned char)*maxTris);
|
if (!mesh.areas)
|
return DT_FAILURE | DT_OUT_OF_MEMORY;
|
mesh.flags = (unsigned short*)alloc->alloc(sizeof(unsigned short)*maxTris);
|
if (!mesh.flags)
|
return DT_FAILURE | DT_OUT_OF_MEMORY;
|
// Just allocate and clean the mesh flags array. The user is resposible for filling it.
|
memset(mesh.flags, 0, sizeof(unsigned short) * maxTris);
|
mesh.nverts = 0;
|
mesh.npolys = 0;
|
memset(mesh.verts, 0, sizeof(unsigned short)*maxVertices*3);
|
memset(mesh.polys, 0xff, sizeof(unsigned short)*maxTris*MAX_VERTS_PER_POLY*2);
|
memset(mesh.areas, 0, sizeof(unsigned char)*maxTris);
|
unsigned short firstVert[VERTEX_BUCKET_COUNT2];
|
for (int i = 0; i < VERTEX_BUCKET_COUNT2; ++i)
|
firstVert[i] = DT_TILECACHE_NULL_IDX;
|
dtFixedArray<unsigned short> nextVert(alloc, maxVertices);
|
if (!nextVert)
|
return DT_FAILURE | DT_OUT_OF_MEMORY;
|
memset(nextVert, 0, sizeof(unsigned short)*maxVertices);
|
dtFixedArray<unsigned short> indices(alloc, maxVertsPerCont);
|
if (!indices)
|
return DT_FAILURE | DT_OUT_OF_MEMORY;
|
dtFixedArray<unsigned short> tris(alloc, maxVertsPerCont*3);
|
if (!tris)
|
return DT_FAILURE | DT_OUT_OF_MEMORY;
|
dtFixedArray<unsigned short> polys(alloc, maxVertsPerCont*MAX_VERTS_PER_POLY);
|
if (!polys)
|
return DT_FAILURE | DT_OUT_OF_MEMORY;
|
for (int i = 0; i < lcset.nconts; ++i)
|
{
|
dtTileCacheContour& cont = lcset.conts[i];
|
// Skip null contours.
|
if (cont.nverts < 3)
|
continue;
|
// Triangulate contour
|
for (int j = 0; j < cont.nverts; ++j)
|
indices[j] = (unsigned short)j;
|
int ntris = triangulate(cont.nverts, cont.verts, &indices[0], &tris[0]);
|
if (ntris <= 0)
|
{
|
// TODO: issue warning!
|
ntris = -ntris;
|
}
|
// Add and merge vertices.
|
for (int j = 0; j < cont.nverts; ++j)
|
{
|
const unsigned char* v = &cont.verts[j*4];
|
indices[j] = addVertex((unsigned short)v[0], (unsigned short)v[1], (unsigned short)v[2],
|
mesh.verts, firstVert, nextVert, mesh.nverts);
|
if (v[3] & 0x80)
|
{
|
// This vertex should be removed.
|
vflags[indices[j]] = 1;
|
}
|
}
|
// Build initial polygons.
|
int npolys = 0;
|
memset(polys, 0xff, sizeof(unsigned short) * maxVertsPerCont * MAX_VERTS_PER_POLY);
|
for (int j = 0; j < ntris; ++j)
|
{
|
const unsigned short* t = &tris[j*3];
|
if (t[0] != t[1] && t[0] != t[2] && t[1] != t[2])
|
{
|
polys[npolys*MAX_VERTS_PER_POLY+0] = indices[t[0]];
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.