forked from mirror/DotRecast
for unity3d
This commit is contained in:
parent
2842c65bb7
commit
12dfb27538
|
@ -75,26 +75,26 @@ namespace DotRecast.Detour.Dynamic.Io
|
|||
{
|
||||
VoxelFile f = new VoxelFile();
|
||||
f.version = 1;
|
||||
f.partition = config.partition;
|
||||
f.filterLowHangingObstacles = config.filterLowHangingObstacles;
|
||||
f.filterLedgeSpans = config.filterLedgeSpans;
|
||||
f.filterWalkableLowHeightSpans = config.filterWalkableLowHeightSpans;
|
||||
f.walkableRadius = config.walkableRadiusWorld;
|
||||
f.walkableHeight = config.walkableHeightWorld;
|
||||
f.walkableClimb = config.walkableClimbWorld;
|
||||
f.walkableSlopeAngle = config.walkableSlopeAngle;
|
||||
f.cellSize = config.cs;
|
||||
f.maxSimplificationError = config.maxSimplificationError;
|
||||
f.maxEdgeLen = config.maxEdgeLenWorld;
|
||||
f.minRegionArea = config.minRegionAreaWorld;
|
||||
f.regionMergeArea = config.mergeRegionAreaWorld;
|
||||
f.vertsPerPoly = config.maxVertsPerPoly;
|
||||
f.buildMeshDetail = config.buildMeshDetail;
|
||||
f.detailSampleDistance = config.detailSampleDist;
|
||||
f.detailSampleMaxError = config.detailSampleMaxError;
|
||||
f.useTiles = config.useTiles;
|
||||
f.tileSizeX = config.tileSizeX;
|
||||
f.tileSizeZ = config.tileSizeZ;
|
||||
f.partition = config.Partition;
|
||||
f.filterLowHangingObstacles = config.FilterLowHangingObstacles;
|
||||
f.filterLedgeSpans = config.FilterLedgeSpans;
|
||||
f.filterWalkableLowHeightSpans = config.FilterWalkableLowHeightSpans;
|
||||
f.walkableRadius = config.WalkableRadiusWorld;
|
||||
f.walkableHeight = config.WalkableHeightWorld;
|
||||
f.walkableClimb = config.WalkableClimbWorld;
|
||||
f.walkableSlopeAngle = config.WalkableSlopeAngle;
|
||||
f.cellSize = config.Cs;
|
||||
f.maxSimplificationError = config.MaxSimplificationError;
|
||||
f.maxEdgeLen = config.MaxEdgeLenWorld;
|
||||
f.minRegionArea = config.MinRegionAreaWorld;
|
||||
f.regionMergeArea = config.MergeRegionAreaWorld;
|
||||
f.vertsPerPoly = config.MaxVertsPerPoly;
|
||||
f.buildMeshDetail = config.BuildMeshDetail;
|
||||
f.detailSampleDistance = config.DetailSampleDist;
|
||||
f.detailSampleMaxError = config.DetailSampleMaxError;
|
||||
f.useTiles = config.UseTiles;
|
||||
f.tileSizeX = config.TileSizeX;
|
||||
f.tileSizeZ = config.TileSizeZ;
|
||||
f.bounds = new float[]
|
||||
{
|
||||
float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity,
|
||||
|
|
|
@ -22,96 +22,98 @@ using System;
|
|||
|
||||
namespace DotRecast.Recast
|
||||
{
|
||||
/// Specifies a configuration to use when performing Recast builds.
|
||||
/// @ingroup recast
|
||||
public class RcConfig
|
||||
{
|
||||
public readonly int partition;
|
||||
public readonly int Partition;
|
||||
|
||||
public readonly bool useTiles;
|
||||
public readonly bool UseTiles;
|
||||
|
||||
/** The width/depth size of tile's on the xz-plane. [Limit: >= 0] [Units: vx] **/
|
||||
public readonly int tileSizeX;
|
||||
public readonly int TileSizeX;
|
||||
|
||||
public readonly int tileSizeZ;
|
||||
public readonly int TileSizeZ;
|
||||
|
||||
/** The xz-plane cell size to use for fields. [Limit: > 0] [Units: wu] **/
|
||||
public readonly float cs;
|
||||
public readonly float Cs;
|
||||
|
||||
/** The y-axis cell size to use for fields. [Limit: > 0] [Units: wu] **/
|
||||
public readonly float ch;
|
||||
public readonly float Ch;
|
||||
|
||||
/** The maximum slope that is considered walkable. [Limits: 0 <= value < 90] [Units: Degrees] **/
|
||||
public readonly float walkableSlopeAngle;
|
||||
public readonly float WalkableSlopeAngle;
|
||||
|
||||
/**
|
||||
* Minimum floor to 'ceiling' height that will still allow the floor area to be considered walkable. [Limit: >= 3]
|
||||
* [Units: vx]
|
||||
**/
|
||||
public readonly int walkableHeight;
|
||||
public readonly int WalkableHeight;
|
||||
|
||||
/** Maximum ledge height that is considered to still be traversable. [Limit: >=0] [Units: vx] **/
|
||||
public readonly int walkableClimb;
|
||||
public readonly int WalkableClimb;
|
||||
|
||||
/**
|
||||
* The distance to erode/shrink the walkable area of the heightfield away from obstructions. [Limit: >=0] [Units:
|
||||
* vx]
|
||||
**/
|
||||
public readonly int walkableRadius;
|
||||
public readonly int WalkableRadius;
|
||||
|
||||
/** The maximum allowed length for contour edges along the border of the mesh. [Limit: >=0] [Units: vx] **/
|
||||
public readonly int maxEdgeLen;
|
||||
public readonly int MaxEdgeLen;
|
||||
|
||||
/**
|
||||
* The maximum distance a simplfied contour's border edges should deviate the original raw contour. [Limit: >=0]
|
||||
* [Units: vx]
|
||||
**/
|
||||
public readonly float maxSimplificationError;
|
||||
public readonly float MaxSimplificationError;
|
||||
|
||||
/** The minimum number of cells allowed to form isolated island areas. [Limit: >=0] [Units: vx] **/
|
||||
public readonly int minRegionArea;
|
||||
public readonly int MinRegionArea;
|
||||
|
||||
/**
|
||||
* Any regions with a span count smaller than this value will, if possible, be merged with larger regions. [Limit:
|
||||
* >=0] [Units: vx]
|
||||
**/
|
||||
public readonly int mergeRegionArea;
|
||||
public readonly int MergeRegionArea;
|
||||
|
||||
/**
|
||||
* The maximum number of vertices allowed for polygons generated during the contour to polygon conversion process.
|
||||
* [Limit: >= 3]
|
||||
**/
|
||||
public readonly int maxVertsPerPoly;
|
||||
public readonly int MaxVertsPerPoly;
|
||||
|
||||
/**
|
||||
* Sets the sampling distance to use when generating the detail mesh. (For height detail only.) [Limits: 0 or >=
|
||||
* 0.9] [Units: wu]
|
||||
**/
|
||||
public readonly float detailSampleDist;
|
||||
public readonly float DetailSampleDist;
|
||||
|
||||
/**
|
||||
* The maximum distance the detail mesh surface should deviate from heightfield data. (For height detail only.)
|
||||
* [Limit: >=0] [Units: wu]
|
||||
**/
|
||||
public readonly float detailSampleMaxError;
|
||||
public readonly float DetailSampleMaxError;
|
||||
|
||||
public readonly RcAreaModification walkableAreaMod;
|
||||
public readonly bool filterLowHangingObstacles;
|
||||
public readonly bool filterLedgeSpans;
|
||||
public readonly bool filterWalkableLowHeightSpans;
|
||||
public readonly RcAreaModification WalkableAreaMod;
|
||||
public readonly bool FilterLowHangingObstacles;
|
||||
public readonly bool FilterLedgeSpans;
|
||||
public readonly bool FilterWalkableLowHeightSpans;
|
||||
|
||||
/** Set to false to disable building detailed mesh **/
|
||||
public readonly bool buildMeshDetail;
|
||||
public readonly bool BuildMeshDetail;
|
||||
|
||||
/** The size of the non-navigable border around the heightfield. [Limit: >=0] [Units: vx] **/
|
||||
public readonly int borderSize;
|
||||
public readonly int BorderSize;
|
||||
|
||||
/** Set of original settings passed in world units */
|
||||
public readonly float minRegionAreaWorld;
|
||||
public readonly float MinRegionAreaWorld;
|
||||
|
||||
public readonly float mergeRegionAreaWorld;
|
||||
public readonly float walkableHeightWorld;
|
||||
public readonly float walkableClimbWorld;
|
||||
public readonly float walkableRadiusWorld;
|
||||
public readonly float maxEdgeLenWorld;
|
||||
public readonly float MergeRegionAreaWorld;
|
||||
public readonly float WalkableHeightWorld;
|
||||
public readonly float WalkableClimbWorld;
|
||||
public readonly float WalkableRadiusWorld;
|
||||
public readonly float MaxEdgeLenWorld;
|
||||
|
||||
/**
|
||||
* Non-tiled build configuration
|
||||
|
@ -146,35 +148,35 @@ namespace DotRecast.Recast
|
|||
float mergeRegionArea, float edgeMaxLen, float edgeMaxError, int vertsPerPoly, bool buildMeshDetail,
|
||||
float detailSampleDist, float detailSampleMaxError, RcAreaModification walkableAreaMod)
|
||||
{
|
||||
this.useTiles = useTiles;
|
||||
this.tileSizeX = tileSizeX;
|
||||
this.tileSizeZ = tileSizeZ;
|
||||
this.borderSize = borderSize;
|
||||
this.partition = RcPartitionType.Of(partition).Value;
|
||||
cs = cellSize;
|
||||
ch = cellHeight;
|
||||
walkableSlopeAngle = agentMaxSlope;
|
||||
walkableHeight = (int)Math.Ceiling(agentHeight / ch);
|
||||
walkableHeightWorld = agentHeight;
|
||||
walkableClimb = (int)Math.Floor(agentMaxClimb / ch);
|
||||
walkableClimbWorld = agentMaxClimb;
|
||||
walkableRadius = (int)Math.Ceiling(agentRadius / cs);
|
||||
walkableRadiusWorld = agentRadius;
|
||||
this.minRegionArea = (int)Math.Round(minRegionArea / (cs * cs));
|
||||
minRegionAreaWorld = minRegionArea;
|
||||
this.mergeRegionArea = (int)Math.Round(mergeRegionArea / (cs * cs));
|
||||
mergeRegionAreaWorld = mergeRegionArea;
|
||||
maxEdgeLen = (int)(edgeMaxLen / cellSize);
|
||||
maxEdgeLenWorld = edgeMaxLen;
|
||||
maxSimplificationError = edgeMaxError;
|
||||
maxVertsPerPoly = vertsPerPoly;
|
||||
this.detailSampleDist = detailSampleDist < 0.9f ? 0 : cellSize * detailSampleDist;
|
||||
this.detailSampleMaxError = cellHeight * detailSampleMaxError;
|
||||
this.walkableAreaMod = walkableAreaMod;
|
||||
this.filterLowHangingObstacles = filterLowHangingObstacles;
|
||||
this.filterLedgeSpans = filterLedgeSpans;
|
||||
this.filterWalkableLowHeightSpans = filterWalkableLowHeightSpans;
|
||||
this.buildMeshDetail = buildMeshDetail;
|
||||
UseTiles = useTiles;
|
||||
TileSizeX = tileSizeX;
|
||||
TileSizeZ = tileSizeZ;
|
||||
BorderSize = borderSize;
|
||||
Partition = RcPartitionType.Of(partition).Value;
|
||||
Cs = cellSize;
|
||||
Ch = cellHeight;
|
||||
WalkableSlopeAngle = agentMaxSlope;
|
||||
WalkableHeight = (int)Math.Ceiling(agentHeight / Ch);
|
||||
WalkableHeightWorld = agentHeight;
|
||||
WalkableClimb = (int)Math.Floor(agentMaxClimb / Ch);
|
||||
WalkableClimbWorld = agentMaxClimb;
|
||||
WalkableRadius = (int)Math.Ceiling(agentRadius / Cs);
|
||||
WalkableRadiusWorld = agentRadius;
|
||||
MinRegionArea = (int)Math.Round(minRegionArea / (Cs * Cs));
|
||||
MinRegionAreaWorld = minRegionArea;
|
||||
MergeRegionArea = (int)Math.Round(mergeRegionArea / (Cs * Cs));
|
||||
MergeRegionAreaWorld = mergeRegionArea;
|
||||
MaxEdgeLen = (int)(edgeMaxLen / cellSize);
|
||||
MaxEdgeLenWorld = edgeMaxLen;
|
||||
MaxSimplificationError = edgeMaxError;
|
||||
MaxVertsPerPoly = vertsPerPoly;
|
||||
DetailSampleDist = detailSampleDist < 0.9f ? 0 : cellSize * detailSampleDist;
|
||||
DetailSampleMaxError = cellHeight * detailSampleMaxError;
|
||||
WalkableAreaMod = walkableAreaMod;
|
||||
FilterLowHangingObstacles = filterLowHangingObstacles;
|
||||
FilterLedgeSpans = filterLedgeSpans;
|
||||
FilterWalkableLowHeightSpans = filterWalkableLowHeightSpans;
|
||||
BuildMeshDetail = buildMeshDetail;
|
||||
}
|
||||
|
||||
public static int CalcBorder(float agentRadius, float cs)
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace DotRecast.Recast
|
|||
{
|
||||
RcVec3f bmin = geom.GetMeshBoundsMin();
|
||||
RcVec3f bmax = geom.GetMeshBoundsMax();
|
||||
Recast.CalcTileCount(bmin, bmax, cfg.cs, cfg.tileSizeX, cfg.tileSizeZ, out var tw, out var th);
|
||||
Recast.CalcTileCount(bmin, bmax, cfg.Cs, cfg.TileSizeX, cfg.TileSizeZ, out var tw, out var th);
|
||||
List<RecastBuilderResult> results = new List<RecastBuilderResult>();
|
||||
if (null != taskFactory)
|
||||
{
|
||||
|
@ -64,7 +64,7 @@ namespace DotRecast.Recast
|
|||
{
|
||||
RcVec3f bmin = geom.GetMeshBoundsMin();
|
||||
RcVec3f bmax = geom.GetMeshBoundsMax();
|
||||
Recast.CalcTileCount(bmin, bmax, cfg.cs, cfg.tileSizeX, cfg.tileSizeZ, out var tw, out var th);
|
||||
Recast.CalcTileCount(bmin, bmax, cfg.Cs, cfg.TileSizeX, cfg.TileSizeZ, out var tw, out var th);
|
||||
Task task;
|
||||
if (1 < threads)
|
||||
{
|
||||
|
@ -210,24 +210,24 @@ namespace DotRecast.Recast
|
|||
// * good choice to use for tiled navmesh with medium and small sized
|
||||
// tiles
|
||||
|
||||
if (cfg.partition == RcPartitionType.WATERSHED.Value)
|
||||
if (cfg.Partition == RcPartitionType.WATERSHED.Value)
|
||||
{
|
||||
// Prepare for region partitioning, by calculating distance field
|
||||
// along the walkable surface.
|
||||
RecastRegion.BuildDistanceField(ctx, chf);
|
||||
// Partition the walkable surface into simple regions without holes.
|
||||
RecastRegion.BuildRegions(ctx, chf, cfg.minRegionArea, cfg.mergeRegionArea);
|
||||
RecastRegion.BuildRegions(ctx, chf, cfg.MinRegionArea, cfg.MergeRegionArea);
|
||||
}
|
||||
else if (cfg.partition == RcPartitionType.MONOTONE.Value)
|
||||
else if (cfg.Partition == RcPartitionType.MONOTONE.Value)
|
||||
{
|
||||
// Partition the walkable surface into simple regions without holes.
|
||||
// Monotone partitioning does not need distancefield.
|
||||
RecastRegion.BuildRegionsMonotone(ctx, chf, cfg.minRegionArea, cfg.mergeRegionArea);
|
||||
RecastRegion.BuildRegionsMonotone(ctx, chf, cfg.MinRegionArea, cfg.MergeRegionArea);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Partition the walkable surface into simple regions without holes.
|
||||
RecastRegion.BuildLayerRegions(ctx, chf, cfg.minRegionArea);
|
||||
RecastRegion.BuildLayerRegions(ctx, chf, cfg.MinRegionArea);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -235,21 +235,21 @@ namespace DotRecast.Recast
|
|||
//
|
||||
|
||||
// Create contours.
|
||||
RcContourSet cset = RecastContour.BuildContours(ctx, chf, cfg.maxSimplificationError, cfg.maxEdgeLen,
|
||||
RcContourSet cset = RecastContour.BuildContours(ctx, chf, cfg.MaxSimplificationError, cfg.MaxEdgeLen,
|
||||
RcConstants.RC_CONTOUR_TESS_WALL_EDGES);
|
||||
|
||||
//
|
||||
// Step 6. Build polygons mesh from contours.
|
||||
//
|
||||
|
||||
RcPolyMesh pmesh = RecastMesh.BuildPolyMesh(ctx, cset, cfg.maxVertsPerPoly);
|
||||
RcPolyMesh pmesh = RecastMesh.BuildPolyMesh(ctx, cset, cfg.MaxVertsPerPoly);
|
||||
|
||||
//
|
||||
// Step 7. Create detail mesh which allows to access approximate height
|
||||
// on each polygon.
|
||||
//
|
||||
RcPolyMeshDetail dmesh = cfg.buildMeshDetail
|
||||
? RecastMeshDetail.BuildPolyMeshDetail(ctx, pmesh, chf, cfg.detailSampleDist, cfg.detailSampleMaxError)
|
||||
RcPolyMeshDetail dmesh = cfg.BuildMeshDetail
|
||||
? RecastMeshDetail.BuildPolyMeshDetail(ctx, pmesh, chf, cfg.DetailSampleDist, cfg.DetailSampleMaxError)
|
||||
: null;
|
||||
return new RecastBuilderResult(tileX, tileZ, solid, chf, cset, pmesh, dmesh, ctx);
|
||||
}
|
||||
|
@ -262,19 +262,19 @@ namespace DotRecast.Recast
|
|||
// Once all geometry is rasterized, we do initial pass of filtering to
|
||||
// remove unwanted overhangs caused by the conservative rasterization
|
||||
// as well as filter spans where the character cannot possibly stand.
|
||||
if (cfg.filterLowHangingObstacles)
|
||||
if (cfg.FilterLowHangingObstacles)
|
||||
{
|
||||
RecastFilter.FilterLowHangingWalkableObstacles(ctx, cfg.walkableClimb, solid);
|
||||
RecastFilter.FilterLowHangingWalkableObstacles(ctx, cfg.WalkableClimb, solid);
|
||||
}
|
||||
|
||||
if (cfg.filterLedgeSpans)
|
||||
if (cfg.FilterLedgeSpans)
|
||||
{
|
||||
RecastFilter.FilterLedgeSpans(ctx, cfg.walkableHeight, cfg.walkableClimb, solid);
|
||||
RecastFilter.FilterLedgeSpans(ctx, cfg.WalkableHeight, cfg.WalkableClimb, solid);
|
||||
}
|
||||
|
||||
if (cfg.filterWalkableLowHeightSpans)
|
||||
if (cfg.FilterWalkableLowHeightSpans)
|
||||
{
|
||||
RecastFilter.FilterWalkableLowHeightSpans(ctx, cfg.walkableHeight, solid);
|
||||
RecastFilter.FilterWalkableLowHeightSpans(ctx, cfg.WalkableHeight, solid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,10 +287,10 @@ namespace DotRecast.Recast
|
|||
// Compact the heightfield so that it is faster to handle from now on.
|
||||
// This will result more cache coherent data as well as the neighbours
|
||||
// between walkable cells will be calculated.
|
||||
RcCompactHeightfield chf = RecastCompact.BuildCompactHeightfield(ctx, cfg.walkableHeight, cfg.walkableClimb, solid);
|
||||
RcCompactHeightfield chf = RecastCompact.BuildCompactHeightfield(ctx, cfg.WalkableHeight, cfg.WalkableClimb, solid);
|
||||
|
||||
// Erode the walkable area by agent radius.
|
||||
RecastArea.ErodeWalkableArea(ctx, cfg.walkableRadius, chf);
|
||||
RecastArea.ErodeWalkableArea(ctx, cfg.WalkableRadius, chf);
|
||||
// (Optional) Mark areas.
|
||||
if (volumeProvider != null)
|
||||
{
|
||||
|
@ -309,7 +309,7 @@ namespace DotRecast.Recast
|
|||
RcHeightfield solid = RecastVoxelization.BuildSolidHeightfield(geom, builderCfg, ctx);
|
||||
FilterHeightfield(solid, builderCfg.cfg, ctx);
|
||||
RcCompactHeightfield chf = BuildCompactHeightfield(geom, builderCfg.cfg, ctx, solid);
|
||||
return RecastLayers.BuildHeightfieldLayers(ctx, chf, builderCfg.cfg.walkableHeight);
|
||||
return RecastLayers.BuildHeightfieldLayers(ctx, chf, builderCfg.cfg.WalkableHeight);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -52,10 +52,10 @@ namespace DotRecast.Recast
|
|||
this.cfg = cfg;
|
||||
this.bmin = bmin;
|
||||
this.bmax = bmax;
|
||||
if (cfg.useTiles)
|
||||
if (cfg.UseTiles)
|
||||
{
|
||||
float tsx = cfg.tileSizeX * cfg.cs;
|
||||
float tsz = cfg.tileSizeZ * cfg.cs;
|
||||
float tsx = cfg.TileSizeX * cfg.Cs;
|
||||
float tsz = cfg.TileSizeZ * cfg.Cs;
|
||||
this.bmin.x += tileX * tsx;
|
||||
this.bmin.z += tileZ * tsz;
|
||||
this.bmax.x = this.bmin.x + tsx;
|
||||
|
@ -83,16 +83,16 @@ namespace DotRecast.Recast
|
|||
// you will need to pass in data from neighbour terrain tiles too! In a simple case, just pass in all the 8
|
||||
// neighbours,
|
||||
// or use the bounding box below to only pass in a sliver of each of the 8 neighbours.
|
||||
this.bmin.x -= cfg.borderSize * cfg.cs;
|
||||
this.bmin.z -= cfg.borderSize * cfg.cs;
|
||||
this.bmax.x += cfg.borderSize * cfg.cs;
|
||||
this.bmax.z += cfg.borderSize * cfg.cs;
|
||||
width = cfg.tileSizeX + cfg.borderSize * 2;
|
||||
height = cfg.tileSizeZ + cfg.borderSize * 2;
|
||||
this.bmin.x -= cfg.BorderSize * cfg.Cs;
|
||||
this.bmin.z -= cfg.BorderSize * cfg.Cs;
|
||||
this.bmax.x += cfg.BorderSize * cfg.Cs;
|
||||
this.bmax.z += cfg.BorderSize * cfg.Cs;
|
||||
width = cfg.TileSizeX + cfg.BorderSize * 2;
|
||||
height = cfg.TileSizeZ + cfg.BorderSize * 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
Recast.CalcGridSize(this.bmin, this.bmax, cfg.cs, out width, out height);
|
||||
Recast.CalcGridSize(this.bmin, this.bmax, cfg.Cs, out width, out height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace DotRecast.Recast
|
|||
RcConfig cfg = builderCfg.cfg;
|
||||
|
||||
// Allocate voxel heightfield where we rasterize our input data to.
|
||||
RcHeightfield solid = new RcHeightfield(builderCfg.width, builderCfg.height, builderCfg.bmin, builderCfg.bmax, cfg.cs, cfg.ch, cfg.borderSize);
|
||||
RcHeightfield solid = new RcHeightfield(builderCfg.width, builderCfg.height, builderCfg.bmin, builderCfg.bmax, cfg.Cs, cfg.Ch, cfg.BorderSize);
|
||||
|
||||
// Allocate array that can hold triangle area types.
|
||||
// If you have multiple meshes you need to process, allocate
|
||||
|
@ -44,7 +44,7 @@ namespace DotRecast.Recast
|
|||
foreach (RcTriMesh geom in geomProvider.Meshes())
|
||||
{
|
||||
float[] verts = geom.GetVerts();
|
||||
if (cfg.useTiles)
|
||||
if (cfg.UseTiles)
|
||||
{
|
||||
float[] tbmin = new float[2];
|
||||
float[] tbmax = new float[2];
|
||||
|
@ -57,16 +57,16 @@ namespace DotRecast.Recast
|
|||
{
|
||||
int[] tris = node.tris;
|
||||
int ntris = tris.Length / 3;
|
||||
int[] m_triareas = Recast.MarkWalkableTriangles(ctx, cfg.walkableSlopeAngle, verts, tris, ntris, cfg.walkableAreaMod);
|
||||
RecastRasterization.RasterizeTriangles(solid, verts, tris, m_triareas, ntris, cfg.walkableClimb, ctx);
|
||||
int[] m_triareas = Recast.MarkWalkableTriangles(ctx, cfg.WalkableSlopeAngle, verts, tris, ntris, cfg.WalkableAreaMod);
|
||||
RecastRasterization.RasterizeTriangles(solid, verts, tris, m_triareas, ntris, cfg.WalkableClimb, ctx);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] tris = geom.GetTris();
|
||||
int ntris = tris.Length / 3;
|
||||
int[] m_triareas = Recast.MarkWalkableTriangles(ctx, cfg.walkableSlopeAngle, verts, tris, ntris, cfg.walkableAreaMod);
|
||||
RecastRasterization.RasterizeTriangles(solid, verts, tris, m_triareas, ntris, cfg.walkableClimb, ctx);
|
||||
int[] m_triareas = Recast.MarkWalkableTriangles(ctx, cfg.WalkableSlopeAngle, verts, tris, ntris, cfg.WalkableAreaMod);
|
||||
RecastRasterization.RasterizeTriangles(solid, verts, tris, m_triareas, ntris, cfg.WalkableClimb, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,17 +46,17 @@ public class RecastTestMeshBuilder
|
|||
{
|
||||
}
|
||||
|
||||
public RecastTestMeshBuilder(IInputGeomProvider m_geom, RcPartition m_partitionType, float m_cellSize,
|
||||
float m_cellHeight, float m_agentHeight, float m_agentRadius, float m_agentMaxClimb, float m_agentMaxSlope,
|
||||
int m_regionMinSize, int m_regionMergeSize, float m_edgeMaxLen, float m_edgeMaxError, int m_vertsPerPoly,
|
||||
float m_detailSampleDist, float m_detailSampleMaxError)
|
||||
public RecastTestMeshBuilder(IInputGeomProvider geom, RcPartition partitionType, float cellSize,
|
||||
float cellHeight, float agentHeight, float agentRadius, float agentMaxClimb, float agentMaxSlope,
|
||||
int regionMinSize, int regionMergeSize, float edgeMaxLen, float edgeMaxError, int vertsPerPoly,
|
||||
float detailSampleDist, float detailSampleMaxError)
|
||||
{
|
||||
RcConfig cfg = new RcConfig(m_partitionType, m_cellSize, m_cellHeight, m_agentHeight, m_agentRadius,
|
||||
m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize, m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError,
|
||||
m_vertsPerPoly, m_detailSampleDist, m_detailSampleMaxError, SampleAreaModifications.SAMPLE_AREAMOD_GROUND);
|
||||
RecastBuilderConfig bcfg = new RecastBuilderConfig(cfg, m_geom.GetMeshBoundsMin(), m_geom.GetMeshBoundsMax());
|
||||
RcConfig cfg = new RcConfig(partitionType, cellSize, cellHeight, agentHeight, agentRadius,
|
||||
agentMaxClimb, agentMaxSlope, regionMinSize, regionMergeSize, edgeMaxLen, edgeMaxError,
|
||||
vertsPerPoly, detailSampleDist, detailSampleMaxError, SampleAreaModifications.SAMPLE_AREAMOD_GROUND);
|
||||
RecastBuilderConfig bcfg = new RecastBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax());
|
||||
RecastBuilder rcBuilder = new RecastBuilder();
|
||||
RecastBuilderResult rcResult = rcBuilder.Build(m_geom, bcfg);
|
||||
RecastBuilderResult rcResult = rcBuilder.Build(geom, bcfg);
|
||||
RcPolyMesh m_pmesh = rcResult.GetMesh();
|
||||
for (int i = 0; i < m_pmesh.npolys; ++i)
|
||||
{
|
||||
|
@ -77,13 +77,13 @@ public class RecastTestMeshBuilder
|
|||
option.detailVertsCount = m_dmesh.nverts;
|
||||
option.detailTris = m_dmesh.tris;
|
||||
option.detailTriCount = m_dmesh.ntris;
|
||||
option.walkableHeight = m_agentHeight;
|
||||
option.walkableRadius = m_agentRadius;
|
||||
option.walkableClimb = m_agentMaxClimb;
|
||||
option.walkableHeight = agentHeight;
|
||||
option.walkableRadius = agentRadius;
|
||||
option.walkableClimb = agentMaxClimb;
|
||||
option.bmin = m_pmesh.bmin;
|
||||
option.bmax = m_pmesh.bmax;
|
||||
option.cs = m_cellSize;
|
||||
option.ch = m_cellHeight;
|
||||
option.cs = cellSize;
|
||||
option.ch = cellHeight;
|
||||
option.buildBvTree = true;
|
||||
|
||||
option.offMeshConVerts = new float[6];
|
||||
|
@ -111,4 +111,4 @@ public class RecastTestMeshBuilder
|
|||
{
|
||||
return meshData;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,17 +47,17 @@ public class RecastTestMeshBuilder
|
|||
{
|
||||
}
|
||||
|
||||
public RecastTestMeshBuilder(IInputGeomProvider m_geom, RcPartition m_partitionType, float m_cellSize,
|
||||
float m_cellHeight, float m_agentHeight, float m_agentRadius, float m_agentMaxClimb, float m_agentMaxSlope,
|
||||
int m_regionMinSize, int m_regionMergeSize, float m_edgeMaxLen, float m_edgeMaxError, int m_vertsPerPoly,
|
||||
float m_detailSampleDist, float m_detailSampleMaxError)
|
||||
public RecastTestMeshBuilder(IInputGeomProvider geom, RcPartition partition, float cellSize,
|
||||
float cellHeight, float agentHeight, float agentRadius, float agentMaxClimb, float agentMaxSlope,
|
||||
int regionMinSize, int regionMergeSize, float edgeMaxLen, float edgeMaxError, int vertsPerPoly,
|
||||
float detailSampleDist, float detailSampleMaxError)
|
||||
{
|
||||
RcConfig cfg = new RcConfig(m_partitionType, m_cellSize, m_cellHeight, m_agentHeight, m_agentRadius,
|
||||
m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize, m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError,
|
||||
m_vertsPerPoly, m_detailSampleDist, m_detailSampleMaxError, SampleAreaModifications.SAMPLE_AREAMOD_GROUND);
|
||||
RecastBuilderConfig bcfg = new RecastBuilderConfig(cfg, m_geom.GetMeshBoundsMin(), m_geom.GetMeshBoundsMax());
|
||||
RcConfig cfg = new RcConfig(partition, cellSize, cellHeight, agentHeight, agentRadius,
|
||||
agentMaxClimb, agentMaxSlope, regionMinSize, regionMergeSize, edgeMaxLen, edgeMaxError,
|
||||
vertsPerPoly, detailSampleDist, detailSampleMaxError, SampleAreaModifications.SAMPLE_AREAMOD_GROUND);
|
||||
RecastBuilderConfig bcfg = new RecastBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax());
|
||||
RecastBuilder rcBuilder = new RecastBuilder();
|
||||
RecastBuilderResult rcResult = rcBuilder.Build(m_geom, bcfg);
|
||||
RecastBuilderResult rcResult = rcBuilder.Build(geom, bcfg);
|
||||
RcPolyMesh m_pmesh = rcResult.GetMesh();
|
||||
for (int i = 0; i < m_pmesh.npolys; ++i)
|
||||
{
|
||||
|
@ -78,13 +78,13 @@ public class RecastTestMeshBuilder
|
|||
option.detailVertsCount = m_dmesh.nverts;
|
||||
option.detailTris = m_dmesh.tris;
|
||||
option.detailTriCount = m_dmesh.ntris;
|
||||
option.walkableHeight = m_agentHeight;
|
||||
option.walkableRadius = m_agentRadius;
|
||||
option.walkableClimb = m_agentMaxClimb;
|
||||
option.walkableHeight = agentHeight;
|
||||
option.walkableRadius = agentRadius;
|
||||
option.walkableClimb = agentMaxClimb;
|
||||
option.bmin = m_pmesh.bmin;
|
||||
option.bmax = m_pmesh.bmax;
|
||||
option.cs = m_cellSize;
|
||||
option.ch = m_cellHeight;
|
||||
option.cs = cellSize;
|
||||
option.ch = cellHeight;
|
||||
option.buildBvTree = true;
|
||||
|
||||
option.offMeshConVerts = new float[6];
|
||||
|
|
|
@ -89,8 +89,8 @@ public class TestDetourBuilder : DetourBuilder
|
|||
option.walkableClimb = agentMaxClimb;
|
||||
option.bmin = pmesh.bmin;
|
||||
option.bmax = pmesh.bmax;
|
||||
option.cs = rcConfig.cs;
|
||||
option.ch = rcConfig.ch;
|
||||
option.cs = rcConfig.Cs;
|
||||
option.ch = rcConfig.Ch;
|
||||
option.buildBvTree = true;
|
||||
/*
|
||||
* option.offMeshConVerts = m_geom->GetOffMeshConnectionVerts();
|
||||
|
|
|
@ -52,27 +52,27 @@ public class TestTiledNavMeshBuilder
|
|||
{
|
||||
}
|
||||
|
||||
public TestTiledNavMeshBuilder(IInputGeomProvider m_geom, RcPartition m_partitionType, float m_cellSize, float m_cellHeight,
|
||||
float m_agentHeight, float m_agentRadius, float m_agentMaxClimb, float m_agentMaxSlope, int m_regionMinSize,
|
||||
int m_regionMergeSize, float m_edgeMaxLen, float m_edgeMaxError, int m_vertsPerPoly, float m_detailSampleDist,
|
||||
float m_detailSampleMaxError, int m_tileSize)
|
||||
public TestTiledNavMeshBuilder(IInputGeomProvider geom, RcPartition partitionType, float cellSize, float cellHeight,
|
||||
float agentHeight, float agentRadius, float agentMaxClimb, float agentMaxSlope, int regionMinSize,
|
||||
int regionMergeSize, float edgeMaxLen, float edgeMaxError, int vertsPerPoly, float detailSampleDist,
|
||||
float detailSampleMaxError, int tileSize)
|
||||
{
|
||||
// Create empty nav mesh
|
||||
DtNavMeshParams navMeshParams = new DtNavMeshParams();
|
||||
navMeshParams.orig = m_geom.GetMeshBoundsMin();
|
||||
navMeshParams.tileWidth = m_tileSize * m_cellSize;
|
||||
navMeshParams.tileHeight = m_tileSize * m_cellSize;
|
||||
navMeshParams.orig = geom.GetMeshBoundsMin();
|
||||
navMeshParams.tileWidth = tileSize * cellSize;
|
||||
navMeshParams.tileHeight = tileSize * cellSize;
|
||||
navMeshParams.maxTiles = 128;
|
||||
navMeshParams.maxPolys = 32768;
|
||||
navMesh = new DtNavMesh(navMeshParams, 6);
|
||||
|
||||
// Build all tiles
|
||||
RcConfig cfg = new RcConfig(true, m_tileSize, m_tileSize, RcConfig.CalcBorder(m_agentRadius, m_cellSize),
|
||||
m_partitionType, m_cellSize, m_cellHeight, m_agentMaxSlope, true, true, true, m_agentHeight, m_agentRadius,
|
||||
m_agentMaxClimb, m_regionMinArea, m_regionMergeArea, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, true,
|
||||
m_detailSampleDist, m_detailSampleMaxError, SampleAreaModifications.SAMPLE_AREAMOD_GROUND);
|
||||
RcConfig cfg = new RcConfig(true, tileSize, tileSize, RcConfig.CalcBorder(agentRadius, cellSize),
|
||||
partitionType, cellSize, cellHeight, agentMaxSlope, true, true, true, agentHeight, agentRadius,
|
||||
agentMaxClimb, m_regionMinArea, m_regionMergeArea, edgeMaxLen, edgeMaxError, vertsPerPoly, true,
|
||||
detailSampleDist, detailSampleMaxError, SampleAreaModifications.SAMPLE_AREAMOD_GROUND);
|
||||
RecastBuilder rcBuilder = new RecastBuilder();
|
||||
List<RecastBuilderResult> rcResult = rcBuilder.BuildTiles(m_geom, cfg, null);
|
||||
List<RecastBuilderResult> rcResult = rcBuilder.BuildTiles(geom, cfg, null);
|
||||
|
||||
// Add tiles to nav mesh
|
||||
|
||||
|
@ -103,13 +103,13 @@ public class TestTiledNavMeshBuilder
|
|||
option.detailVertsCount = dmesh.nverts;
|
||||
option.detailTris = dmesh.tris;
|
||||
option.detailTriCount = dmesh.ntris;
|
||||
option.walkableHeight = m_agentHeight;
|
||||
option.walkableRadius = m_agentRadius;
|
||||
option.walkableClimb = m_agentMaxClimb;
|
||||
option.walkableHeight = agentHeight;
|
||||
option.walkableRadius = agentRadius;
|
||||
option.walkableClimb = agentMaxClimb;
|
||||
option.bmin = pmesh.bmin;
|
||||
option.bmax = pmesh.bmax;
|
||||
option.cs = m_cellSize;
|
||||
option.ch = m_cellHeight;
|
||||
option.cs = cellSize;
|
||||
option.ch = cellHeight;
|
||||
option.tileX = result.tileX;
|
||||
option.tileZ = result.tileZ;
|
||||
option.buildBvTree = true;
|
||||
|
|
|
@ -116,7 +116,7 @@ public class RecastSoloMeshTest
|
|||
//
|
||||
|
||||
// Allocate voxel heightfield where we rasterize our input data to.
|
||||
RcHeightfield m_solid = new RcHeightfield(bcfg.width, bcfg.height, bcfg.bmin, bcfg.bmax, cfg.cs, cfg.ch, cfg.borderSize);
|
||||
RcHeightfield m_solid = new RcHeightfield(bcfg.width, bcfg.height, bcfg.bmin, bcfg.bmax, cfg.Cs, cfg.Ch, cfg.BorderSize);
|
||||
|
||||
foreach (RcTriMesh geom in geomProvider.Meshes())
|
||||
{
|
||||
|
@ -131,8 +131,8 @@ public class RecastSoloMeshTest
|
|||
// Find triangles which are walkable based on their slope and rasterize them.
|
||||
// If your input data is multiple meshes, you can transform them here, calculate
|
||||
// the are type for each of the meshes and rasterize them.
|
||||
int[] m_triareas = Recast.MarkWalkableTriangles(m_ctx, cfg.walkableSlopeAngle, verts, tris, ntris, cfg.walkableAreaMod);
|
||||
RecastRasterization.RasterizeTriangles(m_solid, verts, tris, m_triareas, ntris, cfg.walkableClimb, m_ctx);
|
||||
int[] m_triareas = Recast.MarkWalkableTriangles(m_ctx, cfg.WalkableSlopeAngle, verts, tris, ntris, cfg.WalkableAreaMod);
|
||||
RecastRasterization.RasterizeTriangles(m_solid, verts, tris, m_triareas, ntris, cfg.WalkableClimb, m_ctx);
|
||||
|
||||
}
|
||||
|
||||
|
@ -143,9 +143,9 @@ public class RecastSoloMeshTest
|
|||
// Once all geometry is rasterized, we do initial pass of filtering to
|
||||
// remove unwanted overhangs caused by the conservative rasterization
|
||||
// as well as filter spans where the character cannot possibly stand.
|
||||
RecastFilter.FilterLowHangingWalkableObstacles(m_ctx, cfg.walkableClimb, m_solid);
|
||||
RecastFilter.FilterLedgeSpans(m_ctx, cfg.walkableHeight, cfg.walkableClimb, m_solid);
|
||||
RecastFilter.FilterWalkableLowHeightSpans(m_ctx, cfg.walkableHeight, m_solid);
|
||||
RecastFilter.FilterLowHangingWalkableObstacles(m_ctx, cfg.WalkableClimb, m_solid);
|
||||
RecastFilter.FilterLedgeSpans(m_ctx, cfg.WalkableHeight, cfg.WalkableClimb, m_solid);
|
||||
RecastFilter.FilterWalkableLowHeightSpans(m_ctx, cfg.WalkableHeight, m_solid);
|
||||
|
||||
//
|
||||
// Step 4. Partition walkable surface to simple regions.
|
||||
|
@ -154,11 +154,11 @@ public class RecastSoloMeshTest
|
|||
// Compact the heightfield so that it is faster to handle from now on.
|
||||
// This will result more cache coherent data as well as the neighbours
|
||||
// between walkable cells will be calculated.
|
||||
RcCompactHeightfield m_chf = RecastCompact.BuildCompactHeightfield(m_ctx, cfg.walkableHeight, cfg.walkableClimb,
|
||||
RcCompactHeightfield m_chf = RecastCompact.BuildCompactHeightfield(m_ctx, cfg.WalkableHeight, cfg.WalkableClimb,
|
||||
m_solid);
|
||||
|
||||
// Erode the walkable area by agent radius.
|
||||
RecastArea.ErodeWalkableArea(m_ctx, cfg.walkableRadius, m_chf);
|
||||
RecastArea.ErodeWalkableArea(m_ctx, cfg.WalkableRadius, m_chf);
|
||||
|
||||
// (Optional) Mark areas.
|
||||
/*
|
||||
|
@ -212,18 +212,18 @@ public class RecastSoloMeshTest
|
|||
// along the walkable surface.
|
||||
RecastRegion.BuildDistanceField(m_ctx, m_chf);
|
||||
// Partition the walkable surface into simple regions without holes.
|
||||
RecastRegion.BuildRegions(m_ctx, m_chf, cfg.minRegionArea, cfg.mergeRegionArea);
|
||||
RecastRegion.BuildRegions(m_ctx, m_chf, cfg.MinRegionArea, cfg.MergeRegionArea);
|
||||
}
|
||||
else if (m_partitionType == RcPartition.MONOTONE)
|
||||
{
|
||||
// Partition the walkable surface into simple regions without holes.
|
||||
// Monotone partitioning does not need distancefield.
|
||||
RecastRegion.BuildRegionsMonotone(m_ctx, m_chf, cfg.minRegionArea, cfg.mergeRegionArea);
|
||||
RecastRegion.BuildRegionsMonotone(m_ctx, m_chf, cfg.MinRegionArea, cfg.MergeRegionArea);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Partition the walkable surface into simple regions without holes.
|
||||
RecastRegion.BuildLayerRegions(m_ctx, m_chf, cfg.minRegionArea);
|
||||
RecastRegion.BuildLayerRegions(m_ctx, m_chf, cfg.MinRegionArea);
|
||||
}
|
||||
|
||||
Assert.That(m_chf.maxDistance, Is.EqualTo(expDistance), "maxDistance");
|
||||
|
@ -233,7 +233,7 @@ public class RecastSoloMeshTest
|
|||
//
|
||||
|
||||
// Create contours.
|
||||
RcContourSet m_cset = RecastContour.BuildContours(m_ctx, m_chf, cfg.maxSimplificationError, cfg.maxEdgeLen,
|
||||
RcContourSet m_cset = RecastContour.BuildContours(m_ctx, m_chf, cfg.MaxSimplificationError, cfg.MaxEdgeLen,
|
||||
RcConstants.RC_CONTOUR_TESS_WALL_EDGES);
|
||||
|
||||
Assert.That(m_cset.conts.Count, Is.EqualTo(expContours), "Contours");
|
||||
|
@ -242,7 +242,7 @@ public class RecastSoloMeshTest
|
|||
//
|
||||
|
||||
// Build polygon navmesh from the contours.
|
||||
RcPolyMesh m_pmesh = RecastMesh.BuildPolyMesh(m_ctx, m_cset, cfg.maxVertsPerPoly);
|
||||
RcPolyMesh m_pmesh = RecastMesh.BuildPolyMesh(m_ctx, m_cset, cfg.MaxVertsPerPoly);
|
||||
Assert.That(m_pmesh.nverts, Is.EqualTo(expVerts), "Mesh Verts");
|
||||
Assert.That(m_pmesh.npolys, Is.EqualTo(expPolys), "Mesh Polys");
|
||||
|
||||
|
@ -251,8 +251,8 @@ public class RecastSoloMeshTest
|
|||
// on each polygon.
|
||||
//
|
||||
|
||||
RcPolyMeshDetail m_dmesh = RecastMeshDetail.BuildPolyMeshDetail(m_ctx, m_pmesh, m_chf, cfg.detailSampleDist,
|
||||
cfg.detailSampleMaxError);
|
||||
RcPolyMeshDetail m_dmesh = RecastMeshDetail.BuildPolyMeshDetail(m_ctx, m_pmesh, m_chf, cfg.DetailSampleDist,
|
||||
cfg.DetailSampleMaxError);
|
||||
Assert.That(m_dmesh.nmeshes, Is.EqualTo(expDetMeshes), "Mesh Detail Meshes");
|
||||
Assert.That(m_dmesh.nverts, Is.EqualTo(expDetVerts), "Mesh Detail Verts");
|
||||
Assert.That(m_dmesh.ntris, Is.EqualTo(expDetTris), "Mesh Detail Tris");
|
||||
|
|
|
@ -29,8 +29,6 @@ using NUnit.Framework;
|
|||
|
||||
namespace DotRecast.Recast.Test;
|
||||
|
||||
using static RcConstants;
|
||||
|
||||
[Parallelizable]
|
||||
public class RecastTileMeshTest
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue