Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/recast-navigation-core/src/debug-drawer-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export class DebugDrawerUtils {
this.vertex(x, y, z, color);
};

// this.debugDrawImpl.handleAreaToCol = (_area: number): number => {
// // unused for now...
// return 0;
// };

const primitiveMap: Record<number, DebugDrawerPrimitiveType> = {
[Raw.Module.DU_DRAW_LINES]: 'lines',
[Raw.Module.DU_DRAW_TRIS]: 'tris',
Expand Down
49 changes: 49 additions & 0 deletions packages/recast-navigation-wasm/recast-navigation.idl
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,34 @@ interface duDebugDraw {
};

interface DebugDraw {
unsigned long RGBA(long r, long g, long b, long a);
unsigned long RGBAf(float fr, float fg, float fb, float fa);
unsigned long IntToCol(long i, long a);
void IntToColVector(long i, float[] col);
unsigned long MultCol([Const] unsigned long col, [Const] unsigned long d);
unsigned long DarkenCol(unsigned long col);
unsigned long LerpCol(unsigned long ca, unsigned long cb, unsigned long u);
unsigned long TransCol(unsigned long c, unsigned long a);

void CalcBoxColors(unsigned long[] colors, unsigned long colTop, unsigned long colSide);
void DebugDrawCylinderWire(duDebugDraw dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned long col, [Const] float lineWidth);
void DebugDrawBoxWire(duDebugDraw dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned long col, [Const] float lineWidth);
void DebugDrawArc(duDebugDraw dd, [Const] float x0, [Const] float y0, [Const] float z0, [Const] float x1, [Const] float y1, [Const] float z1, [Const] float h, [Const] float as0, [Const] float as1, unsigned long col, [Const] float lineWidth);
void DebugDrawArrow(duDebugDraw dd, [Const] float x0, [Const] float y0, [Const] float z0, [Const] float x1, [Const] float y1, [Const] float z1, [Const] float as0, [Const] float as1, unsigned long col, [Const] float lineWidth);
void DebugDrawCircle(duDebugDraw dd, [Const] float x, [Const] float y, [Const] float z, [Const] float r, unsigned long col, [Const] float lineWidth);
void DebugDrawCross(duDebugDraw dd, [Const] float x, [Const] float y, [Const] float z, [Const] float size, unsigned long col, [Const] float lineWidth);
void DebugDrawBox(duDebugDraw dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, [Const] unsigned long[] fcol);
void DebugDrawCylinder(duDebugDraw dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned long col);
void DebugDrawGridXZ(duDebugDraw dd, [Const] float ox, [Const] float oy, [Const] float oz, [Const] long w, [Const] long h, [Const] float size, [Const] unsigned long col, [Const] float lineWidth);
void AppendCylinderWire(duDebugDraw dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned long col);
void AppendBoxWire(duDebugDraw dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned long col);
void AppendBoxPoints(duDebugDraw dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned long col);
void AppendArc(duDebugDraw dd, [Const] float x0, [Const] float y0, [Const] float z0, [Const] float x1, [Const] float y1, [Const] float z1, [Const] float h, [Const] float as0, [Const] float as1, unsigned long col);
void AppendArrow(duDebugDraw dd, [Const] float x0, [Const] float y0, [Const] float z0, [Const] float x1, [Const] float y1, [Const] float z1, [Const] float as0, [Const] float as1, unsigned long col);
void AppendCircle(duDebugDraw dd, [Const] float x, [Const] float y, [Const] float z, [Const] float r, unsigned long col);
void AppendCross(duDebugDraw dd, [Const] float x, [Const] float y, [Const] float z, [Const] float size, unsigned long col);
void AppendBox(duDebugDraw dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, [Const] unsigned long[] fcol);
void AppendCylinder(duDebugDraw dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned long col);
};
DebugDraw implements duDebugDraw;

Expand All @@ -1221,11 +1249,26 @@ interface DebugDrawImpl {
void handleVertexWithColor([Const] float x, [Const] float y, [Const] float z, [Const] unsigned long color);
void handleVertexWithColorAndUV([Const] float x, [Const] float y, [Const] float z, [Const] unsigned long color, [Const] float u, [Const] float v);
void handleEnd();

/*
Uncomment this line after the JS examples implement this function, otherwise the error will be thrown:

"a JSImplementation must implement all functions, you forgot DebugDrawImpl::handleAreaToCol."

Also uncomment the `handleAreaToCol()` code in
- `./src/DebugDraw.h`
- `./src/DebugDraw.cpp`
*/
// unsigned long handleAreaToCol(unsigned long area);
};

interface RecastDebugDraw {
void RecastDebugDraw();

void debugDrawTriMesh(duDebugDraw dd, [Const] FloatArray verts, long nverts, [Const] IntArray tris, [Const] FloatArray normals, long ntris, [Const] UnsignedCharArray flags, float texScale);
void debugDrawTriMeshNoFlags(duDebugDraw dd, [Const] FloatArray verts, long nverts, [Const] IntArray tris, [Const] FloatArray normals, long ntris, float texScale);
void debugDrawTriMeshSlope(duDebugDraw dd, [Const] FloatArray verts, long nverts, [Const] IntArray tris, [Const] FloatArray normals, long ntris, float walkableSlopeAngle, float texScale);

void debugDrawHeightfieldSolid(duDebugDraw dd, [Const, Ref] rcHeightfield hf);
void debugDrawHeightfieldWalkable(duDebugDraw dd, [Const, Ref] rcHeightfield hf);

Expand Down Expand Up @@ -1260,3 +1303,9 @@ interface DetourDebugDraw {
void debugDrawTileCacheContours(duDebugDraw dd, [Const, Ref] dtTileCacheContourSet lcset, [Const] float[] orig, [Const] float cs, [Const] float ch);
void debugDrawTileCachePolyMesh(duDebugDraw dd, [Const, Ref] dtTileCachePolyMesh pmesh, [Const] float[] orig, [Const] float cs, [Const] float ch);
};

enum DrawNavMeshFlags {
"DrawNavMeshFlags::DU_DRAWNAVMESH_OFFMESHCONS",
"DrawNavMeshFlags::DU_DRAWNAVMESH_CLOSEDLIST",
"DrawNavMeshFlags::DU_DRAWNAVMESH_COLOR_TILES"
};
140 changes: 140 additions & 0 deletions packages/recast-navigation-wasm/src/DebugDraw/DebugDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,143 @@ void DebugDraw::end()
{
handleEnd();
}

// unsigned int DebugDraw::areaToCol(unsigned int area)
// {
// return handleAreaToCol(area);
// }

unsigned int DebugDraw::RGBA(int r, int g, int b, int a)
{
return duRGBA(r, g, b, a);
}

unsigned int DebugDraw::RGBAf(float fr, float fg, float fb, float fa)
{
return duRGBAf(fr, fg, fb, fa);
}

unsigned int DebugDraw::IntToCol(int i, int a)
{
return duIntToCol(i, a);
}

void DebugDraw::IntToColVector(int i, float *col)
{
return duIntToCol(i, col);
}

unsigned int DebugDraw::MultCol(const unsigned int col, const unsigned int d)
{
return duMultCol(col, d);
}

unsigned int DebugDraw::DarkenCol(unsigned int col)
{
return duDarkenCol(col);
}

unsigned int DebugDraw::LerpCol(unsigned int ca, unsigned int cb, unsigned int u)
{
return duLerpCol(ca, cb, u);
}

unsigned int DebugDraw::TransCol(unsigned int c, unsigned int a)
{
return duTransCol(c, a);
}

void DebugDraw::CalcBoxColors(unsigned int *colors, unsigned int colTop, unsigned int colSide)
{
duCalcBoxColors(colors, colTop, colSide);
}

void DebugDraw::DebugDrawCylinderWire(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col, const float lineWidth)
{
duDebugDrawCylinderWire(dd, minx, miny, minz, maxx, maxy, maxz, col, lineWidth);
}

void DebugDraw::DebugDrawBoxWire(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col, const float lineWidth)
{
duDebugDrawBoxWire(dd, minx, miny, minz, maxx, maxy, maxz, col, lineWidth);
}

void DebugDraw::DebugDrawArc(struct duDebugDraw *dd, const float x0, const float y0, const float z0, const float x1, const float y1, const float z1, const float h, const float as0, const float as1, unsigned int col, const float lineWidth)
{
duDebugDrawArc(dd, x0, y0, z0, x1, y1, z1, h, as0, as1, col, lineWidth);
}

void DebugDraw::DebugDrawArrow(struct duDebugDraw *dd, const float x0, const float y0, const float z0, const float x1, const float y1, const float z1, const float as0, const float as1, unsigned int col, const float lineWidth)
{
duDebugDrawArrow(dd, x0, y0, z0, x1, y1, z1, as0, as1, col, lineWidth);
}

void DebugDraw::DebugDrawCircle(struct duDebugDraw *dd, const float x, const float y, const float z, const float r, unsigned int col, const float lineWidth)
{
duDebugDrawCircle(dd, x, y, z, r, col, lineWidth);
}

void DebugDraw::DebugDrawCross(struct duDebugDraw *dd, const float x, const float y, const float z, const float size, unsigned int col, const float lineWidth)
{
duDebugDrawCross(dd, x, y, z, size, col, lineWidth);
}

void DebugDraw::DebugDrawBox(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, const unsigned int *fcol)
{
duDebugDrawBox(dd, minx, miny, minz, maxx, maxy, maxz, fcol);
}

void DebugDraw::DebugDrawCylinder(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col)
{
duDebugDrawCylinder(dd, minx, miny, minz, maxx, maxy, maxz, col);
}

void DebugDraw::DebugDrawGridXZ(struct duDebugDraw *dd, const float ox, const float oy, const float oz, const int w, const int h, const float size, const unsigned int col, const float lineWidth)
{
duDebugDrawGridXZ(dd, ox, oy, oz, w, h, size, col, lineWidth);
}

void DebugDraw::AppendCylinderWire(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col)
{
duAppendCylinderWire(dd, minx, miny, minz, maxx, maxy, maxz, col);
}

void DebugDraw::AppendBoxWire(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col)
{
duAppendBoxWire(dd, minx, miny, minz, maxx, maxy, maxz, col);
}

void DebugDraw::AppendBoxPoints(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col)
{
duAppendBoxPoints(dd, minx, miny, minz, maxx, maxy, maxz, col);
}

void DebugDraw::AppendArc(struct duDebugDraw *dd, const float x0, const float y0, const float z0, const float x1, const float y1, const float z1, const float h, const float as0, const float as1, unsigned int col)
{
duAppendArc(dd, x0, y0, z0, x1, y1, z1, h, as0, as1, col);
}

void DebugDraw::AppendArrow(struct duDebugDraw *dd, const float x0, const float y0, const float z0, const float x1, const float y1, const float z1, const float as0, const float as1, unsigned int col)
{
duAppendArrow(dd, x0, y0, z0, x1, y1, z1, as0, as1, col);
}

void DebugDraw::AppendCircle(struct duDebugDraw *dd, const float x, const float y, const float z, const float r, unsigned int col)
{
duAppendCircle(dd, x, y, z, r, col);
}

void DebugDraw::AppendCross(struct duDebugDraw *dd, const float x, const float y, const float z, const float size, unsigned int col)
{
duAppendCross(dd, x, y, z, size, col);
}

void DebugDraw::AppendBox(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, const unsigned int *fcol)
{
duAppendBox(dd, minx, miny, minz, maxx, maxy, maxz, fcol);
}

void DebugDraw::AppendCylinder(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col)
{
duAppendCylinder(dd, minx, miny, minz, maxx, maxy, maxz, col);
}
31 changes: 31 additions & 0 deletions packages/recast-navigation-wasm/src/DebugDraw/DebugDraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,42 @@ class DebugDraw : public duDebugDraw
virtual void vertex(const float *pos, unsigned int color, const float *uv);
virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v);
virtual void end();
// virtual unsigned int areaToCol(unsigned int area);

virtual void handleDepthMask(bool state) = 0;
virtual void handleTexture(bool state) = 0;
virtual void handleBegin(duDebugDrawPrimitives prim, float size = 1.0f) = 0;
virtual void handleVertexWithColor(const float x, const float y, const float z, unsigned int color) = 0;
virtual void handleVertexWithColorAndUV(const float x, const float y, const float z, unsigned int color, const float u, const float v) = 0;
virtual void handleEnd() = 0;
// virtual unsigned int handleAreaToCol(unsigned int area) = 0;

unsigned int RGBA(int r, int g, int b, int a);
unsigned int RGBAf(float fr, float fg, float fb, float fa);
unsigned int IntToCol(int i, int a);
void IntToColVector(int i, float *col);
unsigned int MultCol(const unsigned int col, const unsigned int d);
unsigned int DarkenCol(unsigned int col);
unsigned int LerpCol(unsigned int ca, unsigned int cb, unsigned int u);
unsigned int TransCol(unsigned int c, unsigned int a);

void CalcBoxColors(unsigned int *colors, unsigned int colTop, unsigned int colSide);
void DebugDrawCylinderWire(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col, const float lineWidth);
void DebugDrawBoxWire(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col, const float lineWidth);
void DebugDrawArc(struct duDebugDraw *dd, const float x0, const float y0, const float z0, const float x1, const float y1, const float z1, const float h, const float as0, const float as1, unsigned int col, const float lineWidth);
void DebugDrawArrow(struct duDebugDraw *dd, const float x0, const float y0, const float z0, const float x1, const float y1, const float z1, const float as0, const float as1, unsigned int col, const float lineWidth);
void DebugDrawCircle(struct duDebugDraw *dd, const float x, const float y, const float z, const float r, unsigned int col, const float lineWidth);
void DebugDrawCross(struct duDebugDraw *dd, const float x, const float y, const float z, const float size, unsigned int col, const float lineWidth);
void DebugDrawBox(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, const unsigned int *fcol);
void DebugDrawCylinder(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col);
void DebugDrawGridXZ(struct duDebugDraw *dd, const float ox, const float oy, const float oz, const int w, const int h, const float size, const unsigned int col, const float lineWidth);
void AppendCylinderWire(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col);
void AppendBoxWire(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col);
void AppendBoxPoints(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col);
void AppendArc(struct duDebugDraw *dd, const float x0, const float y0, const float z0, const float x1, const float y1, const float z1, const float h, const float as0, const float as1, unsigned int col);
void AppendArrow(struct duDebugDraw *dd, const float x0, const float y0, const float z0, const float x1, const float y1, const float z1, const float as0, const float as1, unsigned int col);
void AppendCircle(struct duDebugDraw *dd, const float x, const float y, const float z, const float r, unsigned int col);
void AppendCross(struct duDebugDraw *dd, const float x, const float y, const float z, const float size, unsigned int col);
void AppendBox(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, const unsigned int *fcol);
void AppendCylinder(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col);
};
15 changes: 15 additions & 0 deletions packages/recast-navigation-wasm/src/DebugDraw/RecastDebugDraw.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
#include "RecastDebugDraw.h"

