2011-09-20 16:24:50 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2011 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Sergey Sharybin
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "recast-capi.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include "Recast.h"
|
|
|
|
|
2011-09-29 21:38:57 +00:00
|
|
|
static rcContext *sctx;
|
|
|
|
|
|
|
|
#define INIT_SCTX() \
|
|
|
|
if (sctx == NULL) sctx = new rcContext(false)
|
|
|
|
|
2011-09-20 16:24:50 +00:00
|
|
|
int recast_buildMeshAdjacency(unsigned short* polys, const int npolys,
|
|
|
|
const int nverts, const int vertsPerPoly)
|
|
|
|
{
|
|
|
|
return (int) buildMeshAdjacency(polys, npolys, nverts, vertsPerPoly);
|
|
|
|
}
|
2011-09-27 09:09:43 +00:00
|
|
|
|
|
|
|
void recast_calcBounds(const float *verts, int nv, float *bmin, float *bmax)
|
|
|
|
{
|
|
|
|
rcCalcBounds(verts, nv, bmin, bmax);
|
|
|
|
}
|
|
|
|
|
|
|
|
void recast_calcGridSize(const float *bmin, const float *bmax, float cs, int *w, int *h)
|
|
|
|
{
|
|
|
|
rcCalcGridSize(bmin, bmax, cs, w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct recast_heightfield *recast_newHeightfield(void)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
return (struct recast_heightfield *) rcAllocHeightfield();
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void recast_destroyHeightfield(struct recast_heightfield *heightfield)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
rcFreeHeightField((rcHeightfield *) heightfield);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int recast_createHeightfield(struct recast_heightfield *hf, int width, int height,
|
|
|
|
const float *bmin, const float* bmax, float cs, float ch)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
INIT_SCTX();
|
|
|
|
return rcCreateHeightfield(sctx, *(rcHeightfield *)hf, width, height, bmin, bmax, cs, ch);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void recast_markWalkableTriangles(const float walkableSlopeAngle,const float *verts, int nv,
|
2016-04-05 18:34:00 +00:00
|
|
|
const int *tris, int nt, unsigned char *areas)
|
2011-09-27 09:09:43 +00:00
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
INIT_SCTX();
|
2016-04-05 18:34:00 +00:00
|
|
|
rcMarkWalkableTriangles(sctx, walkableSlopeAngle, verts, nv, tris, nt, areas);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:34:00 +00:00
|
|
|
void recast_clearUnwalkableTriangles(const float walkableSlopeAngle, const float* verts, int nv,
|
|
|
|
const int* tris, int nt, unsigned char* areas)
|
2011-09-27 09:09:43 +00:00
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
INIT_SCTX();
|
2016-04-05 18:34:00 +00:00
|
|
|
rcClearUnwalkableTriangles(sctx, walkableSlopeAngle, verts, nv, tris, nt, areas);
|
|
|
|
}
|
|
|
|
|
|
|
|
int recast_addSpan(struct recast_heightfield *hf, const int x, const int y,
|
|
|
|
const unsigned short smin, const unsigned short smax,
|
|
|
|
const unsigned char area, const int flagMergeThr)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
return rcAddSpan(sctx, *(rcHeightfield *) hf, x, y, smin, smax, area, flagMergeThr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int recast_rasterizeTriangle(const float *v0, const float *v1, const float *v2,
|
|
|
|
const unsigned char area, struct recast_heightfield *solid,
|
|
|
|
const int flagMergeThr)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
return rcRasterizeTriangle(sctx, v0, v1, v2, area, *(rcHeightfield *) solid, flagMergeThr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int recast_rasterizeTriangles(const float *verts, const int nv, const int *tris,
|
|
|
|
const unsigned char *areas, const int nt, struct recast_heightfield *solid,
|
|
|
|
const int flagMergeThr)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
return rcRasterizeTriangles(sctx, verts, nv, tris, areas, nt, *(rcHeightfield *) solid, flagMergeThr);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void recast_filterLedgeSpans(const int walkableHeight, const int walkableClimb,
|
|
|
|
struct recast_heightfield *solid)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
INIT_SCTX();
|
|
|
|
rcFilterLedgeSpans(sctx, walkableHeight, walkableClimb, *(rcHeightfield *) solid);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void recast_filterWalkableLowHeightSpans(int walkableHeight, struct recast_heightfield *solid)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
INIT_SCTX();
|
|
|
|
rcFilterWalkableLowHeightSpans(sctx, walkableHeight, *(rcHeightfield *) solid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void recast_filterLowHangingWalkableObstacles(const int walkableClimb, struct recast_heightfield *solid)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
rcFilterLowHangingWalkableObstacles(sctx, walkableClimb, *(rcHeightfield *) solid);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:34:00 +00:00
|
|
|
int recast_getHeightFieldSpanCount(struct recast_heightfield *hf)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
return rcGetHeightFieldSpanCount(sctx, *(rcHeightfield *) hf);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct recast_heightfieldLayerSet *recast_newHeightfieldLayerSet(void)
|
|
|
|
{
|
|
|
|
return (struct recast_heightfieldLayerSet *) rcAllocHeightfieldLayerSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
void recast_destroyHeightfieldLayerSet(struct recast_heightfieldLayerSet *lset)
|
|
|
|
{
|
|
|
|
rcFreeHeightfieldLayerSet( (rcHeightfieldLayerSet *) lset);
|
|
|
|
}
|
|
|
|
|
2011-09-27 09:09:43 +00:00
|
|
|
struct recast_compactHeightfield *recast_newCompactHeightfield(void)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
return (struct recast_compactHeightfield *) rcAllocCompactHeightfield();
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void recast_destroyCompactHeightfield(struct recast_compactHeightfield *compactHeightfield)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
rcFreeCompactHeightfield( (rcCompactHeightfield *) compactHeightfield);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int recast_buildCompactHeightfield(const int walkableHeight, const int walkableClimb,
|
2011-09-29 21:38:57 +00:00
|
|
|
struct recast_heightfield *hf, struct recast_compactHeightfield *chf)
|
2011-09-27 09:09:43 +00:00
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
INIT_SCTX();
|
|
|
|
return rcBuildCompactHeightfield(sctx, walkableHeight, walkableClimb,
|
|
|
|
*(rcHeightfield *) hf, *(rcCompactHeightfield *) chf);
|
|
|
|
}
|
2011-09-27 09:09:43 +00:00
|
|
|
|
2011-09-29 21:38:57 +00:00
|
|
|
int recast_erodeWalkableArea(int radius, struct recast_compactHeightfield *chf)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
return rcErodeWalkableArea(sctx, radius, *(rcCompactHeightfield *) chf);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:34:00 +00:00
|
|
|
int recast_medianFilterWalkableArea(struct recast_compactHeightfield *chf)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
return rcMedianFilterWalkableArea(sctx, *(rcCompactHeightfield *) chf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void recast_markBoxArea(const float *bmin, const float *bmax, unsigned char areaId,
|
|
|
|
struct recast_compactHeightfield *chf)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
rcMarkBoxArea(sctx, bmin, bmax, areaId, *(rcCompactHeightfield *) chf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void recast_markConvexPolyArea(const float* verts, const int nverts,
|
|
|
|
const float hmin, const float hmax, unsigned char areaId,
|
|
|
|
struct recast_compactHeightfield *chf)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
rcMarkConvexPolyArea(sctx, verts, nverts, hmin, hmax, areaId, *(rcCompactHeightfield *) chf);
|
|
|
|
}
|
|
|
|
|
|
|
|
int recast_offsetPoly(const float* verts, const int nverts,
|
|
|
|
const float offset, float *outVerts, const int maxOutVerts)
|
|
|
|
{
|
|
|
|
return rcOffsetPoly(verts, nverts, offset, outVerts, maxOutVerts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void recast_markCylinderArea(const float* pos, const float r, const float h,
|
|
|
|
unsigned char areaId, struct recast_compactHeightfield *chf)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
rcMarkCylinderArea(sctx, pos, r, h, areaId, *(rcCompactHeightfield *) chf);
|
|
|
|
}
|
|
|
|
|
2011-09-27 09:09:43 +00:00
|
|
|
int recast_buildDistanceField(struct recast_compactHeightfield *chf)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
INIT_SCTX();
|
|
|
|
return rcBuildDistanceField(sctx, *(rcCompactHeightfield *) chf);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:34:00 +00:00
|
|
|
int recast_buildRegions(struct recast_compactHeightfield *chf,
|
|
|
|
const int borderSize, const int minRegionArea, const int mergeRegionArea)
|
2011-09-27 09:09:43 +00:00
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
INIT_SCTX();
|
|
|
|
return rcBuildRegions(sctx, *(rcCompactHeightfield *) chf, borderSize,
|
2016-04-05 18:34:00 +00:00
|
|
|
minRegionArea, mergeRegionArea);
|
|
|
|
}
|
|
|
|
|
|
|
|
int recast_buildLayerRegions(struct recast_compactHeightfield *chf,
|
|
|
|
const int borderSize, const int minRegionArea)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
return rcBuildLayerRegions(sctx, *(rcCompactHeightfield *) chf, borderSize,
|
|
|
|
minRegionArea);
|
|
|
|
}
|
|
|
|
|
|
|
|
int recast_buildRegionsMonotone(struct recast_compactHeightfield *chf,
|
|
|
|
const int borderSize, const int minRegionArea, const int mergeRegionArea)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
return rcBuildRegionsMonotone(sctx, *(rcCompactHeightfield *) chf, borderSize,
|
|
|
|
minRegionArea, mergeRegionArea);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct recast_contourSet *recast_newContourSet(void)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
return (struct recast_contourSet *) rcAllocContourSet();
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void recast_destroyContourSet(struct recast_contourSet *contourSet)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
rcFreeContourSet((rcContourSet *) contourSet);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int recast_buildContours(struct recast_compactHeightfield *chf,
|
2016-04-05 18:34:00 +00:00
|
|
|
const float maxError, const int maxEdgeLen, struct recast_contourSet *cset,
|
|
|
|
const int buildFlags)
|
2011-09-27 09:09:43 +00:00
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
INIT_SCTX();
|
2016-04-05 18:34:00 +00:00
|
|
|
return rcBuildContours(sctx, *(rcCompactHeightfield *) chf, maxError, maxEdgeLen, *(rcContourSet *) cset, buildFlags);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct recast_polyMesh *recast_newPolyMesh(void)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
return (recast_polyMesh *) rcAllocPolyMesh();
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void recast_destroyPolyMesh(struct recast_polyMesh *polyMesh)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
rcFreePolyMesh((rcPolyMesh *) polyMesh);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:34:00 +00:00
|
|
|
int recast_buildPolyMesh(struct recast_contourSet *cset, const int nvp, struct recast_polyMesh *mesh)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
return rcBuildPolyMesh(sctx, *(rcContourSet *) cset, nvp, *(rcPolyMesh *) mesh);
|
|
|
|
}
|
|
|
|
|
|
|
|
int recast_mergePolyMeshes(struct recast_polyMesh **meshes, const int nmeshes, struct recast_polyMesh *mesh)
|
2011-09-27 09:09:43 +00:00
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
INIT_SCTX();
|
2016-04-05 18:34:00 +00:00
|
|
|
return rcMergePolyMeshes(sctx, (rcPolyMesh **) meshes, nmeshes, *(rcPolyMesh *) mesh);
|
|
|
|
}
|
|
|
|
|
|
|
|
int recast_copyPolyMesh(const struct recast_polyMesh *src, struct recast_polyMesh *dst)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
return rcCopyPolyMesh(sctx, *(const rcPolyMesh *) src, *(rcPolyMesh *) dst);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned short *recast_polyMeshGetVerts(struct recast_polyMesh *mesh, int *nverts)
|
|
|
|
{
|
|
|
|
rcPolyMesh *pmesh = (rcPolyMesh *)mesh;
|
|
|
|
|
|
|
|
if (nverts)
|
|
|
|
*nverts = pmesh->nverts;
|
|
|
|
|
|
|
|
return pmesh->verts;
|
|
|
|
}
|
|
|
|
|
|
|
|
void recast_polyMeshGetBoundbox(struct recast_polyMesh *mesh, float *bmin, float *bmax)
|
|
|
|
{
|
|
|
|
rcPolyMesh *pmesh = (rcPolyMesh *)mesh;
|
|
|
|
|
|
|
|
if (bmin) {
|
|
|
|
bmin[0] = pmesh->bmin[0];
|
|
|
|
bmin[1] = pmesh->bmin[1];
|
|
|
|
bmin[2] = pmesh->bmin[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bmax) {
|
|
|
|
bmax[0] = pmesh->bmax[0];
|
|
|
|
bmax[1] = pmesh->bmax[1];
|
|
|
|
bmax[2] = pmesh->bmax[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void recast_polyMeshGetCell(struct recast_polyMesh *mesh, float *cs, float *ch)
|
|
|
|
{
|
|
|
|
rcPolyMesh *pmesh = (rcPolyMesh *)mesh;
|
|
|
|
|
|
|
|
if (cs)
|
|
|
|
*cs = pmesh->cs;
|
|
|
|
|
|
|
|
if (ch)
|
|
|
|
*ch = pmesh->ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned short *recast_polyMeshGetPolys(struct recast_polyMesh *mesh, int *npolys, int *nvp)
|
|
|
|
{
|
|
|
|
rcPolyMesh *pmesh = (rcPolyMesh *)mesh;
|
|
|
|
|
|
|
|
if (npolys)
|
|
|
|
*npolys = pmesh->npolys;
|
|
|
|
|
|
|
|
if (nvp)
|
|
|
|
*nvp = pmesh->nvp;
|
|
|
|
|
|
|
|
return pmesh->polys;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct recast_polyMeshDetail *recast_newPolyMeshDetail(void)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
return (struct recast_polyMeshDetail *) rcAllocPolyMeshDetail();
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void recast_destroyPolyMeshDetail(struct recast_polyMeshDetail *polyMeshDetail)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
rcFreePolyMeshDetail((rcPolyMeshDetail *) polyMeshDetail);
|
2011-09-27 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int recast_buildPolyMeshDetail(const struct recast_polyMesh *mesh, const struct recast_compactHeightfield *chf,
|
|
|
|
const float sampleDist, const float sampleMaxError, struct recast_polyMeshDetail *dmesh)
|
|
|
|
{
|
2011-09-29 21:38:57 +00:00
|
|
|
INIT_SCTX();
|
|
|
|
return rcBuildPolyMeshDetail(sctx, *(rcPolyMesh *) mesh, *(rcCompactHeightfield *) chf,
|
2011-09-27 09:09:43 +00:00
|
|
|
sampleDist, sampleMaxError, *(rcPolyMeshDetail *) dmesh);
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:34:00 +00:00
|
|
|
int recast_mergePolyMeshDetails(struct recast_polyMeshDetail **meshes, const int nmeshes, struct recast_polyMeshDetail *mesh)
|
|
|
|
{
|
|
|
|
INIT_SCTX();
|
|
|
|
return rcMergePolyMeshDetails(sctx, (rcPolyMeshDetail **) meshes, nmeshes, *(rcPolyMeshDetail *) mesh);
|
|
|
|
}
|
|
|
|
|
2011-09-27 09:09:43 +00:00
|
|
|
float *recast_polyMeshDetailGetVerts(struct recast_polyMeshDetail *mesh, int *nverts)
|
|
|
|
{
|
|
|
|
rcPolyMeshDetail *dmesh = (rcPolyMeshDetail *)mesh;
|
|
|
|
|
|
|
|
if (nverts)
|
|
|
|
*nverts = dmesh->nverts;
|
|
|
|
|
|
|
|
return dmesh->verts;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char *recast_polyMeshDetailGetTris(struct recast_polyMeshDetail *mesh, int *ntris)
|
|
|
|
{
|
|
|
|
rcPolyMeshDetail *dmesh = (rcPolyMeshDetail *)mesh;
|
|
|
|
|
|
|
|
if (ntris)
|
|
|
|
*ntris = dmesh->ntris;
|
|
|
|
|
|
|
|
return dmesh->tris;
|
|
|
|
}
|
|
|
|
|
2011-09-29 21:38:57 +00:00
|
|
|
unsigned int *recast_polyMeshDetailGetMeshes(struct recast_polyMeshDetail *mesh, int *nmeshes)
|
2011-09-27 09:09:43 +00:00
|
|
|
{
|
|
|
|
rcPolyMeshDetail *dmesh = (rcPolyMeshDetail *)mesh;
|
|
|
|
|
|
|
|
if (nmeshes)
|
|
|
|
*nmeshes = dmesh->nmeshes;
|
|
|
|
|
|
|
|
return dmesh->meshes;
|
|
|
|
}
|
2011-09-29 21:38:57 +00:00
|
|
|
|