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-07-28 15:01:22 +03:00
|
|
|
/// Specifies a configuration to use when performing Recast builds.
|
|
|
|
/// @ingroup recast
|
2023-06-08 14:53:03 +03:00
|
|
|
public class RcConfig
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-07-28 15:01:22 +03:00
|
|
|
public readonly int Partition;
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-07-28 15:01:22 +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] **/
|
2023-07-28 15:01:22 +03:00
|
|
|
public readonly int TileSizeX;
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-07-28 15:01:22 +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] **/
|
2023-07-28 15:01:22 +03:00
|
|
|
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] **/
|
2023-07-28 15:01:22 +03:00
|
|
|
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] **/
|
2023-07-28 15:01:22 +03:00
|
|
|
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-07-28 15:01:22 +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] **/
|
2023-07-28 15:01:22 +03:00
|
|
|
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-07-28 15:01:22 +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] **/
|
2023-07-28 15:01:22 +03:00
|
|
|
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-07-28 15:01:22 +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] **/
|
2023-07-28 15:01:22 +03:00
|
|
|
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-07-28 15:01:22 +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-07-28 15:01:22 +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-07-28 15:01:22 +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-07-28 15:01:22 +03:00
|
|
|
public readonly float DetailSampleMaxError;
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-07-28 15:01:22 +03:00
|
|
|
public readonly RcAreaModification 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 **/
|
2023-07-28 15:01:22 +03:00
|
|
|
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] **/
|
2023-07-28 15:01:22 +03:00
|
|
|
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 */
|
2023-07-28 15:01:22 +03:00
|
|
|
public readonly float MinRegionAreaWorld;
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-07-28 15:01:22 +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-07-28 14:43:50 +03:00
|
|
|
public RcConfig(RcPartition partitionType, float cellSize, float cellHeight, float agentHeight, float agentRadius,
|
2023-03-16 19:48:49 +03:00
|
|
|
float agentMaxClimb, float agentMaxSlope, int regionMinSize, int regionMergeSize, float edgeMaxLen,
|
|
|
|
float edgeMaxError, int vertsPerPoly, float detailSampleDist, float detailSampleMaxError,
|
2023-07-10 13:03:47 +03:00
|
|
|
RcAreaModification walkableAreaMod) : this(partitionType, cellSize, cellHeight, agentMaxSlope, true, true, true, agentHeight, agentRadius, agentMaxClimb,
|
2023-03-16 19:48:49 +03:00
|
|
|
regionMinSize, regionMergeSize, edgeMaxLen, edgeMaxError, vertsPerPoly, detailSampleDist, detailSampleMaxError,
|
|
|
|
walkableAreaMod, true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-14 08:02:43 +03:00
|
|
|
* Non-tiled build configuration
|
|
|
|
*/
|
2023-07-28 14:43:50 +03:00
|
|
|
public RcConfig(RcPartition partitionType, float cellSize, float cellHeight, float agentMaxSlope,
|
2023-03-16 19:48:49 +03:00
|
|
|
bool filterLowHangingObstacles, bool filterLedgeSpans, bool filterWalkableLowHeightSpans, float agentHeight,
|
|
|
|
float agentRadius, float agentMaxClimb, int regionMinSize, int regionMergeSize, float edgeMaxLen, float edgeMaxError,
|
2023-07-10 13:03:47 +03:00
|
|
|
int vertsPerPoly, float detailSampleDist, float detailSampleMaxError, RcAreaModification walkableAreaMod,
|
2023-03-16 19:48:49 +03:00
|
|
|
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]
|
|
|
|
}
|
|
|
|
|
2023-07-28 14:43:50 +03:00
|
|
|
public RcConfig(bool useTiles, int tileSizeX, int tileSizeZ, int borderSize, RcPartition partition,
|
2023-03-16 19:48:49 +03:00
|
|
|
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,
|
2023-07-10 13:03:47 +03:00
|
|
|
float detailSampleDist, float detailSampleMaxError, RcAreaModification walkableAreaMod)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-07-28 15:01:22 +03:00
|
|
|
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;
|
2023-03-16 19:48:49 +03:00
|
|
|
}
|
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
public static int CalcBorder(float agentRadius, float cs)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
return 3 + (int)Math.Ceiling(agentRadius / cs);
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
}
|