Better detection of portal edges between tiles.
This commit is contained in:
parent
cd3a68dd9b
commit
620f8fa130
@ -806,24 +806,23 @@ void duDebugDrawContours(duDebugDraw* dd, const rcContourSet& cset, const float
|
|||||||
const rcContour& c = cset.conts[i];
|
const rcContour& c = cset.conts[i];
|
||||||
if (!c.nverts)
|
if (!c.nverts)
|
||||||
continue;
|
continue;
|
||||||
unsigned int color = duIntToCol(c.reg, a);
|
const unsigned int color = duIntToCol(c.reg, a);
|
||||||
|
const unsigned int bcolor = duLerpCol(color,duRGBA(255,255,255,a),128);
|
||||||
for (int j = 0; j < c.nverts; ++j)
|
for (int j = 0, k = c.nverts-1; j < c.nverts; k=j++)
|
||||||
{
|
{
|
||||||
const int* v = &c.verts[j*4];
|
const int* va = &c.verts[k*4];
|
||||||
float fx = orig[0] + v[0]*cs;
|
const int* vb = &c.verts[j*4];
|
||||||
float fy = orig[1] + (v[1]+1+(i&1))*ch;
|
unsigned int col = (va[3] & RC_AREA_BORDER) ? bcolor : color;
|
||||||
float fz = orig[2] + v[2]*cs;
|
float fx,fy,fz;
|
||||||
dd->vertex(fx,fy,fz, color);
|
fx = orig[0] + va[0]*cs;
|
||||||
if (j > 0)
|
fy = orig[1] + (va[1]+1+(i&1))*ch;
|
||||||
dd->vertex(fx,fy,fz, color);
|
fz = orig[2] + va[2]*cs;
|
||||||
|
dd->vertex(fx,fy,fz, col);
|
||||||
|
fx = orig[0] + vb[0]*cs;
|
||||||
|
fy = orig[1] + (vb[1]+1+(i&1))*ch;
|
||||||
|
fz = orig[2] + vb[2]*cs;
|
||||||
|
dd->vertex(fx,fy,fz, col);
|
||||||
}
|
}
|
||||||
// Loop last segment
|
|
||||||
const int* v = &c.verts[0];
|
|
||||||
float fx = orig[0] + v[0]*cs;
|
|
||||||
float fy = orig[1] + (v[1]+1+(i&1))*ch;
|
|
||||||
float fz = orig[2] + v[2]*cs;
|
|
||||||
dd->vertex(fx,fy,fz, color);
|
|
||||||
}
|
}
|
||||||
dd->end();
|
dd->end();
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified,
|
|||||||
// and the neighbour region is take from the next raw point.
|
// and the neighbour region is take from the next raw point.
|
||||||
const int ai = (simplified[i*4+3]+1) % pn;
|
const int ai = (simplified[i*4+3]+1) % pn;
|
||||||
const int bi = simplified[i*4+3];
|
const int bi = simplified[i*4+3];
|
||||||
simplified[i*4+3] = (points[ai*4+3] & RC_CONTOUR_REG_MASK) | (points[bi*4+3] & RC_BORDER_VERTEX);
|
simplified[i*4+3] = (points[ai*4+3] & (RC_CONTOUR_REG_MASK|RC_AREA_BORDER)) | (points[bi*4+3] & RC_BORDER_VERTEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -934,11 +934,19 @@ bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMe
|
|||||||
rcScopedDelete<unsigned char> vflags = (unsigned char*)rcAlloc(sizeof(unsigned char)*maxVertices, RC_ALLOC_TEMP);
|
rcScopedDelete<unsigned char> vflags = (unsigned char*)rcAlloc(sizeof(unsigned char)*maxVertices, RC_ALLOC_TEMP);
|
||||||
if (!vflags)
|
if (!vflags)
|
||||||
{
|
{
|
||||||
ctx->log(RC_LOG_ERROR, "rcBuildPolyMesh: Out of memory 'mesh.verts' (%d).", maxVertices);
|
ctx->log(RC_LOG_ERROR, "rcBuildPolyMesh: Out of memory 'vflags' (%d).", maxVertices);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
memset(vflags, 0, maxVertices);
|
memset(vflags, 0, maxVertices);
|
||||||
|
|
||||||
|
rcScopedDelete<unsigned short> vportal = (unsigned short*)rcAlloc(sizeof(unsigned short)*maxVertices, RC_ALLOC_TEMP);
|
||||||
|
if (!vportal)
|
||||||
|
{
|
||||||
|
ctx->log(RC_LOG_ERROR, "rcBuildPolyMesh: Out of memory 'vportal' (%d).", maxVertices);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
memset(vportal, 0xff, maxVertices);
|
||||||
|
|
||||||
mesh.verts = (unsigned short*)rcAlloc(sizeof(unsigned short)*maxVertices*3, RC_ALLOC_PERM);
|
mesh.verts = (unsigned short*)rcAlloc(sizeof(unsigned short)*maxVertices*3, RC_ALLOC_PERM);
|
||||||
if (!mesh.verts)
|
if (!mesh.verts)
|
||||||
{
|
{
|
||||||
@ -1054,6 +1062,14 @@ bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store portal edges
|
||||||
|
for (int j = 0; j < cont.nverts; ++j)
|
||||||
|
{
|
||||||
|
const int* v = &cont.verts[j*4];
|
||||||
|
if ((v[3] & RC_AREA_BORDER) == 0)
|
||||||
|
vportal[indices[j]] = indices[(j+1) % cont.nverts];
|
||||||
|
}
|
||||||
|
|
||||||
// Build initial polygons.
|
// Build initial polygons.
|
||||||
int npolys = 0;
|
int npolys = 0;
|
||||||
memset(polys, 0xff, maxVertsPerCont*nvp*sizeof(unsigned short));
|
memset(polys, 0xff, maxVertsPerCont*nvp*sizeof(unsigned short));
|
||||||
@ -1150,8 +1166,17 @@ bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMe
|
|||||||
}
|
}
|
||||||
// Remove vertex
|
// Remove vertex
|
||||||
// Note: mesh.nverts is already decremented inside removeVertex()!
|
// Note: mesh.nverts is already decremented inside removeVertex()!
|
||||||
|
// Fixup vertex flags
|
||||||
for (int j = i; j < mesh.nverts; ++j)
|
for (int j = i; j < mesh.nverts; ++j)
|
||||||
vflags[j] = vflags[j+1];
|
vflags[j] = vflags[j+1];
|
||||||
|
// Fixup portal indices
|
||||||
|
for (int j = i; j < mesh.nverts; ++j)
|
||||||
|
vportal[j] = vportal[j+1];
|
||||||
|
for (int j = 0; j < mesh.nverts; ++j)
|
||||||
|
{
|
||||||
|
if (vportal[j] > (unsigned short)i)
|
||||||
|
vportal[j]--;
|
||||||
|
}
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1182,6 +1207,10 @@ bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMe
|
|||||||
const unsigned short* va = &mesh.verts[p[j]*3];
|
const unsigned short* va = &mesh.verts[p[j]*3];
|
||||||
const unsigned short* vb = &mesh.verts[p[nj]*3];
|
const unsigned short* vb = &mesh.verts[p[nj]*3];
|
||||||
|
|
||||||
|
// Make sure the edge is marked as portal.
|
||||||
|
if (vportal[p[j]] != p[nj])
|
||||||
|
continue;
|
||||||
|
|
||||||
if ((int)va[0] == 0 && (int)vb[0] == 0)
|
if ((int)va[0] == 0 && (int)vb[0] == 0)
|
||||||
p[nvp+j] = 0x8000 | 0;
|
p[nvp+j] = 0x8000 | 0;
|
||||||
else if ((int)va[2] == h && (int)vb[2] == h)
|
else if ((int)va[2] == h && (int)vb[2] == h)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user