From e663b617e3f232117f581b4be3e2673aca18745c Mon Sep 17 00:00:00 2001 From: ikpil Date: Wed, 30 Aug 2023 00:02:49 +0900 Subject: [PATCH] for test --- .../Tools/RcObstacleTool.cs | 12 +- src/DotRecast.Recast/RcConfig.cs | 7 +- src/DotRecast.Recast/RcConfigBuilder.cs | 191 ++++++++++++++++++ 3 files changed, 204 insertions(+), 6 deletions(-) create mode 100644 src/DotRecast.Recast/RcConfigBuilder.cs diff --git a/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs index 8a5fbf1..0596ce1 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs @@ -33,18 +33,20 @@ namespace DotRecast.Recast.Toolset.Tools //m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: No vertices and triangles."); return false; } - + _proc.Init(geom); - + // Init cache var bmin = geom.GetMeshBoundsMin(); var bmax = geom.GetMeshBoundsMax(); RcUtils.CalcGridSize(bmin, bmax, setting.cellSize, out var gw, out var gh); int ts = setting.tileSize; - int tw = (gw + ts-1) / ts; - int th = (gh + ts-1) / ts; - + int tw = (gw + ts - 1) / ts; + int th = (gh + ts - 1) / ts; + // Generation params. + var cfg = RcConfig.NewBuilder() + .Build(); // RcConfig cfg = new RcConfig(); // cfg.cs = m_cellSize; // cfg.ch = m_cellHeight; diff --git a/src/DotRecast.Recast/RcConfig.cs b/src/DotRecast.Recast/RcConfig.cs index 09dc38d..8415d57 100644 --- a/src/DotRecast.Recast/RcConfig.cs +++ b/src/DotRecast.Recast/RcConfig.cs @@ -114,7 +114,12 @@ namespace DotRecast.Recast public readonly float WalkableClimbWorld; public readonly float WalkableRadiusWorld; public readonly float MaxEdgeLenWorld; - + + public static RcConfigBuilder NewBuilder() + { + return new RcConfigBuilder(); + } + /** * Non-tiled build configuration */ diff --git a/src/DotRecast.Recast/RcConfigBuilder.cs b/src/DotRecast.Recast/RcConfigBuilder.cs new file mode 100644 index 0000000..4098bb9 --- /dev/null +++ b/src/DotRecast.Recast/RcConfigBuilder.cs @@ -0,0 +1,191 @@ +namespace DotRecast.Recast +{ + public class RcConfigBuilder + { + private int _partition; + private bool _useTiles; + private int _tileSizeX; + private int _tileSizeZ; + private float _cs; + private float _ch; + private float _agentMaxSlope; + private int _agentHeight; + private int _agentMaxClimb; + private int _agentRadius; + private int _edgeMaxLen; + private float _edgeMaxError; + private int _minRegionArea; + private int _mergeRegionArea; + private int _vertsPerPoly; + private float _detailSampleDist; + private float _detailSampleMaxError; + private RcAreaModification _walkableAreaMod; + private bool _filterLowHangingObstacles; + private bool _filterLedgeSpans; + private bool _filterWalkableLowHeightSpans; + + // .. + private bool _buildMeshDetail; + private int _borderSize; + private float _minRegionAreaWorld; + private float _mergeRegionAreaWorld; + private float _walkableHeightWorld; + private float _walkableClimbWorld; + private float _walkableRadiusWorld; + private float _maxEdgeLenWorld; + + public RcConfigBuilder WithPartition(int partition) + { + _partition = partition; + return this; + } + + public RcConfigBuilder WithUseTiles(bool useTiles) + { + _useTiles = useTiles; + return this; + } + + public RcConfigBuilder WithTileSizeX(int tileSizeX) + { + _tileSizeX = tileSizeX; + return this; + } + + public RcConfigBuilder WithTileSizeZ(int tileSizeZ) + { + _tileSizeZ = tileSizeZ; + return this; + } + + public RcConfigBuilder WithCell(float cs) + { + _cs = cs; + return this; + } + + public RcConfigBuilder WithCh(float ch) + { + _ch = ch; + return this; + } + + public RcConfigBuilder WithWalkableSlopeAngle(float walkableSlopeAngle) + { + _agentMaxSlope = walkableSlopeAngle; + return this; + } + + public RcConfigBuilder WithWalkableHeight(int walkableHeight) + { + _agentHeight = walkableHeight; + return this; + } + + public RcConfigBuilder WithWalkableClimb(int walkableClimb) + { + _agentMaxClimb = walkableClimb; + return this; + } + + public RcConfigBuilder WithWalkableRadius(int walkableRadius) + { + _agentRadius = walkableRadius; + return this; + } + + public RcConfigBuilder WithMaxEdgeLen(int maxEdgeLen) + { + _edgeMaxLen = maxEdgeLen; + return this; + } + + public RcConfigBuilder WithMaxSimplificationError(float maxSimplificationError) + { + _edgeMaxError = maxSimplificationError; + return this; + } + + public RcConfigBuilder WithMinRegionArea(int minRegionArea) + { + _minRegionArea = minRegionArea; + return this; + } + + public RcConfigBuilder WithMergeRegionArea(int mergeRegionArea) + { + _mergeRegionArea = mergeRegionArea; + return this; + } + + public RcConfigBuilder WithMaxVertsPerPoly(int maxVertsPerPoly) + { + _vertsPerPoly = maxVertsPerPoly; + return this; + } + + public RcConfigBuilder WithDetailSampleDist(float detailSampleDist) + { + _detailSampleDist = detailSampleDist; + return this; + } + + public RcConfigBuilder WithDetailSampleMaxError(float detailSampleMaxError) + { + _detailSampleMaxError = detailSampleMaxError; + return this; + } + + public RcConfigBuilder WithWalkableAreaMod(RcAreaModification walkableAreaMod) + { + _walkableAreaMod = walkableAreaMod; + return this; + } + + public RcConfigBuilder WithFilterLowHangingObstacles(bool filterLowHangingObstacles) + { + _filterLowHangingObstacles = filterLowHangingObstacles; + return this; + } + + public RcConfigBuilder WithFilterLedgeSpans(bool filterLedgeSpans) + { + _filterLedgeSpans = filterLedgeSpans; + return this; + } + + public RcConfigBuilder WithFilterWalkableLowHeightSpans(bool filterWalkableLowHeightSpans) + { + _filterWalkableLowHeightSpans = filterWalkableLowHeightSpans; + return this; + } + + public RcConfig Build() + { + return new RcConfig( + _useTiles, + _tileSizeX, + _tileSizeZ, + _borderSize, + RcPartition.LAYERS, // _partition + _cs, + _ch, + _agentMaxSlope, + _filterLowHangingObstacles, + _filterLedgeSpans, + _filterWalkableLowHeightSpans, + _agentHeight, + _agentRadius, + _agentMaxClimb, + _minRegionArea, + _mergeRegionArea, + _edgeMaxLen, + _edgeMaxError, + _vertsPerPoly, + _buildMeshDetail, + _detailSampleDist, + _detailSampleMaxError, + _walkableAreaMod); + } + } +} \ No newline at end of file