void duDebugDrawPolyMeshDetail(duDebugDraw* dd, const struct rcPolyMeshDetail& dmesh) { if (!dd) return; dd->begin(DU_DRAW_TRIS); for (int i = 0; i < dmesh.nmeshes; ++i) { const unsigned int* m = &dmesh.meshes[i*4]; const unsigned int bverts = m[0]; const unsigned int btris = m[2]; const int ntris = (int)m[3]; const float* verts = &dmesh.verts[bverts*3]; const unsigned char* tris = &dmesh.tris[btris*4]; unsigned int color = duIntToCol(i, 192); for (int j = 0; j < ntris; ++j) { dd->vertex(&verts[tris[j*4+0]*3], color); dd->vertex(&verts[tris[j*4+1]*3], color); dd->vertex(&verts[tris[j*4+2]*3], color); } } dd->end(); // Internal edges. dd->begin(DU_DRAW_LINES, 1.0f); const unsigned int coli = duRGBA(0,0,0,64); for (int i = 0; i < dmesh.nmeshes; ++i) { const unsigned int* m = &dmesh.meshes[i*4]; const unsigned int bverts = m[0]; const unsigned int btris = m[2]; const int ntris = (int)m[3]; const float* verts = &dmesh.verts[bverts*3]; const unsigned char* tris = &dmesh.tris[btris*4]; for (int j = 0; j < ntris; ++j) { const unsigned char* t = &tris[j*4]; for (int k = 0, kp = 2; k < 3; kp=k++) { unsigned char ef = (t[3] >> (kp*2)) & 0x3; if (ef == 0) { // Internal edge if (t[kp] < t[k]) { dd->vertex(&verts[t[kp]*3], coli); dd->vertex(&verts[t[k]*3], coli); } } } } } dd->end(); // External edges. dd->begin(DU_DRAW_LINES, 2.0f); const unsigned int cole = duRGBA(0,0,0,64); for (int i = 0; i < dmesh.nmeshes; ++i) { const unsigned int* m = &dmesh.meshes[i*4]; const unsigned int bverts = m[0]; const unsigned int btris = m[2]; const int ntris = (int)m[3]; const float* verts = &dmesh.verts[bverts*3]; const unsigned char* tris = &dmesh.tris[btris*4]; for (int j = 0; j < ntris; ++j) { const unsigned char* t = &tris[j*4]; for (int k = 0, kp = 2; k < 3; kp=k++) { unsigned char ef = (t[3] >> (kp*2)) & 0x3; if (ef != 0) { // Ext edge dd->vertex(&verts[t[kp]*3], cole); dd->vertex(&verts[t[k]*3], cole); } } } } dd->end(); dd->begin(DU_DRAW_POINTS, 3.0f); const unsigned int colv = duRGBA(0,0,0,64); for (int i = 0; i < dmesh.nmeshes; ++i) { const unsigned int* m = &dmesh.meshes[i*4]; const unsigned int bverts = m[0]; const int nverts = (int)m[1]; const float* verts = &dmesh.verts[bverts*3]; for (int j = 0; j < nverts; ++j) dd->vertex(&verts[j*3], colv); } dd->end(); }
void duDebugDrawPolyMesh(duDebugDraw* dd, const struct rcPolyMesh& mesh) { if (!dd) return; const int nvp = mesh.nvp; const float cs = mesh.cs; const float ch = mesh.ch; const float* orig = mesh.bmin; dd->begin(DU_DRAW_TRIS); for (int i = 0; i < mesh.npolys; ++i) { const unsigned short* p = &mesh.polys[i*nvp*2]; unsigned int color; if (mesh.areas[i] == RC_WALKABLE_AREA) color = duRGBA(0,192,255,64); else if (mesh.areas[i] == RC_NULL_AREA) color = duRGBA(0,0,0,64); else color = duIntToCol(mesh.areas[i], 255); unsigned short vi[3]; for (int j = 2; j < nvp; ++j) { if (p[j] == RC_MESH_NULL_IDX) break; vi[0] = p[0]; vi[1] = p[j-1]; vi[2] = p[j]; for (int k = 0; k < 3; ++k) { const unsigned short* v = &mesh.verts[vi[k]*3]; const float x = orig[0] + v[0]*cs; const float y = orig[1] + (v[1]+1)*ch; const float z = orig[2] + v[2]*cs; dd->vertex(x,y,z, color); } } } dd->end(); // Draw neighbours edges const unsigned int coln = duRGBA(0,48,64,32); dd->begin(DU_DRAW_LINES, 1.5f); for (int i = 0; i < mesh.npolys; ++i) { const unsigned short* p = &mesh.polys[i*nvp*2]; for (int j = 0; j < nvp; ++j) { if (p[j] == RC_MESH_NULL_IDX) break; if (p[nvp+j] & 0x8000) continue; const int nj = (j+1 >= nvp || p[j+1] == RC_MESH_NULL_IDX) ? 0 : j+1; const int vi[2] = {p[j], p[nj]}; for (int k = 0; k < 2; ++k) { const unsigned short* v = &mesh.verts[vi[k]*3]; const float x = orig[0] + v[0]*cs; const float y = orig[1] + (v[1]+1)*ch + 0.1f; const float z = orig[2] + v[2]*cs; dd->vertex(x, y, z, coln); } } } dd->end(); // Draw boundary edges const unsigned int colb = duRGBA(0,48,64,220); dd->begin(DU_DRAW_LINES, 2.5f); for (int i = 0; i < mesh.npolys; ++i) { const unsigned short* p = &mesh.polys[i*nvp*2]; for (int j = 0; j < nvp; ++j) { if (p[j] == RC_MESH_NULL_IDX) break; if ((p[nvp+j] & 0x8000) == 0) continue; const int nj = (j+1 >= nvp || p[j+1] == RC_MESH_NULL_IDX) ? 0 : j+1; const int vi[2] = {p[j], p[nj]}; unsigned int col = colb; if ((p[nvp+j] & 0xf) != 0xf) col = duRGBA(255,255,255,128); for (int k = 0; k < 2; ++k) { const unsigned short* v = &mesh.verts[vi[k]*3]; const float x = orig[0] + v[0]*cs; const float y = orig[1] + (v[1]+1)*ch + 0.1f; const float z = orig[2] + v[2]*cs; dd->vertex(x, y, z, col); } } } dd->end(); dd->begin(DU_DRAW_POINTS, 3.0f); const unsigned int colv = duRGBA(0,0,0,220); for (int i = 0; i < mesh.nverts; ++i) { const unsigned short* v = &mesh.verts[i*3]; const float x = orig[0] + v[0]*cs; const float y = orig[1] + (v[1]+1)*ch + 0.1f; const float z = orig[2] + v[2]*cs; dd->vertex(x,y,z, colv); } dd->end(); }
void duDebugDrawRawContours(duDebugDraw* dd, const rcContourSet& cset, const float alpha) { if (!dd) return; const float* orig = cset.bmin; const float cs = cset.cs; const float ch = cset.ch; const unsigned char a = (unsigned char)(alpha*255.0f); dd->begin(DU_DRAW_LINES, 2.0f); for (int i = 0; i < cset.nconts; ++i) { const rcContour& c = cset.conts[i]; unsigned int color = duIntToCol(c.reg, a); for (int j = 0; j < c.nrverts; ++j) { const int* v = &c.rverts[j*4]; 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); if (j > 0) dd->vertex(fx,fy,fz,color); } // Loop last segment. const int* v = &c.rverts[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->begin(DU_DRAW_POINTS, 2.0f); for (int i = 0; i < cset.nconts; ++i) { const rcContour& c = cset.conts[i]; unsigned int color = duDarkenCol(duIntToCol(c.reg, a)); for (int j = 0; j < c.nrverts; ++j) { const int* v = &c.rverts[j*4]; float off = 0; unsigned int colv = color; if (v[3] & RC_BORDER_VERTEX) { colv = duRGBA(255,255,255,a); off = ch*2; } float fx = orig[0] + v[0]*cs; float fy = orig[1] + (v[1]+1+(i&1))*ch + off; float fz = orig[2] + v[2]*cs; dd->vertex(fx,fy,fz, colv); } } dd->end(); }
void duDebugDrawContours(duDebugDraw* dd, const rcContourSet& cset, const float alpha) { if (!dd) return; const float* orig = cset.bmin; const float cs = cset.cs; const float ch = cset.ch; const unsigned char a = (unsigned char)(alpha*255.0f); dd->begin(DU_DRAW_LINES, 2.5f); for (int i = 0; i < cset.nconts; ++i) { const rcContour& c = cset.conts[i]; if (!c.nverts) continue; const unsigned int color = duIntToCol(c.reg, a); const unsigned int bcolor = duLerpCol(color,duRGBA(255,255,255,a),128); for (int j = 0, k = c.nverts-1; j < c.nverts; k=j++) { const int* va = &c.verts[k*4]; const int* vb = &c.verts[j*4]; unsigned int col = (va[3] & RC_AREA_BORDER) ? bcolor : color; float fx,fy,fz; fx = orig[0] + va[0]*cs; fy = orig[1] + (va[1]+1+(i&1))*ch; 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); } } dd->end(); dd->begin(DU_DRAW_POINTS, 3.0f); for (int i = 0; i < cset.nconts; ++i) { const rcContour& c = cset.conts[i]; unsigned int color = duDarkenCol(duIntToCol(c.reg, a)); for (int j = 0; j < c.nverts; ++j) { const int* v = &c.verts[j*4]; float off = 0; unsigned int colv = color; if (v[3] & RC_BORDER_VERTEX) { colv = duRGBA(255,255,255,a); off = ch*2; } float fx = orig[0] + v[0]*cs; float fy = orig[1] + (v[1]+1+(i&1))*ch + off; float fz = orig[2] + v[2]*cs; dd->vertex(fx,fy,fz, colv); } } dd->end(); }
void InputGeom::drawConvexVolumes(struct duDebugDraw* dd, bool /*hilight*/) { dd->depthMask(false); dd->begin(DU_DRAW_TRIS); for (int i = 0; i < m_volumeCount; ++i) { const ConvexVolume* vol = &m_volumes[i]; unsigned int col = duIntToCol(vol->area, 32); for (int j = 0, k = vol->nverts-1; j < vol->nverts; k = j++) { const float* va = &vol->verts[k*3]; const float* vb = &vol->verts[j*3]; dd->vertex(vol->verts[0],vol->hmax,vol->verts[2], col); dd->vertex(vb[0],vol->hmax,vb[2], col); dd->vertex(va[0],vol->hmax,va[2], col); dd->vertex(va[0],vol->hmin,va[2], duDarkenCol(col)); dd->vertex(va[0],vol->hmax,va[2], col); dd->vertex(vb[0],vol->hmax,vb[2], col); dd->vertex(va[0],vol->hmin,va[2], duDarkenCol(col)); dd->vertex(vb[0],vol->hmax,vb[2], col); dd->vertex(vb[0],vol->hmin,vb[2], duDarkenCol(col)); } } dd->end(); dd->begin(DU_DRAW_LINES, 2.0f); for (int i = 0; i < m_volumeCount; ++i) { const ConvexVolume* vol = &m_volumes[i]; unsigned int col = duIntToCol(vol->area, 220); for (int j = 0, k = vol->nverts-1; j < vol->nverts; k = j++) { const float* va = &vol->verts[k*3]; const float* vb = &vol->verts[j*3]; dd->vertex(va[0],vol->hmin,va[2], duDarkenCol(col)); dd->vertex(vb[0],vol->hmin,vb[2], duDarkenCol(col)); dd->vertex(va[0],vol->hmax,va[2], col); dd->vertex(vb[0],vol->hmax,vb[2], col); dd->vertex(va[0],vol->hmin,va[2], duDarkenCol(col)); dd->vertex(va[0],vol->hmax,va[2], col); } } dd->end(); dd->begin(DU_DRAW_POINTS, 3.0f); for (int i = 0; i < m_volumeCount; ++i) { const ConvexVolume* vol = &m_volumes[i]; unsigned int col = duDarkenCol(duIntToCol(vol->area, 255)); for (int j = 0; j < vol->nverts; ++j) { dd->vertex(vol->verts[j*3+0],vol->verts[j*3+1]+0.1f,vol->verts[j*3+2], col); dd->vertex(vol->verts[j*3+0],vol->hmin,vol->verts[j*3+2], col); dd->vertex(vol->verts[j*3+0],vol->hmax,vol->verts[j*3+2], col); } } dd->end(); dd->depthMask(true); }