DotRecastNetSim/src/DotRecast.Recast/RecastConfig.cs

187 lines
8.5 KiB
C#
Raw Normal View History

2023-03-14 08:02:43 +03:00
/*
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
2023-03-15 17:00:29 +03:00
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
2023-03-14 08:02:43 +03:00
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
2023-03-16 19:09:10 +03:00
namespace DotRecast.Recast
{
2023-03-16 19:48:49 +03:00
using static RecastConstants;
2023-03-16 19:09:10 +03:00
2023-03-16 19:48:49 +03:00
public class RecastConfig
{
public readonly PartitionType partitionType;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
public readonly bool useTiles;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/** The width/depth size of tile's on the xz-plane. [Limit: >= 0] [Units: vx] **/
public readonly int tileSizeX;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
public readonly int tileSizeZ;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/** The xz-plane cell size to use for fields. [Limit: > 0] [Units: wu] **/
public readonly float cs;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/** The y-axis cell size to use for fields. [Limit: > 0] [Units: wu] **/
public readonly float ch;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/** The maximum slope that is considered walkable. [Limits: 0 <= value < 90] [Units: Degrees] **/
public readonly float walkableSlopeAngle;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/**
2023-03-14 08:02:43 +03:00
* Minimum floor to 'ceiling' height that will still allow the floor area to be considered walkable. [Limit: >= 3]
* [Units: vx]
**/
2023-03-16 19:48:49 +03:00
public readonly int walkableHeight;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/** Maximum ledge height that is considered to still be traversable. [Limit: >=0] [Units: vx] **/
public readonly int walkableClimb;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/**
2023-03-14 08:02:43 +03:00
* The distance to erode/shrink the walkable area of the heightfield away from obstructions. [Limit: >=0] [Units:
* vx]
**/
2023-03-16 19:48:49 +03:00
public readonly int walkableRadius;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/** The maximum allowed length for contour edges along the border of the mesh. [Limit: >=0] [Units: vx] **/
public readonly int maxEdgeLen;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/**
2023-03-14 08:02:43 +03:00
* The maximum distance a simplfied contour's border edges should deviate the original raw contour. [Limit: >=0]
* [Units: vx]
**/
2023-03-16 19:48:49 +03:00
public readonly float maxSimplificationError;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/** The minimum number of cells allowed to form isolated island areas. [Limit: >=0] [Units: vx] **/
public readonly int minRegionArea;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/**
2023-03-14 08:02:43 +03:00
* Any regions with a span count smaller than this value will, if possible, be merged with larger regions. [Limit:
* >=0] [Units: vx]
**/
2023-03-16 19:48:49 +03:00
public readonly int mergeRegionArea;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/**
2023-03-14 08:02:43 +03:00
* The maximum number of vertices allowed for polygons generated during the contour to polygon conversion process.
* [Limit: >= 3]
**/
2023-03-16 19:48:49 +03:00
public readonly int maxVertsPerPoly;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/**
2023-03-14 08:02:43 +03:00
* Sets the sampling distance to use when generating the detail mesh. (For height detail only.) [Limits: 0 or >=
* 0.9] [Units: wu]
**/
2023-03-16 19:48:49 +03:00
public readonly float detailSampleDist;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/**
2023-03-14 08:02:43 +03:00
* The maximum distance the detail mesh surface should deviate from heightfield data. (For height detail only.)
* [Limit: >=0] [Units: wu]
**/
2023-03-16 19:48:49 +03:00
public readonly float detailSampleMaxError;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
public readonly AreaModification walkableAreaMod;
public readonly bool filterLowHangingObstacles;
public readonly bool filterLedgeSpans;
public readonly bool filterWalkableLowHeightSpans;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/** Set to false to disable building detailed mesh **/
public readonly bool buildMeshDetail;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/** The size of the non-navigable border around the heightfield. [Limit: >=0] [Units: vx] **/
public readonly int borderSize;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/** Set of original settings passed in world units */
public readonly float minRegionAreaWorld;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
public readonly float mergeRegionAreaWorld;
public readonly float walkableHeightWorld;
public readonly float walkableClimbWorld;
public readonly float walkableRadiusWorld;
public readonly float maxEdgeLenWorld;
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
/**
2023-03-14 08:02:43 +03:00
* Non-tiled build configuration
*/
2023-03-16 19:48:49 +03:00
public RecastConfig(PartitionType 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,
AreaModification walkableAreaMod) : this(partitionType, cellSize, cellHeight, agentMaxSlope, true, true, true, agentHeight, agentRadius, agentMaxClimb,
regionMinSize, regionMergeSize, edgeMaxLen, edgeMaxError, vertsPerPoly, detailSampleDist, detailSampleMaxError,
walkableAreaMod, true)
{
}
/**
2023-03-14 08:02:43 +03:00
* Non-tiled build configuration
*/
2023-03-16 19:48:49 +03:00
public RecastConfig(PartitionType partitionType, float cellSize, float cellHeight, float agentMaxSlope,
bool filterLowHangingObstacles, bool filterLedgeSpans, bool filterWalkableLowHeightSpans, float agentHeight,
float agentRadius, float agentMaxClimb, int regionMinSize, int regionMergeSize, float edgeMaxLen, float edgeMaxError,
int vertsPerPoly, float detailSampleDist, float detailSampleMaxError, AreaModification walkableAreaMod,
bool buildMeshDetail) : this(false, 0, 0, 0, partitionType, cellSize, cellHeight, agentMaxSlope, filterLowHangingObstacles, filterLedgeSpans,
filterWalkableLowHeightSpans, agentHeight, agentRadius, agentMaxClimb,
regionMinSize * regionMinSize * cellSize * cellSize, regionMergeSize * regionMergeSize * cellSize * cellSize,
edgeMaxLen, edgeMaxError, vertsPerPoly, buildMeshDetail, detailSampleDist, detailSampleMaxError, walkableAreaMod)
{
// Note: area = size*size in [Units: wu]
}
public RecastConfig(bool useTiles, int tileSizeX, int tileSizeZ, int borderSize, PartitionType partitionType,
float cellSize, float cellHeight, float agentMaxSlope, bool filterLowHangingObstacles, bool filterLedgeSpans,
bool filterWalkableLowHeightSpans, float agentHeight, float agentRadius, float agentMaxClimb, float minRegionArea,
float mergeRegionArea, float edgeMaxLen, float edgeMaxError, int vertsPerPoly, bool buildMeshDetail,
float detailSampleDist, float detailSampleMaxError, AreaModification walkableAreaMod)
{
this.useTiles = useTiles;
this.tileSizeX = tileSizeX;
this.tileSizeZ = tileSizeZ;
this.borderSize = borderSize;
this.partitionType = partitionType;
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;
}
public static int calcBorder(float agentRadius, float cs)
{
return 3 + (int)Math.Ceiling(agentRadius / cs);
}
2023-03-14 08:02:43 +03:00
}
}