void RecastDebugDraw::debugDrawTriMesh(duDebugDraw *dd, const FloatArray *verts, int nverts, const IntArray *tris, const FloatArray *normals, int ntris, const UnsignedCharArray *flags, const float texScale)
{
duDebugDrawTriMesh(dd, verts->data, nverts, tris->data, normals->data, ntris, flags->data, texScale);
}

void RecastDebugDraw::debugDrawTriMeshNoFlags(duDebugDraw *dd, const FloatArray *verts, int nverts, const IntArray *tris, const FloatArray *normals, int ntris, const float texScale)
{
duDebugDrawTriMesh(dd, verts->data, nverts, tris->data, normals->data, ntris, nullptr, texScale);
}

void RecastDebugDraw::debugDrawTriMeshSlope(duDebugDraw *dd, const FloatArray *verts, int nverts, const IntArray *tris, const FloatArray *normals, int ntris, const float walkableSlopeAngle, const float texScale)
{
duDebugDrawTriMeshSlope(dd, verts->data, nverts, tris->data, normals->data, ntris, walkableSlopeAngle, texScale);
}

void RecastDebugDraw::debugDrawHeightfieldSolid(duDebugDraw *dd, const rcHeightfield &hf)
{
duDebugDrawHeightfieldSolid(dd, hf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
#include "../../recastnavigation/DebugUtils/Include/DebugDraw.h"
#include "../../recastnavigation/DebugUtils/Include/RecastDebugDraw.h"

#include "../Arrays.h"

class RecastDebugDraw
{
public:
void debugDrawTriMesh(duDebugDraw *dd, const FloatArray *verts, int nverts, const IntArray *tris, const FloatArray *normals, int ntris, const UnsignedCharArray *flags, const float texScale);
void debugDrawTriMeshNoFlags(duDebugDraw *dd, const FloatArray *verts, int nverts, const IntArray *tris, const FloatArray *normals, int ntris, const float texScale);
void debugDrawTriMeshSlope(duDebugDraw *dd, const FloatArray *verts, int nverts, const IntArray *tris, const FloatArray *normals, int ntris, const float walkableSlopeAngle, const float texScale);

void debugDrawHeightfieldSolid(duDebugDraw *dd, const rcHeightfield &hf);
void debugDrawHeightfieldWalkable(duDebugDraw *dd, const rcHeightfield &hf);
void debugDrawCompactHeightfieldSolid(duDebugDraw *dd, const rcCompactHeightfield &chf);
Expand Down